# Running really slow for a relatively simple program

**URL:** https://discourse.processing.org/t/running-really-slow-for-a-relatively-simple-program/20762
**Category:** Coding Questions
**Created:** [May 11, 2020, 11:14pm UTC](https://discourse.processing.org/t/running-really-slow-for-a-relatively-simple-program/20762 "2020-05-11T23:14:24Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Xabdro](https://avatars.discourse-cdn.com/v4/letter/x/8baadc/32.png) [@Xabdro](https://discourse.processing.org/u/Xabdro)
#### Post date: [May 11, 2020, 11:14pm UTC](https://discourse.processing.org/t/running-really-slow-for-a-relatively-simple-program/20762/1 "2020-05-11T23:14:25Z")

</div>

I’ve made much more complicated programs than this yet its running at 30fps when at low resolution. If I go fullscreen it drops to less than ten fps. I think I must be missing something really obvious that is causing this massive slowdown but I can’t see what it is. Any help would be greatly appreciated.

```auto
float[] randomV;
int density = 200;
int lowB = 0;
int change = 1;
float hue = 0;
  float bri = 0;
  float r = 0;

void setup(){
size(500,500);
//fullScreen(P2D);
 background(0);
 //noLoop();
 noFill();
 strokeWeight(3);
 randomV = new float[density];
 generateRandomV();
 
 colorMode(HSB,360,100,100);
}

void draw(){
  background(0);
  translate(450,250);
  for(int i=density-1; i>0; i--){
    hue = map(i,0,density,lowB,lowB+80);
    bri = map(i,density,0,100,600);
    stroke((hue+(randomV[i]*10))%360,100,bri,50);
    r = randomV[i];
   ellipse(-i-r,0,10+((i+r)*2),10+((i+r)*2)); 
  }
  if(lowB==280){
   change = -1;
  }else if(lowB==0){
   change = 1; 
  }
  if(frameCount%2==0){
  lowB+=change;
  }

  
}

void generateRandomV(){
  for(int i = 0; i<density; i++){
  randomV[i] = random(20); 
 }
}

void mousePressed(){
 generateRandomV(); 
}

```

---

<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: [May 11, 2020, 11:39pm UTC](https://discourse.processing.org/t/running-really-slow-for-a-relatively-simple-program/20762/2 "2020-05-11T23:39:27Z")

</div>

Hello,

It rocks with:  
`size(1000, 1000, FX2D);`

and

`size(1000, 1000, P3D);`

P3D rapidly declined as density increased.

I added this to monitor frameRate:

```auto
  if (frameCount%5 == 0)
    surface.setTitle(str(frameRate));

```

[https://processing.org/reference/setTitle\_.html](https://processing.org/reference/setTitle_.html)

There is a comment about _FX2D_ here:  
[https://processing.org/reference/environment/](https://processing.org/reference/environment/)

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/e/e02c40ecfaae7cdc80f0b48d8e8cc61c976556a6.jpeg)

`:)`

---

<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: [May 12, 2020, 2:53am UTC](https://discourse.processing.org/t/running-really-slow-for-a-relatively-simple-program/20762/3 "2020-05-12T02:53:23Z")

</div>

Hello,

Another approach is to create all of your shapes in advance.

Reference:  
[https://processing.org/tutorials/pshape/](https://processing.org/tutorials/pshape/)

In setup():

```auto
  for (int i=density-1; i>0; i-=1) 
    {
    //hue = map(i, 0, density, lowB, lowB+80);
    //bri = map(i, density, 0, 100, 600);
    //stroke((hue+(randomV[i]*10))%360, 100, bri, 50);
    r = randomV[i];
    float r1 = i+r;
    float r2 = 10+(r1*2);
    shapes[i] = createShape(ELLIPSE, -r1, 0, r2, r2);
    }

```

Use the same loop in draw() but color and display shape the shape:

```auto
    color c = color((hue+(randomV[i]*10))%360, 100, bri, 50);
    shapes[i].setStroke(c);
    shape(shapes[i], 0, 0);

```

[https://processing.org/tutorials/pshape/](https://processing.org/tutorials/pshape/)  
[https://processing.org/reference/PShape\_setStroke\_.html](https://processing.org/reference/PShape_setStroke_.html)

With density of 1000 I got 60 fps with P2D, P3D, FX2D but slow with default renderer.

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/5/59a8105fbba006b6c61846b214d14db9b305c407.png)

`:)`

---

<div class="post-metadata">

### Author: ![Xabdro](https://avatars.discourse-cdn.com/v4/letter/x/8baadc/32.png) [@Xabdro](https://discourse.processing.org/u/Xabdro)
#### Post date: [May 12, 2020, 4:21pm UTC](https://discourse.processing.org/t/running-really-slow-for-a-relatively-simple-program/20762/4 "2020-05-12T16:21:42Z")

</div>

Thank you so much for your help. I’d not heard of FX2D. I’ve never encountered this level of slowdown with P2D. I assumed that since I was drawing 2D shapes I should use a 2D renderer so didn’t even think of P3D. Kind of strange. Probably above my level of expertise to understand why this is.  
Thanks for the detailed response 😃

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [May 14, 2020, 6:23am UTC](https://discourse.processing.org/t/running-really-slow-for-a-relatively-simple-program/20762/5 "2020-05-14T06:23:54Z")

</div>

> [@Xabdro](#):
>
> I’ve never encountered this level of slowdown with P2D.

It is ellipse. I’m not sure why, but switch to rect 58-50 fps… back to ellipse, 17fps.
