xxxxxxxxxx
160
let myImg;
let pics = [];
let input;
let uploaded = false;
let assignedFirst = false;
let imageIndex = 0;
let curX = 0;
let curY = 0;
let wUnit = 0;
let hUnit = 0;
// function preload(){
// myImg = loadImage('dan2.png');
// }
function setup() {
rectMode(CORNER);
frameRate(30);
input = createFileInput(handleFile, "yes");
input.position(0, 0);
imageMode(CORNER);
// noStroke();
}
function handleFile(file) {
input.remove();
//print(file);
pics.push(loadImage(file.data));
//lateSetup();
if (!assignedFirst) {
assignedFirst = true;
myImg = loadImage(file.data, imageLoaded);
}
}
function imageLoaded() {
createCanvas(myImg.width, myImg.height);
// myImg.resize(width / 2, 0);
ratio = myImg.width / myImg.height;
print(ratio);
transparentColor = color(0, 0);
curSize = myImg.width / 5;
uploaded = true;
chosen = false;
}
function lateSetup() {
print("LATESETUP");
//input.remove();
}
function draw() {
// noLoop();
if(uploaded){
image(myImg,0,0);
}
}
function nextImage() {
imageIndex++;
myImg = pics[imageIndex];
imageLoaded();
}
function mousePressed(){
wUnit = myImg.width/4;
hUnit = myImg.height/2;
for(let i=0; i<8;i++){
if(i==0){
curX = wUnit * 3;
curY = hUnit;
getter();
curY=0;
}
if(i >0 && i < 5){
getter();
curX-=wUnit;
}
if(i >= 5){
curY = hUnit;
getter();
curX += wUnit;
}
}
for(let i=0; i<8; i++){
print(pics[i]);
pics[i].save(i+1+".png")
}
}
function getter(){
curImg = get(curX,curY,wUnit,hUnit);
pics.push(curImg);
}
function keyPressed() {
}