-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
64 lines (49 loc) · 1.17 KB
/
sketch.js
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
let center;
let velocity;
let mouse;
let dir;
let m;
function setup() {
createCanvas(640, 240);
}
function draw() {
background(255);
stroke(0);
fill(127);
if(center != null){
circle(center.x, center.y, 48);
center.add(velocity);
if (center.x > width || center.x < 0) {
velocity.x = velocity.x * -1;
}
if (center.y > height || center.y < 0) {
velocity.y = velocity.y * -1;
}
}
if(mouseIsPressed){
dir = null;
velocity = null;
mouse = createVector(mouseX, mouseY);
mouse.sub(center);
m = mouse.mag();
fill(0);
rect(0, 0, m, 10);
translate(center.x, center.y);
line(0,0, mouse.x,mouse.y);
}
}
function mousePressed(){
//console.log("Press");
center = createVector(mouseX, mouseY);
//circle(position.x, position.y, 48);
}
function mouseReleased(){
//console.log("release");
dir = p5.Vector.sub(mouse,createVector(0,0));
dir.normalize();
dir.mult(m/50);
console.log(m);
velocity = createVector(dir.x,dir.y);
velocity.add(dir);
velocity.limit(50);
}