Skip to content

Commit

Permalink
feat: ✨ add volume slider for the song
Browse files Browse the repository at this point in the history
  • Loading branch information
simonberner committed Mar 15, 2024
1 parent 0a078c0 commit 75ee954
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ let initialUniverse;
let resolution = 10;
let birdsong;
let playButton;
let volumeSlider;

/**
* Preload function is used to preload any necessary assets before the setup() is called. It is called once.
Expand Down Expand Up @@ -35,10 +36,13 @@ function setup() {
// draw and position the button
playButton = createButton('Start/Stop sound');
playButton.position(0, 500);

// call playSound when play button clicked
playButton.mousePressed(playSound);

// create volume slider
volumeSlider = createSlider(0, 1, 0.5, 0);
volumeSlider.position(120, 500);

// set playback mode to 'restart'
birdsong.playMode('restart');
}
Expand Down Expand Up @@ -71,6 +75,9 @@ function draw() {
}
}
initialUniverse = calcNextGen(initialUniverse);

// Set volume for the birdsong
birdsong.setVolume(volumeSlider.value());
}

function playSound() {
Expand Down

0 comments on commit 75ee954

Please sign in to comment.