turtle库基本函数的使用

import turtle   #导入turtle库

turtle.speed(5)  #画笔移动的速度
turtle.penup()  #提起画笔,移动画笔但并不会绘制图形
turtle.pendown()  #放下画笔,移动画笔即开始绘制
turtle.left(90)  #逆时针转动画笔90度
turtle.right(90)  #顺时针时针转动画笔90度
turtle.fd(25)  #向前移动指定距离 fd=forward
#turtle.bd(30)   #向后移动指定距离 bd=backward
turtle.fillcolor("red")  #填充颜色
turtle.begin_fill()  #开始填充

turtle.circle(200,50)  #画一个圆 200 是半径,50 是弧度
turtle.end_fill()  #结束填充

#在程序的最后一行加一行
#不然画画结束后会自动退出
turtle.done()

例子:

import turtle   
#画个正方形,填充颜色为:红色
turtle.fillcolor("red")   
turtle.begin_fill()   

turtle.speed(5)  
turtle.fd(25)   

turtle.left(90)     
turtle.fd(25)

turtle.left(90)
turtle.fd(25)

turtle.left(90)
turtle.fd(25)
turtle.end_fill()

#画个弧度,填充颜色为:绿色
turtle.fillcolor("green")
turtle.begin_fill()
turtle.circle(200,180)

turtle.end_fill()

turtle.done()   #可以使画布不出现(未响应)

turtle库 用途:
可以绘制自己想要的任何图形。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值