Hello,

I’m currently trying to come up with a pythonic way in Grasshopper to draw the Fibonacci squares.

My plan is to feed a Fibonacci sequence (i.e. 0, 1, 1, 3, 4, 7, etc.) into a Python container. For each Fibonacci number in the sequence, the vertices of the square will be produced by starting at an initial point, placing the next point at a given direction x-units (where x is a Fibonacci number) from the start point and changing the direction by 90° to the right. This is going to be repeated 4 times producing 4 vertices that will form a square per Fibonacci number.

The starting point of the next number will always be the 3 vertex of the previous square, from which a new square will be drawn for the next Fibonacci number in the sequence.

(The circle fragments of each square will produce a Fibonacci spiral.)

So far I’ve come up with this:

```
def draw_square(start_pt, dir, side_length):
vtx = []
vtx.append(start_pt)
rot_dir = dir # rotated direction
for i in range(2):
# find next point by moving x-units (side_length) in a given direction (dir)
vtx.append(next_pt)
# rotate the direction by 90° to the right and save it to rot_dir for the next iteration
return vtx
```

If the function `draw_square`

is called it should return a list of vertices `vtx`

, representing a square with a side length of `side_length`

. Its first point is the `start_pt`

. Its next points are drawn at a distance `side_length`

and a direction `dir`

from their previous points. The direction is than, at each generation, rotated by 90° to the right an so fourth.

```
squares = []
for i, num in enumerate(fibonacci_sequence):
if i == 0: # first square
start_pt = (0,0,0)
start_dir = (1, 0, 0)
square = draw_square(start_pt, start_dir, num)
squares.append(square)
else: # other squares
start_pt = squares[-1][2] # 3 vertex of last square
dir = rs.VectorUnitize(rs.VectorCreate(squares[-1][1], start_pt))
square = draw_square(start_pt, dir, num)
squares.append(square)
```

The function `draw_square`

is called for each number in the Fibonacci sequence and produces a square with the side length of the number.

The first square is produced with a changeable start point and direction. The following squares heavily depend on the first one. Their start point is the 3rd vertex of the previous square, and their direction is calculated by normalising the vector between the 3rd and 2nd vertex of the previous square.

The square thus produced are saved in a list of lists and output as tree.

In the function `draw_square`

, I don’t get how I could calculate the next point by side length and direction only?

Is the rest of the code plausible?

Any help is greatly welcome.