Increasing the frameRate when updating pixels
in
Programming Questions
•
2 years ago
Hi
I was writing something like this for a larger sketch and wondered if there is a way to increase the framerate? Is there a better way to recalculate and update all pixels?
I was writing something like this for a larger sketch and wondered if there is a way to increase the framerate? Is there a better way to recalculate and update all pixels?
- PGraphics pg;
void setup(){
size(900,450);
noFill();
pg = createGraphics(width, height, P2D);
}
void draw(){
float sinFactor = width/(mouseX+1);
float cosFactor = height/(mouseY+1);
background(0);
pg.loadPixels();
for(int i = 0; i < width; i++){
for(int j = 0; j < height; j++){
color p = color( ( 127.5 * sin(radians(j)*sinFactor) * cos(radians(i)*cosFactor) ) + 127.5 );
pg.pixels[j*width+i] = p;
}
}
pg.updatePixels();
image(pg,0,0);
println(frameRate);
}
1