def n_square(n): zofka = SvgTurtle(500, 500) angle = (1 - 2 / n) * 180 for x in range(n): zofka.forward(50) zofka.left(180 - angle) zofka.save("{}_square.svg".format(n))
def n_square_points(n): zofka = SvgTurtle(550, 850) points = [] angle = (1 - 2 / n) * 180 for x in range(n): zofka.forward(400) zofka.left(180 - angle) points.append(list(zofka.position())) return points
def my_picture(): zofka = SvgTurtle(500, 500) angle = 1 for x in range(10000): zofka.forward(40) zofka.left(angle) angle += 5 if x % 3 == 0: angle -= 5 zofka.save("my_awsome_svg.svg")
def pentagram_relative(): zofka = SvgTurtle(500, 500) for x in range(5): zofka.forward(200) zofka.left(180 - 36) zofka.right(36) length = 100/sin(radians(54)) angle = (1 - 2 / 5) * 180 for x in range(5): zofka.forward(length) zofka.left(180 - angle) zofka.save("relative_pentagram.svg")
def pentagram_absolute(): zofka = SvgTurtle(500, 500) angle = (1 - 2 / 5) * 180 positions = [] for x in range(5): zofka.forward(200) zofka.left(180-108) positions.append(zofka.position()) for x in range(5): zofka.line(positions[x][0], positions[x][1], positions[x-1][0], positions[x-1][1]) for x in range(5): zofka.line(positions[x][0], positions[x][1], positions[x - 2][0], positions[x - 2][1]) zofka.save("absolute_pentragram.svg")
def triangles(): zofka = SvgTurtle(500, 500) length = 30 zofka.left(90) for x in range(15): positions = [] for x in range(3): zofka.forward(length, write=False) positions.append(zofka.position()) zofka.left(180) zofka.forward(length, write=False) zofka.right(60) positions.append(positions[0]) for x in range(3): zofka.line(positions[x][0], positions[x][1], positions[x+1][0], positions[x+1][1]) length += 30 zofka.save("triangles.svg")
def svg_star(lines, tops, radius, name): # save svg file with star turtle = SvgTurtle(400, 400) angle = 180 - (1 - (2 / (lines * tops))) * 180 distance = radius * 2 * sin(pi / (lines * tops)) # needed calculations for star for top in range(tops): for x in [-1, 1]: turtle.set_pos(400, 400) turtle.left(360 / tops * top) turtle.forward(radius) turtle.left(x * 180 - x * angle / 2) end_of_line = SvgTurtle(400, 400) end_of_line.right(360 / tops * (x - top)) for line in range(lines): turtle.left(x * angle) turtle.forward(distance) end_of_line.forward(radius / lines) turtle.connector(end_of_line) turtle.save(name)
def star(n): zofka = SvgTurtle(500, 500) for x in range(2*n): zofka.forward(150) zofka.left(180 - 180/n) zofka.save("star.svg")
def blow(): zofka = SvgTurtle(500, 500) for x in range(12): zofka.left(360/12) n_square(zofka, 12) zofka.save("blow.svg")