/* * File: RingShadow.java * --------------------- * This program draws a ring and its shadow. This * version of the program draws several circles to make the rings * wider. Some coordinate values are explicit. * * As of Chapter 2, you don't yet have methods or the loop * statements and would therefore have to write this program * using a single unsubdivided run method; * this code shows the program as you will eventually write it. * * Author: CS1MD3 */ import acm.graphics.*; import acm.program.*; import java.awt.*; public class RingShadow extends GraphicsProgram { public void run() { /* draw the shadow */ addRing(250, 180, Color.GRAY); /* draw the ring above the shadow */ addRing(250, 150, Color.YELLOW); } /* * Adds a ring to the canvas at position (*x*, *y*) and of color * *color*. The radius of the ring is RING_RADIUS and the thickness * is THICKNESS pixels. */ private void addRing(int x, int y, Color color) { int height = RING_RADIUS / 2; /* draw ring THICKNESS times to make the ring wider */ for (int i = 0; i < THICKNESS; i++) { GOval ring = new GOval(x + i, y + i, 2 * (RING_RADIUS - i), 2 * (height - i)); ring.setColor(color); ring.setFilled(false); add(ring); } /* for i */ } /* addRing */ /* Private constants */ private static final int RING_RADIUS = 100; private static final int THICKNESS = 10; }