import Myro.*; public class TenAMClass { private MyroCanvas myCanvas; private static final double GRAVITY = 0.98; private static final double ENERGYLOSS = 0.8; private static final double TARGETX = 200; private static final double TARGETY= 280; public TenAMClass() { myCanvas = new MyroCanvas("Yee Haw!", 410, 300); myCanvas.setVisible(true); while (!MyroListener.isKeyPressed()) { int r = MyroUtils.randomInt(0, 255); int g = MyroUtils.randomInt(0, 255); int b = MyroUtils.randomInt(0, 255); double xStart = 50; //MyroUtils.randomInt(50, 360); double yStart = 50; //MyroUtils.randomInt(50, 250); double xVelocity; // = MyroUtils.randomDouble() * .90 + 15.0; double yVelocity; // = -(MyroUtils.randomDouble() * .90 + 11.0); double overBounce; boolean notDone = true; xVelocity = MyroGUI.inputDouble("xVelocity"); yVelocity = MyroGUI.inputDouble("yVelocity"); MyroCircle target = new MyroCircle(myCanvas, (int)TARGETX, (int)TARGETY, 20); target.setOutlineColor(new java.awt.Color(r,g,b)); target.setFillColor(new java.awt.Color(b,r,g)); target.makeFilled(); target.visible(); MyroLine line = new MyroLine(myCanvas, (int)xStart, (int)yStart, (int)(xStart+xVelocity), (int)(yStart + yVelocity)); line.setOutlineColor(new java.awt.Color(r,g,b) ); line.visible(); MyroUtils.sleep(2.0); line.invisible(); while(notDone) { //Draw circle at x,y MyroCircle circle = new MyroCircle(myCanvas, (int)xStart, (int)yStart, 10); circle.setOutlineColor(new java.awt.Color(r,g,b)); circle.setFillColor(new java.awt.Color(b,r,g)); circle.makeFilled(); circle.visible(); //add gravity to y velocity yVelocity += GRAVITY; //add the velocities to x and y xStart += xVelocity; yStart += yVelocity; if (Math.abs(xVelocity) < 1) xVelocity = 0.0; //right side overBounce = xStart - 405; if (overBounce > 0) { xStart -= 2.0*overBounce; xVelocity *= -1.0; xVelocity *= ENERGYLOSS; yVelocity *= ENERGYLOSS; } overBounce = xStart - 5; if (overBounce < 0) { xStart -= 2.0*overBounce; xVelocity *= -1.0; xVelocity *= ENERGYLOSS; yVelocity *= ENERGYLOSS; } overBounce = yStart - 295; if(overBounce > 0) { yStart -= 2.0*overBounce; yVelocity *= -1.0; xVelocity *= ENERGYLOSS; yVelocity *= ENERGYLOSS; if (Math.abs(yVelocity) < 2) { yVelocity = 0.0; if (Math.abs(xVelocity) < 1) { notDone = false; } } } double distance = Math.sqrt((xStart-TARGETX)*(xStart-TARGETX) + (yStart-TARGETY)*(yStart-TARGETY)); //if distance <= sum of radii //sleep MyroUtils.sleep(0.01); circle.invisible(); } //int xEnd = MyroUtils.randomInt(50, 360); //int yEnd = MyroUtils.randomInt(50, 250); /* if (MyroUtils.randomInt(1,10) < 10) { MyroLine line = new MyroLine(myCanvas, xStart, yStart, xEnd, yEnd); line.setOutlineColor(new java.awt.Color(r,g,b) ); line.visible(); } else { MyroCircle circle = new MyroCircle(myCanvas, xStart, yStart, 10); circle.setOutlineColor(new java.awt.Color(r,g,b)); circle.setFillColor(new java.awt.Color(b,r,g)); circle.makeFilled(); circle.invisible(); } */ MyroUtils.sleep(0.001); } } }