def interpret_Lsytem(path, forward=7, angle=60, filename='', ignore = None): """ @param turtle The turtle to guide @param dist Distance to be made with each 'forward' @param angle Angle for 'left' and 'right' """ turtle = Turtle(filename) turtle.left(180) if ignore == None: ignore = [] stack = [] for c in path: if c == '+': turtle.right(angle) elif c == '-': turtle.left(angle) elif c == '[': stack.append(turtle.serialize()) elif c == ']': turtle.deserialize(stack.pop()) elif c not in ignore: turtle.forward(forward) if filename: turtle.save() return
def triangles(side=100, step=20, n=10): t = Turtle('triangles') d = 300 for i in xrange(n): side += (3*step) t.polygon(3, side) t.right(120) t.pen_up() t.forward(step) t.left(120) t.back(step) t.pen_down() t.save()
def squares(max_levels = 15): t = Turtle('squares') d = 300 for i in range(max_levels): for i in range(4): t.forward(d) t.right(90) t.forward(d/4) t.right(90/5) d = sqrt((d/4)**2 + (d - d/4)**2) t.save()
from Turtle import Turtle import math dist = 100 golden_ratio = (1 + 5**0.5) / 2 turtle = Turtle('pentagram_rel') turtle.right(90 / 5) for i in range(5): turtle.right(360 / 5) turtle.forward(dist) turtle.right(90 + 90 / 5) for i in range(5): turtle.right((180 - (360 / 5)) / 3) if i % 2 == 0: turtle.forward(dist * golden_ratio) else: turtle.back(dist * golden_ratio) turtle.save() #################### pentagram absolute import svgwrite from math import sin, sqrt, tan, cos, pi def render(lines):
from Turtle import Turtle import math turtle = Turtle('r_polygon') n = 5 dist = 1000 / n for i in range(n): turtle.right(360/n) turtle.forward(dist) turtle.save()
from Turtle import Turtle import math turtle = Turtle('r_polygon') n = 5 dist = 1000 / n for i in range(n): turtle.right(360 / n) turtle.forward(dist) turtle.save()
draw.penDown() angle = 180 - 360. / (2 * n) for i in xrange(n): draw.forward(a) draw.right(angle) draw.penUp() if __name__ == "__main__": draw = Turtle("test_pictures") draw.penUp() draw.setCoord(-50, -50) draw.forward(100) draw.right(90) draw.forward(50) draw.left(90) regularPolygon(draw, 100, 5) draw.resetDir() draw.right(36) star(draw, 100 * (sin(108 / 360. * 2 * pi) / sin(36 / 360. * 2 * pi)), 5) draw.resetDir() draw.forward(300) verticies = regularPolygon(draw, 100, 5) for i, vortex in enumerate(verticies[:3]): draw.addLine(vortex, verticies[(i + 2) % len(verticies)])