/* * Program that draws concentric circles of varying closeness. */ import objectdraw.*; import java.awt.*; public class CrazyCircles extends FrameWindowController { public void onMouseMove(Location point) { canvas.clear(); Location center = new Location(canvas.getWidth() / 2, canvas.getHeight() / 2); // get the distance from the current mouse point // to the center of the canvas double distanceToCenter = center.distanceTo(point); if (distanceToCenter == 0) { return; } // now, using a loop, write code that draws concentric circles, // where the radius of the innermost circle is the same as // the distance from the mouse point to the center of the canvas, // the radius of the next circle is twice that distance, the // radius of the next one is 3 times that distance, etc. // the circles should be drawn until the diameter of the last // circle drawn is >= the width of the canvas double currentCircleX = center.getX(); double currentCircleY = center.getY(); double radius = 0; while (radius < canvas.getWidth()) { currentCircleX = currentCircleX - distanceToCenter; currentCircleY = currentCircleY - distanceToCenter; radius = radius + distanceToCenter; new FramedOval(currentCircleX, currentCircleY, radius * 2, radius * 2, canvas); } } }