Hello @Erik,
Give it a try!
I like to generate code to test such things under different conditions.
Some code to test performance:
// Performance setting boundaries for shapes
// glv
// 2023-12-31
// v1.0.0
boolean c;
int d, dt, off, mo;
void setup()
{
size(500, 500);
println(cnt);
d = 40;
mo = 4; // The 4 was for testing to see boundary conditions!
off = 40/2-mo;
}
void draw()
{
surface.setTitle(str(int(frameRate)) + " " + str(dt));
int t0 = millis();
for (int i=0; i<5000; i++)
{
float x = random(-500, 1000);
float y = random(-500, 1000);
// Uncomment to change offset with mouse
//mo = (int) map(mouseX, 0, width, -100, 100);
//off = 40/2 + mo;
if (cnt == 0)
{
fill(255, 255, 0);
circle(x, y, d);
}
else if (cnt == 1)
{
c = x<(0-off) || x>(499+off) || y<(0-off) || y>(499+off);
if (c)
{
fill(255, 0, 0);
circle(x, y, d);
}
}
else if (cnt == 2)
{
c = x>(0+off) && x<(499-off) && y>(0+off) && y<(499-off);
if (c)
{
fill(0, 255, 0);
circle(x, y, d);
}
}
}
int t1 = millis();
dt = t1-t0;
//println(t, dt); // Printing to console can slow things down!
}
int cnt;
void mousePressed()
{
cnt++;
cnt = cnt%3;
println(cnt);
}
Click on mouse to go through the difference conditions.
This seemed to provide the best performance for the code provided:
I wrote this quickly and will revisit another day. Not drawing any conclusions as yet.
Feel free to scrutinize code and make changes.
Have fun!
:)