<p>我正在尝试创建一个蒙德里安艺术程序……我有随机生成方块的代码……但是我在用原色随机填充方块时遇到了麻烦?有人知道怎么解决吗?这是我的代码:</p>
<pre><code>import turtle
import random
turtle.screensize(1000,1000)
turtle.setworldcoordinates(-500,-500,500,500)
piet = turtle.Turtle()
piet.speed(300)
#primary colors, red, blue, yellow
#piet.color(red,blue,yellow)
rectangles = int(input('How many rectangles should be drawn? '))
rectangle_w = int(input('What should be the max width of the rectangles? '))
rectangle_h = int(input('What should be the max height of the rectangles? '))
def mondrian(t,random_w,random_h):
piet.begin_fill()
for number_r in range(1):
for box in range(2):
t.left(90)
t.forward(random_w)
t.left(90)
t.forward(random_h)
piet.end_fill()
mondrian(piet,random.randint(10,rectangle_w),random.randint(10,rectangle_h))
def repeat_mondrian():
for i in range(rectangles - 1):
mondrian(piet, random.randint(10, rectangle_w), random.randint(10, rectangle_h))
repeat_mondrian()
</code></pre>
<p>谢谢!:)</p>