top of page

03.23.2018: One Lesson of Python

Today's soundtrack is Falkenbach: Asa.

This afternoon's lesson in Coding Projects in Python continues work in Turtle Graphics. This lesson is called "Kaleido-spiral"; in it, I'll be learning to tell Python how to make pre-programmed repeating shapes and patterns.

I started by importing Turtle, then making the background black, setting the turtle speed to fast, and setting the pen size to 4. I made the pen colour red, then told the turtle to draw a 30 pixel circle.

To make the command repeat, I used a recursion loop: I made a "draw circle" function, and inside that function, I told the function to call itself, thus creating a loop! Right now, the program loops a circle endlessly in the same place at the same size.

To add variety to this program, I import the "cycle" function from itertools, then told the program what colours to cycle through, told the size to increase by 5 for each circle, then added angle and shift values so that I could increase them by 1 for each circle.

For fun, I figured out how to increase the pen size each loop, making it look as if the circles were getting larger due to proximity; I also used the 'cycle' function with various grey-based backgrounds to make the background colour go from white to black to grey and back again.


bottom of page