如何在Python上画圣诞树?
最简单的方法:
height=5stars=1foriinrange (height ) :print ) (' height-I ) ) *' * stars ) ) stars=2print )
哈哈,我总觉得欺骗了大家。
其实我想介绍Turtle库画圣诞树。
importturtlescreen=turtle.screen () screen.setup ) 375, 700 ) circle=turtle.turtle (circle.shape ) circle (color ) red (circle.speed ) fastest ) cirrcle square.shape(square ) are.up ) circle.goto ) ) 0,13 ) 3360y=30*Iforjinrange(I-k ) : x=30 * j square.goto(x ) x,-y 280 ) square -y 280 ) square.stamp (ifi %4==0: x=30 * (J1 ) circle.color(red ) ) circle.goto(-x, -y 280 ) circle -y 280 ) circle.stamp (k=3ifi %4==3: x=30 * (J1 ) circle.color('yellow ' ) circle.goto(x () -y 280 -y 280 ) circle.stamp (square.color (brown ) forIinrange ) 13,17 ) : y=30 * i for j in range(2)2) 3360 x=
效果:
导入树#定义圣诞树的绿叶函数deftree(d,s ) : ifd=0: return turtle.forward ) s ) tree(d-1, s * .8 ) turtle.right ) ) ) ) 65 s * .5 ) turtle.right(120 ) tree ) d-3、s * .5 ) turtle.right(120 ) n=100 ' ' '设定绘图速度' fastest ' : ' fast ' :10 ' normal ' :6 ' slow ' :3 ' slowest ' :1 ' ' turtle.speer ter ' yellow'(turtle.left(126 ) # turtle.begin_fill ) for i in range(5)5) : turtle.forward (n/5 ) turtle.rand
请添加编辑并回复关键字。 [数据可视化]、
效果:
你记住了吗? 欢迎文章下面的信息交流
如果对你有用的话
“转发朋友圈”和“看着”是最大的支持