-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
190 lines (165 loc) · 6.06 KB
/
index.html
File metadata and controls
190 lines (165 loc) · 6.06 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Perlin Noise</title>
<!-- <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/p5@0.5.14/lib/p5.min.js"></script> -->
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/p5@latest/lib/p5.min.js"></script>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<main></main>
<script type="text/javascript">
var type;
var options = {
Background: '#0a0a0a',
Color1: '#ffffff',
Color2: '#0799f2',
Color3: '#45217c',
Length: 10,
Nums: 400,
Size: 2,
noiseScale: 800,
ColorMode: 'Normal',
Random: function () {
var Length = random(1, 50);
LengthControl.setValue(Length);
var Nums = random(200, 1000);
NumsControl.setValue(Nums);
var noiseScale = random(200, 4000);
noiseControl.setValue(noiseScale);
var Size = random(1, 4);
SizeControl.setValue(Size);
var Cmode = random(['Normal', 'Linera Gradient', 'Splice']);
ColorControl.setValue(Cmode);
setup();
},
Save: function () {
saveFrames("Perlin-Noise", "png", 1, 1);
},
}
var particles = [];
var maxLife;
function setup() {
console.log('Setup');
backgroundColor = color(options.Background);
createCanvas(windowWidth, windowHeight);
background(options.Background);
for (var i = 0; i < 2500; i++) {
particles[i] = new Particle();
}
}
function draw() {
console.log('Draw');
noStroke();
smooth();
maxLife = options.Length;
for (var i = 1; i < options.Nums; i++) {
var iterations = map(i, 0, options.Nums, 5, 1);
var radius = options.Size;
particles[i].move(iterations);
particles[i].checkEdge();
var alpha = 255;
var particleColor;
var fadeRatio;
fadeRatio = min(particles[i].life * 5 / maxLife, 1);
fadeRatio = min((maxLife - particles[i].life) * 5 / maxLife, fadeRatio);
var lifeRatioGrayscale = min(255, (255 * particles[i].life / maxLife) + red(backgroundColor));
if (options.ColorMode == 'Normal') {
if (i % 3 == 0) particleColor = options.Color1;
if (i % 3 == 1) particleColor = options.Color2;
if (i % 3 == 2) particleColor = options.Color3;
}
if (options.ColorMode == 'Linera Gradient') {
var percent1 = norm(particles[i].pos.x, 0, width / 2);
var percent2 = norm(particles[i].pos.x, width / 2, width);
from = color(options.Color1);
middle = color(options.Color2);
to = color(options.Color3);
between1 = lerpColor(from, middle, percent1);
between2 = lerpColor(middle, to, percent2);
if (particles[i].pos.x > 0 && particles[i].pos.x < width / 2) {
particleColor = between1;
} else {
particleColor = between2;
}
}
if (options.ColorMode == 'Radial Gradient') {
var distance = dist(particles[i].pos.x, particles[i].pos.y, width / 2, height / 2);
var percent1 = norm(distance, 0, 400);
var percent2 = norm(distance, 400, width / 2);
from = color(options.Color1);
middle = color(options.Color2);
to = color(options.Color3);
between1 = lerpColor(from, middle, percent1);
between2 = lerpColor(middle, to, percent2);
if (distance < 400) {
particleColor = between1;
} else {
particleColor = between2;
}
}
if (options.ColorMode == 'Splice') {
if (particles[i].pos.x >= width / 3 && particles[i].pos.x <= width / 3 * 2) {
if (i % 3 == 0) particleColor = options.Color1;
if (i % 3 == 1) particleColor = options.Color2;
if (i % 3 == 2) particleColor = options.Color3;
} else if (particles[i].pos.x < width / 3) {
if (i % 3 == 0) particleColor = 20;
if (i % 3 == 1) particleColor = 100;
if (i % 3 == 2) particleColor = 220;
} else if (particles[i].pos.x > width / 3 * 2) {
if (i % 3 == 0) particleColor = color(255 - red(options.Color1), 255 - green(options.Color1), 255 - blue(options.Color1));
if (i % 3 == 1) particleColor = color(255 - red(options.Color2), 255 - green(options.Color2), 255 - blue(options.Color2));
if (i % 3 == 2) particleColor = color(255 - red(options.Color3), 255 - green(options.Color3), 255 - blue(options.Color3));
}
}
fill(red(particleColor), green(particleColor), blue(particleColor), alpha * fadeRatio);
particles[i].display(radius);
}
}
function Particle() {
this.vel = createVector(0, 0);
this.pos = createVector(random(-50, width + 50), random(-50, height + 50));
this.life = random(0, maxLife);
this.move = function (iterations) {
if ((this.life -= 0.01666) < 0) this.respawn();
while (iterations > 0) {
var angle = noise(this.pos.x / options.noiseScale, this.pos.y / options.noiseScale) * TWO_PI * options.noiseScale;
this.vel.x = cos(angle);
this.vel.y = sin(angle);
this.vel.mult(0.2);
this.pos.add(this.vel);
--iterations;
}
}
this.checkEdge = function () {
if (this.pos.x > width || this.pos.x < 0 || this.pos.y > height || this.pos.y < 0) {
this.respawn();
}
}
this.respawn = function () {
this.pos.x = random(-50, width + 50);
this.pos.y = random(-50, height + 50);
this.life = maxLife;
}
this.display = function (r) {
ellipse(this.pos.x, this.pos.y, r, r);
}
}
function touchStarted() {
background(options.Background);
for (var i = 0; i < options.Nums; i++) {
particles[i].respawn();
particles[i].life = random(0, maxLife);
}
}
</script>
</body>
</html>