xxxxxxxxxx
100
// adapted from coding train tutorial: https://www.youtube.com/watch?v=IKB1hWWedMk
// song 1: https://www.youtube.com/watch?v=qb9WgYW0ruE
// song 2: https://www.youtube.com/watch?v=NcuU1Xw6hfs
let w = 800;
let h = 1200;
let cols, rows;
let scl = 20;
let terrain;
let yoff;
let xoff;
let slider;
let slider2;
let button2;
let song2;
function setup() {
createCanvas(740, 600, WEBGL);
colorMode(HSB)
song = loadSound('kinky.mp3', loaded);
song2 = loadSound('poorleno.mp3')
amp = new p5.Amplitude();
slider = createSlider(0, 0.1, 0.075, 0.005)
slider2 = createSlider(0, 1, 1, 0.01)
cols = w / scl;
rows = h / scl;
}
function loaded() {
console.log('Song is Loaded')
// buttons wont load until the song is loaded - this insures button can't be pressed until the song is ready
button = createButton('play Kinky');
button2 = createButton('play Royksopp')
button.mousePressed(togglePlaying);
button2.mousePressed(togglePlaying2)
}
function togglePlaying2() {
if (!song2.isPlaying() && !song.isPlaying()) { // if song is NOT playing - play when the button is pressed
song2.playMode('restart') // fixes "jump" bug
song2.play();
button2.html('Pause Royksopp');
} else { // if song is playing
song2.pause();
button2.html('Ruseme Royksopp');
}
}
function togglePlaying() {
if (!song.isPlaying() && !song2.isPlaying()) { // if song is NOT playing - play when the button is pressed
song.playMode('restart') // fixes "jump" bug
song.play();
button.html('Pause Kinky');
} else { // if song is playing
song.pause();
button.html('Resume Kinky');
}
}
function draw() {
background(0, 0, 0);
masterVolume(slider2.value())
smooth(1);
let vol = amp.getLevel();
rotateX(PI / 3);
translate(-500, -300)
yoff = 0
for (let y = 0; y < cols; y++) {
xoff = 0
beginShape(TRIANGLE_STRIP)
for (let x = 0; x < rows; x++) {
let colr = map(noise(xoff, yoff, vol), 0, 0.50, 360, 0);
fill(colr, 100, 100, 0.5)
stroke(colr, 100, 100, 0.1)
let zoff = map(noise(xoff, yoff, vol), 0, 1, -300, 350) //remove 2 multiplier
vertex(x * scl, y * scl, zoff); //add multipliers for interesting effects
vertex(x * scl, (y + 1) * scl, zoff); //add multipliers for interesting effects
xoff += slider.value();
}
yoff += slider.value();
endShape()
}
}