本文摘自php中文网,作者(*-*)浩,侵删。
周末学习了一下turtle库的基本函数,试着画了一只大耳朵小兔子,灵感来源是jellycat邦尼兔。turtle库中circle()函数用来画弧,但和通常先确定原点,再根据半径、夹角画弧的方法有所不同。使用之后,便能理解circle()函数的巧妙。收获是:边想边做边改胜过完美的空想。

绘制效果如图 :

在circle(radius,extent)函数中,参数radius取像素值、extent取角度的整数值,两参数均可取正负值。运行以下代码,可以直观地理解circle(radius,extent)函数参数正负值时的绘制特点:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | from turtle import *
pensize(5)
pencolor( 'green' )
circle(100,90)
pu()
goto (0,0)
seth(0)
pd()
pencolor( 'orange' )
circle(100,-90)
pu()
goto (0,0)
seth(0)
pd()
pencolor( 'blue' )
circle(-100,90)
pu()
goto (0,0)
seth(0)
pd()
pencolor( 'red' )
circle(-100,-90)
|
circle()函数以画笔当前方向(y')为y轴方向,以经过画笔当前绝对坐标(x0,假设y0=0)、垂直于y轴的方向为x轴方向,则圆心(即原点)坐标为(x0-radius=0,0),由当前画笔位置(x0,y0)为弧线起始点,画出extent角度的圆弧。为了方便理解,我绘制了circle()函数的相对坐标体系,如下图。需要注意的是:radius为正时,圆心在当前位置左侧(如下图);radius为负时,圆心在当前位置右侧;extent为正时,顺画笔当前方向绘制,extent为负时,逆画笔当前方向绘制。
以上为个人的学习理解,初识turtle,不当之处欢迎指正。
原创作品,仅供学习使用,侵权者自重!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | #绘制大耳朵兔
from turtle import *
speed(10)
#小兔的面部
color( 'pink' )
pensize(5)
circle(radius=100)#脸
#眼睛
pencolor( 'black' )
#左眼
pu()
goto (-45,92)
pd()
begin_fill()
color((0,0,0),(0,0,0.1))
circle(radius=15)
#右眼
pu()
goto (45,92)
pd()
circle(radius=15)
end_fill()
#鼻子
pu()
goto (20,60)
color( 'pink' )
pd()
begin_fill()
goto (-20,60)
goto (0,45)
goto (20,60)
end_fill()
#嘴
goto (0,45)
goto (0,40)
seth(-90)
circle(10,120)
pu()
goto (0,40)
seth(-90)
pd()
circle(-10,120)
#小兔的耳朵
#左耳
pu()
goto (-60,180)#
seth(200)
pd()
circle(radius=350,extent=90)
goto (-98,110)
#右耳
pu()
goto (60,180)#
seth(-20)
pd()
circle(radius=-350,extent=90)
goto (98,110)
#小兔的身体
pu()
goto (20,3)
seth(-25)
pd()
circle(radius=-250,extent=25)
circle(radius=-135,extent=260)
seth(50)
circle(radius=-250,extent=25)
##小兔的胳膊
#左臂
pu()
seth(180)
goto (-30,-3)
pd()
#小短胳膊
##circle(radius=270,extent=20)
##circle(radius=20,extent=190)
circle(radius=248,extent=30)
circle(radius=29,extent=185)
#右臂
pu()
seth(0)
goto (30,-3)
pd()
circle(radius=-248,extent=30)
circle(radius=-27,extent=184)
##小兔的脚
##左脚
pu()
goto (-162,-260)#
pd()
seth(0)
circle(radius=41)
#右脚
pu()
goto (164,-260)
pd()
circle(radius=41)
done()
|
以上就是如何用Python画一只兔子——turtle库circle()画圆函数的详细用法介绍的详细内容,更多文章请关注木庄网络博客!!
相关阅读 >>
Python的系统学习实例
Python调用mysql更新数据的方法
Python学习法则
Python学习日记
学完Python能做什么?
自学Python可以做什么兼职
Python怎么读txt文件
如何利用Python将byte array转为string
信息竞赛一定要Python吗
Python是一种面向什么的高级语言
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » 如何用Python画一只兔子——turtle库circle()画圆函数的详细用法介绍