Demo sketches are stuttering / hanging up

Hello @User442B,

Try this code with and without P2D (or P3D):

/**
 * Bounce. 
 * 
 * When the shape hits the edge of the window, it reverses its direction. 
 */
 
 import processing.javafx.*;
 
int rad = 60;        // Width of the shape
float xpos, ypos;    // Starting position of shape    

float xspeed = 1.4;  // Speed of the shape
float yspeed = 1.1;  // Speed of the shape

int xdirection = 1;  // Left or Right
int ydirection = 1;  // Top to Bottom

int tlast;

boolean toggle = false;

void setup() 
  {
  //size(640, 760, P2D);
  size(640, 760);
  println("Renderer: " + g.getClass().getName());  

  frameRate(30);
  ellipseMode(RADIUS);
  // Set the starting position of the shape
  xpos = width/2;
  ypos = height/4;
  tlast = millis();
  background(102);
}

void draw() 
{
  //background(102);
  fill(102);
  noStroke();
  rect(0, 0, width, height-400);
  int tnow = millis();
  int tdif = tnow-tlast;
  int y = height-5*(tdif-33)-200;
  int tmp = frameCount%width;
  int x = tmp;
  if (tmp == 0)
    background(102);
  tlast = tnow;
  //println(x, tdif);
  stroke(255, 255, 0);
  strokeWeight(abs(tdif-33));
  point(x, y);
  
  // Update the position of the shape
  xpos = xpos + ( xspeed * xdirection );
  ypos = ypos + ( yspeed * ydirection );
  
  // Test to see if the shape exceeds the boundaries of the screen
  // If it does, reverse its direction by multiplying by -1
  if (xpos > width-rad || xpos < rad) 
    {
    xdirection *= -1;
    }
  if (ypos > height-rad-400 || ypos < rad) 
    {
    ydirection *= -1;
    }

  // Draw the shape
  fill(255);
  noStroke();
  ellipse(xpos, ypos, rad, rad);
  }

For frameRate(30) the expected period T = 1/30 = 33.33 ms
The above code plots the deviation from 33 ms.

size(640, 760) output:

size(640, 760, P3D) output:

Another exploration of this I did in the past:

Just an exploration…

P2D and P3D use OPENGL which can use hardware rendering on GPU.

References:

:)