用python繪製玫瑰花

2021-10-03 15:17:51 字數 2613 閱讀 4174

參考了這篇部落格

在其基礎上加了些注釋

import turtle

# 設定初始位置

turtle.penup(

)# 提起畫筆

turtle.left(90)

# 逆時針旋轉九十度

turtle.fd(

200)

# 向前移動一段距離 fd=forward

turtle.pendown(

)# 放下畫筆移動畫筆開始繪製

turtle.right(90)

# 順時針旋轉九十度

# 花蕊

turtle.fillcolor(

"red"

)# 填充顏色

turtle.begin_fill(

)# 開始填充

turtle.circle(10,

180)

# 畫一圓,10是半徑,180是弧度

turtle.circle(25,

110)

turtle.left(50)

turtle.circle(60,

45)turtle.circle(20,

170)

turtle.right(24)

turtle.fd(30)

turtle.left(10)

turtle.circle(30,

110)

turtle.fd(20)

turtle.left(40)

turtle.circle(90,

70)turtle.circle(30,

150)

turtle.right(30)

turtle.fd(15)

turtle.circle(80,

90)turtle.left(15)

turtle.fd(45)

turtle.right(

165)

turtle.fd(20)

turtle.left(

155)

turtle.circle(

150,80)

turtle.left(50)

turtle.circle(

150,90)

turtle.end_fill(

)# 結束填充

# 花瓣1

turtle.left(

150)

turtle.circle(-90

,70)turtle.left(20)

turtle.circle(75,

105)

turtle.setheading(60)

# urtle.setheading(angle) 或 turtle.seth(angle):改變行進方向 angle:行進方向的絕對角度,可以為負值

'''turtle.setheading(angle)在旋轉乙個角度後(angle為正,逆時針旋轉,

angle為負,順時針旋轉),執行turtle.fd(distance)後,

小烏龜的方向恢復到正x方向,即東(east)

'''turtle.circle(80,

98)turtle.circle(-90

,40)# 花瓣2

turtle.left(

180)

turtle.circle(90,

40)turtle.circle(-80

,98)turtle.setheading(-83

)# 葉子1

turtle.fd(30)

turtle.left(90)

turtle.fd(25)

turtle.left(45)

turtle.fillcolor(

"green"

)turtle.begin_fill(

)turtle.circle(-80

,90)turtle.right(90)

turtle.circle(-80

,90)turtle.end_fill(

)turtle.right(

135)

turtle.fd(60)

turtle.left(

180)

turtle.fd(85)

turtle.left(90)

turtle.fd(80)

# 葉子2

turtle.right(90)

turtle.right(45)

turtle.fillcolor(

"green"

)turtle.begin_fill(

)turtle.circle(80,

90)turtle.left(90)

turtle.circle(80,

90)turtle.end_fill(

)turtle.left(

135)

turtle.fd(60)

turtle.left(

180)

turtle.fd(60)

turtle.right(90)

turtle.circle(

200,60)

# 設定成畫完不會自動退出

turtle.done(

)

用 python 繪製玫瑰花

用 python 繪製玫瑰花。需求 用 python 繪製一朵玫瑰花,獻給你喜歡的人 輸入 你的想象力 輸出 玫瑰花。如下 rosedraw.py import turtle as t 定義乙個曲線繪製函式 defdegreecurve n,r,d 1 for i in range n t.left...

Python 玫瑰花繪製

設定初始位置 turtle.penup 提起畫筆 turtle.pensize 5 turtle.left 90 逆時針旋轉九十度 turtle.fd 200 向前移動一段距離 fd forward turtle.pendown 放下畫筆移動畫筆開始繪製 turtle.right 90 順時針旋轉九...

python玫瑰花數量的含義 玫瑰花數量代表的含義

1朵玫瑰代表 我的心中只有你 only you!2朵玫瑰代表 這世界只有我倆!3朵玫瑰代表 我愛你 i love you!4朵玫瑰代表 至死不渝!5朵玫瑰代表 由衷欣賞!6朵玫瑰代表 互敬 互愛 互諒!7朵玫瑰代表 我偷偷地愛著你!8朵玫瑰代表 感謝你的關懷扶持及鼓勵!9朵玫瑰代表 長久 alway...