rendered paste body#!/usr/bin/env pythonimport ImageDrawimport Imageimport mathdef f(a): x = abs(int(a)) b = a / x for y in range(1, x): yield y * b class Turtle(object): def __init__(self, width=125, height=125): self.im = Image.new('RGBA', (width,height)) self.draw = ImageDraw.Draw(self.im) self.width = width self.height = height self.number = 0 self.home() def snapshot(self): self.save("avatar-%04d.gif"%self.number,"GIF") self.number += 1 def home(self): self.x = self.width/2 self.y = self.height/2 self.heading = -90 def line(self,x,y,a,b, fill = "blue", width=1): self.draw.line([(x, y), (a,b)], fill=fill, width=width) def save(self, filename, format="PNG"): f= open(filename,"w") self.im.save(f,format) f.close() def radians(self): return self.heading * math.pi / 180 def forward(self, ln): for l in f(ln): x = self.x + l * math.cos(self.radians()) y = self.y + l * math.sin(self.radians()) self.line(self.x, self.y, x, y) self.x = x self.y = y self.snapshot() def back(self, l): self.forward(-l) def right(self, a): self.heading = ( self.heading + a ) % 360 def left(self, a): self.right(-a)def X(t, l, s): if l == 0: t.forward(s) t.left(60) t.forward(s) t.left(60) t.forward(s) else: Y(t, l-1, s/2.0) t.left(60) X(t, l-1, s/2.0) t.left(60) Y(t, l-1, s/2.0)def Y(t, l, s): if l == 0: t.forward(s) t.right(60) t.forward(s) t.right(60) t.forward(s) else: X(t, l-1, s/2.0) t.right(60) Y(t, l-1, s/2.0) t.right(60) X(t, l-1, s/2.0)t = Turtle()t.y = t.height -10t.x = t.x + 2t.right(30)X(t, 4, 60 )#t.save('foo.png')