So ive been working on a little project today and ran into an issue, wondering if anyone can tell my why its happening, theres a get() line commented out under the draw function, with it commented out it breaks and stops working as intended but with that line running it works as intended, maybe ive just overlooked something or maybe P3D needs fixing, i actually found the issue by accident as i put the same get function in a print statement to get color values, so it was a fluke but worked
heres my code
int total = 10000;
Mover[] movers = new Mover[total];
boolean paused = false;
PGraphics img;
void setup() {
size(1000, 1000, P3D);
surface.setVisible(true);
img = createGraphics(width, height, P3D);
img.loadPixels();
noSmooth();
for (int i = 0; i < total; i++) {
movers[i] = new Mover();
}
}
void draw() {
surface.setTitle(str((int)frameRate));
background(0);
img.beginDraw();
//img.get(0,0);
if (!paused) {
img.noStroke();
img.fill(0, 30);
img.rect(0, 0, width, height);
}
for (Mover m : movers) {
if (!paused) {
m.boundary();
m.update();
}
m.show();
}
image(img, 0, 0);
img.endDraw();
}
void keyPressed() {
if (key == ' ') paused = !paused;
}
and heres the class for the movers
class Mover {
PVector pp, pos, move, senseL, senseR, center;
int senseDist;
int index;
float SL, SR;
int sensorSpread;
int sensorTurnRate;
int sensorSize;
int borderTurnRate;
int turnRate;
int xl,yl,xr,yr;
int pixelCount = width*height;
Mover() {
pos = new PVector(width/2,height/2);
pp = pos.copy();
move = PVector.random2D().mult(3);
senseL = new PVector();
senseR = new PVector();
senseDist = 20;
sensorSpread = 30;
sensorTurnRate = 20;
sensorSize = 2;
borderTurnRate = 30;
turnRate = 15;
}
void update() {
senseL.set(senseDist, 0);
senseL.rotate(move.heading() + radians(-sensorSpread));
senseL.add(pos.copy());
senseR.set(senseDist, 0);
senseR.rotate(move.heading() + radians(sensorSpread));
senseR.add(pos.copy());
SL = 0;
SR = 0;
for (int j = -sensorSize; j < sensorSize; j++) {
for (int i = -sensorSize; i < sensorSize; i++) {
xl = floor(senseL.x+i);
yl = floor(senseL.y+j);
xr = floor(senseR.x+i);
yr = floor(senseR.y+j);
SL += img.brightness(img.pixels[(xl + yl * width + pixelCount) % pixelCount]);
SR += img.brightness(img.pixels[(xr + yr * width + pixelCount) % pixelCount]);
}
}
if (SL > SR) {
move.rotate(radians(-sensorTurnRate));
} else if (SR > SL) {
move.rotate(radians(sensorTurnRate));
} else {
move.rotate(radians(random(-turnRate, turnRate)));
}
pos.add(move);
}
boolean sense(PVector v) {
if (v.x < 0 || v.x > width || v.y < 0 || v.y > height) {
return true;
}
return false;
}
void boundary() {
if (sense(senseL)) {
move.rotate(radians(borderTurnRate));
}
if (sense(senseR)) {
move.rotate(radians(-borderTurnRate));
}
if (sense(senseL) && sense(senseR)) {
move.rotate(PI);
}
}
void show() {
img.stroke(255);
img.strokeWeight(2);
img.line(pp.x, pp.y, pos.x, pos.y);
pp.set(pos.copy());
}
}