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()
相关推荐
阿尔的代码屋4 小时前
[大模型实战 07] 基于 LlamaIndex ReAct 框架手搓全自动博客监控 Agent
人工智能·python
AI探索者21 小时前
LangGraph StateGraph 实战:状态机聊天机器人构建指南
python
AI探索者21 小时前
LangGraph 入门:构建带记忆功能的天气查询 Agent
python
FishCoderh1 天前
Python自动化办公实战:批量重命名文件,告别手动操作
python
躺平大鹅1 天前
Python函数入门详解(定义+调用+参数)
python
曲幽1 天前
我用FastAPI接ollama大模型,差点被asyncio整崩溃(附对话窗口实战)
python·fastapi·web·async·httpx·asyncio·ollama
两万五千个小时1 天前
落地实现 Anthropic Multi-Agent Research System
人工智能·python·架构
哈里谢顿1 天前
Python 高并发服务限流终极方案:从原理到生产落地(2026 实战指南)
python
用户8356290780512 天前
无需 Office:Python 批量转换 PPT 为图片
后端·python
markfeng82 天前
Python+Django+H5+MySQL项目搭建
python·django