# Ellen Doutre-Burgess # CS 1400 - 003 Assignment 10 # This is the program for the patterns that the user will choose from # These are the libraries we will be using import turtle import random # To get out random colors colorOptions = ["pink", "blue", "purple", "green", "red", "yellow"] # So we can play again def reset(): turtle.reset() turtle.speed(0) # Also so we can play again def setup(): turtle.speed() turtle.setup(1000, 800) ##### Fix the rotation # Draw the circle with recangles def drawRectanglePattern(centerX, centerY, offset, width, height, count, rotation): for i in range(count): for j in range(count): color = random.choice(colorOptions) turtle.penup() turtle.goto(centerX, centerY) turtle.right(rotation) turtle.forward(offset) drawRectangle(width, height, color) # Draw the rectangle def drawRectangle(width, height, color): turtle.color(color) turtle.pendown() turtle.forward(height) turtle.right(90) turtle.forward(width) turtle.right(90) turtle.forward(height) turtle.right(90) turtle.forward(width) turtle.right(90) # Draw lots of patterns def drawSuperPattern(num): for i in range(num): centerX = random.randint(-500, 500) centerY = random.randint(-400, 400) offset = random.randint(0, 100) radius = random.randint(5, 50) count = random.randint(1, 100) rotation = (360 / count) drawCirclePattern(centerX, centerY, offset, radius, count, rotation) # Draw the circle with circles def drawCirclePattern(centerX, centerY, offset, rotation, radius=50, count=25): for i in range(count): for j in range(count): color = random.choice(colorOptions) turtle.penup() turtle.goto(centerX, centerY) turtle.right(rotation) turtle.forward(offset) drawCircle(radius, color) #Draw the circle def drawCircle(radius, color): turtle.color(color) turtle.pendown() turtle.circle(radius) def done(): turtle.done() def main(): # Setup pattern pattern.setup() # Play again loop playAgain = True while playAgain: # Present a menu to the user # Let them select 'Super' mode or 'Single' mode print("Choose a mode") print("1) Rectangle Pattern") print("2) Circle Pattern") print("3) Super Pattern") mode = eval(input("Which mode do you want to play? 1, 2 or 3: ")) # If they choose 'Rectangle Patterns' if mode == 1: #### Add Input Statement(s) as needed #### centerX, centerY = eval(input("Enter a center point (x, y): ")) offset = eval(input("Enter the offset from the center you want: ")) width = eval(input("Enter the width you want: ")) height = eval(input("Enter the height you want: ")) count = eval(input("Enter how many rectangles you want: ")) rotation = (360 / count) #### End Add Inputs Statement(s) #### # Draw the rectangle pattern pattern.drawRectanglePattern(centerX, centerY, offset, width, height, count, rotation) # If they choose 'Circle Patterns' elif mode == 2: #### Add Input Statement(s) as needed #### centerX, centerY = eval(input("Enter a center point (x, y): ")) offset = eval(input("Enter the offset from the center you want: ")) radius = eval(input("Enter the radius you want: ")) count = eval(input("Enter how many circles you want: ")) rotation = (360 / count) #### End Add Inputs Statement(s) #### # Draw the circle pattern pattern.drawCirclePattern(centerX, centerY, offset, rotation, radius, count) # If they choose 'Super Patterns' elif mode == 3: #### Add Input Statement(s) as needed #### num = eval(input("Enter how many shapes you want: ")) #### End Add Inputs Statement(s) #### if num == "": pattern.drawSuperPattern() else: pattern.drawSuperPattern(num) # Play again? print("Do you want to play again?") print("1) Yes, and keep drawings") print("2) Yes, and clear drawings") print("3) No, I am all done") response = eval(input("Choose 1, 2, or 3: ")) if response == 1: playAgain = True #### Add Statement(s) to clear drawings and play again #### elif response == 2: pattern.reset() pattern.setup() playAgain = True #### End Add Inputs Statement(s) #### else: playAgain = False # print a message saying thank you print("Thanks for playing!") pattern.done() main()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question