Help needed please in code

Within setup and main. I am creating a pg graphics at x,y resolution, placing a value in centre. Then randomly choosing a point. If the point = centre then x,y found.

Wth am I doing wrong??

PGraphics pg;

float col=10;

int count=0;

int xsize=1500;
int ysize=500;
int tempx;
int tempy;
int temppixel;
float pixheight;

int pixel;

void setup(){
size(1500, 500);
noSmooth();
colorMode(RGB,255);
pg=createGraphics(xsize, ysize);
pg.noSmooth();
pg.beginDraw();
pg.background(0,0,0);
pg.loadPixels();
pg.fill(255);
pg.strokeCap(SQUARE);
frameRate(1);

int px=xsize/2;
int py=ysize/2;
pixel=(px+(py*xsize));
pg.pixels[pixel] = color(200,200,200);

positionchange();

}

void draw(){
pg.colorMode(RGB,255);
pg.beginDraw();
pg.updatePixels();
image(pg,0,0,1500,500);
}

void positionchange(){
tempx=int(random(1,xsize));
tempy=int(random(1,ysize));
temppixel=(tempx+(tempy*xsize));
pixheight=red(pg.pixels[temppixel]);

println(temppixel);

if (pixheight==0); {
positionchange();
}

}

you loop it too much. Find another way to do it.

How though?? It’s sooooo simple but can’t think how ???

But it has to be looped until the centre point is found

Code in other language:

position:

randomize

x=(int(rnd(xmax)))

y=(int(rnd(ymax)))

get pixel x,y color r2,g2,b2

if r2=0 then goto position

return

you need to add a way to find if the pixel has been checked yet.
image
What I am trying to signal in this image is that you go over the previously checked squares. In results in an infinite loop

Why is something so difficult so hard within Processing!! ??

Ok.
Using PG graphics.
Everything is black apart from middle point.

Go to a routine that randomly finds that point and re-iterates till it’s done.

Once done, display the point found (middle) on screen.