xxxxxxxxxx
41
// https://Discourse.Processing.org/t/pls-critique-my-code/12855/2
// @Epignosis567 & @GoToLoop (2019-Jul-21)
'use strict';
function preload() {
ori = loadImage(FOLDER + IMG_NAME);
song = loadSound(FOLDER + SONG_NAME);
}
const IMG_NAME = 'image.png', SONG_NAME = 'recording.mp3',
FOLDER = 'assets/', SUSPEND_STATE = 'suspended', FPS = 12;
var touchStarted = mousePressed, touchMoved = mouseMoved;
let ori, img, song;
function setup() {
windowResized();
_renderer.style('display', 'block');
frameRate(FPS).imageMode(CENTER);
}
function draw() {
clear().image(img, mouseX, mouseY);
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight, true);
(img = ori.get()).resize(width >> 1, height >> 1);
}
function mousePressed() {
const audCtx = getAudioContext();
audCtx.state === SUSPEND_STATE && audCtx.resume();
return mouseMoved();
}
function mouseMoved() {
song.isPlaying() || song.play();
return false;
}