Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can somebody shoe me how to write above program by using Java code? Thanks Lab03Bronze CORO opp. OD ODPOWOOD Write a drawing program that lets

image text in transcribedimage text in transcribed

Can somebody shoe me how to write above program by using Java code? Thanks

Lab03Bronze CORO opp. OD ODPOWOOD Write a drawing program that lets you make images like the one shown here. Circles should be drawn continuously (one new one per frame), with their centres at the mouse position. The colours of the circles (a shade of grey) should be controlled by the vertical position of the mouse - black (0) at the top of the canvas, and white (255) at the bottom. The diameters of the circles should be controlled by the horizontal position of the mouse - tiny (0) on the left, and full size (MAX_SIZE) on the right. 1. Create an Active Processing program and create a canvas with a black background in the setup block. Your program should work with a canvas of any size, square or rectangular. 2. Create two global state variables (named size and shade) which will control the diameter of the next circle, and its shade of grey. 3. Create a global constant MAX_SIZE which will control the size of the largest circles. In the example above, MAX_SIZE is set to 100. 4. Define a small function void drawCircle( ) which will draw a circle at the current mouse location, using size and shade to control its colour and diameter. 5. Define a small function void setSizeAndShade( ) which will set the variables size and shade according to the mouse position. a. Note: The expression MAX_SIZE*mouseX/width will give you an answer that varies from 0 to MAX_SIZE, as mouseX varies from 0 to width. Since we're using int variables only, it's important to write it this way. If you calculate mouseX/width first you'll always get 0. But multiplying X*mouseX first gives you a big number, and then dividing by width at the end will work and give you the right answer. 6. Call setSizeAnd Shade () and drawCircle() in the usual draw() function. Labosilver - 0 X Create a program that simulates a ball hanging from the mouse on an elastic band. 1. Create the usual setup and draw blocks, and resize the canvas to 500x500 in the setup block. Create two global int instance variables, ballX and bally, to keep track of the ball's position. Also create a constant to set the ball's diameter (the one in the image has a diameter of 20 pixels). The ball should start at the center of the canvas. Define a small function void drawBall( ) which will draw the ball, connected to the mouse's position by an "elastic band (a simple white line). Give the ball a colour of your choice, with a coloured outline. Using the command strokeWeight(2); will give a thicker line that will look better than a thin one. 4. Define a small function void moveBall( ) which will make the ball try to move toward the mouse, but be pulled down by gravity at the same time, giving an elastic effect. a. Define a global constant BAND_STRENGTH representing the pulling power of the elastic band. Add the difference between the mouse's position and the ball's position, divided by BAND_STRENGTH, to move the ball. Do this for both x and y separately. (So if BAND_STRENGTH is 5 only 1/5th of the difference will be added. The larger this number is, the slower the ball will move toward the mouse.) Try a value of 8 for the BAND_STRENGTH to start with. b. Define a global constant GRAVITY. Simply add this much to the Y position of the ball (but not to X) to pull the ball down. Try 10 for GRAVITY at the start. 5. Your draw() function should clear the background to black, and then call your moveBall() and drawBall() functions. Presto! Bouncing ball! 6. Did you use constants properly? Can you change the strength of the rubber band by changing only one constant? How about the amount of gravity? Numbers like those should always be named constants. (Try using different values to get different effects.) Lab03Bronze CORO opp. OD ODPOWOOD Write a drawing program that lets you make images like the one shown here. Circles should be drawn continuously (one new one per frame), with their centres at the mouse position. The colours of the circles (a shade of grey) should be controlled by the vertical position of the mouse - black (0) at the top of the canvas, and white (255) at the bottom. The diameters of the circles should be controlled by the horizontal position of the mouse - tiny (0) on the left, and full size (MAX_SIZE) on the right. 1. Create an Active Processing program and create a canvas with a black background in the setup block. Your program should work with a canvas of any size, square or rectangular. 2. Create two global state variables (named size and shade) which will control the diameter of the next circle, and its shade of grey. 3. Create a global constant MAX_SIZE which will control the size of the largest circles. In the example above, MAX_SIZE is set to 100. 4. Define a small function void drawCircle( ) which will draw a circle at the current mouse location, using size and shade to control its colour and diameter. 5. Define a small function void setSizeAndShade( ) which will set the variables size and shade according to the mouse position. a. Note: The expression MAX_SIZE*mouseX/width will give you an answer that varies from 0 to MAX_SIZE, as mouseX varies from 0 to width. Since we're using int variables only, it's important to write it this way. If you calculate mouseX/width first you'll always get 0. But multiplying X*mouseX first gives you a big number, and then dividing by width at the end will work and give you the right answer. 6. Call setSizeAnd Shade () and drawCircle() in the usual draw() function. Labosilver - 0 X Create a program that simulates a ball hanging from the mouse on an elastic band. 1. Create the usual setup and draw blocks, and resize the canvas to 500x500 in the setup block. Create two global int instance variables, ballX and bally, to keep track of the ball's position. Also create a constant to set the ball's diameter (the one in the image has a diameter of 20 pixels). The ball should start at the center of the canvas. Define a small function void drawBall( ) which will draw the ball, connected to the mouse's position by an "elastic band (a simple white line). Give the ball a colour of your choice, with a coloured outline. Using the command strokeWeight(2); will give a thicker line that will look better than a thin one. 4. Define a small function void moveBall( ) which will make the ball try to move toward the mouse, but be pulled down by gravity at the same time, giving an elastic effect. a. Define a global constant BAND_STRENGTH representing the pulling power of the elastic band. Add the difference between the mouse's position and the ball's position, divided by BAND_STRENGTH, to move the ball. Do this for both x and y separately. (So if BAND_STRENGTH is 5 only 1/5th of the difference will be added. The larger this number is, the slower the ball will move toward the mouse.) Try a value of 8 for the BAND_STRENGTH to start with. b. Define a global constant GRAVITY. Simply add this much to the Y position of the ball (but not to X) to pull the ball down. Try 10 for GRAVITY at the start. 5. Your draw() function should clear the background to black, and then call your moveBall() and drawBall() functions. Presto! Bouncing ball! 6. Did you use constants properly? Can you change the strength of the rubber band by changing only one constant? How about the amount of gravity? Numbers like those should always be named constants. (Try using different values to get different effects.)

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_2

Step: 3

blur-text-image_3

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

Big Data Fundamentals Concepts, Drivers & Techniques

Authors: Thomas Erl, Wajid Khattak, Paul Buhler

1st Edition

0134291204, 9780134291208

More Books

Students also viewed these Databases questions

Question

Discuss global cultural differences in GLOBE dimensions.

Answered: 1 week ago

Question

LO1 Discuss the objectives of human resource management.

Answered: 1 week ago