from turtle import * #imports the libraries import random def regshape(x,y): #regshape could be used to create any regular shape for i in range(0,x): #x is the no of sides forward(y) #y is the length of each side right(180-((180*(x-2))/x)) #this is the formula for an exterior angle of a regular polygon colorsred = ["#330000", "#660000", "#990000", "#cc0000", "#ff0000", "#ff3333"] colorsyellow = ["#332900", "#665200", "#997a00", "#cca300", "#ffcc00", "#ffd633"] colorsgreen = ["#003300", "#006600", "#009900", "#00cc00", "#00ff00", "#33ff33"] colorscyan = ["#003333", "#006666", "#009999", "#00cccc", "#00ffff", "#33ffff"] colorsblue = ["#000033", "#000066", "#000099", "#0000cc", "#0000ff", "#3333ff"] colorspurple = ["#260033", "#4c0066", "#730099", "#9900cc", "#bf00ff", "#cc33ff"] colors = ["#000000"] #choose pensize while True: try: size = int(input("Enter the pensize (Must be 10 or lower.)")) except Exception: size = 12 if size > 11: print("Please enter an integer that is 10 or lower.") elif size < 1: print ("Please don't.") else: pensize(size) break #choose no. of shapes per rotation while True: try: loopno = int(input("Input the number of shapes you want in one rotation. (A lower value is recommended.)")) except Exception: loopno = 0 if loopno < 1: print ("Please enter a positive integer.") elif loopno > 5000: print ("I don't even know if it works with a loop number this high.") print ("Go ahead if you really want to watch the shape redraw itself over and over again without moving.") break elif loopno > 30: print ("This won't be as fun as you seem to think it will.") break else: break #choose colours while True: colorchoice = input("What colour do you want the shapes to be (red, yellow, green, cyan, blue or purple)?") if colorchoice == "red": colors = colorsred break elif colorchoice == "yellow": colors = colorsyellow break elif colorchoice == "green": colors = colorsgreen break elif colorchoice == "cyan": colors = colorscyan break elif colorchoice == "blue": colors = colorsblue break elif colorchoice == "purple": colors = colorspurple break else: print("Enter red, yellow, green, cyan, blue or purple.") #option to add more colours while True: colorchoice = input("Do you want to add another colour? If you do, type the colour. If not, type 0.") if colorchoice == "red": colors.extend(colorsred) elif colorchoice == "yellow": colors.extend(colorsyellow) elif colorchoice == "green": colors.extend(colorsgreen) elif colorchoice == "cyan": colors.extend(colorscyan) elif colorchoice == "blue": colors.extend(colorsblue) elif colorchoice == "purple": colors.extend(colorspurple) elif colorchoice == "0": break else: print("Enter red, yellow, green, cyan, blue or purple, or 0 if you don't want another colour.") #choose background colour while True: colorchoice = input("What colour do you want the background to be (red, yellow, green, cyan, blue, purple, black or white)?") if colorchoice == "red": bgcolor('#ffcccc') break elif colorchoice == "yellow": bgcolor('#fff5cc') break elif colorchoice == "green": bgcolor('#ccffcc') break elif colorchoice == "cyan": bgcolor('#ccffff') break elif colorchoice == "blue": bgcolor('#ccccff') break elif colorchoice == "purple": bgcolor('#f2ccff') break elif colorchoice == "black": bgcolor('#000000') break elif colorchoice == "white": break else: print("Enter red, yellow, green, cyan, blue, purple, black or white.") while(True): #sets the program to keep drawing forever color(random.choice(colors)) #chooses one colour from the list sidelen=(random.randint(20,100)) #sets the side length to something between 20-100 inc. sideno=(random.randint(3,8)) #sets the number of sides to between 3-8 inc. for i in range(0,loopno): #repeats the loop the number of times specified by the user at the beginning regshape(sideno,sidelen) #replaces x and y in the definition of regshape with sideno and sidelen right(360/loopno)