用python输出圣诞树_教你怎样用Python画了一棵圣诞树,赶紧来学习
文中的文本及圖片來源于互聯網,僅作學習培訓、溝通交流應用,不具備一切商業行為,如有什么問題請立即在線留言以作解決。
下列文章內容來源于IT新手入門
共享給大伙兒一篇文章,教你如何用Python畫了一棵圣誕樹,趕緊來學習培訓。
怎樣用Python畫一個圣誕樹呢?
非常簡單:
height?=?5stars?=?1for?i?in?range(height):????print(('?'?*?(height?-?i))???('*'?*?stars))
stars??=?2print(('?'?*?height)???'|')
實際效果:
哈哈哈哈哈哈,總有一種騙了大伙兒的覺得。
實際上文中是想詳細介紹Turtle庫來畫圣誕樹。
import?turtle
screen?=?turtle.Screen()
screen.setup(375,?700)
circle?=?turtle.Turtle()
circle.shape('circle')
circle.color('red')
circle.speed('fastest')
circle.up()
square?=?turtle.Turtle()
square.shape('square')
square.color('green')
square.speed('fastest')
square.up()
circle.goto(0,?280)
circle.stamp()
k?=?0for?i?in?range(1,?13):
y?=?30?*?i????for?j?in?range(i?-?k):
x?=?30?*?j
square.goto(x,?-y???280)
square.stamp()
square.goto(-x,?-y???280)
square.stamp()????if?i?%?4?==?0:
x?=?30?*?(j???1)
circle.color('red')
circle.goto(-x,?-y???280)
circle.stamp()
circle.goto(x,?-y???280)
circle.stamp()
k??=?3????if?i?%?4?==?3:
x?=?30?*?(j???1)
circle.color('yellow')
circle.goto(-x,?-y???280)
circle.stamp()
circle.goto(x,?-y???280)
circle.stamp()
square.color('brown')for?i?in?range(13,?17):
y?=?30?*?i????for?j?in?range(2):
x?=?30?*?j
square.goto(x,?-y???280)
square.stamp()
square.goto(-x,?-y???280)
square.stamp()
實際效果:
方式二:
import?turtle#?界定圣誕樹的綠葉子涵數def?tree(d,?s):????if?d?<=?0:????????return
turtle.forward(s)
tree(d?-?1,?s?*?.8)
turtle.right(120)
tree(d?-?3,?s?*?.5)
turtle.right(120)
tree(d?-?3,?s?*?.5)
turtle.right(120)
turtle.backward(s)
n?=?100"""?設定制圖速率
'fastest'?:??0
'fast'????:??10
'normal'??:??6
'slow'????:??3
'slowest'?:??1"""turtle.speed('fastest')?#?設定速率turtle.left(90)
turtle.forward(3?*?n)
turtle.color("orange",?"yellow")
turtle.left(126)#?turtle.begin_fill()for?i?in?range(5):
turtle.forward(n?/?5)
turtle.right(144)
turtle.forward(n?/?5)
turtle.left(72)
turtle.end_fill()
turtle.right(126)
turtle.color("dark?green")
turtle.backward(n?*?4.8)#?實行涵數tree(15,?n)
turtle.backward(n?/?5)
實際效果:
總結
以上是生活随笔為你收集整理的用python输出圣诞树_教你怎样用Python画了一棵圣诞树,赶紧来学习的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 64位Win7 安装配置 64位Orac
- 下一篇: 永宏B1主机2个常见问题