Python Turtle Code: Peacock Tail

Published: 13 February 2022
on channel: Basic Python Turtle Art
216
3

A spread-out tail using 3 kinds of feathers. The Python Turtle code uses 2 switches: sw1 for main or primary feather, and sw2 for secondary feathers A and B.

Please feel free to copy and paste the Python Turtle code below. Don't hesitate to ask questions about the code if you have any. Enjoy!
import turtle
scrin = turtle.Screen()
t = turtle.Turtle()
t.pensize(5)
t.speed(4)
t.right(20)
sw1 = 0 #switch: sw1 = 0 for main "feather", sw1 = 1 for secondary ones
sw2 = 0 #secondswitch: sw2 = 0 for secondary "feather" A, = 1 for B
for i in range(23):
t.penup()
t.goto(0, -120)
t.forward(50)
t.pendown()
t.forward(290)
if sw1 == 0: #conditional for main "feather", which has circles at tip of rib
t.right(90)
t.fillcolor("red")
for j in [20, 10]:
t.begin_fill()
t.circle(j)
t.end_fill()
t.fillcolor("yellow")
t.left(100)
sw1 = 1 #sw1 switches to 1 from 0 to avoid successive main "feathers"
else:
if sw2 == 0: #conditional for secondary "feather" A, which has circles at mid rib
t.backward(100)
t.right(90)
t.fillcolor("red")
for j in [20, 10]:
t.begin_fill()
t.circle(j)
t.end_fill()
t.fillcolor("yellow")
t.left(100)
sw1 = 0 #sw1 switches back to 0 after a secondary "feather" is drawn
sw2 = 1 #sw2 switches to 1 from 0 to avoid successive secondary "feathers" A
else: #conditional for secondary "feather" B, which has circles at low rib
t.backward(200)
t.right(90)
t.fillcolor("red")
for j in [20, 10]:
t.begin_fill()
t.circle(j)
t.end_fill()
t.fillcolor("yellow")
t.left(100)
sw1 = 0 #sw1 switches back to 0 after a secondary "feather" is drawn
sw2 = 0 #sw2 switches back to 0 to avoid successive secondary "feathers" B
scrin.exitonclick()


On this page of the site you can watch the video online Python Turtle Code: Peacock Tail with a duration of hours minute second in good quality, which was uploaded by the user Basic Python Turtle Art 13 February 2022, share the link with friends and acquaintances, this video has already been watched 216 times on youtube and it was liked by 3 viewers. Enjoy your viewing!