Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this question, you will write a program that allows the user to move and re-size a single circle. The behaviour of your program should

For this question, you will write a program that allows the user to move and re-size a single circle. The behaviour of your program should be as follows: When the program starts, there should be a small circle on the canvas (the example shows a white circle on a black canvas, but the colors are irrelevant; use what you like) When the user presses a number key (i.e. 0 through 9), the diameter of the circle should multiplicatively increase by the value of the number pressed. For example, if the user presses the "3" key, the circle should triple in size. (if the user presses a key that is not a digit, your program will crash; that is ok, you dont need to handle this case) When the user clicks the mouse, the circle should be moved to the location of the mouse and reset to its original size. Figure 1: Small circle starts in the middle (left); triples in size when 3 is pressed (middle) and then moves and resets to original size when mouse is clicked, then doubles in size when 2 is pressed. Heres a description of how to go about your work Step 1 Dene a function called calculate_size(). This function should have two input parameters: the old diameter of the circle (an integer), and the digit key that was pressed on the keyboard (a string). The function should rst convert the digit from a string to an integer (hint: use the int() function to do this) and then multiply it with the old diameter and return the result. This isnt a lot of work for the function to do (in fact, it might just be 1 line of code), but the point is to practice using parameters and return values. Importantly, the function should not use global variables in any way. Step 2 Once you are sure your function from step 1 is working, you can add the interactive parts of your program. Make sure to use a good Model-View-Controller design and decide what your global variables will be, then add your setup(), draw(), mouseClicked() and keyPressed() functions. Call your calculate_size() function in the right place when you need to change the size of the circle (hint: this will only be in keyPressed()).

programming language is Python

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Theory Icdt 99 7th International Conference Jerusalem Israel January 10 12 1999 Proceedings Lncs 1540

Authors: Catriel Beeri ,Peter Buneman

1st Edition

3540654526, 978-3540654520

More Books

Students also viewed these Databases questions