Last time we made a heart in Turtle, this time we will make a spinning windmill, first put down the picture and see the finished effect

Now let’s start coding

# Design leaves

A leaf can be realized by using two triangles, one deep and one shallow. The following code is written to take the leaf in the direction of 0 degrees as an example

# Use a loop to generate 4 leaves instead

With one leaf, it’s easy to generate four leaves. We just write a loop where we use multiples of 90 to specify the lower Angle, and the rest of the drawing code is the same

# Add a stick

To add a slightly thicker stick to the bottom of the windmill, we just set the thickness of the brush and draw a straight line

# The rotation of a windmill

The windmill is finished, but now how do we get it to turn? See the code where we loop out four leaves, where we specify that the Angle is a multiple of 90, and we have fixed the direction of the leaf, and if we change that Angle to a variable, we can turn the leaf to a different Angle. For ease of use, let’s first draw a function that can receive its own specified Angle.

Modify the following code

``import turtle as t t.speed(0) def draw(r): Penup () t.goto(0,0) t.pendown() t.goto(0,-150) t.pensize(1) for I in range(4): # color('#50B2F8') t.Pagin_fill () t.florward (100) T.harvest (150) t.harvest (70) t.ed_fill () # dark blue triangle near center t.Harvest ('#063EC5') T.foot (90) t.fowler (35) t.ed_fill () draw(30)Copy the code``

The Angle can be changed, but the rotation animation is not there yet. How do you do that? We can write a loop to call the draw function

``For r in range (0360 * 100, 3) : We can also use the while loop to keep it going, step 3 corresponds to the rotation speed, T.racer (False) t.colear () draw(r) time.sleep(0.01) t.Hiturtle () t.racer (True)Copy the code``

Okay, now that the windmill is finally spinning, let’s post the finished code

``import turtle as t import time def draw(r): Penup () t.goto(0,0) t.pendown() t.goto(0,-150) t.pensize(1) for I in range(4): # color('#50B2F8') t.Pagin_fill () t.florward (100) T.harvest (150) t.harvest (70) t.ed_fill () # dark blue triangle near center t.Harvest ('#063EC5') T. speed(1) draw(0) for r in range(0,360*100,3): We can also use the while loop to keep it going, step 3 corresponds to the rotation speed, T racer(False) t.clear() draw(r) time.sleep(0.01) t.Hiturtle () t.racer (True) t.Tone ()Copy the code``