Press the right arrow key to make the monkey give a judging look. Press the left arrow key to make the monkey look away.
xxxxxxxxxx
var look
var away
var imagenum = 1
function preload(){
look = loadImage('monkeylook.png')
away = loadImage('monkeyaway.png')
}
function setup() {
createCanvas(400, 400);
background(220);
imageMode(CENTER)
}
function draw() {
if(imagenum == 1){
image(look, width/2, height/2)
}
if(imagenum == 2){
image(away, width/2, height/2)
}
}
function keyPressed(){
if(keyCode == RIGHT_ARROW){
imagenum += 1
}
if(keyCode == LEFT_ARROW){
imagenum -= 1
}
if(imagenum <= 1){
imagenum = 1
}
if(imagenum >= 2){
imagenum = 2
}
}