重型机械采矿模拟器安卓版
105.08MB · 2025-11-02
from turtle import * # 导入turtle库所有功能(绘图工具)
from time import sleep # 导入sleep函数(用于延迟,但代码中未实际使用)
go_to(x, y):移动画笔位置def go_to(x, y):
up() # 抬起画笔(不绘制)
goto(x, y) # 移动到坐标(x, y)
down() # 放下画笔(准备绘制)
head(x, y, r):绘制头部和身体def head(x,y,r):
go_to(x,y) # 移动到头部起始点
speed(1) # 绘图速度(1-10递增,0为最快)
circle(r) # 绘制圆形头部(半径r)
leg(x,y) # 调用leg()函数绘制腿部
leg()继续绘制身体的其他部分。leg(x, y):绘制腿部def leg(x,y):
right(90) # 右转90度(向下)
forward(180) # 画身体主干(长度180)
right(30) # 右转30度
forward(100) # 画右腿
left(120) # 左转120度
go_to(x,y-180) # 移动到身体底部
forward(100) # 画左腿
right(120) # 右转120度
forward(100) # 延伸左腿
left(120) # 左转120度
hand(x,y) # 调用hand()函数绘制手臂
hand()画手臂。hand(x, y):绘制手臂def hand(x,y):
go_to(x,y-60) # 移动到手臂起始点(身体中间)
forward(100) # 画右臂
left(60) # 左转60度
forward(100) # 延伸右臂
go_to(x, y - 90) # 移动到左侧手臂起始点
right(60) # 右转60度
forward(100) # 画左臂
right(60) # 右转60度
forward(100) # 延伸左臂
left(60) # 左转60度
eye(x,y) # 调用eye()函数绘制眼睛
eye(x, y):绘制眼睛def eye(x,y):
go_to(x-50,y+130) # 移动到左眼位置
right(90) # 右转90度(向下)
forward(50) # 画左眼(竖线)
go_to(x+40,y+130) # 移动到右眼位置
forward(50) # 画右眼(竖线)
left(90) # 左转90度(复位方向)
def big_Circle(size): # 绘制大弧线(爱心外侧)
speed(20)
for i in range(150): # 循环150次,每次移动size距离并右转0.3度
forward(size)
right(0.3)
def line(size): # 绘制直线(爱心中间)
speed(1)
forward(51*size) # 长度为51*size
def small_Circle(size): # 绘制小弧线(爱心内侧)
speed(10)
for i in range(210): # 循环210次,每次移动size距离并右转0.786度
forward(size)
right(0.786)
def heart(x, y, size): # 组合成爱心
go_to(x, y)
left(150)
begin_fill() # 开始填充颜色
line(size) # 画中间直线
big_Circle(size) # 画右侧大弧线
small_Circle(size) # 画右侧小弧线
left(120) # 转向左侧
small_Circle(size) # 画左侧小弧线
big_Circle(size) # 画左侧大弧线
line(size) # 画左侧直线(闭合爱心)
end_fill() # 结束填充(用粉色填充)
main():主函数(程序入口)def main():
pensize(2) # 画笔粗细为2
color('red', 'pink') # 画笔颜色红色,填充颜色粉色
head(-120, 100, 100) # 绘制头部(坐标(-120,100),半径100)
heart(250, -80, 1) # 绘制爱心(坐标(250,-80),大小1)
go_to(200, -300) # 移动到文字位置
# 写入文字:"To: 史上最好的小鱼~"
write("To: 史上最好的小鱼~", move=True, align="left", font=("楷体", 20, "normal"))
done() # 保持绘图窗口
main() # 执行主函数
运行代码后,会绘制出:
sleep函数导入后未使用,可删除。head→leg→hand→eye),可改为平铺调用更清晰。
from turtle import *
from time import sleep
def go_to(x, y):
up()
goto(x, y)
down()
def head(x,y,r):
go_to(x,y)
speed(1)
circle(r)
leg(x,y)
def leg(x,y):
right(90)
forward(180)
right(30)
forward(100)
left(120)
go_to(x,y-180)
forward(100)
right(120)
forward(100)
left(120)
hand(x,y)
def hand(x,y):
go_to(x,y-60)
forward(100)
left(60)
forward(100)
go_to(x, y - 90)
right(60)
forward(100)
right(60)
forward(100)
left(60)
eye(x,y)
def eye(x,y):
go_to(x-50,y+130)
right(90)
forward(50)
go_to(x+40,y+130)
forward(50)
left(90)
def big_Circle(size):
speed(20)
for i in range(150):
forward(size)
right(0.3)
def line(size):
speed(1)
forward(51*size)
def small_Circle(size):
speed(10)
for i in range(210):
forward(size)
right(0.786)
def heart(x, y, size):
go_to(x, y)
left(150)
begin_fill()
line(size)
big_Circle(size)
small_Circle(size)
left(120)
small_Circle(size)
big_Circle(size)
line(size)
end_fill()
def main():
pensize(2)
color('red', 'pink')
head(-120, 100, 100)
heart(250, -80, 1)
go_to(200, -300)
write("To: 史上最好的小鱼~", move=True, align="left", font=("楷体", 20, "normal"))
done()
main()