// Leaf.java - fractal animation for arcadia play // // adapted from fractal4.p // // Daniel Scharstein 9/28/2003 import java.applet.*; import java.awt.*; import java.util.*; public class Leaf3 extends Applet { LeafCanvas3 c; public void init () { setLayout(new BorderLayout()); add("South", new Button("Clear")); int psize = 1; // pointsize for drawing (1 or 2) c = new LeafCanvas3(psize); c.setBackground(new Color(0, 0, 120)); add("Center", c); } public boolean action(Event evt, Object arg) { if (evt.target instanceof Button) { if ("Clear".equals(arg)) { c.clear(); return true; } } // other events should be handled by superclass return super.action(evt, arg); } } class LeafCanvas3 extends Canvas { Vector v = new Vector(); Random rand = new Random(); // new Random(seed) int count = 0; int rad = 1; // point size (1 or 2) public LeafCanvas3(int psize) { rad = psize; } Image offscreen; Dimension offscreensize; Graphics offgraphics; // update() is like paint(), except it doesn't erase the old image first public void update(Graphics g) { Dimension d = size(); // initially (or when size changes) create new image if ((offscreen == null) || (d.width != offscreensize.width) || (d.height != offscreensize.height)) { offscreen = createImage(d.width, d.height); offscreensize = d; offgraphics = offscreen.getGraphics(); offgraphics.setFont(getFont()); } // erase old contents in first few iterations if (count < 30) { offgraphics.setColor(getBackground()); offgraphics.fillRect(0, 0, d.width, d.height); } // now, draw as usual, but use offgraphics instead of g // draw all circles offgraphics.setColor(Color.yellow); for (int i=0; i