Created
December 23, 2016 15:36
-
-
Save shogonir/9f109826391f26adaf3b767dda06634e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def drawLine (point1, point2) : | |
points = [] | |
try : | |
slope = 1.0 * (point2.y - point1.y) / (point2.x - point1.x) | |
if abs(slope) > 1.0 : | |
top, bottom = (point1, point2) if point1.y > point2.y else (point2, point1) | |
for y in range(bottom.y, top.y + 1) : | |
progress = 1.0 * (y - bottom.y) / (top.y - bottom.y) | |
x = int(bottom.x + progress * (top.x - bottom.x)) | |
points.append(Vector2(x, y)) | |
else : | |
right, left = (point1, point2) if point1.x > point2.x else (point2, point1) | |
for x in range(left.x, right.x + 1) : | |
progress = 1.0 * (x - left.x) / (right.x - left.x) | |
y = int(left.y + progress * (right.y - left.y)) | |
points.append(Vector2(x, y)) | |
except ZeroDivisionError : | |
pass | |
return points |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment