Require urgent help! What am I doing wrong??
Maths is correct, but…
Overview:
To display a source image (example 15000 X 5000 PX) on 1920 X 1080 destination output. (keeping the correct aspect for destination)
Due to source image being > destination size, am selecting initial random positions from source image, holding the correct aspect ratio to the destination, not exceeding an output > a selected area from source. (I.e magnified) , but scaled / reduced accordingly - keeping the original aspect to destination).
Random areas from source are initially calculated and scaled down accordingly (held in an array - top left, bottom right, so to define an area from source), then displayed to destination accordingly
Issue:
Maths is fine, but something wrong with code.
Will not update selected source outputs to display, unless current window is moved via mouse. (Not updating)
Current Code:
(Please help!!)
PImage img;
PImage newimg;
int sxsize;
int sysize;
int xsize;
int ysize;
int points=100;
int[] x1=new int[points+1];
int[] x2=new int[points+1];
int[] y1=new int[points+1];
int[] y2=new int[points+1];
int xpos;
int ypos;
int distx;
int disty;
int i;
float t1;
float t2;
float aspect;
void setup(){
//fullScreen(1);
size (1920,1080);
noSmooth();
frameRate(25);
img=loadImage("1.jpg"); // use image @ 15000 X 5000 PX
sxsize=img.width;
sysize=img.height;
xsize=1920;
ysize=1080;
aspect=float(xsize)/float(ysize);
// set points
setpoints();
}
void draw(){
// get= x,y start width,height
for (i=1; i<=points; i++) {
xpos=x1[i];
ypos=y1[i];
distx=(x2[i]-x1[i]);
disty=(y2[i]-y1[i]);
newimg=img.get(xpos,ypos,distx,disty); // grab image from 1.jgp @ correct aspect ratio already calculated
newimg.resize(xsize,ysize);
image(newimg,0,0);
}
}
void setpoints(){
for (i=1; i<=points; i++) {
// set y1,y2 in array points
while(true){ // find distance in y> output screen size
t1=int(random(sysize));
t2=int(random(sysize));
if(abs(t1-t2)>ysize){
break;
}
}
// if t1<t2 then OK
y1[i]=int(t1);
y2[i]=int(t2);
if (y1[i]>y2[i]){ // if t1>t2 then swap
y1[i]=int(t2);
y2[i]=int(t1);
} // end if
// set x1,x2 points
float xmaxsize=(y2[i]-y1[i])*aspect; // calc max grab width dependant on aspect ratio based upon y1,y2
t1=int(random(sxsize-xmaxsize)); // select a random area from source image less xmagesize
t2=int(((y2[i]-y1[i])*aspect))+t1; // add aspect amount to t1 so to have bottom right coordinate.
x1[i]=int(t1);
x2[i]=int(t2);
if(x1[i]>x2[i]){
x1[i]=int(t2);
x2[i]=int(t1);
}
}
}