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 squares(): zofka = SvgTurtle(500, 500) length = 400 cor_length = sqrt(0.75**2 + 0.25**2) cor_angle = degrees(asin(0.25/cor_length)) for y in range(50): for x in range(4): zofka.forward(length) zofka.right(90) zofka.forward(length*0.25) zofka.right(cor_angle) length = length * cor_length zofka.save("squares_in_squares.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)