Low frameRate, my code gives 10 - 15 frames

Hello everyone. My code doesnt give me 30 frameRate even i dont do much thing there ! Help me please, thanks.

String s = "belli";
PFont font;
int tileCount = 25;
float tileWidth, tileHeight;


void setup() {
  size(800, 800);
  tileWidth = 25;
  tileHeight = 30;
  font = createFont("aktif.otf", 200);
  textFont(font);
  textSize(18);
  //textAlign(CENTER, CENTER);
  noCursor();
} 

void draw() {
  background(255);
  for (int gridY=0; gridY<tileCount-3; gridY++) {
    for (int gridX=0; gridX<tileCount; gridX++) {
      float posX = tileWidth*gridX+100;
      float posY = tileHeight*gridY+80;
      float angle = atan2(mouseY-posY, mouseX-posX) + radians(90);
      pushMatrix();
      translate(posX, posY);
      rotate (angle);
      fill(0);
      text(s.charAt((gridX+gridY)%5), 0, 0);
      popMatrix();
    }
  }
  fill(255, 0, 0);
  noStroke();
  circle(mouseX, mouseY, 30);
  fill(0);
  text(""+frameRate+"", 90, 20);
}

Your fonts are causing an issue.

The font issue is because I(and you probably too) haven’t installed the font.
For me it is running a pretty stable frameCount between 58 and 60.
Mybe try setting frameCount manually to 60 by using frameRate(60);, however is 60 the default frame rate set by processing, so if your processor isn’t fast enough 60fps can’t be achieved (see https://processing.org/reference/frameRate_.html).

I made the same observation…

A solid 60 fps commenting the fonts:

  //font = createFont("aktif.otf", 200);
  //textFont(font);

:)

@glv @Bobby54 @paulgoux I have to use that font. Do I have a chance to get 30fps ?

Try font = createFont("aktif.otf", 18); and remove textSize(18);.

If that doesn’t work, rasterise each character into a PImage and replace text() with image().

I don’t think that’s a good idea since loading and drawing images takes longer and has a bigger impact on the processor.

1st variant helped a little, now i got 20 - 22 fps… better) Thanks.

If I were you make a class Letter with position and char etc. and fill an 1D-array of Letter with the data (in setup())

Then in draw() you would have less calculating.

Still you would have 25x25 pushMatrix calls which is expensive.

Hello,

Try it with another renderer and report (just curious) your frame rates:

  size(800, 800);
  //size(800, 800, FX2D);
  //size(800, 800, P2D);
  //size(800, 800, P3D);

https://processing.org/reference/environment/
https://www.processing.org/tutorials/rendering/

I am getting solid frame rates while actively moving mouse with one of the other renderers.

:)

4 Likes

Hello, thank u @glv!
size(800, 800, P2D) and size(800, 800, P3D) are helped ! 60 fps, wonderfull !

2 Likes