import java.awt.*;
import java.applet.*;
import java.lang.*;
public class Onevar extends Applet
{
Graphics bG;
Graphics sG;
Image bI;
Color back = new Color(247, 243, 234);
Color pback = new Color(192, 255, 192);
Color plines = new Color(0, 255, 0);
Color tback = new Color(192, 192, 255);
Color tlines = new Color(0, 0, 255);
Color black = new Color(0, 0, 0);
Color origin = new Color(255, 0, 255);
Color pcolor = new Color(255, 0, 0);
double m = 0.5;
double pstart = 0.5;
double thigh = 8.0;
int ip;
int running = 0;
public void init()
{
bI = createImage(this.size().width, this.size().height);
bG = bI.getGraphics();
drawback();
}
public void paint(Graphics g)
{
g.drawImage(bI, 0, 0, this);
sG = getGraphics();
}
public void update(Graphics g)
{
g.drawImage(bI, 0, 0, this);
}
public int fscale(double y)
{
int k;
k = (int) java.lang.Math.round(100 - 100 * y);
return k;
}
public int leftpscale(double y)
{
int k;
k = (int) java.lang.Math.round(100.0 + 100.0 * y);
return k;
}
public int rightpscale(double y)
{
int k;
k = (int) java.lang.Math.round(100.0 - 100.0 * y);
return k;
}
public int tscale(double t)
{
int k;
k = (int) java.lang.Math.round(250.0 + 250.0 * t/thigh);
return k;
}
public double solution(double t)
{
double z;
z = pstart * java.lang.Math.exp(m * t);
return z;
}
public void drawback()
{
bG.setColor(back);
bG.fillRect(0, 0, 501, 251);
bG.setColor(pback);
bG.fillRect(0, 0, 201, 201);
bG.setColor(tlines);
bG.fillRect(250, 220, 251, 21);
bG.setColor(tback);
bG.fillRect(253, 223, 245, 15);
bG.setColor(tback);
bG.fillRect(250, 0, 251, 201);
bG.setColor(pcolor);
bG.drawLine(0, 100, 201, 100);
bG.drawLine(0, 220, 201, 220);
bG.drawLine(250, 0, 250, 200);
for (int i = 0; i < 201; i = i + 10)
{
bG.setColor(tlines);
bG.drawLine(250, i, 500, i);
bG.setColor(plines);
bG.drawLine(i, 0, i, 200);
}
bG.setColor(black);
bG.drawLine(0, fscale(-m), 200, fscale(m));
bG.setColor(origin);
bG.fillOval(98, 98, 5,5);
bG.fillOval(98, 218, 5, 5);
bG.fillOval(248, 98, 5, 5);
bG.setColor(black);
for (int i = 10; i < 95; i = i + 30)
{
bG.drawLine(i, 240, i + 20, 240);
}
for (int i = 110; i < 195; i = i + 30)
{
bG.drawLine(i, 240, i + 20, 240);
}
if (m > 0)
{
bG.drawLine(10, 240, 12, 238);
bG.drawLine(10, 240, 12, 242);
bG.drawLine(40, 240, 42, 238);
bG.drawLine(40, 240, 42, 242);
bG.drawLine(70, 240, 72, 238);
bG.drawLine(70, 240, 72, 242);
bG.drawLine(130, 240, 128, 238);
bG.drawLine(130, 240, 128, 242);
bG.drawLine(160, 240, 158, 238);
bG.drawLine(160, 240, 158, 242);
bG.drawLine(190, 240, 188, 238);
bG.drawLine(190, 240, 188, 242);
}
if (m < 0)
{
bG.drawLine(30, 240, 28, 238);
bG.drawLine(30, 240, 28, 242);
bG.drawLine(60, 240, 58, 238);
bG.drawLine(60, 240, 58, 242);
bG.drawLine(90, 240, 88, 238);
bG.drawLine(90, 240, 88, 242);
bG.drawLine(110, 240, 112, 238);
bG.drawLine(110, 240, 112, 242);
bG.drawLine(140, 240, 142, 238);
bG.drawLine(140, 240, 142, 242);
bG.drawLine(170, 240, 172, 238);
bG.drawLine(170, 240, 172, 242);
}
ip = leftpscale(pstart);
bG.drawLine(ip, 216, ip, 208);
bG.drawLine(ip, 216, ip + 2, 214);
bG.drawLine(ip, 216, ip - 2, 214);
ip = rightpscale(pstart);
bG.drawLine(238, ip, 246, ip);
bG.drawLine(244, ip + 2, 246, ip);
bG.drawLine(244, ip - 2, 246, ip);
}
public boolean mouseDown(Event evt, int mx, int my)
{
if (running == 1)
{
return true;
}
if ((mx < 205) && (mx > 195) && (my < 201))
{
m = (100.0 - my)/100.0;
drawback();
sG.drawImage(bI, 0, 0, this);
}
if ((my > 210) && (mx < 201))
{
pstart = (mx - 100)/100.0;
drawback();
sG.drawImage(bI, 0, 0, this);
}
if ((mx > 225) && (mx < 270) && (my < 201))
{
pstart = (100 - my)/100.0;
drawback();
sG.drawImage(bI, 0, 0, this);
}
if ((my > 219) && (my < 241) && (mx > 249))
{
simulate();
}
return true;
}
public void simulate()
{
double ot, nt, op, np, sp, st, check;
nt = 0;
np = pstart;
running = 1;
drawback();
bG.setColor(black);
bG.fillOval(leftpscale(pstart) - 3, 217, 7, 7);
sG.drawImage(bI, 0, 0, this);
for(int i = 5; i < 251; i = i + 5)
{
check = solution(thigh * (i - 5) /250);
if ((check < 1) && (check > -1))
{
drawback();
bG.setColor(black);
st = thigh * i / 250.0;
sp = solution(st);
bG.fillOval(leftpscale(sp) - 3, 217, 7, 7);
for(int j = 5; j < i + 1; j = j + 5)
{
ot = thigh * (j - 5)/250.0;
nt = thigh * j/250.0;
op = solution(ot);
np = solution(nt);
bG.drawLine(tscale(ot), rightpscale(op),
tscale(nt), rightpscale(np));
}
bG.fillOval(tscale(nt) - 3, rightpscale(np) - 3, 7, 7);
sG.drawImage(bI, 0, 0, this);
}
}
running = 0;
}
}
Copyright c 1997 by
Frank Wattenberg, Department of Mathematics, Montana State University,
Bozeman, MT 59717