xxxxxxxxxx
122
///OVLÁDANIE
// Click = zastavit / spustit hudba
// Mouse Drag = otacanie kocky
// Arrow up = music speed up
// Arrow down = cancle arrow up
// Arrow left = distort music
// Arrow down = cancle arrow left
// f = fullscreen / cancel fullscreen
let a = 0;
let b = 0;
let song;
let son;
let cnv;
let fft;
let peakDetect;
let pulseSize = 0;
function preload(){
song = loadSound('track1.mp3');
}
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
fft = new p5.FFT();
peakDetect = new p5.peakDetect();
}
function draw() {
background(0,0,0);
orbitControl();
ambientLight(0);
fft.analyze();
peakDetect.update(fft);
if (peakDetect.isDetected){
pulseSize = 250;
}
pointLight(pulseSize, 255, 0, 400, 0, 400);
pointLight(0, pulseSize, 255, 400, 0, -400);
pointLight(255, 0, pulseSize, -400, 0, 400);
box
push();
translate(0, 0, 0);
rotateX(frameCount * 0.01);
rotateY(frameCount * 0.01);
specularMaterial(255, 204, 0);
noStroke()
box(200);
pop();
push();
translate(0, 0, 0);
rotateX(frameCount * 0.01);
rotateY(frameCount * 0.01);
noFill();
stroke(a);
strokeWeight(30)
box(1000);
pop();
push();
translate(0, 0, 0);
rotateX(frameCount * 0.03);
rotateY(frameCount * 0.03);
noFill();
stroke(b);
strokeWeight(30)
box(1000);
pop();
if (keyIsDown(UP_ARROW) === true) {
a = 255
song.rate(2);
}
if (keyIsDown(DOWN_ARROW) === true) {
a = 0
song.rate(1);
}
if (keyIsDown(LEFT_ARROW) === true) {
b = 255
song.rate(0.25);
}
if (keyIsDown(RIGHT_ARROW) === true) {
b = 0
song.rate(1);
}
pulseSize = max(pulseSize - 20, 0);
// fill (255)
// ellipse (0,0,pulseSize)
}
function keyPressed() {
if (key == 'f') {
let fs = fullscreen();
fullscreen(!fs);
}
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}
function mousePressed(){
if (song.isPlaying()){
song.pause();
} else {
song.play();
}
}