Python Turtle Code: Peacock Tail

Опубликовано: 13 Февраль 2022
на канале: 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()


На этой странице сайта вы можете посмотреть видео онлайн Python Turtle Code: Peacock Tail длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Basic Python Turtle Art 13 Февраль 2022, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 216 раз и оно понравилось 3 зрителям. Приятного просмотра!