-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from codedex-io/exrlla/new-soundboard-tutorial
Add Build an Interactive SoundBoard with p5.js tutorial
- Loading branch information
Showing
19 changed files
with
894 additions
and
0 deletions.
There are no files selected for viewing
757 changes: 757 additions & 0 deletions
757
...-interactive-soundboard-with-p5js/build-an-interactive-soundboard-with-p5js.mdx
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+74.5 KB
...nteractive-soundboard-with-p5js/images/Screenshot 2023-07-25 at 11.55.50 AM.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+41.3 KB
projects/build-an-interactive-soundboard-with-p5js/images/anatomy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+104 KB
projects/build-an-interactive-soundboard-with-p5js/images/buttons2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.14 MB
projects/build-an-interactive-soundboard-with-p5js/images/code-path.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.77 MB
projects/build-an-interactive-soundboard-with-p5js/images/drag-and-drop-p5-tut.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+371 KB
projects/build-an-interactive-soundboard-with-p5js/images/empty-example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+432 KB
projects/build-an-interactive-soundboard-with-p5js/images/lib-p5-files.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+71.6 KB
projects/build-an-interactive-soundboard-with-p5js/images/server-start.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+119 KB
projects/build-an-interactive-soundboard-with-p5js/images/sound-files.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+52.1 KB
projects/build-an-interactive-soundboard-with-p5js/images/vscode-files.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+94.6 KB
projects/build-an-interactive-soundboard-with-p5js/images/weird-buttons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+49.4 KB
projects/build-an-interactive-soundboard-with-p5js/images/weird2-buttons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions
27
projects/build-an-interactive-soundboard-with-p5js/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!DOCTYPE html> | ||
<html lang=""> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>funky soundboard</title> | ||
<link rel="icon" type="image/x-icon" href="kirby.png"> | ||
<style> | ||
body { | ||
padding: 0; | ||
margin: 0; | ||
} | ||
</style> | ||
<script src="./p5.min.js"></script> | ||
<script src="./p5.sound.js"></script> | ||
<script src="./p5.sound.min.js"></script> | ||
<script src="sketch.js"></script> | ||
</head> | ||
|
||
<body> | ||
<main> | ||
|
||
</main> | ||
</body> | ||
|
||
</html> |
110 changes: 110 additions & 0 deletions
110
projects/build-an-interactive-soundboard-with-p5js/sketch.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
let width = window.innerWidth; | ||
let height = window.innerHeight; | ||
|
||
let buttons_top = []; | ||
let buttons_middle = []; | ||
let buttons_bottom = []; | ||
|
||
let vine_boom; | ||
let retro_game; | ||
let whoosh; | ||
let acute_guitar; | ||
let guitar_string; | ||
let guitar_notif; | ||
|
||
function setup() { | ||
canvas=createCanvas(width,height); | ||
vine_boom = loadSound('vine_boom.mp3'); | ||
retro_game = loadSound('retro_game.wav'); | ||
whoosh = loadSound('whoosh.wav'); | ||
acute_guitar = loadSound('acute_guitar.wav'); | ||
guitar_string = loadSound('guitar_string.wav'); | ||
guitar_notif = loadSound('guitar_notif.wav'); | ||
|
||
|
||
|
||
let b1 = new Button(width/3, height/3, 200, 80, color(226, 132, 19), color(244, 190, 124), vine_boom); | ||
let b2 = new Button(width/2, height/3, 200, 80, color(0, 159, 183), color(153, 241, 255), retro_game); | ||
let b3 = new Button(2*width/3, height/3, 200, 80, color(145, 145, 233), color(204, 204, 245), whoosh); | ||
|
||
let b4 = new Button(width/3, height/2, 200, 80, color(205,92,92), color(240,128,128), vine_boom); | ||
let b5 = new Button(width/2, height/2, 200, 80, color(72,209,204), color(175,238,238), retro_game); | ||
let b6 = new Button(2*width/3, height/2, 200, 80, color(255,215,0), color(255,255,0), whoosh); | ||
|
||
let b7 = new Button(width/3, 2*height/3, 200, 80, color(255, 163, 175), color(255, 214, 220), acute_guitar); | ||
let b8 = new Button(width/2, 2*height/3, 200, 80, color(143, 45, 86), color(216, 131, 166), guitar_string); | ||
let b9 = new Button(2*width/3, 2*height/3, 200, 80, color(236, 78, 32), color(234, 162, 133), guitar_notif); | ||
|
||
buttons_top.push(b1); | ||
buttons_top.push(b2); | ||
buttons_top.push(b3); | ||
|
||
buttons_middle.push(b4); | ||
buttons_middle.push(b5); | ||
buttons_middle.push(b6); | ||
|
||
buttons_bottom.push(b7); | ||
buttons_bottom.push(b8); | ||
buttons_bottom.push(b9); | ||
} | ||
|
||
function mousePressed() { | ||
for (let i = 0; i < buttons_top.length; i++) { | ||
buttons_top[i].clicked(mouseX, mouseY); | ||
buttons_middle[i].clicked(mouseX, mouseY); | ||
buttons_bottom[i].clicked(mouseX, mouseY); | ||
} | ||
|
||
} | ||
|
||
function mouseReleased() { | ||
for (let i = 0; i < buttons_top.length; i++) { | ||
buttons_top[i].y = height/3; | ||
buttons_middle[i].y = height/2; | ||
buttons_bottom[i].y = 2*height/3; | ||
} | ||
} | ||
|
||
function draw() { | ||
background(51, 92, 129); | ||
noStroke(); | ||
for (let i = 0; i < buttons_top.length; i++) { | ||
buttons_top[i].show(); | ||
buttons_middle[i].show(); | ||
buttons_bottom[i].show(); | ||
} | ||
} | ||
|
||
class Button { | ||
constructor(x, y, w, h, color, accent, sound) { | ||
this.x = x; | ||
this.y = y; | ||
this.w = w; | ||
this.h = h; | ||
this.color = color; | ||
this.accent = accent; | ||
this.sound = sound; | ||
} | ||
|
||
show() { | ||
noStroke(); | ||
fill(this.color); | ||
rect((this.x - 100), this.y, this.w, 50); | ||
|
||
fill(this.accent); | ||
ellipse(this.x, this.y, this.w, this.h); | ||
|
||
fill(this.color); | ||
arc(this.x, (this.y + 50), this.w, this.h, TWO_PI, PI); | ||
} | ||
|
||
clicked(px, py) { | ||
let d = dist(px, py, this.x, this.y); | ||
|
||
if (d < this.w / 2) { | ||
this.y = this.y + 10; | ||
this.sound.play(); | ||
} | ||
} | ||
|
||
} |