Question: You are going to create a program that draws cool patterns. The user will have three modes to choose from: Rectangle Pattern - A circular

You are going to create a program that draws cool patterns. The user will have three modes to choose from:
Rectangle Pattern - A circular pattern created by drawing multiple rectangles
Circle Pattern - A circular pattern created by drawing multiple circles
Super Pattern - A random selection of some number of Rectangle and Circle Patterns
Coding Notes
task1.py - Use the starter file given and only fill in the appropriate areas. Do not modify any code that is there already, only add to it. This file will help you with defining the functions in pattern.py.
You will need to fill in the input functions, so that depending on what the user selects, you ask them for the necessary information to call the function
You will also need to add code to either clear the screen or play again
Besides these, you should not modify the starter code given
pattern.py - You must define the following functions. Include the design for functions with an *.
setup()
Call drawly.start()
Set a window title
Set speed to 10 to make life less painful
Use default window sizes (do nothing special)
reset()- Erase all of the patterns and start over
Either draw a white rectangle to fill the screen OR
Call redraw() without drawing anything before it
*draw_rectangle_pattern()
See additional information below
*draw_circle_pattern()
See additional information below
*draw_super_pattern()
Parameter is a the number of patterns to draw
Use default of 5
Randomly draw Rectangle and Circle patterns. Each pattern should be based on random values.
Use reasonable random values (some can be negative) so patterns are drawn on the screen
set_random_color()
Do not use any parameters
Set drawly to draw in a random color
Use at least 4 colors (hint: use random.choice, and create a constant list of colors in the global scope)
get_distance_point(distance, angle)
This returns an x, y coordinate as a list. It is the point located at the given distance and angle relative to 0,0.
You'll use it to draw in the right place
If you give this function an angle from 0-360 and a distance (the offset), it will return the correct x and y coordinates of a point that distance away using that angle (assuming an origin of 0,0)
Use this as an offset from the center x and y of your shapes to figure out where to draw them
Use this code:
import math
def get_distance_point(distance, angle):
x_pos = distance * math.cos(math.radians(angle))
y_pos = distance * math.sin(math.radians(angle))
return [x_pos, y_pos]
Make sure to read the rubric to see the additional requirements.
Drawing Rectangle Pattern
The Rectangle Pattern has 6 parts to it
Center position - This is the x, y center point of the circular pattern that is drawn
Offset - This is the distance from the center position to the top left corner of each rectangle. It can be a positive or negative number
Height - The height of a rectangle
Width - The width of a rectangle
Count - The number of rectangles to draw within the 360 degree pattern. They should be evenly spaced around the center.
Rotation - The number of degrees each rectangle is rotated in relation to the line from the Center Position to the starting corner of the rectangle. A rotation of 0 would mean the top of the rectangle would be an extension of the line from the center of the pattern to the top left corner. It does not matter which direction your rotation goes, which means you can go either clockwise or counter clockwise for a positive rotation value. Negative values would go the opposite (nothing special to do to make that happen).
Each individual rectangle should be a new random color. You should use at least 4 different colors.
Hints:
It helps to set this up as a for loop so that you loop from 0 to 360, count number of times.
Remember that the third argument in a range function is the step size, not the count.
Supplying a rotation_angle argument to drawly.rectangle() will rotate the rectangle a certain number of degrees
rotation_point=drawly.RotationPoint.TOP_LEFT in your drawly.rectangle() function will make your rectangle rotate around the top_left corner of it
Drawing Circle Pattern
The Circle Pattern has 4 parts to it
Center position - This is the x, y center point of the circular pattern that is drawn
Offset - This is the distance from the center position the closest point of the circle. It can be a positive or negative number (Don't do anything special for negative numbers. It'll just work if you get positive numbers working). Note that the center point of each circle should be 'radius + offset' distance from the Center Position of the pattern.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!