Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In java, using the StdDraw class, make a bouncing ball animation in a triangle,

ID: 3850226 • Letter: I

Question

In java, using the StdDraw class, make a bouncing ball animation in a triangle, NOT a box.

Below is the example of the bouncing ball animation in a box. It needs to be altered to a triangle:

Explanation / Answer

public void move() { if (Math.abs(rx + vx) + radius > 1.0) bounceOffVerticalWall(); if (Math.abs(ry + vy) + radius > 1.0) bounceOffHorizontalWall(); rx = rx + vx; ry = ry + vy; } // draw the ball public void draw() { StdDraw.filledCircle(rx, ry, radius); } // test client public static void main(String[] args) { // create and initialize two balls Ball b1 = new Ball(); Ball b2 = new Ball(); // animate them StdDraw.setXscale(-1.0, +1.0); StdDraw.setYscale(-1.0, +1.0); StdDraw.enableDoubleBuffering(); while (true) { StdDraw.clear(StdDraw.GRAY); StdDraw.setPenColor(StdDraw.BLACK); b1.move(); b2.move(); b1.draw(); b2.draw(); StdDraw.show(); StdDraw.pause(20); } } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote