Print() Causes Animation Lagging - Are there fixes? What else causes lags?

Hello Forum,

I am in the processing of shifting from Processing to p5Js for my high school class that is now online starting Monday. We love to use print() to learn but I noticed that it causes severe lag for animations (see example with it on and off).

Is there a simple way to prevent this?
Also, are there other functions or strategies that I should be aware of to prevent lagging?

Thank you for your help.



let x = 75; 
let speed = 3;

function setup() {
  createCanvas(300,300);
}

function draw() {
  background(255);
  print ("x=",x);
  print ("speed=",speed);
  
  if ( (x<0) || (x>300)){
    speed = speed * -1;
	}    
  
	  x = x + speed;
    fill(0,0,255);
    ellipse (x,150,50,50);      

}//close draw
1 Like

You can print() at 1 FPS rather than 60 FPS:

frameCount % 60 || print(`x = ${ x }, spd = ${ speed }`);
2 Likes

Or just use text(), it’s cooler than print

2 Likes

Or sample printing your logger at a much slower rate than the frameRate – e.g. 1 FPS.

1 Like