sclass AnimatedLine { int w = 128, h = 128, maxSpeed = 1; int y, speed; Graphics2D g; void setSize(int w, int h) { this.w = w; this.h = h; } void setGraphics(Graphics2D g) { this.g = g; } void start { y = random(h); newSpeed(); } void newSpeed { speed = random(-maxSpeed, maxSpeed); } void paint { fillRect(g, 0, 0, w, h, Color.white); drawLine(g, 0, y, w, y, Color.black); } void nextFrame { if (oneIn(20)) newSpeed(); y = clamp(y+speed, 0, h-1); } }