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()
相关推荐
艾伦~耶格尔14 分钟前
【集合框架LinkedList底层添加元素机制】
java·开发语言·学习·面试
yujkss28 分钟前
Python脚本每天爬取微博热搜-终版
开发语言·python
yzx99101331 分钟前
小程序开发APP
开发语言·人工智能·python·yolo
飞翔的佩奇1 小时前
【完整源码+数据集+部署教程】二维码与查找模式检测系统源码和数据集:改进yolo11-CSwinTransformer
python·yolo·计算机视觉·数据集·yolo11·二维码与查找模式检测
大霞上仙1 小时前
实现自学习系统,输入excel文件,能学习后进行相应回答
python·学习·excel
啊阿狸不会拉杆1 小时前
《算法导论》第 32 章 - 字符串匹配
开发语言·c++·算法
Caven771 小时前
【pytorch】reshape的使用
pytorch·python
无规则ai1 小时前
动手学深度学习(pytorch版):第四章节—多层感知机(5)权重衰减
人工智能·pytorch·python·深度学习
你知道网上冲浪吗2 小时前
【原创理论】Stochastic Coupled Dyadic System (SCDS):一个用于两性关系动力学建模的随机耦合系统框架
python·算法·数学建模·数值分析
钢铁男儿2 小时前
Python 正则表达式核心元字符全解析
python