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()
相关推荐
这里有鱼汤3 分钟前
“对象”?对象你个头!——Python世界观彻底崩塌的一天
后端·python
尘浮72813 分钟前
60天python训练计划----day59
开发语言·python
wh393316 分钟前
使用Python将PDF转换成word、PPT
python·pdf·word
船长@Quant33 分钟前
数学视频动画引擎Python库 -- Manim Voiceover 语音服务 Speech Services
python·数学·manim·动画引擎·语音旁白
Chef_Chen41 分钟前
从0开始学习R语言--Day39--Spearman 秩相关
开发语言·学习·r语言
不学会Ⅳ1 小时前
Mac M芯片搭建jdk源码环境(jdk24)
java·开发语言·macos
好开心啊没烦恼2 小时前
Python 数据分析:计算,分组统计1,df.groupby()。听故事学知识点怎么这么容易?
开发语言·python·数据挖掘·数据分析·pandas
lljss20203 小时前
Python11中创建虚拟环境、安装 TensorFlow
开发语言·python·tensorflow
空中湖3 小时前
tensorflow武林志第二卷第九章:玄功九转
人工智能·python·tensorflow
CodeCraft Studio4 小时前
CAD文件处理控件Aspose.CAD教程:使用 Python 将绘图转换为 Photoshop
python·photoshop·cad·aspose·aspose.cad