Repository navigation
Expand file tree
/
Copy pathacceleration.js
More file actions
86 lines (74 loc) · 2.07 KB
/
Copy pathacceleration.js
File metadata and controls
86 lines (74 loc) · 2.07 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
let mover;
function setup() {
createCanvas(640, 240);
mover = new Mover();
}
function draw() {
background(255);
mover.update();
mover.checkEdges();
mover.show();
}
class Mover {
constructor() {
this.position = createVector(width / 2, height / 2);
this.velocity = p5.Vector.random2D();
this.perlinOffset = createVector(0, 1000);
//this.acceleration = createVector(0, 0);
this.acceleration = p5.Vector.random2D();
}
update() {
this.acceleration.add(createVector(
map(noise(this.perlinOffset.x), 0, 1, -3, 3),
map(noise(this.perlinOffset.y), 0, 1, -3, 3)
));
//this.acceleration.mult(random(2));
this.velocity.add(this.acceleration);
this.velocity.limit(10);
print(`velocity ${this.velocity}`);
this.position.add(this.velocity);
this.perlinOffset.add(1, 1);
}
show() {
stroke(0);
strokeWeight(2);
fill(127);
circle(this.position.x, this.position.y, 48);
}
checkEdges() {
if (this.position.x > width) {
this.position.x = 0;
} else if (this.position.x < 0) {
this.position.x = width;
}
if (this.position.y > height) {
this.position.y = 0;
} else if (this.position.y < 0) {
this.position.y = height;
}
}
step() {
this.position = createVector(
map(noise(this.velocity.x), 0, 1, 0, width),
map(noise(this.velocity.y), 0, 1, 0, height)
);
this.velocity = this.velocity.add(0.01, 0.01);
}
}
class PerlinStep {
constructor() {
this.velocity = createVector(0, 10000);
}
step() {
this.position = createVector(
map(noise(this.velocity.x), 0, 1, 0, width),
map(noise(this.velocity.y), 0, 1, 0, height)
);
this.velocity = this.velocity.add(0.01, 0.01);
}
show() {
stroke('orange');
strokeWeight(1);
ellipse(this.position.x, this.position.y, 16, 16);
}
}