Skip to content

Instantly share code, notes, and snippets.

@cameronp98
Created April 4, 2014 20:37
Show Gist options
  • Select an option

  • Save cameronp98/9982675 to your computer and use it in GitHub Desktop.

Select an option

Save cameronp98/9982675 to your computer and use it in GitHub Desktop.
import turtle
def shape(turtle, num_sides, side_length, colors=None):
if colors is None:
colors = ["black"]
angle = 360/num_sides
for i in range(3):
turtle.forward(side_length)
turtle.pencolor(colors[i%len(colors)])
turtle.lt(angle)
return turtle
def spiral(turtle, num_sides, num_shapes, scale=20, colors=None):
angle = 360/num_shapes
for i in range(num_shapes):
shape(turtle, num_sides, scale*(i+1), colors)
turtle.rt(angle)
def main():
turtle.speed(0)
colors = ["#004358", "#1F8A70", "#BEDB39"]
# draw 200 hexagons starting with side length 3
spiral(turtle, num_sides=6, num_shapes=200, scale=3, colors=colors)
turtle.mainloop()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment