import java.awt.*;
import java.applet.*;
import java.lang.*;
class Source
{ public int top = 5;
public int left;
public Color button_back;
public Color button_marker;
public int marker_x = 0;
public int marker_y = 0;
public double vx = 0;
public double vy = 0;
public double vz = 1;
public boolean in_button(int x, int y)
{ return(((x - left - 50) * (x - left - 50) +
(y - top - 50) * (y - top - 50)) < 2500);
}
public void place_button(int x, int y)
{ marker_x = x - left - 50;
marker_y = y - top - 50;
vx = marker_x/50.0;
vy = -marker_y/50.0;
vz = java.lang.Math.sqrt(1 - vx * vx - vy * vy);
}
public void draw_button(Graphics g)
{ g.setColor(button_back);
g.fillOval(left, top, 100, 100);
g.setColor(button_marker);
g.fillOval(marker_x + left + 47, marker_y + 50, 6, 6);
}
public Source(int left, Color button_back, Color button_marker)
{ this.left = left;
this.button_back = button_back;
this.button_marker = button_marker;
}
}
public class Monochrome extends Applet
{
Graphics bG;
Image bI;
public void init()
{
bI = createImage(this.size().width, this.size().height);
bG = bI.getGraphics();
}
public void update(Graphics g)
{
paint(g);
}
Source white =
new Source(110, new Color(64, 64, 64), new Color(255, 255, 255));
public boolean mouseDown(Event evt, int x, int y)
{ if (white.in_button(x, y))
{ white.place_button(x, y);
repaint();
}
return true;
}
public void paint(Graphics g)
{ int countx, county;
double x, y, z;
double workreal;
int work;
white.draw_button(bG);
for (countx = 2; countx < 103; countx = countx + 1)
{ for (county = 5; county < 106; county = county + 1)
{ x = (countx - 52.0) / 50.0;
y = -(county - 55.0) / 50.0;
if (x * x + y * y < 1.0)
{ z = java.lang.Math.sqrt(1 - x * x - y * y);
workreal = x * white.vx + y * white.vy +
z * white.vz;
workreal = java.lang.Math.max(0.0, workreal);
work = (int) java.lang.Math.round(workreal * 255);
bG.setColor(new Color(work, work, work));
bG.drawRect(countx, county, 1, 1);
}
if (x * x + y * y >= 1.0)
{ bG.setColor(Color.black);
bG.drawRect(countx, county, 1, 1);
}
}
g.drawImage(bI, 0, 0, this);
}
}
}
Copyright c 1995 by Frank Wattenberg Department of Mathematics, Carroll College, Helena, MT 59625.