画正方形、平行四边形、六边形、五角星、风车(四个半圆)
import turtle
def square(side_length):
"""正方形"""
for _ in range(4):
turtle.forward(side_length)
turtle.right(90)
def parallelogram(base, height):
"""平行四边形"""
for _ in range(2):
turtle.forward(base)
turtle.left(60)
turtle.forward(height)
turtle.left(120)
def hexagon(side_length):
"""六边形"""
for _ in range(6):
turtle.forward(side_length)
turtle.right(60)
def star(size):
"""五角星"""
for _ in range(5):
turtle.forward(size)
turtle.right(144)
def half_circle(radius):
"""半圆"""
turtle.circle(radius, 180)
def windmill(radius):
"""风车"""
for _ in range(4):
half_circle(radius)
turtle.left(90)
def main():
turtle.speed(2)
turtle.pensize(2)
turtle.pencolor("pink")
turtle.penup()
turtle.goto(-200, 200)
turtle.pendown()
square(100)
turtle.penup()
turtle.goto(-50, 200)
turtle.pendown()
parallelogram(100, 50)
turtle.penup()
turtle.goto(150, 200)
turtle.pendown()
hexagon(100)
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
star(100)
turtle.penup()
turtle.goto(200, -200)
turtle.pendown()
windmill(50)
turtle.done()
if __name__ == "__main__":
main()