-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandomWalkComponent.java
43 lines (35 loc) · 1002 Bytes
/
RandomWalkComponent.java
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
import java.awt.Graphics;
import javax.swing.JComponent;
public class RandomWalkComponent extends JComponent {
/**
*
*/
private static final long serialVersionUID = 1L;
Drunkard walk;
// public void paintComponent(Graphics g) {
// super.paintComponent(g);
// }
public RandomWalkComponent(Drunkard walk) {
this.walk = walk;
// step = walk.theStepSize;
// for(int i = 0; i < step; i++) {
// origX = walk.getCurrentLoc().getX();
// origY = walk.getCurrentLoc().getY();
// walk.takeStep();
// postX = walk.getCurrentLoc().getX();
// postY = walk.getCurrentLoc().getY();
// paintComponent(g);
// }
}
public void paintComponent(Graphics g) {
// super.paintComponent;
for(int i = 0; i < walk.theStepSize; i++) {
int origX = walk.getCurrentLoc().getX();
int origY = walk.getCurrentLoc().getY();
walk.takeStep();
int postX = walk.getCurrentLoc().getX();
int postY = walk.getCurrentLoc().getY();
g.drawLine(origX, origY, postX, postY);
}
}
}