├── .gitignore
├── README.md
├── audio
├── DEMO_1.mp3
├── DEMO_2.mp3
├── DEMO_3.mp3
├── DEMO_4.mp3
└── DEMO_5.mp3
├── css
├── demo.css
└── normalize.css
├── favicon.ico
├── index.html
├── index2.html
├── index3.html
├── index4.html
├── index5.html
└── js
├── main1.js
├── main2.js
├── main3.js
├── main4.js
└── main5.js
/.gitignore:
--------------------------------------------------------------------------------
1 | *.DS_Store
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Creative Audio Visualizers
2 |
3 | An exploration of modern, line-style sound visualization powered by p5js and its p5.sound library. By Yannis Yannakopoulos.
4 |
5 | 
6 |
7 | [Article on Codrops](https://tympanus.net/codrops/?p=33934)
8 |
9 | [Demo](http://tympanus.net/Development/AudioVisualizers/)
10 |
11 | ## Credits
12 |
13 | - [p5js](http://www.p5js.org)
14 |
15 | ## License
16 | This resource can be used freely if integrated or build upon in personal or commercial projects such as websites, web apps and web templates intended for sale. It is not allowed to take the resource "as-is" and sell it, redistribute, re-publish it, or sell "pluginized" versions of it. Free plugins built using this resource should have a visible mention and link to the original work. Always consider the licenses of all included libraries, scripts and images used.
17 |
18 | ## Misc
19 |
20 | Follow Yannis: [Twitter](https://twitter.com/neundex)
21 |
22 | Follow Codrops: [Twitter](http://www.twitter.com/codrops), [Facebook](http://www.facebook.com/codrops), [Google+](https://plus.google.com/101095823814290637419), [GitHub](https://github.com/codrops), [Pinterest](http://www.pinterest.com/codrops/), [Instagram](https://www.instagram.com/codropsss/)
23 |
24 |
25 | [© Codrops 2018](http://www.codrops.com)
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/audio/DEMO_1.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codrops/AudioVisualizers/feac3eaeffe913792ec0de773cb14f77e3c0b4e8/audio/DEMO_1.mp3
--------------------------------------------------------------------------------
/audio/DEMO_2.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codrops/AudioVisualizers/feac3eaeffe913792ec0de773cb14f77e3c0b4e8/audio/DEMO_2.mp3
--------------------------------------------------------------------------------
/audio/DEMO_3.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codrops/AudioVisualizers/feac3eaeffe913792ec0de773cb14f77e3c0b4e8/audio/DEMO_3.mp3
--------------------------------------------------------------------------------
/audio/DEMO_4.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codrops/AudioVisualizers/feac3eaeffe913792ec0de773cb14f77e3c0b4e8/audio/DEMO_4.mp3
--------------------------------------------------------------------------------
/audio/DEMO_5.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codrops/AudioVisualizers/feac3eaeffe913792ec0de773cb14f77e3c0b4e8/audio/DEMO_5.mp3
--------------------------------------------------------------------------------
/css/demo.css:
--------------------------------------------------------------------------------
1 | @import url('https://fonts.googleapis.com/css?family=Roboto:400');
2 | *,
3 | *::after,
4 | *::before {
5 | box-sizing: border-box;
6 | }
7 |
8 | body {
9 | font-family: 'Roboto', sans-serif;
10 | font-weight: 400;
11 | color: #fff;
12 | background: #000;
13 | overflow: hidden;
14 | font-size: 0.85rem;
15 | }
16 |
17 | .demo-1 {
18 | color: #2376a5;
19 | }
20 |
21 | .demo-2 {
22 | color: #c83f2b;
23 | }
24 |
25 | .demo-3 {
26 | color: #1d3cbb;
27 | }
28 |
29 | .demo-4 {
30 | color: #ffeb3b;
31 | }
32 |
33 | .demo-5 {
34 | color: #5b0ff5;
35 | }
36 |
37 | a {
38 | text-decoration: none;
39 | color: inherit;
40 | outline: none;
41 | }
42 |
43 | a:hover,
44 | a:focus {
45 | color: #333;
46 | }
47 |
48 | .hidden {
49 | position: absolute;
50 | overflow: hidden;
51 | width: 0;
52 | height: 0;
53 | pointer-events: none;
54 | }
55 |
56 | /* Icons */
57 | .icon {
58 | display: block;
59 | width: 1.5em;
60 | height: 1.5em;
61 | margin: 0 auto;
62 | fill: currentColor;
63 | }
64 |
65 | /* Header */
66 | .codrops-header {
67 | position: absolute;
68 | left: 0;
69 | top: 0;
70 | display: flex;
71 | flex-direction: row;
72 | flex-wrap: wrap;
73 | align-items: center;
74 | width: 100%;
75 | padding: 2vmax;
76 | z-index: 1;
77 | }
78 |
79 | .codrops-header__title {
80 | font-size: 1em;
81 | margin: 0;
82 | padding: 0 1em;
83 | color: #fff;
84 | }
85 |
86 | .codrops-header__tagline {
87 | margin: 0;
88 | }
89 |
90 | /* Top Navigation Style */
91 | .codrops-links {
92 | position: relative;
93 | display: flex;
94 | justify-content: center;
95 | text-align: center;
96 | white-space: nowrap;
97 | }
98 |
99 | .codrops-icon {
100 | display: inline-block;
101 | margin: 0.25em;
102 | padding: 0.25em;
103 | }
104 |
105 | /* Demo links */
106 | .demos {
107 | margin: 0 0 0 3rem;
108 | }
109 |
110 | .demo {
111 | margin: 0 1em 0.5em 0;
112 | padding: 0 0 0.25em;
113 | }
114 |
115 | .demo:hover,
116 | .demo--current {
117 | color: #fff;
118 | }
119 |
120 | /* Content */
121 | .content {
122 | padding: 3em 0;
123 | }
124 |
125 | .content.main {
126 | min-height: 100vh;
127 | padding: 0;
128 | }
129 |
130 | .canvas-wrapper {
131 | position: relative;
132 | min-height: 100vh;
133 | overflow: hidden;
134 | }
135 |
136 | canvas {
137 | position: absolute;
138 | left: 50%;
139 | top: 50%;
140 | -webkit-transform: translate(-50%, -50%);
141 | transform: translate(-50%, -50%);
142 | width: 100%;
143 | height: 100%;
144 | }
145 |
146 | .p5_loading {
147 | background: black;
148 | position: fixed;
149 | left: 0;
150 | top: 0;
151 | background: rgb(0, 0, 0);
152 | width: 100%;
153 | height: 100%;
154 | z-index: 9;
155 | overflow: hidden;
156 | }
157 |
158 | .p5_loading__inner {
159 | position: absolute;
160 | left: 50%;
161 | top: 50%;
162 | -webkit-transform: translate3d(-50%, -50%, 0);
163 | transform: translate3d(-50%, -50%, 0);
164 | display: flex;
165 | }
166 |
167 | .p5_loading__inner span {
168 | display: block;
169 | width: 100px;
170 | height: 100px;
171 | border-radius: 100%;
172 | background: rgb(255, 255, 255);
173 | margin: 0 20px;
174 | transform-origin: center;
175 | animation: noiseLoad 0.5s infinite ease-in-out alternate;
176 | }
177 |
178 | .p5_loading__inner span:nth-child(2) {
179 | animation-delay: 0.33s;
180 | }
181 |
182 | .p5_loading__inner span:nth-child(3) {
183 | animation-delay: 0.66s;
184 | }
185 |
186 | @keyframes noiseLoad {
187 | from {
188 | transform: scale(0);
189 | background: rgb(255, 255, 255);
190 | }
191 |
192 | to {
193 | transform: scale(1);
194 | background: rgb(0, 0, 0);
195 |
196 | }
197 | }
198 |
199 | #uploading-animation {
200 | display: none;
201 | }
202 |
203 | #uploading-animation.is-visible {
204 | display: block;
205 | }
206 |
207 | .upload-btn::before,
208 | .toggle-btn {
209 | padding: 10px;
210 | text-align: center;
211 | text-transform: uppercase;
212 | letter-spacing: 0.1em;
213 | color: currentColor;
214 | position: absolute;
215 | bottom: 2vmax;
216 | border: 1px solid;
217 | width: 255px;
218 | }
219 |
220 | .upload-btn::before {
221 | content: 'Upload your track';
222 | display: inline-block;
223 | left: 2vmax;
224 | outline: none;
225 | white-space: nowrap;
226 | -webkit-user-select: none;
227 | cursor: pointer;
228 | }
229 |
230 | .upload-btn:hover::before {
231 | color: #fff;
232 | }
233 |
234 | .toggle-btn {
235 | background: transparent;
236 | color: currentColor;
237 | right: 2vmax;
238 | }
239 |
240 | .toggle-btn:focus {
241 | outline: none;
242 | }
243 |
244 | .toggle-btn:hover {
245 | color: #fff;
246 | }
247 |
248 | @media screen and (max-width: 55em) {
249 | .codrops-header {
250 | flex-direction: column;
251 | justify-content: center;
252 | }
253 | .demos {
254 | width: 100%;
255 | margin: 1em 0 0;
256 | text-align: center;
257 | }
258 | .toggle-btn {
259 | right: 10px;
260 | bottom: 5.5em;
261 | width: calc(100% - 20px);
262 | }
263 | .upload-btn::before {
264 | position: absolute;
265 | bottom: 9em;
266 | left: 10px;
267 | width: calc(100% - 20px);
268 | }
269 | }
270 |
--------------------------------------------------------------------------------
/css/normalize.css:
--------------------------------------------------------------------------------
1 | article,aside,details,figcaption,figure,footer,header,hgroup,main,nav,section,summary{display:block;}audio,canvas,video{display:inline-block;}audio:not([controls]){display:none;height:0;}[hidden]{display:none;}html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;}body{margin:0;}a:focus{outline:thin dotted;}a:active,a:hover{outline:0;}h1{font-size:2em;margin:0.67em 0;}abbr[title]{border-bottom:1px dotted;}b,strong{font-weight:bold;}dfn{font-style:italic;}hr{-moz-box-sizing:content-box;box-sizing:content-box;height:0;}mark{background:#ff0;color:#000;}code,kbd,pre,samp{font-family:monospace,serif;font-size:1em;}pre{white-space:pre-wrap;}q{quotes:"\201C" "\201D" "\2018" "\2019";}small{font-size:80%;}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline;}sup{top:-0.5em;}sub{bottom:-0.25em;}img{border:0;}svg:not(:root){overflow:hidden;}figure{margin:0;}fieldset{border:1px solid #c0c0c0;margin:0 2px;padding:0.35em 0.625em 0.75em;}legend{border:0;padding:0;}button,input,select,textarea{font-family:inherit;font-size:100%;margin:0;}button,input{line-height:normal;}button,select{text-transform:none;}button,html input[type="button"],input[type="reset"],input[type="submit"]{-webkit-appearance:button;cursor:pointer;}button[disabled],html input[disabled]{cursor:default;}input[type="checkbox"],input[type="radio"]{box-sizing:border-box;padding:0;}input[type="search"]{-webkit-appearance:textfield;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box;}input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration{-webkit-appearance:none;}button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0;}textarea{overflow:auto;vertical-align:top;}table{border-collapse:collapse;border-spacing:0;}
--------------------------------------------------------------------------------
/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codrops/AudioVisualizers/feac3eaeffe913792ec0de773cb14f77e3c0b4e8/favicon.ico
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Creative Audio Visualizers | Demo 1 | Codrops
8 |
9 |
10 |
11 |
12 |
13 |
14 |
17 |
18 |
19 |
20 |
31 |
32 |
54 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/index2.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Creative Audio Visualizers | Demo 2 | Codrops
8 |
9 |
10 |
11 |
12 |
13 |
14 |
17 |
18 |
19 |
20 |
31 |
32 |
54 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/index3.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Creative Audio Visualizers | Demo 3 | Codrops
8 |
9 |
10 |
11 |
12 |
13 |
14 |
17 |
18 |
19 |
20 |
31 |
32 |
54 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/index4.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Creative Audio Visualizers | Demo 4 | Codrops
8 |
9 |
10 |
11 |
12 |
13 |
14 |
17 |
18 |
19 |
20 |
31 |
32 |
54 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/index5.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Creative Audio Visualizers | Demo 5 | Codrops
8 |
9 |
10 |
11 |
12 |
13 |
14 |
17 |
18 |
19 |
20 |
31 |
32 |
54 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/js/main1.js:
--------------------------------------------------------------------------------
1 | var pieces, radius, fft, mapMouseX, mapMouseY, toggleBtn, audio, uploadBtn, uploadedAudio, uploadAnim;
2 | var colorPalette = ["#000", "rgba(22, 59, 72, 0.5)", "#00a6e0", "#002a38"];
3 | var uploadLoading = false;
4 |
5 | function preload() {
6 | audio = loadSound("audio/DEMO_1.mp3");
7 | }
8 |
9 |
10 | function uploaded(file) {
11 | uploadLoading = true;
12 | uploadedAudio = loadSound(file.data, uploadedAudioPlay);
13 | }
14 |
15 |
16 | function uploadedAudioPlay(audioFile) {
17 |
18 | uploadLoading = false;
19 |
20 | if (audio.isPlaying()) {
21 | audio.pause();
22 | }
23 |
24 | audio = audioFile;
25 | audio.loop();
26 | }
27 |
28 |
29 | function setup() {
30 |
31 | uploadAnim = select('#uploading-animation');
32 |
33 | createCanvas(windowWidth, windowHeight);
34 |
35 | toggleBtn = createButton("Play / Pause");
36 |
37 | uploadBtn = createFileInput(uploaded);
38 |
39 | uploadBtn.addClass("upload-btn");
40 |
41 | toggleBtn.addClass("toggle-btn");
42 |
43 | toggleBtn.mousePressed(toggleAudio);
44 |
45 |
46 | fft = new p5.FFT();
47 |
48 | audio.loop();
49 |
50 | }
51 |
52 | function draw() {
53 |
54 | // Add a loading animation for the uploaded track
55 | if (uploadLoading) {
56 | uploadAnim.addClass('is-visible');
57 | } else {
58 | uploadAnim.removeClass('is-visible');
59 | }
60 |
61 | background(colorPalette[0]);
62 |
63 | noFill();
64 |
65 | fft.analyze();
66 |
67 | var bass = fft.getEnergy("bass");
68 | var treble = fft.getEnergy("treble");
69 | var mid = fft.getEnergy("mid");
70 |
71 | var mapMid = map(mid, 0, 255, -radius, radius);
72 | var scaleMid = map(mid, 0, 255, 1, 1.5);
73 |
74 | var mapTreble = map(treble, 0, 255, -radius, radius);
75 | var scaleTreble = map(treble, 0, 255, 1, 1.5);
76 |
77 | var mapbass = map(bass, 0, 255, -100, 800);
78 | var scalebass = map(bass, 0, 255, 0, 0.8);
79 |
80 | mapMouseX = map(mouseX, 0, width, 4, 10);
81 | mapMouseY = map(mouseY, 0, height, windowHeight / 4, windowHeight);
82 |
83 | pieces = mapMouseX;
84 | radius = mapMouseY;
85 |
86 | translate(windowWidth / 2, windowHeight / 2);
87 |
88 | strokeWeight(1);
89 |
90 | for (i = 0; i < pieces; i += 0.5) {
91 |
92 | rotate(TWO_PI / pieces);
93 |
94 |
95 | /*---------- BASS ----------*/
96 | push();
97 | strokeWeight(5);
98 | stroke(colorPalette[1]);
99 | scale(scalebass);
100 | rotate(frameCount * -0.5);
101 | line(mapbass, radius / 2, radius, radius);
102 | line(-mapbass, -radius / 2, radius, radius);
103 | pop();
104 |
105 |
106 |
107 | /*---------- MID ----------*/
108 | push();
109 | strokeWeight(0.5);
110 | stroke(colorPalette[2]);
111 | scale(scaleMid);
112 | line(mapMid, radius / 2, radius, radius);
113 | line(-mapMid, -radius / 2, radius, radius);
114 | pop();
115 |
116 |
117 | /*---------- TREMBLE ----------*/
118 | push();
119 | stroke(colorPalette[3]);
120 | scale(scaleTreble);
121 | line(mapTreble, radius / 2, radius, radius);
122 | line(-mapTreble, -radius / 2, radius, radius);
123 | pop();
124 |
125 | }
126 |
127 | }
128 |
129 |
130 | function toggleAudio() {
131 | if (audio.isPlaying()) {
132 | audio.pause();
133 | } else {
134 | audio.play();
135 | }
136 | }
137 |
138 |
139 | function windowResized() {
140 | resizeCanvas(windowWidth, windowHeight);
141 | }
--------------------------------------------------------------------------------
/js/main2.js:
--------------------------------------------------------------------------------
1 | var pieces, radius, fft, mapMouseX, mapMouseY, audio, toggleBtn, uploadBtn, uploadedAudio, uploadAnim;
2 | var colorPalette = ["#0f0639", "#ff006a", "#ff4f00", "#00f9d9"];
3 | var uploadLoading = false;
4 |
5 | function preload() {
6 | audio = loadSound("audio/DEMO_2.mp3");
7 | }
8 |
9 | function uploaded(file) {
10 | uploadLoading = true;
11 | uploadedAudio = loadSound(file.data, uploadedAudioPlay);
12 | }
13 |
14 | function uploadedAudioPlay(audioFile) {
15 |
16 | uploadLoading = false;
17 |
18 | if (audio.isPlaying()) {
19 | audio.pause();
20 | }
21 |
22 | audio = audioFile;
23 | audio.loop();
24 | }
25 |
26 | function setup() {
27 |
28 | uploadAnim = select('#uploading-animation');
29 |
30 | createCanvas(windowWidth, windowHeight);
31 |
32 | toggleBtn = createButton("Play / Pause");
33 |
34 | uploadBtn = createFileInput(uploaded);
35 |
36 | uploadBtn.addClass("upload-btn");
37 |
38 | toggleBtn.addClass("toggle-btn");
39 |
40 | toggleBtn.mousePressed(toggleAudio);
41 |
42 | fft = new p5.FFT();
43 | audio.loop();
44 |
45 | pieces = 4;
46 | radius = windowHeight / 4;
47 |
48 | }
49 |
50 | function draw() {
51 |
52 | // Add a loading animation for the uploaded track
53 | if (uploadLoading) {
54 | uploadAnim.addClass('is-visible');
55 | } else {
56 | uploadAnim.removeClass('is-visible');
57 | }
58 |
59 | background(colorPalette[0]);
60 |
61 | fft.analyze();
62 | var bass = fft.getEnergy("bass");
63 | var treble = fft.getEnergy(100, 150);
64 | var mid = fft.getEnergy("mid");
65 |
66 | var mapbass = map(bass, 0, 255, -100, 800);
67 | var scalebass = map(bass, 0, 255, 0.5, 1.2);
68 |
69 | var mapMid = map(mid, 0, 255, -radius / 4, radius * 4);
70 | var scaleMid = map(mid, 0, 255, 1, 1.5);
71 |
72 | var mapTreble = map(treble, 0, 255, -radius / 4, radius * 4);
73 | var scaleTreble = map(treble, 0, 255, 1, 1.5);
74 |
75 | mapMouseX = map(mouseX, 0, width, 2, 0.1);
76 | mapMouseY = map(mouseY, 0, height, windowHeight / 8, windowHeight / 6);
77 |
78 | pieces = mapMouseX;
79 | radius = mapMouseY;
80 |
81 | var mapScaleX = map(mouseX, 0, width, 1, 0);
82 | var mapScaleY = map(mouseY, 0, height, 0, 1);
83 |
84 |
85 | translate(width / 2, height / 2);
86 |
87 | for (i = 0; i < pieces; i += 0.01) {
88 |
89 | rotate(TWO_PI / pieces);
90 |
91 | /*---------- BASS ----------*/
92 | push();
93 | strokeWeight(1);
94 | stroke(colorPalette[1]);
95 | scale(scalebass);
96 | rotate(frameCount * -0.5);
97 | line(mapbass, radius / 2, radius, radius);
98 | line(-mapbass, -radius / 2, radius, radius);
99 | pop();
100 |
101 |
102 | /*---------- MID ----------*/
103 | push();
104 | strokeWeight(1);
105 | stroke(colorPalette[2]);
106 | line(mapMid, radius, radius * 2, radius * 2);
107 | pop();
108 |
109 |
110 | /*---------- TREMBLE ----------*/
111 | push();
112 | stroke(colorPalette[3]);
113 | scale(scaleTreble);
114 | line(mapTreble, radius / 2, radius, radius);
115 | pop();
116 |
117 | }
118 |
119 | }
120 |
121 | function toggleAudio() {
122 | if (audio.isPlaying()) {
123 | audio.pause();
124 | } else {
125 | audio.play();
126 | }
127 | }
128 |
129 | function windowResized() {
130 | resizeCanvas(windowWidth, windowHeight);
131 | }
--------------------------------------------------------------------------------
/js/main3.js:
--------------------------------------------------------------------------------
1 | var pieces, radius, fft, mapMouseX, mapMouseY, audio, toggleBtn, uploadBtn, uploadedAudio, uploadAnim;
2 | var bgColor = "#0c0f27";
3 | var bassColor = ["#313e9b", "#1200b3"];
4 | var midColor = "#da1500";
5 | var trembleColor = "#728d0d";
6 | var uploadLoading = false;
7 |
8 | function preload() {
9 | audio = loadSound("audio/DEMO_3.mp3");
10 | }
11 |
12 |
13 | function uploaded(file) {
14 | uploadLoading = true;
15 | uploadedAudio = loadSound(file.data, uploadedAudioPlay);
16 | }
17 |
18 |
19 | function uploadedAudioPlay(audioFile) {
20 |
21 | uploadLoading = false;
22 |
23 | if (audio.isPlaying()) {
24 | audio.pause();
25 | }
26 |
27 | audio = audioFile;
28 | audio.loop();
29 | }
30 |
31 |
32 | function setup() {
33 |
34 | uploadAnim = select('#uploading-animation');
35 | createCanvas(windowWidth, windowHeight);
36 | pieces = 30;
37 | radius = windowHeight / 4;
38 |
39 | toggleBtn = createButton("Play / Pause");
40 |
41 | uploadBtn = createFileInput(uploaded);
42 |
43 | uploadBtn.addClass("upload-btn");
44 |
45 | toggleBtn.addClass("toggle-btn");
46 |
47 | toggleBtn.mousePressed(toggleAudio);
48 |
49 | fft = new p5.FFT();
50 | audio.loop();
51 |
52 | }
53 |
54 |
55 |
56 | function draw() {
57 |
58 | // Add a loading animation for the uploaded track
59 | // -----------------------------------------------
60 | if (uploadLoading) {
61 | uploadAnim.addClass('is-visible');
62 | } else {
63 | uploadAnim.removeClass('is-visible');
64 | }
65 |
66 | background(bgColor);
67 | strokeWeight(1);
68 |
69 | fft.analyze();
70 |
71 | var bass = fft.getEnergy("bass");
72 | var treble = fft.getEnergy(50, 110);
73 | var mid = fft.getEnergy("mid");
74 |
75 | var mapMid = map(mid, 0, 255, -radius, radius);
76 | var scaleMid = map(mid, 0, 255, 1, 1.5);
77 |
78 | var mapTreble = map(treble, 0, 255, -radius / 2, radius * 2);
79 | var scaleTreble = map(treble, 0, 255, 0.5, 2);
80 |
81 | var mapbass = map(bass, 0, 255, 0, 200);
82 | var scalebass = map(bass, 0, 255, 0, 0.8);
83 |
84 | mapMouseX = map(mouseX, 0, width, 100, 200);
85 | mapMouseScale = map(mouseX, 0, width, 0.35, 0.2);
86 | mapMouseY = map(mouseY, 0, height, windowHeight / 4, windowHeight);
87 |
88 | pieces = 9;
89 | radius = 200;
90 |
91 | translate(windowWidth / 2, windowHeight / 2);
92 |
93 | for (i = 0; i < pieces; i += 1) {
94 |
95 | rotate(TWO_PI / pieces);
96 |
97 | noFill();
98 |
99 |
100 | /*---------- BASS ----------*/
101 | push();
102 | strokeWeight(8);
103 | stroke(bassColor[0]);
104 | scale(scalebass + mapMouseScale);
105 | rotate(-frameCount * 0.05);
106 | point(mapbass, radius / 2);
107 | stroke(bassColor[1]);
108 | strokeWeight(2.2);
109 | line(mapMouseX, mouseY, radius, radius);
110 | pop();
111 |
112 |
113 |
114 | /*---------- MID ----------*/
115 | push();
116 | stroke(midColor);
117 | strokeWeight(4);
118 | rotate(-frameCount * 0.01);
119 | point(mapMid, radius);
120 | pop();
121 |
122 |
123 | /*---------- TREMBLE ----------*/
124 | push();
125 | stroke(trembleColor);
126 | strokeWeight(4);
127 | scale(scaleTreble);
128 | rotate(frameCount * 0.01);
129 | point(-100, radius / 2);
130 | point(100, radius / 2);
131 | pop();
132 |
133 | }
134 |
135 | }
136 |
137 |
138 |
139 | function toggleAudio() {
140 | if (audio.isPlaying()) {
141 | audio.pause();
142 | } else {
143 | audio.play();
144 | }
145 | }
146 |
147 |
148 | function windowResized() {
149 | resizeCanvas(windowWidth, windowHeight);
150 | }
--------------------------------------------------------------------------------
/js/main4.js:
--------------------------------------------------------------------------------
1 | var pieces, radius, fft, analyzer, mapMouseX, mapMouseY, audio, toggleBtn, uploadBtn, uploadedAudio, uploadAnim;
2 | var colorPalette = ["#676767", "#232D22", "#C1C1C2", "#FFF903"];
3 | var uploadLoading = false;
4 |
5 | /*=============================================
6 | SETUP
7 | =============================================*/
8 |
9 | function preload() {
10 | audio = loadSound("audio/DEMO_4.mp3");
11 | }
12 |
13 | function uploaded(file) {
14 | uploadLoading = true;
15 | uploadedAudio = loadSound(file.data, uploadedAudioPlay);
16 | }
17 |
18 |
19 | function uploadedAudioPlay(audioFile) {
20 |
21 | uploadLoading = false;
22 |
23 | if (audio.isPlaying()) {
24 | audio.pause();
25 | }
26 |
27 | audio = audioFile;
28 | audio.loop();
29 | }
30 |
31 | function setup() {
32 |
33 | uploadAnim = select('#uploading-animation');
34 |
35 | createCanvas(windowWidth, windowHeight);
36 |
37 | toggleBtn = createButton("Play / Pause");
38 |
39 | uploadBtn = createFileInput(uploaded);
40 |
41 | uploadBtn.addClass("upload-btn");
42 |
43 | toggleBtn.addClass("toggle-btn");
44 |
45 | toggleBtn.mousePressed(toggleAudio);
46 |
47 | analyzer = new p5.Amplitude();
48 | fft = new p5.FFT();
49 | audio.loop();
50 |
51 | }
52 |
53 |
54 |
55 | /*=============================================
56 | DRAW
57 | =============================================*/
58 | function draw() {
59 |
60 | // Add a loading animation for the uploaded track
61 | // -----------------------------------------------
62 | if (uploadLoading) {
63 | uploadAnim.addClass('is-visible');
64 | } else {
65 | uploadAnim.removeClass('is-visible');
66 | }
67 |
68 | background(colorPalette[0]);
69 | translate(windowWidth / 2, windowHeight / 2);
70 |
71 | level = analyzer.getLevel();
72 | fft.analyze();
73 |
74 | var bass = fft.getEnergy("bass");
75 | var treble = fft.getEnergy(2, 250);
76 | var mid = fft.getEnergy(1, 250);
77 |
78 | if (!audio.isPlaying()) {
79 | var mapBassX = map(mouseX, 0, width, 400, 1200);
80 |
81 | for (var b = 0; b < 70; b++) {
82 |
83 | push();
84 | noFill();
85 | stroke(colorPalette[1]);
86 | rotate(b);
87 | var mapScale = map(b, 0, 100, 0, 3);
88 | strokeWeight(1);
89 | bezier(mapBassX - b, 20, 10, 20, 100, 50, mouseY, mouseY);
90 | pop();
91 |
92 | }
93 | } else {
94 |
95 | /*---------- BASS ----------*/
96 | var _mapBassX = map(mouseX, 0, width, 400, 1200);
97 | for (var b = 0; b < bass; b++) {
98 | var _mapScale = map(b, 0, bass, 0, 3);
99 | push();
100 | noFill();
101 | stroke(colorPalette[1]);
102 | rotate(b * frameCount);
103 | strokeWeight(_mapScale);
104 | bezier(_mapBassX - b, 20, 10, 20, 100, 50, mouseY, mouseY);
105 | pop();
106 | }
107 |
108 |
109 | /*---------- MID ----------*/
110 | for (var m = 0; m < mid; m += 20) {
111 |
112 | var angle = m * 3 * random();
113 | strokeWeight(1);
114 | push();
115 |
116 | fill(random(100, 255), random(100, 255), random(100, 255), random(0, 255));
117 | fill(colorPalette[2]);
118 | rotate(angle * 5);
119 | scale(level / 2);
120 |
121 | if (audio.currentTime() > 5) {
122 | rect(mouseX + m * 10, mouseY + m * 50, m * 7, m * 7);
123 | }
124 |
125 | pop();
126 |
127 | }
128 |
129 |
130 | /*---------- TREMBLE ----------*/
131 | for (var j = 5; j < treble; j += 20) {
132 |
133 | var angleT = j * 3 * random();
134 | strokeWeight(1);
135 | push();
136 | fill(colorPalette[3]);
137 | rotate(angleT * 5);
138 | scale(level / 4);
139 |
140 | if (audio.currentTime() > 7) {
141 | rect(mouseX * j + 10, mouseY * j, 200 * j, j * 5);
142 | }
143 | pop();
144 |
145 | }
146 |
147 | }
148 |
149 |
150 | }
151 |
152 |
153 | function toggleAudio() {
154 | if (audio.isPlaying()) {
155 | audio.pause();
156 | } else {
157 | audio.play();
158 | }
159 | }
160 |
161 |
162 | function windowResized() {
163 | resizeCanvas(windowWidth, windowHeight);
164 | }
--------------------------------------------------------------------------------
/js/main5.js:
--------------------------------------------------------------------------------
1 | var pieces, radius, fft, analyzer, mapMouseX, mapMouseY, audio, toggleBtn, uploadBtn, uploadedAudio, uploadAnim;
2 | var colorPalette = ["#02073c", "#5b0ff5", "#f50fac", "#f50fac"];
3 | var uploadLoading = false;
4 |
5 | /*=============================================
6 | SETUP
7 | =============================================*/
8 |
9 | function preload() {
10 | audio = loadSound("audio/DEMO_5.mp3");
11 | }
12 |
13 | function uploaded(file) {
14 | uploadLoading = true;
15 | uploadedAudio = loadSound(file.data, uploadedAudioPlay);
16 | }
17 |
18 |
19 | function uploadedAudioPlay(audioFile) {
20 |
21 | uploadLoading = false;
22 |
23 | if (audio.isPlaying()) {
24 | audio.pause();
25 | }
26 |
27 | audio = audioFile;
28 | audio.loop();
29 | }
30 |
31 | function setup() {
32 |
33 | uploadAnim = select('#uploading-animation');
34 |
35 | createCanvas(windowWidth, windowHeight);
36 |
37 | toggleBtn = createButton("Play / Pause");
38 |
39 | uploadBtn = createFileInput(uploaded);
40 |
41 | uploadBtn.addClass("upload-btn");
42 |
43 | toggleBtn.addClass("toggle-btn");
44 |
45 | toggleBtn.mousePressed(toggleAudio);
46 |
47 | analyzer = new p5.Amplitude();
48 | fft = new p5.FFT();
49 | audio.loop();
50 |
51 | }
52 |
53 |
54 |
55 | /*=============================================
56 | DRAW
57 | =============================================*/
58 | function draw() {
59 |
60 | // Add a loading animation for the uploaded track
61 | // -----------------------------------------------
62 | if (uploadLoading) {
63 | uploadAnim.addClass('is-visible');
64 | } else {
65 | uploadAnim.removeClass('is-visible');
66 | }
67 |
68 | background(colorPalette[0]);
69 |
70 | translate(windowWidth / 2, windowHeight / 2);
71 |
72 | level = analyzer.getLevel();
73 | fft.analyze();
74 |
75 | var bass = fft.getEnergy(100, 150);
76 | var treble = fft.getEnergy(150, 250);
77 | var mid = fft.getEnergy("mid");
78 |
79 | var mapMid = map(mid, 0, 255, -100, 200);
80 | var scaleMid = map(mid, 0, 255, 1, 1.5);
81 |
82 | var mapTreble = map(treble, 0, 255, 200, 350);
83 | var scaleTreble = map(treble, 0, 255, 0, 1);
84 |
85 | var mapbass = map(bass, 0, 255, 50, 200);
86 | var scalebass = map(bass, 0, 255, 0.05, 1.2);
87 |
88 | mapMouseX = map(mouseX, 0, width, 1, 50);
89 | mapMouseXbass = map(mouseX, 0, width, 1, 5);
90 | mapMouseY = map(mouseY, 0, height, 2, 6);
91 |
92 | pieces = 20;
93 | radius = 100;
94 |
95 | for (i = 0; i < pieces; i += 0.1) {
96 |
97 | rotate(TWO_PI / (pieces / 2));
98 |
99 | noFill();
100 |
101 | /*---------- BASS ----------*/
102 | push();
103 | stroke(colorPalette[1]);
104 | rotate(frameCount * 0.002);
105 | strokeWeight(0.5);
106 | polygon(mapbass + i, mapbass - i, mapMouseXbass * i, 3);
107 | pop();
108 |
109 |
110 | /*---------- MID ----------*/
111 | push();
112 | stroke(colorPalette[2]);
113 | strokeWeight(0.2);
114 | polygon(mapMid + i / 2, mapMid - i * 2, mapMouseX * i, 7);
115 | pop();
116 |
117 |
118 | /*---------- TREMBLE ----------*/
119 | push();
120 | stroke(colorPalette[3]);
121 | strokeWeight(0.6);
122 | scale(mouseX * 0.0005);
123 | rotate((mouseX * 0.002));
124 | polygon(mapTreble + i / 2, mapTreble - i / 2, mapMouseY * i / 2, 3);
125 | pop();
126 |
127 | }
128 |
129 | }
130 |
131 |
132 | function toggleAudio() {
133 | if (audio.isPlaying()) {
134 | audio.pause();
135 | } else {
136 | audio.play();
137 | }
138 | }
139 |
140 |
141 | function windowResized() {
142 | resizeCanvas(windowWidth, windowHeight);
143 | }
144 |
145 | function polygon(x, y, radius, npoints) {
146 | var angle = TWO_PI / npoints;
147 | beginShape();
148 | for (var a = 0; a < TWO_PI; a += angle) {
149 | var sx = x + cos(a) * radius;
150 | var sy = y + sin(a) * radius;
151 | vertex(sx, sy);
152 | }
153 | endShape(CLOSE);
154 | }
--------------------------------------------------------------------------------