中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

使用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
澄迈县| 防城港市| 临汾市| 安福县| 莲花县| 汝南县| 河南省| 瓦房店市| 芒康县| 临城县| 剑河县| 临泉县| 贵州省| 陆良县| 阜新市| 南平市| 许昌市| 临沧市| 广昌县| 合山市| 宁远县| 囊谦县| 若羌县| 宣武区| 皮山县| 崇左市| 济源市| 蒙城县| 竹北市| 潮州市| 德州市| 木里| 新兴县| 海门市| 大竹县| 富裕县| 大安市| 三都| 文安县| 海林市| 彝良县|