# Why doesn't this halftone code work?

**URL:** <https://discourse.processing.org/t/why-doesnt-this-halftone-code-work/23738>\
**Category:** Beginners\
**Tags:** homework\
**Created:** [September 8, 2020, 2:02pm UTC](https://discourse.processing.org/t/why-doesnt-this-halftone-code-work/23738 "2020-09-08T14:02:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gatz\_gaz](https://avatars.discourse-cdn.com/v4/letter/g/bb73d2/32.png) [@gatz\_gaz](https://discourse.processing.org/u/gatz_gaz)\
**Post date:** [September 8, 2020, 2:02pm UTC](https://discourse.processing.org/t/why-doesnt-this-halftone-code-work/23738/1 "2020-09-08T14:02:18Z")

</div>

```auto

PImage foto;

int maxImages = 6; // Img in totale
int imageIndex = 0; // Img iniziale

PImage[] images = new PImage[maxImages]; // Serie di Img

void setup() {
  size(2300, 1700);
   foto = loadImage("Data/nin0.jpg");
 
  for (int i = 0; i < images.length; i ++ ) {
    images[i] = loadImage( "nin" + i + ".jpg" );

  }
}
void draw(){
  
  noLoop();
  noFill();
  strokeWeight(.003);
  stroke(255,0,0);
  
  foto.loadPixels();
   for (int y = 0; y < foto.height; y++) {
    for (int x = 0; x < foto.width; x++) {
      int loc = x + y*foto.width;
      float r = red(foto.pixels[loc]);
      float g = green(foto.pixels[loc]);
      float b = blue(foto.pixels[loc]);
      float c = (0.21*r + 0.72*g + 0.07*b);
      float colore = map(c, 0, 255, 0, 10);
      ellipse(x*15, y*15, colore, colore);
      background(255);
       
   
    foto.updatePixels();  
    image(foto, 0, 0);
    imageIndex = (imageIndex + 1);
    saveFrame("output/file_" + imageIndex + ".png");
    exit();
      

    }
   }
  float colore;
}

```

---

<div class="post-metadata">

**Author:** ![SomeOne](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/someone/32/8639_2.png) [@SomeOne](https://discourse.processing.org/u/SomeOne)\
**Post date:** [September 8, 2020, 3:29pm UTC](https://discourse.processing.org/t/why-doesnt-this-halftone-code-work/23738/2 "2020-09-08T15:29:47Z")

</div>

> [@gatz\_gaz](#):
>
> `exit();`

You stop the program with exit() inside the inner loop. You don’t need it because noLoop() stops rerunning of draw().

Second problem is that foto is uninitialized variable and should cause null pointer exception
