xxxxxxxxxx
65
// An example of how the CPX and p5js can work together to create a unique
// interactive experience
//
// Try using this with the MakeCode + CPX program:
// https://makecode.com/_8hfMVCYDRVPs
//
// For a version without sound, see:
//
//
// By Jon Froehlich
// @jonfroehlich
// http://makeabilitylab.io
//
let imgApple;
let imgBanana;
let imgLime;
let imgOrange;
let currentImg;
let sndApple;
let sndBanana;
let sndLime;
let sndOrange;
function preload() {
sndApple = loadSound('sounds/Apple.mp3');
sndBanana = loadSound('sounds/Banana.mp3');
sndLime = loadSound('sounds/Lime.mp3');
sndOrange = loadSound('sounds/Orange.mp3');
imgApple = loadImage("images/apple.png");
imgBanana = loadImage("images/banana.png");
imgLime = loadImage("images/lime.png");
imgOrange = loadImage("images/orange.png");
}
function setup() {
createCanvas(600, 450);
currentImg = imgApple;
}
function draw() {
background(220);
image(currentImg, 0, 0);
}
function keyTyped() {
print(key);
if (key == '1') {
currentImg = imgApple;
sndApple.play();
}else if(key == '2'){
currentImg = imgOrange;
sndOrange.play();
}else if(key == '3'){
currentImg = imgBanana;
sndBanana.play();
}else if(key == '4'){
currentImg = imgLime;
sndLime.play();
}
}