python——用Turtle画画写名字

python——用Turtle画画写名字,第1张

python——用Turtle画画写名字

Turtle库是Python语言中一个很流行的绘制图像的函数库,利用这个库会生成一个画布,在画布中有我们看不见的一个默认以中心点为原点的坐标轴,在原点会有一个初始默认朝东的画笔(箭头),一般我们把这个箭头叫做海龟,箭头的朝向就是海龟头的朝向

这个动图展示的就是我利用Turtle库画的一个名字画,下面附上代码:

import time
import turtle
from random import random

t = turtle
t.speed(3)
t.hideturtle()
t.color('black')
t.pensize(10)

# 一
t.penup()
t.goto(-110, 60)
t.pendown()
t.forward(100)

# |
t.penup()
t.goto(-60, 125)
t.right(90)
t.pendown()
t.forward(266)

# 丿
t.penup()
t.goto(-60, 45)
t.right(45)
t.pendown()
t.forward(90)

# 丶
t.penup()
t.goto(-60, 38)
t.left(90)
t.pendown()
t.forward(40)

# 小一
t.penup()
t.goto(20, 60)
t.left(45)
t.pendown()
t.forward(90)

# |
t.penup()
t.goto(65, 123)
t.right(90)
t.pendown()
t.forward(123)

# 大一
t.penup()
t.goto(0, -5)
t.left(90)
t.pendown()
t.forward(130)

# 小一
t.penup()
t.goto(20, -65)
t.pendown()
t.forward(90)

# |
t.penup()
t.goto(65, -14)
t.right(90)
t.pendown()
t.forward(120)

# 大一
t.penup()
t.goto(0, -135)
t.left(90)
t.pendown()
t.forward(130)

# 画圆
t.color('red')
t.pensize(3)
t.penup()
t.goto(15, -200)
t.pendown()
t.circle(180)

t.exitonclick()
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.


函数

解释

hideturtle

隐藏画笔

speed

画笔速度,1-10,1最慢,10最快

color

后可传参(2个参数),不传为默认设置,第一个参数为画笔颜色,第二个参数为填充颜色

pensize

画笔粗细,越大越粗

penup

画笔拿起,之后画笔运动时不画下轨迹

pendown

默认是这个状态,画笔落下,之后画笔运动会画出轨迹

forward(num)

画笔运动,num为运动像素数,即长度

right (a)

画笔方向向右旋转a角度,顺时针旋转

left(a)

画笔方向向左旋转a角度,逆时针旋转

goto(x,y)

将画笔移动到坐标轴x,y位置,在pendowm下会画下轨迹

goto(x,y)

将画笔移动到坐标轴x,y位置,在pendowm下会画下轨迹

circle(a)

以当前点为圆心,画一个半径为a的圆

exitonclick

点击关闭,画笔运行完不再自动退出画布

下面是在论坛看到的一个大佬的画樱花树的代码,生成的结果比上面的复杂很多,但在弄懂我上面代码的情况下很容易看懂
-----------------------------------
©著作权归作者所有:来自51CTO博客作者轮回摆渡者的原创作品,如需转载,请注明出处,否则将追究法律责任
python——用Turtle画画写名字
https://blog.51cto.com/guipc/3992765

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/zaji/5579491.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-14
下一篇 2022-12-14

发表评论

登录后才能评论

评论列表(0条)

保存