Graphical User Interface of Python Library
Riverbank Computing | Introduction
Welcome to wxPython! | wxPython
Game Development with Python Library
Panda3D | Open Source Framework for 3D Rendering & Games
Virtual Reality of Python Library
WayneKeenan/python-vrzero: There's a blog about this repository here: (github.com)
cmbruns/pyovr: Python bindings for Oculus Rift virtual reality SDK (github.com)
Vizard | Virtual Reality software for researchers (worldviz.com)
Graphic Art of Python Library
fogleman/Quads: Computer art based on quadtrees. (github.com)
jontonsoup4/ascii_art: Converts images to ASCII art (github.com)
turtle — Turtle graphics — Python 3.11.3 documentation
Rose drawing example
import turtle as t
# 定义一个曲线绘制函数
def DegreeCurve(n, r, d=1):
for i in range(n):
t.left(d)
t.circle(r, abs(d))
# 初始位置设定
s = 0.2 # size
t.setup(450*5*s, 750*5*s)
t.pencolor("black")
t.fillcolor("red")
t.speed(100)
t.penup()
t.goto(0, 900*s)
t.pendown()
# 绘制花朵形状
t.begin_fill()
t.circle(200*s,30)
DegreeCurve(60, 50*s)
t.circle(200*s,30)
DegreeCurve(4, 100*s)
t.circle(200*s,50)
DegreeCurve(50, 50*s)
t.circle(350*s,65)
DegreeCurve(40, 70*s)
t.circle(150*s,50)
DegreeCurve(20, 50*s, -1)
t.circle(400*s,60)
DegreeCurve(18, 50*s)
t.fd(250*s)
t.right(150)
t.circle(-500*s,12)
t.left(140)
t.circle(550*s,110)
t.left(27)
t.circle(650*s,100)
t.left(130)
t.circle(-300*s,20)
t.right(123)
t.circle(220*s,57)
t.end_fill()
# 绘制花枝形状
t.left(120)
t.fd(280*s)
t.left(115)
t.circle(300*s,33)
t.left(180)
t.circle(-300*s,33)
DegreeCurve(70, 225*s, -1)
t.circle(350*s,104)
t.left(90)
t.circle(200*s,105)
t.circle(-500*s,63)
t.penup()
t.goto(170*s,-30*s)
t.pendown()
t.left(160)
DegreeCurve(20, 2500*s)
DegreeCurve(220, 250*s, -1)
# 绘制一个绿色叶子
t.fillcolor('green')
t.penup()
t.goto(670*s,-180*s)
t.pendown()
t.right(140)
t.begin_fill()
t.circle(300*s,120)
t.left(60)
t.circle(300*s,120)
t.end_fill()
t.penup()
t.goto(180*s,-550*s)
t.pendown()
t.right(85)
t.circle(600*s,40)
# 绘制另一个绿色叶子
t.penup()
t.goto(-150*s,-1000*s)
t.pendown()
t.begin_fill()
t.rt(120)
t.circle(300*s,115)
t.left(75)
t.circle(300*s,100)
t.end_fill()
t.penup()
t.goto(430*s,-1070*s)
t.pendown()
t.right(30)
t.circle(-600*s,35)
t.done()
This code draws a rose pattern using the turtle module. The specific implementation is as follows:
-
A function is defined
DegreeCurve
, which is used to draw an arc and contains three parameters: then
number of line segments of the drawn arc,r
the radius of the arc, and thed
drawing direction, that is, the positive value is counterclockwise, and the negative value is clockwise . -
Initialize parameters such as the size of the turtle canvas, brush color and fill color, and set the drawing speed.
-
Draw a flower shape: first draw a circle, then draw two arcs with a radius of 200s and an arc with a radius of 100s, then draw two curves with a radius of 50s and an arc with a radius of 350s, and finally draw a section with a radius of A curve of 70s, an arc with a radius of 150s, a curve with a radius of 50s, an arc with a radius of 400s, a curve with a radius of 50s and a straight line going forward 250s.
-
Draw the flower branch shape: rotate right 150 degrees, move forward 280s, rotate left 115 degrees, draw an arc with a radius of 300s, a curve with a radius of 225s, an arc with a radius of 350s, rotate 90 degrees to the left, draw An arc with a radius of 200s and an arc with a radius of 500s, and finally draw a curve with 20 line segments and a radius of 2500s and a curve with 220 line segments and a radius of 250s.
-
Draw two green leaves: draw two arcs with a radius of 300s and a straight line with a radius of 600s, and then draw the second leaf, which contains two arcs with a radius of 300s and an arc with a radius of 600s.
-
When drawing is complete, close the turtle canvas.