91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

使用python圖形模塊turtle庫繪制櫻花、玫瑰、圣誕樹代碼實現

小云
102
2023-09-17 03:10:46
欄目: 編程語言

以下是使用Python的turtle庫繪制櫻花、玫瑰和圣誕樹的代碼實現。

櫻花:

import turtle
def draw_branch(branch_len):
if branch_len > 3:
if branch_len < 30:
turtle.pencolor("pink")
else:
turtle.pencolor("brown")
turtle.forward(branch_len)
turtle.right(20)
draw_branch(branch_len - 15)
turtle.left(40)
draw_branch(branch_len - 15)
turtle.right(20)
turtle.penup()
turtle.backward(branch_len)
turtle.pendown()
def draw_sakura():
turtle.speed(0)
turtle.penup()
turtle.left(90)
turtle.backward(200)
turtle.pendown()
draw_branch(100)
turtle.exitonclick()
draw_sakura()

玫瑰:

import turtle
def draw_flower():
turtle.color("red")
turtle.begin_fill()
turtle.left(50)
turtle.forward(133)
turtle.circle(50, 180)
turtle.right(140)
turtle.circle(50, 180)
turtle.forward(133)
turtle.end_fill()
def draw_stem():
turtle.color("green")
turtle.right(90)
turtle.forward(200)
def draw_rose():
turtle.penup()
turtle.backward(100)
turtle.pendown()
draw_flower()
draw_stem()
turtle.exitonclick()
draw_rose()

圣誕樹:

import turtle
def draw_tree(branch_len):
if branch_len > 5:
turtle.forward(branch_len)
turtle.right(20)
draw_tree(branch_len - 15)
turtle.left(40)
draw_tree(branch_len - 15)
turtle.right(20)
turtle.backward(branch_len)
def draw_star():
turtle.color("yellow")
turtle.begin_fill()
for _ in range(5):
turtle.forward(50)
turtle.right(144)
turtle.end_fill()
def draw_christmas_tree():
turtle.speed(0)
turtle.penup()
turtle.left(90)
turtle.backward(200)
turtle.pendown()
turtle.color("green")
turtle.begin_fill()
turtle.forward(100)
turtle.right(90)
turtle.forward(20)
turtle.right(90)
turtle.forward(20)
turtle.right(90)
turtle.forward(20)
turtle.left(90)
turtle.forward(50)
turtle.left(90)
turtle.forward(20)
turtle.left(90)
turtle.forward(20)
turtle.right(90)
turtle.forward(100)
turtle.end_fill()
turtle.penup()
turtle.left(90)
turtle.forward(120)
turtle.left(90)
turtle.pendown()
draw_tree(100)
turtle.penup()
turtle.backward(100)
turtle.pendown()
draw_star()
turtle.exitonclick()
draw_christmas_tree()

這些代碼可以在Python環境中運行,并使用turtle庫來繪制相應的圖形。

0
平陆县| 怀化市| 油尖旺区| 奇台县| 老河口市| 宣武区| 裕民县| 祥云县| 高碑店市| 盘锦市| 逊克县| 勃利县| 博湖县| 犍为县| 太和县| 尼木县| 东明县| 天水市| 徐闻县| 于田县| 广昌县| 石阡县| 长海县| 绥江县| 太仓市| 鹿邑县| 嘉峪关市| 邢台县| 武威市| 九龙城区| 乌兰县| 新绛县| 土默特右旗| 西丰县| 徐水县| 读书| 哈巴河县| 紫云| 英超| 兰考县| 闸北区|