# coding=utf-8
#引用turtle库
import turtle
'''设置画笔属性函数'''
def huabi(a,d,b,c):
turtle.color(a,d)#设置画笔颜色,填充颜色
turtle.pensize(b)#设置画笔大小
turtle.speed(c)#设置画笔速度
'''直线函数'''
def huaxian(a,b,c,d):
turtle.penup()#提笔在另一个地方画图
turtle.goto(a,b)#将画笔移动到坐标为200,200的位置
turtle.pendown()#落笔,画出运动轨迹
turtle.goto(c,d)#将画笔移动到坐标为200,200的位置
'''构斜坡图函数'''
def axy():
huabi("white","gray",2,8)#设置画笔红色
turtle.hideturtle()#隐藏画笔形状
turtle.begin_fill()#填充开始
huaxian(-500,300,-300,0)
huaxian(-300,0,-490,-50)
huaxian(-490,-50,-600,300)
huaxian(-600,300,-500,300)
turtle.end_fill()#结束填充
turtle.begin_fill()#填充开始
huaxian(-300,0,0,0)
huaxian(0,0,-70,-50)
huaxian(-70,-50,-490,-50)
huaxian(-490,-50,-300,0)
turtle.end_fill()
turtle.begin_fill()
huaxian(0,0,200,200)
huaxian(230,160,230,-50)
huaxian(230,-50,-70,-50)
turtle.end_fill()
turtle.begin_fill()#填充开始
huaxian(150,300,280,250)
huaxian(280,250,280,400)
huaxian(280,400,150,400)
huaxian(150,400,150,300)
turtle.end_fill()
'''下自由球的位置函数'''
def bxy():
huabi("white","yellow",2,8)#设置画笔红色,填充为黄色,笔大小为2,画笔速度为8
turtle.penup()#提笔在另一个地方画图
turtle.goto(200,400)#将画笔移动到坐标为200,400的位置
turtle.showturtle()#显示画笔形状
turtle.shape("circle")#设置画笔形状为圆
turtle.shapesize(2,outline=2)#设置大小
'''球运动轨迹函数'''
def raxy():
huabi("white","black",12,1)
turtle.goto(200,222)#将画笔移动到坐标为200,222的位置
d=200#当前x轴为200
f=222#当前y轴为222
for c in range(230):
d=d-1
f=f-1
turtle.goto(d,f)#将画笔移动到坐标为0,22的位置
for c in range(298):
d=d-1
turtle.goto(d,f)#将画笔移动到坐标为-298,22的位置
for c in range(200):
d=d-1
f=f+1.5
turtle.goto(d,f)#将画笔移动到坐标为-298,22的位置
for c in range(200):
d=d+1
f=f-1.5
turtle.goto(d,f)#将画笔移动到坐标为-298,22的位置
for c in range(298):
d=d+1
turtle.goto(d,f)#将画笔移动到坐标为0,22的位置
for c in range(200):
d=d+1
f=f+1
turtle.goto(d,f)#将画笔移动到坐标为200,222的位置
for a in range(40):
b=20
b+=a**1.01
turtle.goto(200+b,222+b)#与模拟墙体相撞弹回
for a in range(1000):
b=20
b+=a**1.01
turtle.goto(200+b,222-b)#自由落体运动
turtle.delay(1)
'''主函数'''
turtle.screensize(1000,600,'white') #画布大小颜色的设置
turtle.setup(width=1200,height=800) #初始位置
axy()
bxy()
raxy()
Python turtle 乌龟图基本知识与应用
最新推荐文章于 2023-03-20 23:06:22 发布