// Display an interactive dancing stick figure import java.awt.*; import java.net.*; import java.util.*; public class StickFigureApplet extends GenericApplet { GraphicFigure f; public void render(Graphics g) { if (damage) { if (f == null) f = new GraphicFigure(getCodeBase(), "StickFigure"); g.setColor(Color.white); g.fillRect(0, 0, bounds().width, bounds().height); g.setColor(Color.black); f.render(g); } } double t = 0.; public boolean mouseDrag(Event e, int x, int y) { damage = true; t += .2; for (int i = 0 ; i < f.size() ; i++) if (f.name(i) != null) { f.matrix(i).rotateX(1.2*Math.cos( i + .678*t)); f.matrix(i).rotateY(1.2*Math.cos(.9*i + .890*t)); f.matrix(i).rotateZ(1.2*Math.cos(.8*i + t)); } return true; } } class GraphicFigure extends KVMFile { GraphicFigure(URL context, String URLName) { super(context, URLName); } Graphics g; public void render(Graphics g) { this.g = g; super.render(); } public void drawLine(double x1, double y1, double x2, double y2) { g.drawLine((int)(3*x1), (int)(3*y1), (int)(3*x2), (int)(3*y2)); } public void drawJoint(String name, double x, double y) { } }