turtle.write(s [,font=("font-name",font_size,"font_type")]):写文本,s为文本内容,font是字体的参数,分别为字体名称,大小和类型;font为可选项,font参数也是可选项
代码
import turtle as t
import random
t.speed(0)
for i in range(50):
t.circle(80)
t.right(100)
t.done()
代码
import turtle as t
import random
# 圆环
# 奥运五环
t.pensize(9)
# 蓝环
t.color('blue')
t.circle(75)
t.penup()
t.forward(150)
t.pendown()
# 黑环
t.color('black')
t.circle(75)
t.penup()
t.forward(150)
t.pendown()
# 红环
t.color('red')
t.circle(75)
t.penup()
t.goto(220, -100)
t.pendown()
# 黄环
t.color('yellow')
t.circle(75)
t.penup()
t.goto(100, -100)
t.pendown()
# 绿环
t.color('green')
t.circle(75)
# 字体
t.color('black')
t.penup()
t.goto(50, 200)
t.pendown()
t.write('北京 2022', font=('YouYuan', 32))
t.done()
代码
import turtle as t
import random
#美国盾牌
t.penup()
t.goto(0,-200)
t.pendown()
t.color('red')
t.begin_fill()
t.circle(200)
t.end_fill()
t.penup()
t.goto(0, -150)
t.pendown()
t.color('white')
t.begin_fill()
t.circle(150)
t.end_fill()
t.penup()
t.goto(0, -100)
t.pendown()
t.color('red')
t.begin_fill()
t.circle(100)
t.end_fill()
t.penup()
t.goto(0, -60)
t.pendown()
t.color('blue')
t.begin_fill()
t.circle(60)
t.end_fill()
t.penup()
t.goto(-50, 18)
t.pendown()
t.color('white')
t.begin_fill()
for i in range(5):
t.forward(105)
t.right(144)
t.end_fill()
t.done()
代码
import turtle as t
import random
# 彩旗飘飘
t.colormode(255)
for i in range(20):
# 设置RGB值,随机生成
red = random.randint(0, 255)
green = random.randint(0, 255)
blue = random.randint(0, 255)
# 设置气球随机位置,随机生成x,y坐标
x = random.randint(-400, 400)
y = random.randint(-100, 300)
# 移动到指定的位置
t.penup()
t.goto(x, y)
t.pendown()
# 设置填充颜色
t.color(red, green, blue)
# 填充和画圆
t.begin_fill()
t.circle(30)
t.end_fill()
# 画线
t.right(90)
t.forward(30)
t.left(90)
t.done()
代码
import turtle as t
import random
if __name__ == '__main__':
# 繁星漫天
# 夜空
t.speed(0)
t.screensize(800, 600, 'black')
t.colormode(255)
t.pensize(250)
for i in range(10):
t.goto(-500, 400 - i * 100)
t.color(i * 20, i * 20, i * 20)
t.forward(1000)
# 星星
for j in range(25):
x = random.randint(-400, 400)
y = random.randint(0, 400)
size = random.randint(5, 20)
t.color('yellow')
t.penup()
t.goto(x, y)
t.pendown()
t.pensize(3)
t.begin_fill()
for i in range(4):
t.forward(size)
t.left(30)
t.forward(size)
t.right(120)
t.end_fill()
t.done()