/* * Program that draws concentric circles of varying closeness. */ import objectdraw.*; import java.awt.*; public class CrazyCircles extends FrameWindowController { private Location center; public void begin() { center = new Location(canvas.getWidth() / 2, canvas.getHeight() / 2); } public void onMouseMove(Location point) { canvas.clear(); // get the distance from the current mouse point // to the center of the canvas double distanceToCenter = center.distanceTo(point); // 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 diameter = 0; while (diameter < canvas.getWidth()) { currentCircleX = currentCircleX - distanceToCenter; currentCircleY = currentCircleY - distanceToCenter; diameter = diameter + distanceToCenter * 2; new FramedOval(currentCircleX, currentCircleY, diameter, diameter, canvas); } } }