## Create a Keyboard with PureData

dark mode light mode Search Menu
Search

# Make a Turtle Move in Circles

Cristiano Medeiros Dalbem on Flickr

Today we’re going to play around with a little code, a little geometry, and a little art!

The goal: drawing whimsical spirals across our screen. The language: Python, which is beginner-friendly and perfect for simple code. We’re also going to use Turtle, Python’s popular graphics extension.

Start by navigating to https://repl.it/languages/python_turtle. In the left-hand editor, set up the basics of our program with the following code:

```from turtle import Turtle, Screen
screen = Screen()
rosa = Turtle()
rosa.shape('turtle')
```

First, we import some functions from the turtle library. Libraries are collections of code files written by experts. Often, you can find functions to perform tricky tasks that would be annoying to write yourself. No point in reinventing the wheel!

Next, we create our turtle, Rosa, and we make a screen for her to draw on. We also use the “shape” function to change Rosa’s icon into a turtle. If you run the code at this point, you should see a blank screen with Rosa chilling in the centre. You can run your code by hitting the green button near the top of the screen.

Before diving into more complex shapes, let’s warm up Rosa by making her draw a circle:

```rosa.circle(100)
```

The value between the brackets of the “circle” function determines the size of the circle Rosa is drawing. In a circle, all the points on the edge are the same distance from the centre. The length between the edge and the centre is known as the radius. A bigger radius means a bigger circle.

Degrees are a unit we use to measure angles. Imagine cutting a gigantic pie into 360 equal slices. Each slice would have an angle of 1 degree. If you put 180 pieces together, you get a half circle, and 180 degrees. What about quarter circle? That would require 90 pieces of pie, or 90 degrees.

When you’re using the “circle” function, you can add a second argument to specify the number of degrees. What happens if you use a negative number? Or a number bigger than 360?

```rosa.circle(100, -180)
```

### SEND IT INTO A SPIRAL

To create a spiral, we need to stop Rosa halfway through her circle. This means that she’ll only turn 180 degrees instead of 360. Afterwards, we’ll start a new, bigger circle. Again, Rosa only completes half of it before stopping.

If we repeat this process multiple times, increasing the radius by 20 units at a time, the result is a perfect spiral!

Any time you see the word “repeat” in your programming instructions, it’s time to use a loop. Writing the same code over and over is boring. Instead, let’s throw in some variables, and keep our code short with the help of a while loop:

```from turtle import Turtle, Screen
screen = Screen()
rosa = Turtle()
rosa.shape('turtle')

```

The “+=“ symbol is a programming shorthand for “increase by the following amount”.

The “while loop” runs until its condition is no longer true. In our case, that means the loop will repeat over and over until we’ve increased the radius of our circle so that it’s bigger than 200. Try it out!

Ta-da! If you want to create even more cool spirals, try multiplying the radius by a fixed value instead of adding to it. A low value, like 1.3 or 1.5, should keep things interesting.

``` radius *= 1.3
```

#### Turtle built-in commands

http://www.eg.bucknell.edu/~hyde/Python3/TurtleDirections.html

#### First turtle program

https://interactivepython.org/runestone/static/thinkcspy/PythonTurtle/OurFirstTurtleProgram.html

#### Python turtle module

https://www.simplifiedpython.net/python-turtle-module/

#### Python Turtle Colors

https://ecsdtech.com/8-pages/121-python-turtle-colors

#### Turtle Command flash cards

https://quizlet.com/156092424/python-turtle-commands-v-36-flash-cards/

#### Python turtle cheat sheet

https://compuzzle.wordpress.com/2015/05/04/python-turtle-cheat-sheet-and-geometric-shapes/

#### Python Turtle Graphics

https://gameswithcode.com/python-turtle-graphics/

#### python-turtle-programming-for-kids

https://www.gordonchoi.com/python-turtle-programming-for-kids/