Question

I'm writing a program where user specified number of hexagons are drawn. I'm having trouble figuring out the correct position of the hexagons. They have to be positioned correctly so that they are as close to eachother as possible. example of what I mean (positioning):

hexagons

My idea is to define a function (drawing a simple hexagon) and after each hexagon, the turtle would return back to the middle of the first hexagon and move to a new correct position and execute the function again. Ideally this would be repeated user specified amount of times.

I'm new to programming, help would be greatly appreciated.

Était-ce utile?

La solution

This is geometry.

Let's say you are in the center of your first hexagon, facing west. Size of hexagone segment is L.

With your turtle, move forward L distance, turn 60 degree right, move forward L distance again: you are are at the center of another hexagon.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top