# Why does the frameRate drop so much when I load about 100 pictures into the program

**URL:** https://discourse.processing.org/t/why-does-the-framerate-drop-so-much-when-i-load-about-100-pictures-into-the-program/38196
**Category:** Coding Questions
**Created:** [August 2, 2022, 4:04pm UTC](https://discourse.processing.org/t/why-does-the-framerate-drop-so-much-when-i-load-about-100-pictures-into-the-program/38196 "2022-08-02T16:04:37Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![urlxd](https://avatars.discourse-cdn.com/v4/letter/u/a88e4f/32.png) [@urlxd](https://discourse.processing.org/u/urlxd)
#### Post date: [August 2, 2022, 4:04pm UTC](https://discourse.processing.org/t/why-does-the-framerate-drop-so-much-when-i-load-about-100-pictures-into-the-program/38196/1 "2022-08-02T16:04:37Z")

</div>

hello, i would like to know. why does the frameRate drop so much when I load about 100 pictures into the program. And how to fix it. Pictures from one color, with squares there is no such thing. 😐

---

<div class="post-metadata">

### Author: ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)
#### Post date: [August 2, 2022, 4:06pm UTC](https://discourse.processing.org/t/why-does-the-framerate-drop-so-much-when-i-load-about-100-pictures-into-the-program/38196/2 "2022-08-02T16:06:49Z")

</div>

Hi @urlxd,

One need to see your code to be able to analyse…

Cheers  
— mnse

---

<div class="post-metadata">

### Author: ![urlxd](https://avatars.discourse-cdn.com/v4/letter/u/a88e4f/32.png) [@urlxd](https://discourse.processing.org/u/urlxd)
#### Post date: [August 2, 2022, 4:18pm UTC](https://discourse.processing.org/t/why-does-the-framerate-drop-so-much-when-i-load-about-100-pictures-into-the-program/38196/3 "2022-08-02T16:18:59Z")

</div>

```auto
int size = 100;

int W = 20;
int H = 20;

PImage block;

Cell cell[][] = new Cell[W][H];
void setup (){
  fullScreen(1);
  block = createImage(size,size,RGB);
  block = loadImage("block.png");
  
  for(int x = 0; x < W; x++){
    for(int y = 0; y < H; y++){
      cell[x][y] = new Cell(x,y);
    }
  }
}

void draw (){
  background (0);
  for(int x = 0; x < W; x++){
    for(int y = 0; y < H; y++){
      cell[x][y].make();
    }
  }
  fill(255,0,0);
  text(frameRate, 100,100);
}

class Cell{
  
  int x,y;
  
  Cell(int x, int y){
    this.x = x;
    this.y = y;
  }
  
  void make(){
    image(block, x * size, y * size, size,size);
  }
}

```

[block|1x1](https://discourse.processing.org/uploads/short-url/5tfJxFxVGY8yXXycqbDXpp0Ugb4.png)

---

<div class="post-metadata">

### Author: ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)
#### Post date: [August 2, 2022, 4:39pm UTC](https://discourse.processing.org/t/why-does-the-framerate-drop-so-much-when-i-load-about-100-pictures-into-the-program/38196/4 "2022-08-02T16:39:39Z")

</div>

Hi @urlxd,

Please try this. Im not able to test as iam currently only have mobile access …

Cheers  
— mnse

```auto
int size = 100;

int W = 20;
int H = 20;

PImage block;

Cell cell[][] = new Cell[W][H];
void setup (){
  // use P2D renderer
  fullScreen(P2D, 1);
  // Useless
  //block = createImage(size,size,RGB);
  block = loadImage("block.png");
  // If block not having size size do
  block.resize(size,size);
  
  for(int x = 0; x < W; x++){
    for(int y = 0; y < H; y++){
      cell[x][y] = new Cell(x,y);
    }
  }
}

void draw (){
  background (0);
  for(int x = 0; x < W; x++){
    for(int y = 0; y < H; y++){
      cell[x][y].make();
    }
  }
  fill(255,0,0);
  text(frameRate, 100,100);
}

class Cell{
  
  int x,y;
  
  Cell(int x, int y){
    this.x = x;
    this.y = y;
  }
  
  void make(){
    image(block, x * size, y * size);
  }
}

```

---

<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: [August 2, 2022, 6:20pm UTC](https://discourse.processing.org/t/why-does-the-framerate-drop-so-much-when-i-load-about-100-pictures-into-the-program/38196/5 "2022-08-02T18:20:08Z")

</div>

Hello,

I get 60 fps with your code with:

`fullScreen(P2D, 1);`

Reference:  
[https://processing.org/reference/fullScreen\_.html](https://processing.org/reference/fullScreen_.html)

`:)`

---

<div class="post-metadata">

### Author: ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)
#### Post date: [August 2, 2022, 7:18pm UTC](https://discourse.processing.org/t/why-does-the-framerate-drop-so-much-when-i-load-about-100-pictures-into-the-program/38196/6 "2022-08-02T19:18:36Z")

</div>

Damn typo 😀

Thx @glv for correction …

Cheers  
---- mnse

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [August 2, 2022, 9:45pm UTC](https://discourse.processing.org/t/why-does-the-framerate-drop-so-much-when-i-load-about-100-pictures-into-the-program/38196/7 "2022-08-02T21:45:27Z")

</div>

> [@mnse](#):
>
> `x * size, y * size`

this can be calculated and stored in the constructor

```auto
x2= x * size;
y2= y * size;

```

and then the image line is just

```auto
    image(block, x2, y2);

```

---

<div class="post-metadata">

### Author: ![urlxd](https://avatars.discourse-cdn.com/v4/letter/u/a88e4f/32.png) [@urlxd](https://discourse.processing.org/u/urlxd)
#### Post date: [August 3, 2022, 4:15am UTC](https://discourse.processing.org/t/why-does-the-framerate-drop-so-much-when-i-load-about-100-pictures-into-the-program/38196/8 "2022-08-03T04:15:01Z")

</div>

Thanks. I also only have a mobile phone because the PC is weak.

---

<div class="post-metadata">

### Author: ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)
#### Post date: [August 3, 2022, 5:28am UTC](https://discourse.processing.org/t/why-does-the-framerate-drop-so-much-when-i-load-about-100-pictures-into-the-program/38196/9 "2022-08-03T05:28:04Z")

</div>

Hi @Chrisir,

This is a reasonable improvement, especially since the issue here is about performance…

> [@Chrisir](#):
>
> this can be calculated and stored in the constructor
> 
> ```auto
> x2= x * size;
> y2= y * size;
> 
> ```
> 
> and then the image line is just
> 
> ```auto
> image(block, x2, y2);
> 
> ```

However, based on the code above, I wouldn’t do it that way. Since in this case the size is not used for the class at all, I would do it directly at initialization…

`cell[x][y] = new Cell(x*size,y*size);`

and below just

`image(block, x, y);`

Cheers  
— mnse
