import java.awt.*; public class AnimatedColor { public static void main(String[] args) { DrawingPanel p = new DrawingPanel(300, 300); Graphics g = p.getGraphics(); // This is a forever loop // If you do this in your animations you won't be able // to save them as an image for(;;) { // Animate from white to green for (int i = 255; i > 0; i-=5) { drawCircle(p, g, i); } // Animate from green to whtie for (int i = 0; i < 255; i+=5) { drawCircle(p, g, i); } } } // Erases the canvas // Draws a circle at 100, 100 of size 100 and color shade, 255, shade // Sleeps the panel for 1/20 of a second public static void drawCircle(DrawingPanel p, Graphics g, int shade) { g.setColor(Color.WHITE); g.drawRect(0, 0, 300, 300); g.setColor(new Color(shade, 255, shade)); g.fillOval(100, 100, 100, 100); p.sleep(50); } }