-
Notifications
You must be signed in to change notification settings - Fork 0
/
Walker.java
51 lines (42 loc) · 1.28 KB
/
Walker.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
44
45
46
47
48
49
50
51
import processing.core.PApplet;
import java.util.Random;
public class Walker extends PApplet {
double x;
double y;
float t = 0.0f;
float tInc = 0.01f;
Random rand = new Random();
private PApplet sketch;
Walker(PApplet sketch) {
this.sketch = sketch;
x = (double) this.sketch.width/2;
y = (double) this.sketch.height/2;
}
void display() {
// this.sketch.stroke(0);
int R = (int) this.sketch.map(this.sketch.noise(1f, t), 0.0f, 1.0f, 0f, 255f);
int G = (int) this.sketch.map(this.sketch.noise(2f, t), 0.0f, 1.0f, 0f, 255f);
int B = (int) this.sketch.map(this.sketch.noise(3f, t), 0.0f, 1.0f, 0f, 255f);
this.sketch.stroke(R,G,B);
this.sketch.point((int) x, (int) y);
}
void step() {
// double stepx = rand.nextGaussian();
// double stepy = rand.nextGaussian();
double stepx = rand.nextInt(3) - 1;
double stepy = rand.nextInt(3) - 1;
x += stepx;
y += stepy;
t += tInc;
}
float montecarlo() {
while(true) {
float r1 = rand.nextFloat(1);
float probability = r1;
float r2 = rand.nextFloat(1);
if (r2 < probability) {
return r1;
}
}
}
}