Bad perfomance
in
Programming Questions
•
2 months ago
Hi, i got a very little framerate with this sketch:
- PVector [] stars=new PVector[300];
float increment = 0.015;
float cycle=0;
int i;
void setup() {
size(800, 200, OPENGL);
for (i=0;i<300;i++)
stars[i]=new PVector(random(width), random(height));
}
void draw() {
loadPixels();
float xoff = 0.0+cycle;
for (int x = 0; x < width; x++) {
xoff += increment;
float yoff = 0;
for (int y = 0; y < height; y++) {
yoff += increment;
float blu = map(noise(xoff, yoff), 0, 1, 20, 79);
float red = map(noise(xoff, yoff), 0, 1, 1, 36);
float green=map(noise(xoff, yoff), 0, 1, 1, 9);
pixels[x+y*width] = color(red, green, blu);
}
updatePixels();
}
cycle-=0.03;
star();
println(frameRate);
}
void star()
{
fill(255);
for (i=0;i<200;i++)
{
stars[i].x+=0.06;
if (stars[i].x>width)
{
stars[i].x=random(0, 1);
stars[i].y=random(0, height);
}
ellipse(stars[i].x, stars[i].y, 2, 2);
}
}
The framerate is stable to 13/14 FPS, my pc is able to run games like Crysis or Max Payne 3 so i can't understand why this little program is so slow.
1