Created
August 1, 2010 08:54
-
-
Save mmisono/503140 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
#!/usr/bin/env python | |
import Image,ImageDraw | |
import math | |
PI = math.pi | |
SQRT2 = math.sqrt(2) | |
xpos = 0 | |
ypos = 0 | |
def dragon(draw,order,length,angle,sign): | |
if not order : | |
global xpos,ypos | |
gx = xpos+length*math.cos(angle) | |
gy = ypos+length*math.sin(angle) | |
draw.line([(xpos,ypos),(gx,gy)],fill=0) | |
xpos = gx | |
ypos = gy | |
else : | |
dragon(draw,order-1, length/SQRT2, angle-sign*PI/4, -1.0) | |
dragon(draw,order-1, length/SQRT2, angle+sign*PI/4, 1.0) | |
if __name__ == '__main__' : | |
im = Image.new("L",(300,300),255) | |
draw = ImageDraw.Draw(im) | |
xpos = 100 | |
ypos = 175 | |
dragon(draw,order=10,length=100,angle=0,sign=1) | |
im.show() | |
im.save("dragon.png","PNG") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment