// author: Rachel Gollub, 1995
// Bubbles!
import java.awt.*;
import java.applet.*;
public class test004 extends Applet implements Runnable {
Thread artist=null;
int bubble=0, thisbubble=0; // # of bubbles on screen, and current bubble
int MAXBUBBLES = 25; // Maximum bubbles on screen
int stepper = 4; // Counter for which bubbles to move when
int record[][] = new int[MAXBUBBLES][5]; // Array that holds bubbles
public void draw_bubble(int x, int y, int r, Color col, Graphics g) {
int i;
for (i=x-r; i<=x+r; i++) { // Draws a circle
g.setColor(col);
g.drawLine(i, y - (int)(Math.sqrt( r*r - ( (i-x)*(i-x) ))),
i, y + (int)(Math.sqrt( r*r - ( (i-x)*(i-x) ))));
}
}
public void move_bubble(int x, int y, int r, Color col, int step, Graphics g) {
int i;
for (i=x-r; i<=x+r; i++) { // Draws the upper edge of a circle
g.setColor(col);
g.drawLine(i, y - (int)(Math.sqrt( r*r - ( (i-x)*(i-x) ))),
i, y + step - (int)(Math.sqrt( r*r - ( (i-x)*(i-x) ))));
}
for (i=x-r; i<=x+r; i++) { // Draws the lower edge of the circle
g.setColor(Color.black);
g.drawLine(i, y + (int)(Math.sqrt( r*r - ( (i-x)*(i-x) ))),
i, y + step + (int)(Math.sqrt( r*r - ( (i-x)*(i-x) ))));
}
}
public void paint(Graphics g) {
int i, j, tmp;
if (bubble < MAXBUBBLES || thisbubble < MAXBUBBLES) {
record[thisbubble][0]=(int)(Math.random() * 500);
record[thisbubble][1]=230;
record[thisbubble][2]=(int)(Math.random() * 500)/20;
record[thisbubble][3]=(int)(Math.random() * 255);
record[thisbubble][4]=(int)(Math.random() * 255);
draw_bubble(record[thisbubble][0],record[thisbubble][1],
record[thisbubble][2],new java.awt.Color(record[thisbubble][3],
record[thisbubble][4], 255), g);
if (bubble < MAXBUBBLES) {
bubble++; thisbubble++;
}
else
thisbubble = MAXBUBBLES;
}
for (i=0; i= -1; tmp = tmp - 2)
draw_bubble(record[i][0], record[i][1], record[i][2]-tmp,
Color.lightGray, g);
draw_bubble(record[j][0], record[j][1], record[j][2],
new java.awt.Color(record[j][3], record[j][4], 255), g);
record[i][1] = -1; record[i][2]=0;
}
}
}
if (record[i][1]+record[i][2] < 0 && bubble >= MAXBUBBLES) {
thisbubble = i;
}
stepper=(int)(Math.random()*10);
}
}
public void update(Graphics g) {
paint(g);
}
public void start() {
setBackground(Color.black);
artist = new Thread(this);
artist.start();
}
public void stop() {
artist = null;
}
public void run() {
while (artist != null) {
try {Thread.sleep(50);} catch (InterruptedException e){}
repaint();
}
artist = null;
}
}