From 75ee9540ce170ad73503ba80e4e5229f888c1d53 Mon Sep 17 00:00:00 2001 From: Simon Berner Date: Fri, 15 Mar 2024 11:06:32 +0100 Subject: [PATCH] feat: :sparkles: add volume slider for the song --- src/sketch.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/sketch.js b/src/sketch.js index c44590d..1d081b6 100644 --- a/src/sketch.js +++ b/src/sketch.js @@ -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. @@ -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'); } @@ -71,6 +75,9 @@ function draw() { } } initialUniverse = calcNextGen(initialUniverse); + + // Set volume for the birdsong + birdsong.setVolume(volumeSlider.value()); } function playSound() {