Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// JavaLine.java
// (c) Neil Gershenfeld 9/1/97
// demonstrates Java by animating sin(k*x)/k*x
//
import java.awt.Graphics;
public class JavaLine extends java.applet.Applet
implements Runnable {
Thread T;
final int NPTS = 500;
final int NSTEPS = 100;
int point,step;
int x[] = new int[NPTS];
int y[] = new int[NPTS];
public void start() {
if (T == null) {
T = new Thread(this);
T.start();
}
}
public void stop() {
if (T != null) {
T = null;
}
}
public void run() {
double r;
while (true) {
for (step = 1; step < NSTEPS; ++step) {
for (point = 0; point < (NPTS-1); ++point) {
r = 100 * (step*(point+0.5-NPTS/2))/(NPTS*NSTEPS);
x[point] = point;
y[point] = (int) ((NPTS/2) - (NPTS/2)*Math.sin(r)/r);
}
repaint();
try {Thread.sleep(10);}
catch (InterruptedException e) { }
}
}
}
public void paint(Graphics g) {
for (point = 1; point < (NPTS-1); ++point) {
g.drawLine(x[point-1],y[point-1],x[point],y[point]);
}
}
}