Skip to main content

A Python turtle graphics library with multi-turtle support and OpenGL rendering

Project description

StarsTurtle - Python 海龟绘图库

StarsTurtle 是一个基于 PyQt5 实现的 Python 海龟绘图库,提供了类似于 Python 内置 turtle 模块的功能,但具有更多高级特性和更好的可视化效果。

特性

  • 兼容性: 提供与标准 turtle 模块类似的 API
  • 多海龟支持: 可以同时创建多个海龟对象进行绘制
  • 高清渲染: 支持抗锯齿和高质量渲染
  • 多种形状: 海龟支持多种形状(classic, arrow, turtle, circle, square, triangle)
  • 丰富的绘图功能: 支持绘制各种几何图形和自定义图形
  • 填充功能: 支持图形填充功能
  • 动画控制: 可调节绘制速度
  • 图片导出: 支持将绘制结果保存为图片

安装依赖

pip install PyQt5

快速开始

基本使用

import StarsTurtle

# 移动和绘制
StarsTurtle.forward(100)  # 向前移动100像素
StarsTurtle.left(90)      # 左转90度
StarsTurtle.right(45)     # 右转45度

# 设置属性
StarsTurtle.color(StarsTurtle.RED)  # 设置颜色
StarsTurtle.width(3)                # 设置线条宽度

# 绘制基本图形
StarsTurtle.draw_square(100)        # 绘制正方形
StarsTurtle.draw_circle(50)         # 绘制圆形
StarsTurtle.draw_triangle(80)       # 绘制三角形

# 显示窗口
StarsTurtle.done()
使用海龟对象
python
import StarsTurtle

# 创建海龟对象
t = StarsTurtle.create_turtle()

# 使用面向对象的方式
t.forward(100)
t.left(90)
t.color(StarsTurtle.BLUE)

# 绘制复杂图形
t.begin_fill(StarsTurtle.YELLOW)
t.draw_square(100)
t.end_fill()

StarsTurtle.done()

API 说明

基本移动命令

forward(distance): 向前移动指定距离
left(angle): 左转指定角度
right(angle): 右转指定角度
goto(x, y): 移动到指定坐标
home(): 回到起始位置 (400, 300)
绘图控制
penup(): 抬起画笔
pendown(): 放下画笔
speed(s): 设置绘制速度 (1-10)
clear(): 清空画布
颜色和样式
color(color): 设置画笔颜色
width(width): 设置线条宽度
shape(shape_type): 设置海龟形状
可视化控制
showturtle(): 显示海龟
hideturtle(): 隐藏海龟
isvisible(): 检查海龟是否可见
填充功能
begin_fill(color=None): 开始填充
end_fill(): 结束填充
绘制几何图形
draw_square(size, color=None, x=None, y=None): 绘制正方形
draw_circle(radius, color=None, step_mode=False, x=None, y=None): 绘制圆形
draw_triangle(size, color=None, x=None, y=None): 绘制三角形
draw_rectangle(width, height, color=None, x=None, y=None): 绘制矩形
draw_polygon(sides, size, color=None, x=None, y=None): 绘制多边形
文字绘制
text(content, x, y, color=None, font_size=12, font_name="SimHei"): 绘制文字
图片保存
save_image(file_path=None, image_format="PNG"): 保存图片
预定义颜色常量
RED, GREEN, BLUE, WHITE, BLACK, YELLOW, CYAN, MAGENTA
多海龟示例
python
import StarsTurtle

# 创建多个海龟
t1 = StarsTurtle.create_turtle(x=200, y=200, color=StarsTurtle.RED)
t2 = StarsTurtle.create_turtle(x=400, y=400, color=StarsTurtle.BLUE)

# 分别控制
t1.forward(100)
t2.left(90)
t2.forward(100)

StarsTurtle.done()

错误处理

当遇到参数错误时,系统会提供详细的错误信息和正确的使用示例。

保存作品

使用 save_image() 函数可以将绘制的作品保存为图片文件。

贡献

欢迎去CSDN账号:@小羊羊Python来改进这个项目!

许可证

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

starsturtle-1.0.4.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

starsturtle-1.0.4-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file starsturtle-1.0.4.tar.gz.

File metadata

  • Download URL: starsturtle-1.0.4.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for starsturtle-1.0.4.tar.gz
Algorithm Hash digest
SHA256 0ba9f7e4a693ccdec6e5c1ce3c07756fe1fe0c86d18c1ef57d0e3c669ddfeda7
MD5 0db9ae9567fa64404af2a819237e2d8e
BLAKE2b-256 113c49b9494e15ecdfe5fb4c21143d01683f73ca847a375921c6354081178ad1

See more details on using hashes here.

File details

Details for the file starsturtle-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: starsturtle-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for starsturtle-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 387ce5c58eef7fe1834a9ddff837586ef18df305155cb150422378c4e40d9e6c
MD5 f827c11473cfa26c721f699a37b41794
BLAKE2b-256 c87a4c14414b157f521de508e6eb24aa017b5813a8278db43ec1ff2059d6a8ba

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page