Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #modern art
- from turtle import *
- from random import *
- colormode(255)
- #create random colours by generating a random integer for each color element
- def randomcolor():
- red = randint(0, 255)
- green = randint(0, 255)
- blue = randint(0, 255)
- color(red, green, blue)
- #use a random number to determine the where the shape should be placed
- def randomplace():
- penup()
- n = 200
- x = randint(-n, n)
- y = randint(-n, n)
- goto(x,y)
- pendown()
- #draw a rectangle passing in the speed and calling the color and place functions
- def drawrectangle(spd):
- speed(spd)
- randomcolor()
- randomplace()
- length=randint(10,100)
- height=randint(10,100)
- #color in the rectangle
- begin_fill()
- forward(length)
- right(90)
- forward(height)
- right(90)
- forward(length)
- right(90)
- forward(height)
- right(90)
- end_fill()
- #using the dot function to create circles of diferent sizes and colors
- def draw_circle(spd):
- speed(spd)
- randomcolor()
- randomplace()
- r = randint(1,100)
- dot(r*2)
- #function for looping through the rectangles and circles
- def modern_art(n, spd):
- for i in range(n):
- drawrectangle(spd)
- print(spd,n)
- # randomly generate the number of loops of circles based on the number of rectangles.
- n = randint(1,4) * n
- for i in range(n):
- draw_circle(spd)
- print(spd, n)
- #call the function passing the number of iterations and the speed.
- modern_art(10, 9)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement