/
index.html
150 lines (137 loc) · 3.45 KB
/
index.html
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<html>
<head>
<meta charset="UTF-8">
<title>Particle.js</title>
<script src="build/particle.js"></script>
<script src="main.js"></script>
<style>
html, body, canvas {
padding: 0;
margin: 0;
}
#canvas button {
position: fixed;
top: 10px;
left: 10px;
}
.codearea {
display: block;
}
.codearea textarea, .codearea p {
display: inline-block;
}
</style>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-61180804-2', 'auto');
ga('send', 'pageview');
</script>
</head>
<body>
<div id="form">
<label for="behavior">Presets:</label>
<button onclick="selectPreset('ocean')">Ocean</button>
<button onclick="selectPreset('blackhole')">Black Hole</button>
<button onclick="selectPreset('sinwave')">Sin Wave</button>
<br>
<div class="codearea">
<textarea name="behavior" id="behavior" cols="50" rows="40" style="font-family: monospace;">
{
pathType: 'multivariate',
baseX: 500,
baseY: 500,
path: function(t) {
t = t % 10;
if (t < 2.5) {
return [10, 0];
} else if (t < 5) {
return [0, 10];
} else if (t < 7.5) {
return [-10, 0];
} else {
return [0, -10];
}
var y = 0;
var x = t;
return [x, y];
},
speed: function() {
return 0 + (Math.random() * 1);
},
offset: function() {
return (Math.random() * 3) - 1.5;
},
backgroundColor: 'rgba(52, 152, 219, 1.0)',
color: function() {
var rn = Math.random();
if (rn < 0.2) {
return 'rgba(255, 255, 255, 1.0)';
} else if (rn < 0.4) {
return 'rgba(255, 255, 255, 0.6)';
} else if (rn < 0.6) {
return 'rgba(41, 128, 185,1.0)';
} else if (rn < 0.8) {
return 'rgba(26, 188, 156,1.0)';
} else {
return 'rgba(46, 204, 113,1.0)';
}
},
size: 3,
count: 100,
placement: 'linear'
}
</textarea>
<textarea readonly cols="50" rows="40" style="font-family: monospace; opacity: 0.5;">
// EXAMPLE CONFIGURATION
{
// path() function defines the path
// the particle follows
path: function(x) {
var y = 50 * Math.sin(x / 100);
return y;
},
// speed() calculates a one time
// constant speed that determines
// the incrementation rate of x
speed: function() {
return 2 + (Math.random() * 4);
},
// offset() generates a percentage (decimal)
// that spreads the particles out over
// the canvas
offset: function() {
return (Math.random() * 3) - 1.5;
},
// defines the background color
backgroundColor: 'rgba(52, 152, 219, 1.0)',
// color() is called once for each particle
// to generate their color
color: function() {
var rn = Math.random();
if (rn < 0.5) {
return 'rgba(255, 255, 255, 1.0)';
} else {
return 'rgba(46, 204, 113,1.0)';
}
},
// size of each particle
size: 3,
// number of particles
count: 5000,
// ¯\_(ツ)_/¯
placement: 'random'
}
</textarea>
</div>
<br>
<button onclick="submitBehavior()">Run it!</button>
</div>
<div id="canvas" style="display: none;">
<button onclick="returnToMenu()">Go back</button>
<canvas id="particles"></canvas>
</div>
</body>
</html>