Random Circles

Create an interactive Processing program that creates 20 random circles and allows the user to select one at a time. If
the user selects a circle, it turns green. If the user presses the ‘+’ or ‘-‘ keys after selecting a circle, the circle increases or
decreases in size. If the user presses the ‘w’, ‘a’, ‘s’, or ‘d’ keys after selecting the circle, the circle moves up, left, down,
or right.
Program Behaviour:
 Use a 600×600 canvas
 Create 20 circles and store information about the circles using a global list of records
o Circles should initially be given random locations (the centre of the circle should be within the bounds of
the canvas) and should initially be given a random diameter that is between 20 and 50 pixels.
o Give each circle a unique ID number: the first circle should have ID 1 and the last circle should have ID 20
 If the user clicks on a circle, store that circle’s ID number in a global variable to indicate which circle is selected
o If the user clicks but their cursor is not inside any circle, the ‘selected’ variable should be set to 0 to
indicate that no circle is selected
 Draw all of the circles on a black background
o If a circle is selected (based on its ID number), fill the circle with green; otherwise, fill the circle with grey
 The following keypresses will change the selected circle (and will do nothing if there is no selected circle):
o If the user presses ‘+’, increase the diameter of the selected circle by 1
o If the user presses ‘-‘, decrease the diameter of the selected circle by 1 (with a minimum of 20)
o If the user presses ‘w’, move the selected circle up by 1
o If the user presses ‘s’, move the selected circle down by 1
o If the user presses ‘a’, move the selected circle left by 1
o If the user presses ‘d’, move the selected circle right by 1

×
New Download