Next <==>
All
-rw-r--r-- 1 kinzler www 1816 Apr 9 1996 StackedRects.class
-rw-r--r-- 1 kinzler www 1776 Apr 9 1996 StackedRects.java
<applet code=StackedRects.class width=150 height=75>
Cannot run the StackedRects applet.
</applet>
import java.applet.Applet;
import java.awt.*;
///////////////////////////////////////////////////////////////////////////////
// StackedRects // Declaration ////////////////////////////////////////////////
public class StackedRects extends Applet {
int width = 480, height = 280; // 4x4 minimum
int thick = 10;
String url = "http://www.cs.indiana.edu/hyplan/kinzler/fun/"
+ "StackedRects/index.html";
public String getAppletInfo() {
return
"StackedRects - a continuous, random graphic of overlaying rectangles\n"
+ "Development version 00: display a single random rectangle pair\n"
+ "Steve Kinzler, kinzler@cs.indiana.edu, Nov 95/Mar 96\n" + url;
}
// StackedRects // Initialization /////////////////////////////////////////////
public void init() {
Dimension d = size();
if (d.width >= 4) width = d.width;
if (d.height >= 4) height = d.height;
resize(width, height);
}
// StackedRects // Graphics ///////////////////////////////////////////////////
public void paint(Graphics g) {
double maxa = width / 2.0 - 2.0 * thick;
double maxb = height / 2.0 - 2.0 * thick;
int a = (int) (Math.random() * maxa);
int b = (int) (Math.random() * maxb);
int x = width - 1 - (int) (Math.random() * maxa);
int y = height - 1 - (int) (Math.random() * maxb);
int t = thick;
int w = x - a + 1;
int h = y - b + 1;
g.setColor(getForeground());
g.fillRect(a, b, w, t);
g.fillRect(a, y-t+1, w, t);
g.fillRect(a, b, t, h);
g.fillRect(x-t+1, b, t, h);
g.setColor(getBackground());
g.fillRect(a+t, b+t, w-t-t, t);
g.fillRect(a+t, y-t-t+1, w-t-t, t);
g.fillRect(a+t, b+t, t, h-t-t);
g.fillRect(x-t-t+1, b+t, t, h-t-t);
}
}