mouse always starts top left,
actually even if mouse is not over window
( there are some more tricks to detect that )
but the first problem / question
if you want paint the circles over each other its ok,
if you want only one circle ( following mouse ) use:
void setup () {
size(500, 500);
noStroke();
}
void draw () {
background(200, 200, 0);
if (mousePressed) fill(0,200,0);
else fill(0,0,200);
ellipse(mouseX, mouseY, width/2,width/2);
}
now i try some older tests about mouse in or not, combined with window focused or not,
still there are situations where the top/left circle shows.
boolean paint = true;
public boolean mousePresent = false;
void setup () {
size(500, 500);
noStroke();
if ( paint) background(0);
println("use: key [p]");
}
void draw () {
if ( !paint ) background(200, 200, 0);
if ( mousePresent && focused ) {
if (mousePressed) fill(0, 200, 0);
else fill(0, 0, 200);
ellipse(mouseX, mouseY, width/8, width/8);
}
}
void keyPressed() {
if ( key == 'p' ) paint = !paint;
}
public void mouseExited() {
mousePresent = false;
}
public void mouseEntered() {
mousePresent = true;
}
so
no, looks like you even need a start state:
boolean paint = true, start = false, mousePresent = false;
void setup () {
size(500, 500);
noStroke();
if ( paint) background(0);
println("use: key [p] for toggle painting\nkey [s] for start");
}
void draw () {
if ( !paint ) background(200, 200, 0);
if ( mousePresent && focused && start) {
if (mousePressed) fill(0, 200, 0);
else fill(0, 0, 200);
ellipse(mouseX, mouseY, width/8, width/8);
}
}
void keyPressed() {
if ( key == 'p' ) paint = !paint;
if ( key == 's' ) start = true;
}
public void mouseExited() {
mousePresent = false;
}
public void mouseEntered() {
mousePresent = true;
}
now when you press key [s] the first circle appears at mouse position.