3
answers
0
watching
284
views
1 Jan 2018

20. (2 points) Fill in the blanks so this program creates two balls. Balll should start at location (50,100) with zero y velocity and 0.2 x velocity. Ball2 should start at (300,100) with zero y velocity and -0.2 x velocity. The balls should then fall according to gravity as specified in the Ball class. They should each be 10 pixels in diameter, Ball balli, bal12; float gravity = 0.1; void setup() { size (400, 400); balll = ball2 = fill (255,0,0); void draw() { background (255); class Ball ! float x, y, xVel, yvel; int diam; Ball (float xStart, float ystart, float xv, float yv, int diameter) x = xStart; y = yStart; xVel = xV; yvel = y; diam = diameter; void update() { // check if hit the ground so need to reverse the velocity if (y > height-diam/2) { yvel = -yvel; // adjust position based on velocity y = y + yvel; x = x + xVel; // adjust the velocity - increasing due to gravity yvel = yvel + gravity; // always accelerate down // add some drag yvel = yvel*0.99; void draw() { // draw the ball ellipse (x, y, diam, diam);

For unlimited access to Homework Help, a Homework+ subscription is required.

Unlock all answers

Get 1 free homework help answer.
Already have an account? Log in
Already have an account? Log in
Hubert Koch
Hubert KochLv2
2 Jan 2018
Already have an account? Log in
Start filling in the gaps now
Log in