Categories: Turtle

Turtle Turbines

Turtle Turbines

You can draw nice turbines with Python turtle with the codes in this tutorial.

We will explain how you can twist to code to give more flavor to your drawing as well.

Basic turtle illustration - turbine
import turtle

t = turtle.Turtle()

for i in range(10):
    t.forward(200)
    t.right(120)
    t.forward(40)
    t.goto(0,0)
    t.left(84)

turtle.done()

Turtle Pensize

pensize() will let you control the thickness of the pen. Look at the code below:
Basic turtle illustration - turbine (pensize = 5)
import turtle

t = turtle.Turtle()
t.pensize(5)

for i in range(10):
    t.forward(200)
    t.right(120)
    t.forward(40)
    t.goto(0,0)
    t.left(84)
    
turtle.done()

Turtle Colors

Using color() you can give your pen a color. Using a list of predefined colors you can loop through the colors with a simple trick. % operator will give the remainder from a division.

colors[i%6] will make sure colors only takes an index from 1 to 6 so each color gets assigned and then the index goes back to zero when i reaches a multiple of 6.

Turtle spiral example with color iteration
import turtle

colors = ["red", "blue", "green", "gray", "orange", "black"]
a = turtle.Turtle()

for i in range(30):
    a.forward(20+i)
    a.left(30 - i/1.5)
    a.color(colors[i%6])

turtle.done()
Basic turtle illustration - turbine (iterating colors)
import turtle

t = turtle.Turtle()
colors = ['red', 'blue', 'orange', 'green', 'black', 'brown']

for i in range(10):
    t.color(colors[i%6])
    t.forward(200)
    t.right(120)
    t.forward(40)
    t.goto(0,0)
    t.left(84)

turtle.done()

Combining codes

Let’s add a post to our turbine so it can rotate one day.

Basic turtle illustration - turbine (with the post)
import turtle

t = turtle.Turtle()
colors = ['red', 'blue', 'orange', 'green', 'black', 'brown']
t.pensize(20)

t.goto(0,150)
t.right(90)
t.color('gray')
t.forward(470)

t.pensize(3)

t.penup()
t.goto(0,150)
t.pendown()

for i in range(10):
    t.color(colors[i%6])
    t.forward(200)
    t.right(120)
    t.forward(40)
    t.goto(0,150)
    t.fillcolor("black")
    t.left(84)



turtle.done()

Basic turtle illustration - turbine (more elegant shapes)
import turtle

def turbase(thickness):

    t = turtle.Turtle()
    t.pensize(thickness)
    t.color('lightgray')
    t.penup()    
    t.goto(4,0)
    t.pendown()
    t.right(90)
    t.forward(400)


def turwings(thickness, startingdegree):
    t = turtle.Turtle()
    t.pensize(thickness)
    colors = ['red', 'blue', 'orange', 'green', 'black', 'brown']    
    t.color("darkblue")
    i=30
    
    t.penup()
    t.forward(20)
    t.pendown()
    t.right(startingdegree)
    t.forward(300)
    t.left(174)
    t.forward(300)
    
    
    t.right(45)
    t.forward(300)
    t.left(175)
    t.forward(300)
    
    
    t.right(70)
    t.forward(300)
    t.left(175)
    t.forward(300)
    
    t.fillcolor('red')    
turbase(20)
turwings(3, 257.5)
turtle.done()

If you enjoyed this Python turtle lesson, feel free to spread it.

Usag1r

Share
Published by
Usag1r

Recent Posts

Benefits of Bokeh over Python visualization libraries like Seaborn, Matplotlib & Plotly

ContentsIntroductionBokeh vs Seaborn & MatplotlibBokeh vs PlotlySummary Introduction As computer science activity booms, you might…

11 months ago

History of Speech-to-Text AI models

History of Speech-to-Text Models​ & Current Infrastructure As speech technology continues to advance, so too…

1 year ago

Advanced Level Python Tips & Tricks

Python Tips & Tricks (Part III) Advanced Level HolyPython.com Here are more Python tips about…

1 year ago

Intermediate Level Python Tips & Tricks

Python Tips & Tricks (Part II) Intermediate Level HolyPython.com The list continues with slightly more…

1 year ago

When is Python 4 Coming Out?

Almost 15 years after the release of Python 3 many people are wondering when Python…

2 years ago

How to Create an app with a 3D model using VIKTOR

Introduction We are going to need smart engineering solutions to solve our planet's problems (and…

2 years ago