Python turtle 乌龟图基本知识与应用

# 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()

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值