Question: Using Processing and Python code. For this question, you will need to start using variables in your program. You will create a simple program that



For this question, you will need to start using variables in your program. You will create a simple program that consists of a white circle on a black background that the user can move and re-size. The following describes what your program should do in more detail. Draw a black background on a 300 x 300 pixel canvas. There is a single circle on the canvas, initially in the middle. . If the user pressed the 'I' key, the size of the circle should increase. If the user presses the 'd' key, the size of the circle should decrease. . On a mouse click, move the circle to the location of the mouse. The circle should stay the same size! Figure 1: Circle with its size changing as the 'l' or 'd' keys are pressed Recalling the Model-View-Controller programming style, you will need to think about how to build a model for this program. What pieces of information will your program need to remember over time? You'll need a variable for each such piece of information, and these variables ARE your model of the problem. Once you've decided on your model , you simply have to choose the right interactive functions to put code that will either display or change the model as appropriate. In particular: draw() is your view. Function calls to both background() and ellipse() should ONLY be put here. mouseClicked) and keyPressed() are your controllers, Statements that change the variables in your model should go here. Note: You may notice that your program can act strangely when the size of your circle is reduced to a negative number. Don't worry about this for now. In a future class, we will learn how to fix that! O Python sketch_210209a 1 X = 150 2 y = 150 4 5 def setup(): size(300, 300) 7 8 9 def draw (): 10 global x, y 11 background (0) 12 ellipse (x, y, 30, 30) 13 14 def mouseClicked (): 15 global x, y 16 X = mouse 17 y = mouseY 18 19 20 21 def keyPressed(): 22 global x, y if key == "1": 24 ellipse (x, y, 60, 60) 25 if key == "d": 26 ellipse (x, y, 15, 15) 27 23 29 Console Cookie Monster loves cookies, but he is practicing self-restraint. For this question, you will write a program where the user can move a cookie around Cookie Monster's face (but miraculously. Cookie Monster will not eat it). The following describes what your program should do in more detail Draw a picture of Cookie Monster's face in the middle of the canvas Achocolate-chip cookie should follow the mouse. The cookie consists of a light-brown circle with at least 5 small darker circles (the chocolate chips) on its surface. Figure 2. Cookie Monster's face, with the cookie following the mouse and moving to different locations In order to draw the cookie that follows the mouse, define a function called draw_cookie(x, y). This function should draw the chocolate-chip cookie centered at the (x,y) coordinates given as the function's parameters. In particular, the body of this function should NOT reference mousex and mousey in any way. Instead, in your draw() function, you should call the draw_cookie() function, using mousex and mousey as the arguments for the function call Python 2 3 4 5 6 7 sketch_210209a 1 def cookie_moster(): fill(0,50,255) ellipse(150, 150, 150, 140) fill(0) ellipse(150,170,130,60) fill(255) ellipse(120,100,50,50) 8 fill(255) ellipse (180,100,50,50) 10 fill(0) 11 ellipse(115,90,20,20) 12 fill(o) 13 ellipse(175, 105,20,20) 14 15 def setup(): 16 size(300,300) 17 cookie_mosterol 18 19 def draw(): 20 fill(235, 70 ,30) 21 ellipse(150, 150, 60, 60) 22 fill(o) 23 ellipse(150, 150, 5, 5) 24 ellipse(165, 150, 5, 5) 25 ellipse(150, 170, 5, 26 ellipse (145, 130, 5, 27 ellipse(135, 170, 5, 5) 28 ellipse(125, 150, 5, 5)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
