xxxxxxxxxx
135
let myImg;
let circleMask;
let ratio;
let xPos=0;
let transparentColor;
let curSize;
let chosenX, chosenY, chosenSize;
let chosen=false;
let pics = [];
let input;
let uploaded=false;
// function preload(){
// myImg = loadImage('dan2.png');
// }
function setup() {
input = createFileInput(handleFile,"yes");
input.position(0, 0);
}
function handleFile(file){
//print(file);
pics.push(file);
lateSetup();
}
function lateSetup(){
print("LATESETUP");
//input.remove();
createCanvas(myImg.width, myImg.height);
myImg.resize(width,0);
ratio = myImg.width/myImg.height;
print(ratio);
transparentColor = color(0,0);
curSize = myImg.width/5;
}
function draw() {
if(uploaded){
background(0,0);
strokeWeight(2);
if(!chosen){
image(myImg,0,0);
fill(color(200,0));
if(keyIsDown(UP_ARROW)){
curSize+=1.5;
}
if(keyIsDown(DOWN_ARROW)){
curSize-=1.5;
}
ellipse(mouseX,mouseY,curSize,curSize);
}
}
}
function keyPressed(){
if(keyCode === RIGHT_ARROW){
chosenX = mouseX;
chosenY = mouseY;
chosenSize=curSize;
chosen=true;
clear();
makeMask();
}
// if(keyCode === UP_ARROW){ ]
// curSize+=7;
// }
// if(keyCode === DOWN_ARROW){
// curSize-=7;
// }
}
function makeMask(){
circleMask = createGraphics(myImg.width,myImg.height);
circleMask.fill('(rgba(0,0,0,1)');
circleMask.ellipse(mouseX,mouseY,curSize,curSize);
myImg.mask(circleMask);
image(myImg,0,0);
//Use GET to find and get a small png that's just the circle we want
//TODO: resize back to original size then map where the circle should be
let finalImage;
finalImage = get(chosenX-chosenSize,chosenY-chosenSize,chosenSize*2,chosenSize*2);
finalImage.save("circled","png");
}