【发布时间】:2019-08-12 23:02:41
【问题描述】:
我想出了如何制作一棵树,但它有时会产生随机设计。相反,我想知道如何制作一棵三枝树,所有东西都统一。谢谢!
import turtle
import random
turtle.speed(0)
turtle.hideturtle()
turtle.tracer(0,0)
def draw_line(x,y,angle,length,color,size):
turtle.up()
turtle.goto(x,y)
turtle.seth(angle)
turtle.color(color)
turtle.pensize(size)
turtle.down()
turtle.forward(length)
def draw_tree(x,y,angle,length,color,size,thiccness,n):
if n == 0:
return
if n <= 3:
color = 'lime green'
draw_line(x,y,angle,length,color,size)
cx = turtle.xcor()
cy = turtle.ycor()
draw_tree(cx,cy,angle-thiccness+random.uniform(-8,8),length/(1.3+random.uniform(-.2,.2)),color,size*(0.8+random.uniform(-.1,.1)),thiccness,n-1)
draw_tree(cx,cy,angle+thiccness+random.uniform(-8,8),length/(1.3+random.uniform(-.2,.2)),color,size*(0.8+random.uniform(-.1,.1)),thiccness,n-1)
draw_tree(0,-350,90,150,'brown',10,30,10)
turtle.update()
【问题讨论】:
-
您能否提供制服和随机设计的示例图片,以便我们查看从您的角度来看,问题是什么?
标签: python drawing turtle-graphics