CLICK to start music and animation. Press LEFT and RIGHT ARROW KEYS to adjust rotation speed. HOLD mouse to pause. RELEASE mouse to resume.
xxxxxxxxxx
let file;
let tune;
let angle = 0;
let av = 1;
let saveav = 1;
let mode = 'opening';
function preload() {
file = loadImage('muybridge.jpg')
soundFormats('mp3', 'ogg');
tune = loadSound('dailydownload_20151231_128.mp3');
}
function setup() {
createCanvas(windowWidth, windowHeight);
background(100);
angleMode(DEGREES);
imageMode(CENTER);
file.resize(2 * height, 2 * height);
}
function draw() {
switch (mode) {
case 'opening':
background(255);
fill(0);
textAlign(CENTER, CENTER);
textSize(height / 14);
text('click to start audio', width / 2, height / 2);
break;
case 'playing':
background(255);
translate(width / 2, 0);
push();
rotate(angle);
image(file, 0, 0);
pop();
angle += av;
checkInputs();
break;
}
}
function checkInputs() {
if (keyIsDown(RIGHT_ARROW)) {
av -= 0.1;
saveav -= 0.1;
}
if (keyIsDown(LEFT_ARROW)) {
av += 0.1;
saveav += 0.1;
}
if (mouseIsPressed) {
av = lerp(av, 0, 0.05);
} else {
av = lerp(av, saveav, 0.05);
}
saveav = map(mouseX, 0,width, 9*PI,-9*PI);
}
function mousePressed() {
if (!tune.isPlaying()) {
tune.play();
mode = 'playing';
} else {
saveav = av;
}
}