Python Turtle - Code a Square Tutorial

preview_player
Показать описание
Learn how to quickly draw 3 different squares using Python's Turtle module.

~ CODE ~

from turtle import *

speed(0)
bgcolor("black")

# Outlined Square
penup()
goto(-350, 100)
pendown()
pensize(5)
color("magenta")

for i in range(4):
forward(150)
left(90)

# Multi-Coloured Square (Stroke only)
penup()
goto(-175, 100)
pendown()

for i in ["yellow", "red", "blue", "purple"]:
color(i)
forward(150)
left(90)

# Square with Fill and Stroke
penup()
goto(0, 100)
color("orange", "yellow")
pendown()
begin_fill()

for i in range(4):
forward(150)
left(90)
end_fill()

hideturtle()

exitonclick()
Рекомендации по теме
Комментарии
Автор

you have literally just saved my life..

asal
Автор

You can use import turtle instead of from turtle import

pelzumi
Автор

Hi there! thanks a lot but what if I wanted the lines to go from black to red to black again and so on for a polygon?

tameralbouz