Last active
August 26, 2022 09:29
-
-
Save 0xKD/4433688 to your computer and use it in GitHub Desktop.
DDA in Python
This file contains hidden or 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 ROUND(a): | |
return int(a + 0.5) | |
def drawDDA(x1,y1,x2,y2): | |
x,y = x1,y1 | |
length = abs((x2-x1) if abs(x2-x1) > abs(y2-y1) else (y2-y1)) | |
dx = (x2-x1)/float(length) | |
dy = (y2-y1)/float(length) | |
print 'x = %s, y = %s' % (((ROUND(x),ROUND(y)))) | |
for i in range(length): | |
x += dx | |
y += dy | |
print 'x = %s, y = %s' % (((ROUND(x),ROUND(y)))) | |
drawDDA(2,5,10,20) |
'x = %s, y = %s' % (((ROUND(x),ROUND(y)))) this statement should be in parenthesis, else it shows error in VScode.
'x = %s, y = %s' % (((ROUND(x),ROUND(y)))) this statement should be in parenthesis, else it shows error in VScode.
This is python2 code
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should work now