-
Notifications
You must be signed in to change notification settings - Fork 0
/
intro.js
130 lines (90 loc) · 2.06 KB
/
intro.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
var w = []; // array of Jitter objects
var n, N = 10;
var down = true;
var hue ;
var strW, elpW;
function setup() {
var myCanvas = createCanvas(windowWidth/1.5,windowWidth/2.5);
myCanvas.parent("myBanner");
frameRate(20);
smooth();
imageMode(CENTER);
// Create walkers
for (var i=0; i<N; i++) {
w.push(new Walker());
}
n = 0;
// color defintions
colorMode(HSB);
background(255,40);
hue = random(250);
// for mobile
if(width>500) {
strW = 1.4; elpW = 2.0;
}
else {
strW = 0.8; elpW = 1.4;
}
}
function draw() {
noStroke();
fill(255,80);
rect(0,0,width,height);
var o = round(map(mouseX,0,width,1,8));
var f = map(mouseY, 0, height, 0.01, 0.8);
//noiseDetail(4,f);
if (frameCount % 30 == 0 ) {
if( down == true ) n--;
else n++;
}
if (n < 1) {
down = false;
n++;
hue = random(255);
}
if (n ==N) {down=true;}
for (var i = 0; i < n; i++) {
w[i].walk();
w[i].mouseRepel();
w[i].display();
for (var j = 0; j <= i; j++) {
if(i!=j){
strokeWeight(strW);
stroke(hue,200,160,30);
line(w[i].x,w[i].y,w[j].x,w[j].y);
}
}
}
if (frameCount % 10 == 0) hue=(hue+1)%255;
}
// Walker class
function Walker() {
this.x = random(width);
this.y = random(height);
this.px = this.x;
this.py = this.y;
this.noffx = this.x;
this.noffy = this.y;
// Display walker
this.display = function() {
fill(hue,60,120);
noStroke();
ellipse(this.x, this.y, elpW, elpW);
}
// Walk
this.walk =function() {
this.px = this.x;
this.py = this.y;
this.x = map(noise(this.noffx),0,1,0,width);
this.y = map(noise(this.noffy),0,1,0,height);
this.noffx += 0.01;
this.noffy += 0.01;
}
// Repel
this.mouseRepel =function() {
var deltax = map(mouseX, 0,width,width/10,-width/10);
var deltay = map(mouseY, 0,height,height/10,-height/10);
this.x = constrain(this.x+deltax,0,width);
this.y = constrain(this.y+deltay,0,height);
}
}