Wow, thanks Giles! What you said worked like a charm!
It finally got to work.
With the code below, i can draw my selection from
anywhere in the image, to anywhere in the image,
and the selection will correspond perfectly!
Greets,
Vincent.
Code:
int venster,start,geslacht,startX,startY;
int startX_klein,startY_klein,moveX,moveY;
PImage klas,selectie,klas_klein;
PFont lettertype1;
void setup(){
size(500,500);
textAlign(CENTER);
imageMode(CENTER);
lettertype1=createFont("Verdana",20);
textFont(lettertype1);
klas_klein=loadImage("klas_klein.jpg");
klas=loadImage("klas.jpg");}
void mousePressed(){
if(venster==2){
if((mouseX>=70)&&
(mouseX<=430)&&
(mouseY>=165)&&
(mouseY<=335)){
start=1;
startX_klein=mouseX;
startY_klein=mouseY;}}}
void mouseReleased(){
if(venster==0){
if((mouseX>=215)&&
(mouseX<=285)&&
(mouseY>=235)&&
(mouseY<=265)){
{venster=1;}}}
if(venster>0){
if((mouseX>=30)&&
(mouseX<=100)&&
(mouseY>=30)&&
(mouseY<=60))
{start=0;
venster=venster-1;}}
if(venster==1){
if((mouseX>=140)&&
(mouseX<=210)&&
(mouseY>=235)&&
(mouseY<=265))
{geslacht=1;
venster=2;}
if((mouseX>=290)&&
(mouseX<=360)&&
(mouseY>=235)&&
(mouseY<=265))
{geslacht=2;
venster=2;}}
if(venster==2){
if(start==1){
if((mouseX<70)||
(mouseX>430)||
(mouseY<165)||
(mouseY>335))
{start=0;}
if((mouseX>=70)&&
(mouseX<=430)&&
(mouseY>=165)&&
(mouseY<=335))
{background(255);
float startX=map(startX_klein,70,430,0,1440);
float startY=map(startY_klein,165,335,0,680);
float moveX=map(mouseX,70,430,0,1440);
float moveY=map(mouseY,165,335,0,680);
selectie=klas.get(min(int(moveX),int(startX)),
min(int(moveY),int(startY)),abs(int(moveX)-int(startX)),
abs(int(moveY)-int(startY)));
venster=3;}}}}
void draw(){
if(venster>0)
{background(255);
fill(255);
rect(30,30,70,30);
fill(0);
text("<-",65,53);}
if(venster==0)
{background(255);
fill(0);
rect(215,235,70,30);
text("Welcome to the Body-program.",250,450);
fill (255);
text("Start",250,257);}
if(venster==1)
{fill(0);
rect(150,235,60,30);
rect(290,235,60,30);
text("First choose your gender.",250,450);
fill(255);
text("M",180,257);
text("F",320,257);}
if(venster==2){
{fill(0);
rect(65,160,370,180);
text("Now select your head.",250,450);
image(klas_klein,250,250);}
if(start==1)
{fill(255,50);
rect(startX_klein,startY_klein,
mouseX-startX_klein,mouseY-startY_klein);}}
if(venster==3)
{text("Is this the head you wanted?",250,450);
image(selectie,250,250);}}