-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathSketch.java
More file actions
54 lines (47 loc) · 1.18 KB
/
Sketch.java
File metadata and controls
54 lines (47 loc) · 1.18 KB
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
51
52
53
54
import java.util.ArrayList;
import processing.core.PApplet;
public class Sketch extends PApplet {
final int WIDTH = 400;
final int HEIGHT = 100;
final int WALKER_COUNT = 50;
ArrayList<Walker> walkers;
public void settings() {
size(400, 100);
walkers = new ArrayList<Walker>();
for(int i=0; i<WALKER_COUNT; i++)
walkers.add( new Walker(this,WIDTH,HEIGHT,1) );
for(int i=0; i<WALKER_COUNT; i++)
walkers.add( new Walker(this,WIDTH,HEIGHT,0) );
System.out.println(walkers);
}
public void setup() {
background(152, 190, 100);
}
public void draw() {
background(152, 190, 100);
walkers.sort( (w1,w2) -> Float.compare(w1.x, w2.x) );
for(int i=0; i<WALKER_COUNT*2; i++)
{
Walker w = walkers.get(i);
if(w.dx>0)
{
for(int j=i+1; j<WALKER_COUNT*2; j++)
{
if( w.lookForward(walkers.get(j)) )
break;
}
}
else
{
for(int j=i-1; j>=0; j--)
{
if( w.lookForward(walkers.get(j)) )
break;
}
}
}
walkers.forEach( (w) -> w.oneStep() );
walkers.forEach( (w) -> w.show() );
delay(10);
}
}