# Demo sketches are stuttering / hanging up

**URL:** <https://discourse.processing.org/t/demo-sketches-are-stuttering-hanging-up/41268>\
**Category:** Beginners\
**Created:** [March 13, 2023, 6:28pm UTC](https://discourse.processing.org/t/demo-sketches-are-stuttering-hanging-up/41268 "2023-03-13T18:28:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![User442B](https://avatars.discourse-cdn.com/v4/letter/u/db5fbb/32.png) [@User442B](https://discourse.processing.org/u/User442B)\
**Post date:** [March 13, 2023, 6:28pm UTC](https://discourse.processing.org/t/demo-sketches-are-stuttering-hanging-up/41268/1 "2023-03-13T18:28:14Z")

</div>

Hi. I recently installed processing and have begun learning it. I have noticed that my sketches are stuttering, sometimes even hanging up for a moment. This happens even when I run demo sketches, such as Bounce from the motion examples. I have checked the frame rate of these sketches and found it’s steady and consistent. It doesn’t reflect the stuttering at all.

For context, this is with the latest version of Processing on windows 10. I did try an earlier version (3.5.4) and still had the stuttering issues. Has anyone else experienced this?

UPDATE: The issue seems to only happen when using P2D or the default renderer. When I change to P3D, the stutter is gone

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [March 14, 2023, 1:23am UTC](https://discourse.processing.org/t/demo-sketches-are-stuttering-hanging-up/41268/2 "2023-03-14T01:23:28Z")

</div>

Hello @User442B,

Try the bounce example with a higher frameRate:

```auto
float xspeed = 1.4; // Speed of the shape
float yspeed = 1.1; // Speed of the shape
frameRate(60); //default

```

I adjusted the step size to half of what it was with _frameRate(30)_.

`:)`

---

<div class="post-metadata">

**Author:** ![User442B](https://avatars.discourse-cdn.com/v4/letter/u/db5fbb/32.png) [@User442B](https://discourse.processing.org/u/User442B)\
**Post date:** [March 14, 2023, 9:46pm UTC](https://discourse.processing.org/t/demo-sketches-are-stuttering-hanging-up/41268/3 "2023-03-14T21:46:03Z")

</div>

Thank you for the quick reply. I made these adjustments, and while it makes the overall movement smoother there is still some stutter. I can tell because for brief periods of time it is super smooth, but then all of a sudden it will become a bit choppy and then smooth again. It is not a terrible stutter, but it is there nonetheless.

I’ve found older threads that seem to have this same problem, but none of the ones I found had an answer

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [March 15, 2023, 1:38am UTC](https://discourse.processing.org/t/demo-sketches-are-stuttering-hanging-up/41268/4 "2023-03-15T01:38:34Z")

</div>

Hello @User442B,

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

```auto
/**
 * 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:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/5/9/5949981533082ae71629e91e83fa2c94f0e3de20.png)

size(640, 760, P3D) output:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/a/9/a9f96963e64c56c0a747d86b900e7840506d9c9b.png)

Another exploration of this I did in the past:

> [@FrameRate hiccups](https://discourse.processing.org/t/framerate-hiccups/11947/20):
>
> I’d be interested what you see with framerate set to 120, or 240 or higher, or maybe even not multiples of 60. JOGL should lock to vsync so should end up with a similar output framerate on a 60Hz display. I think there may be some clock drift going on between the timer and GPU though. I wonder what this would be like on a 75Hz display too?!

Just an exploration…

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

References:

> **[Render Techniques](https://processing.org/tutorials/rendering/)**
>
> Tools for rendering geometries in Processing.

> **[OpenGL](https://en.wikipedia.org/wiki/OpenGL)**
>
> OpenGL (Open Graphics Library) is a cross-language, cross-platform application programming interface (API) for rendering 2D and 3D vector graphics. The API is typically used to interact with a graphics processing unit (GPU), to achieve hardware-accelerated rendering.
> Silicon Graphics, Inc. (SGI) began developing OpenGL in 1991 and released it on June 30, 1992; applications use it extensively in the fields of computer-aided design (CAD), virtual reality, scientific visualization, information vi...

`:)`
