Skip to content

Instantly share code, notes, and snippets.

@mmisono
Created August 1, 2010 08:54
Show Gist options
  • Save mmisono/503140 to your computer and use it in GitHub Desktop.
Save mmisono/503140 to your computer and use it in GitHub Desktop.
#!/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