import java.awt.*;
import java.applet.*;
import java.lang.*;
public class Logistic extends Applet
{
Graphics bG;
Graphics sG;
Image bI;
Color back = new Color(247, 243, 234);
Color cobback = new Color(192, 255, 192);
Color coblines = new Color(0, 255, 0);
Color timeback = new Color(192, 192, 255);
Color timelines = new Color(0, 0, 255);
Color function = new Color(255, 0, 0);
Color diagonal = new Color(0, 0, 0);
Color ameter = new Color(255, 192, 192);
Color black = new Color(0, 0, 0);
double x, y, ox, oy, px, py;
double C = 1000;
double a = 2.8;
double start = 50.0;
int n = 40;
int ok;
int k;
public void init()
{
bI = createImage(this.size().width, this.size().height);
bG = bI.getGraphics();
ox = start;
oy = start;
ok = 0;
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 cyscale(double z)
{
int iy;
iy = (int) java.lang.Math.round(205 - 200 * z / C);
return iy;
}
public int cxscale(double z)
{
int ix;
ix = (int) java.lang.Math.round(5 + 200 * z / C);
return ix;
}
public int txscale(int z)
{
int ix;
ix = (int) (215 + java.lang.Math.round(z * 200.0 / n));
return ix;
}
public int ascale(double z)
{
int ix;
ix = (int) (10 + java.lang.Math.round((a - 2) * 200));
return ix;
}
public void drawback()
{
bG.setColor(back);
bG.fillRect(0, 0, 421, 251);
bG.setColor(cobback);
bG.fillRect(5, 5, 201, 201);
bG.setColor(timeback);
bG.fillRect(215, 5, 201, 201);
bG.setColor(coblines);
for (int iy = 5; iy < 206; iy = iy + 20)
{
bG.drawLine(5, iy, 205, iy);
bG.drawLine(iy, 5, iy, 205);
}
bG.setColor(timelines);
for (int iy = 5; iy < 206; iy = iy + 20)
{
bG.drawLine(215, iy, 415, iy);
}
for (int iy = 0; iy < n + 1; iy = iy + 10)
{
bG.drawLine(txscale(iy), 5, txscale(iy), 205);
}
bG.setColor(diagonal);
bG.drawLine(5, 205, 205, 5);
bG.setColor(function);
px = 0;
py = 0;
for (int i = 1; i < 201; i = i + 1)
{
x = px + C / 200.0;
y = x * a * (1 - x / C);
bG.drawLine(cxscale(px), cyscale(py), cxscale(x), cyscale(y));
px = x;
py = y;
}
bG.setColor(ameter);
bG.fillRect(10, 215, ascale(a) - 9, 31);
bG.setColor(black);
bG.drawLine(10, 215, 10, 245);
bG.drawLine(210, 215, 210, 245);
bG.drawLine(410, 215, 410, 245);
bG.drawLine(10, 230, 410, 230);
for (int ix = 10; ix < 415; ix = ix + 20)
{
bG.drawLine(ix, 225, ix, 235);
}
bG.fillOval(txscale(0) - 2, cyscale(start) - 2, 5, 5);
bG.fillOval(cxscale(start) - 2, cyscale(0) - 2, 5, 5);
bG.drawLine(cxscale(start), cyscale(0), cxscale(start), cyscale(start));
}
public boolean mouseDown(Event evt, int mx, int my)
{
if (my < 190)
{
k = ok + 1;
x = a * (1 - ox/C) * ox;
y = x;
bG.setColor(black);
bG.drawLine(cxscale(ox), cyscale(oy), cxscale(ox), cyscale(y));
bG.drawLine(cxscale(ox), cyscale(y), cxscale(x), cyscale(y));
bG.fillOval(cxscale(ox) - 1, cyscale(y) - 1, 3, 3);
if (k < n + 1)
{
bG.drawLine(txscale(ok), cyscale(oy), txscale(k), cyscale(y));
bG.fillOval(txscale(k) - 1, cyscale(y) - 1, 3, 3);
}
ok = k;
ox = x;
oy = y;
}
if (my > 215)
{
mx = java.lang.Math.max(mx, 10);
mx = java.lang.Math.min(mx, 410);
a = 2.0 + (mx - 10.0)/200.0;
ox = start;
oy = start;
ok = 0;
drawback();
}
if (java.lang.Math.abs(my - cyscale(0)) < 10)
{
mx = java.lang.Math.max(mx, 5);
mx = java.lang.Math.min(mx, 205);
start = C * (mx - 5.0)/200.0;
ox = start;
oy = start;
ok = 0;
drawback();
}
sG.drawImage(bI, 0, 0, this);
return true;
}
}
Copyright c 1997 by
Frank Wattenberg, Department of Mathematics, Montana State University,
Bozeman, MT 59717