# Shape Spiral # Goal

### 4. Modify code to change pattern # Make a square

### Making a square is simply a combination of forwards followed by 90 degree left turns. The number of times we would need to repeat those steps is equal to the number of sides or 4.

``import turtle as t``

``for i in range(4):``
``    t.forward(100)``
``    t.left(90)``

# Changing color

### What color does this make? That's right, purple!  # Randomizing color

### To make these random colors we can have the computer pick 3 random numbers between 0 and 255 and then combine them to create a RGB color code!

``import turtle as t``
``from random import randint``

``    r = randint(0,255)``
``    g = randint(0,255) ``
``    b = randint(0,255)``
``     ``
``    t.colormode(255) ``
``    t.pencolor(r,g,b)``

# Making a spiral

### In general, a spiral starts at a single point, turns into a curved line, and slowly grows bigger in size and radius. So we would need our square to do the same. The square needs to slowly grow in size while rotating. We can tackle these separately then combine the results.  # Growing square

### While in a loop we can slowing increase the size of the square by adding a multiple of i, or the current iteration value.

``import turtle as t``

``for i in range(25):``
``    t.forward(50 + 5*i)``
``    t.left(90)``

# Rotating the square

### Making a square requires each turn to be 90 degrees. By making the turn angle slightly bigger than 90 degrees the result still looks like a square, but creates the appearance of a rotating square.

``import turtle as t``

``for i in range(25):``
``    t.forward(250)``
``    t.left(90.991)``  # Putting the pieces together

``import turtle as t``

``for i in range(150):``
``    t.forward(50 + 5*i)``
``    t.left(90.991)``

### And lastly we add in the random colors

``import turtle as t``
``from random import randint``

``for i in range(400):``
`` ``
``    r = randint(0,255)``
``    g = randint(0,255) ``
``    b = randint(0,255)``
``     ``
``    t.colormode(255) ``
``    t.pencolor(r,g,b)``
``    t.forward(50 + i)``
``    t.right(90.991)``

# Final Program

``import turtle as t``
``from random import randint``
``t.bgcolor('black')``
``t.speed(100)``

``for i in range(400):``
`` ``
``    r = randint(0,255)``
``    g = randint(0,255) ``
``    b = randint(0,255)``
``     ``
``    t.colormode(255) ``
``    t.pencolor(r,g,b)``
``    t.forward(50 + i)``
``    t.right(90.991)``