-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvet2.html
More file actions
40 lines (35 loc) · 1.1 KB
/
vet2.html
File metadata and controls
40 lines (35 loc) · 1.1 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
<html>
<head>
<title>Vector 2 - Adding Vectors</title>
<script src="https://cdn.jsdelivr.net/npm/p5@1.5.0/lib/p5.min.js"></script>
<script>
class Walker {
constructor(x, y) {
this.pos = createVector(width / 2, height / 2);
this.velocity = createVector(1, -1);
}
update() {
// this.pos.x += this.velocity.x;
// this.pos.y += this.velocity.y;
this.pos.add(this.velocity);
}
show() {
stroke(255);
strokeWeight(3);
fill(255, 100);
ellipse(this.pos.x, this.pos.y, 32);
}
}
var walker;
function setup() {
createCanvas(200, 200);
walker = new Walker();
}
function draw() {
background(0);
walker.update();
walker.show();
}
</script>
</head>
</html>