xxxxxxxxxx
113
var s1=true;
let img1;
let img2;
//Contact Sheet Calibration Variables
const sx = 25; //top left x
const sy = 182; //top left y
const sWidth = 204; //width of frame
const sHeight = 119; //height of frame
const xGap=8; //gap in x direction
const yGap=14; //gap in y direction
const xNum = 5; //frames across
const yNum = 10; //frames down
const fullWidth = 1190; //full width of image
const fullHeight = 1880; //full height of image
//Animation frame variables
let dx = 0; //location of aniamtion in canvas
let dy = 0; //location of aniamtion in canvas
let dWidth = 400; //destination width
let dHeight = 400;//destination height
//Variables for frame on contact sheet
let x;
let y;
let i = 0;
let j = 0;
let fr = 8; //frame rate
function preload() {
img1 = loadImage("LittleBunnyScan-1.png");
img2 = loadImage("LittleBunnyScan-2.png");
}
function setup() {
createCanvas(460, 400);
frameRate(fr);
}
function draw() {
x = sx + (sWidth+xGap) * i;
y = sy + (sHeight+yGap) * j;
if(s1){
image(img1, dx, dy, dWidth, dHeight, x, y, sWidth, sHeight);
}else{
image(img2, dx, dy, dWidth, dHeight, x, y, sWidth, sHeight);
}
//if we are not on the last column
if (i != xNum-1) {
i = i + 1; //advance column
}else{
i = 0; //go back to column 0 and advance row
//advance row
if(j != yNum-1){ //if not on last row
j = j + 1; //advance row
}else{
j = 0;
if ((i = xNum-1) && (j = yNum-1)){
(s1=false);
if (i != xNum-1) {
i = i + 1; //advance column
}else{
i = 0; //go back to column 0 and advance row
//advance row
if(j != yNum-1){ //if not on last row
j = j + 1; //advance row
}else{
j = 0;
}
}
}
}
}
// print("("+i+","+j+")");
// print("("+x+","+y+")");
// function keyPressed() {
// if (keyCode === UP_ARROW) {
// fr = fr+1;
// frameRate(fr);
// console.log("FrameRate:"+j+"fps");
// } else if (keyCode === DOWN_ARROW) {
// fr = fr- 1;
// frameRate(fr);
// console.log("FrameRate:"+j+"fps");
// }
}