-
Notifications
You must be signed in to change notification settings - Fork 0
/
atomshape.js
74 lines (67 loc) · 1.69 KB
/
atomshape.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
function atomShape(x, y, d, h, n) {
this.x = x;
this.y = y;
this.dia = d;
this.h = h;
this.n = n;
this.a = 0;
this.overlap = false;
this.clicked = false;
this.col = color(random(255), random(255), random(255), 25);
this.rotspeed = random(0.5, 3);
this.moveSpeed = random(1.0);
this.display = function() {
push();
smooth();
/*
if overlap -> display with this grey stroke , fill half
else if clicked -> display with wide stroke regular fill
else -> display this stroke regular fill
*/
if (this.overlap)
{
stroke(100,100,100,50);
strokeWeight(1);
fill(red(this.col),green(this.col),blue(this.col),alpha(this.col)*0.5);
}
else if (this.clicked){
stroke(0,0,0,50);
strokeWeight(3);
fill(this.col);
}
else
{
fill(this.col);
stroke(0,0,0,100);
strokeWeight(1);
}
translate(this.x, this.y);
rotate(this.a);
for (i = 0; i < this.n; i++) {
rotate( 180.0 / this.n);
ellipse(0, 0, this.dia, this.h)
}
pop();
this.a = this.a + this.rotspeed;
}
this.update = function() {
this.x = this.x + random(this.moveSpeed * -1, this.moveSpeed);
this.y = this.y + random(this.moveSpeed * -1, this.moveSpeed);
}
//
this.beingClicked = function() {
var d = dist(mouseX, mouseY, this.x, this.y);
if (d < this.dia) {
return true;
} else {
return false;
}
}
this.intersectsWith = function(anotherAtom) {
if (dist(this.x, this.y, anotherAtom.x, anotherAtom.y) < ((this.dia * 0.5) + (anotherAtom.dia * 0.5))) {
return true;
} else {
return false;
}
}
}