ctx.line(x, y, dx, dy) # Colored oval. ctx.strokewidth((depth+1)*0.25) ctx.fill(0.8-v*0.25, 0.8, 0.8-v, alpha*0.5) ctx.oval(x-w/6, y-w/6, w/3, w/3) # Create a branching root. if random() > 0.8 and depth > 0: root(x, y, angle, depth-1, alpha) x = dx y = dy # Continue growing at less alpha and depth. if depth > 0: root(x, y, angle, depth-1, alpha) if __name__ == "__main__": radial_gradient( [Color(0.05, 0.06, 0.0), Color(0.125, 0.150, 0.0)], -150, -150, radius=900 ) root(300, 300, angle=-90, depth=8) ctx.save('test_images/superfolia.png')
ctx = Context(width=400, height=400) def setup(): global x, y, w, h, m, n1, n2, n3, i x, y = 200, 200 w, h = 100, 100 m = 6.0 n1 = 1.0 n2 = 1.0 n3 = 1.0 i = 0.0 def draw(): global x, y, w, h, m, n1, n2, n3, i m = 12 n1 = 5.0 + sin(i) n2 = 10 + cos(i) * 10 n3 = sin(i) * 10 i += 0.05 ctx.rotate(i*10) p = path(ctx, x, y, w, h, m, n1, n2, n3) ctx.drawpath(p) setup() draw() ctx.save('test_images/supershape.png')
b.grow(distance, curl, step) def draw(self): """ Draw the plant. """ for tendril in self.tendrils: tendril.draw() def path(self): """ Return the plant as a path consisting of ovals. """ path = BezierPath() for tendril in self.tendrils: tendril.draw(path) return path if __name__ == "__main__": ctx.background(0.12, 0.12, 0.06) ctx.nofill() ctx.stroke(1, 0.5) ctx.strokewidth(0.5) plant = Plant(300, 300, tendrils=20) for i in range(200): plant.grow(curl=1, step=0.02) plant.draw() ctx.save('test_images/tendrils.png')