编程语言
首页 > 编程语言> > 蒙德里安艺术计划Python

蒙德里安艺术计划Python

作者:互联网

我正在尝试创建Mondrian Art程序….我有随机生成正方形的代码..但是我在用原色随机填充正方形方面遇到麻烦吗?有谁知道该如何解决?这是我的代码:

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()

谢谢!

标签:turtle-graphics,python-3-x,python
来源: https://codeday.me/bug/20191118/2031247.html