?方案所需準備
Python官方手冊。?這里是我找到的中文版。
一個可執行Python的解釋器
Ttultle簡介來源
?
烏龜圖形是一個不錯的方式來為孩子們介紹編程。它是Wally Feurzig和Seymour Papert在1966年開發的原始Logo編程語言的一部分。
想象一只在x-y平面上,從(0,0)開始的海龜機器人。在import?turtle之后,輸入命令turtle.forward(15),然后它就在屏幕上動起來了!當它移動時會沿著他面向的方向畫出一條15像素長的線。輸入命令turtle.right(25),然后它就會原地順時針轉25度。
Turtle star(星)
海龜可以重復簡單動作來繪制復雜的圖形。
fromturtleimport*
color('red', 'yellow')
begin_fill()
whileTrue:
??? forward(200)
??? left(170)
??? ifabs(pos()) <1:
??????? break
end_fill()
done()
通過將這些類似的命令組合在一起,可以很容易地繪制復雜的圖形。
turtle模塊是Python 2.5標準版以來同名模塊的擴展版本。
-------------------------------------------------------------------------------------------
turtle模塊常用命令
Turtle的運動
移動和繪制
forward()
?|?fd()
?向前backward()
?|?bk()
?|?back()
?向后right()
?|?rt()
?向右left()
?|?lt()
?向左goto()
?|?setpos()
?|?setposition()
?設定坐標setx() 設定x坐標
sety()
?設定y坐標setheading()
?|?seth()
?設定朝向home()
circle()
dot()
stamp()
clearstamp()
clearstamps()
undo()
speed()
告訴烏龜的狀態
position()
?|?pos()
towards()
xcor()
ycor()
heading()
distance()
設置和測量
degrees()
radians()
筆控制
繪圖狀態
pendown()
?|?pd()
?|?down()
penup()
?|?pu()
?|?up()
pensize()
?|?width()
pen()
isdown()
顏色控制
color()
pencolor()
fillcolor()
填充
filling()
begin_fill()
end_fill()
更多繪圖控制
reset()
clear()
write()
烏龜狀態
能見度
showturtle()
?|?st()
hideturtle()
?|?ht()
isvisible()
出現
shape()
resizemode()
shapesize()
?|?turtlesize()
shearfactor()
settiltangle()
tiltangle()
tilt()
shapetransform()
get_shapepoly()
使用事件
onclick()
onrelease()
ondrag()
特殊龜方法
begin_poly()
end_poly()
get_poly()
clone()
getturtle()
?|?getpen()
getscreen()
setundobuffer()
undobufferentries()
24.1.2.2.?Methods of TurtleScreen/Screen
窗口控制
bgcolor()
bgpic()
clear()
?|?clearscreen()
reset()
?|?resetscreen()
screensize()
setworldcoordinates()
動畫控制
delay()
tracer()
update()
使用屏幕事件
listen()
onkey()
?|?onkeyrelease()
onkeypress()
onclick()
?|?onscreenclick()
ontimer()
mainloop()
?|?done()
設置和特殊方法
mode()
colormode()
getcanvas()
getshapes()
register_shape()
?|?addshape()
turtles()
window_height()
window_width()
輸入法
textinput()
numinput()
篩選特異性方法
bye()
exitonclick()
setup()
title()
--------------------------------------------------------------------------------------
運行第一段命令
import?turtle turtle.forward(200)
這里代表的是 引用 海龜 畫圖庫
庫 命令 向前 200距離
這樣第一個命令就成功運行了。畫筆向前200距離
turtle.forward
2. ? 第二個命令
turtle.right(144)
讓箭頭發生向右144度的變化,這個角度是可以算出來的,大家參考 官網文檔就知道怎么算的了。
import?turtle turtle.forward(200) turtle.right(144) turtle.forward(200) turtle.right(144) turtle.forward(200) turtle.right(144) turtle.forward(200) turtle.right(144) turtle.forward(200)
效果圖
一共五個筆畫,五個角度
用Python畫的五角星就畫出來了.
Pthon語言龜叔給Python的定位是“優雅”、“明確”、“簡單”,所以Python程序看上去總是簡單易懂,初學者學Python,不但入門容易,而且將來深入下去,可以編寫那些非常非常復雜的程序。
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ????????????????????????????????????????????2017年11月3日 王宇林
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
轉載于:https://blog.51cto.com/xwxhvip/1978841