python画正方形、平行四边形、六边形、五角星、风车(四个半圆)

画正方形、平行四边形、六边形、五角星、风车(四个半圆)

python 复制代码
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)  # 旋转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()
相关推荐
databook7 小时前
Manim实现脉冲闪烁特效
后端·python·动效
程序设计实验室8 小时前
2025年了,在 Django 之外,Python Web 框架还能怎么选?
python
倔强青铜三9 小时前
苦练Python第46天:文件写入与上下文管理器
人工智能·python·面试
用户25191624271113 小时前
Python之语言特点
python
刘立军13 小时前
使用pyHugeGraph查询HugeGraph图数据
python·graphql
数据智能老司机16 小时前
精通 Python 设计模式——创建型设计模式
python·设计模式·架构
数据智能老司机17 小时前
精通 Python 设计模式——SOLID 原则
python·设计模式·架构
c8i19 小时前
django中的FBV 和 CBV
python·django
c8i19 小时前
python中的闭包和装饰器
python
这里有鱼汤1 天前
小白必看:QMT里的miniQMT入门教程
后端·python