-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
79 lines (56 loc) · 1.2 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
var bubbles = [];
function setup() {
createCanvas(window.innerWidth, window.innerHeight);
//frameRate(1000);
}
/*Esta funcion se remite alrededor de los 30fps*/
function draw() {
background(0);
var i;
var z;
for(i=0;i<bubbles.length;i++){
bubbles[i].move();
bubbles[i].display();
for(z=0;z<bubbles.length;z++){
if(z!=i && bubbles[i].collapse(bubbles[z])){
bubbles[i].speedX *= -1
bubbles[i].speedY *= -1;
}
}
}
}
function mousePressed(){
bubbles.push(new Bubble(mouseX,mouseY));
}
function Bubble(x,y){
this.x = x;
this.minusX = false;
this.y = y;
this.minusY = false;
this.r = random(10,20);
this.speedX = random(-2,2);
this.speedY = random(-2,2);
this.display = function(){
fill(255);
ellipse(this.x,this.y,this.r*2,this.r*2);
}
this.move = function(){
if(this.x > width || this.x < 0){
this.speedX *= -1;
}
if(this.y > height || this.y < 0){
this.speedY *= -1;
}
this.x = this.x+this.speedX;
this.y = this.y+this.speedY;
}
this.collapse = function(bubble){
var distancia = int(dist(this.x, this.y, bubble.x, bubble.y));
//alert(distancia);
if(distancia < this.r+bubble.r){
return true;
}else{
return false;
}
}
}