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()
相关推荐
码银30 分钟前
Java 集合:泛型、Set 集合及其实现类详解
java·开发语言
大G哥32 分钟前
PHP标签+注释+html混写+变量
android·开发语言·前端·html·php
傻啦嘿哟37 分钟前
HTTP代理基础:网络新手的入门指南
开发语言·php
fish_study_csdn38 分钟前
pytest 技术总结
开发语言·python·pytest
咖啡调调。1 小时前
使用Django框架表单
后端·python·django
BO_S__1 小时前
python调用ffmpeg对截取视频片段,可批量处理
python·ffmpeg·音视频
就叫飞六吧1 小时前
如何判断你的PyTorch是GPU版还是CPU版?
人工智能·pytorch·python
曹牧2 小时前
Java 调用webservice接口输出xml自动转义
java·开发语言·javascript
pyengine3 小时前
基于pandoc的MarkDown格式与word相互转换小工具开发(pyqt5)
开发语言·python·qt·word
YuSun_WK3 小时前
配置MambaIRv2: Attentive State Space Restoration的环境
开发语言·python