# How can I get this halftone effect on a folder containing images, and then export them to another folder?

**URL:** <https://discourse.processing.org/t/how-can-i-get-this-halftone-effect-on-a-folder-containing-images-and-then-export-them-to-another-folder/23711>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [September 6, 2020, 1:17pm UTC](https://discourse.processing.org/t/how-can-i-get-this-halftone-effect-on-a-folder-containing-images-and-then-export-them-to-another-folder/23711 "2020-09-06T13:17:41Z")\
**Posts on this page:** 4\
**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 6, 2020, 1:17pm UTC](https://discourse.processing.org/t/how-can-i-get-this-halftone-effect-on-a-folder-containing-images-and-then-export-them-to-another-folder/23711/1 "2020-09-06T13:17:41Z")

</div>

![NIN0](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/4/4c9da3b987893c76a6620cfb4837e17c48bda7a1.png)

---

<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 6, 2020, 1:42pm UTC](https://discourse.processing.org/t/how-can-i-get-this-halftone-effect-on-a-folder-containing-images-and-then-export-them-to-another-folder/23711/2 "2020-09-06T13:42:58Z")

</div>

How much help do you need? Or on what skill level? Do you have any code yet ready? It would be a good starting point to help you forward.

---

<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 6, 2020, 6:12pm UTC](https://discourse.processing.org/t/how-can-i-get-this-halftone-effect-on-a-folder-containing-images-and-then-export-them-to-another-folder/23711/3 "2020-09-06T18:12:27Z")

</div>

I have this code, but I just want it to be exported in halftone

```auto

 
PImage img;
int bsize = 3 ;
boolean offset = true;
 
import processing.pdf.*;
 
void setup() {
 
  println( brightness( color(255)));
  println( brightness( color(0)));
 
  noStroke();
  img = loadImage("testpattern.jpg");
  size(500, 500);
  background(255);
  //tint(255, 170);
  image(img, 0, 0);
 
  noLoop();
  beginRecord(PDF, "Halftonize export.pdf"); 
 
  //filter(POSTERIZE,4);
  //filter(THRESHOLD);
  noTint();
 
  for (int x=0; x < width; x+=bsize) {
    for (int y=0; y < height; y += bsize) {
 
      color c = getavg(x, y, bsize);
      float b = brightness(c);
      int r = 0;
 
      fill(0);
 
      if ( b > 0 && b < 50) {
        r = bsize;
      }
      if ( b > 50 && b < 90) {
        r = floor(bsize * .9);
      }
      if ( b > 90 && b < 130) {
        r = floor(bsize * .8);
      }
      if ( b > 130 && b < 190) {
        r = floor(bsize * .4);
      }
      if ( b > 190 && b < 230) {
        r = floor(bsize * .2);
      }
      if ( b > 230) {
        r = 1;
      }
 
      if ( offset) {
        ellipse(x+bsize, y, r, r);
      }
      else {
        ellipse(x, y, r, r);
      }
      offset = ! offset;
    }
  }
 
  println("Finished");
  //saveFrame("output/output##.jpg");
}
 
color getavg(int x, int y, int blocksize) {
  float r =0;
  float g =0;
  float b =0;
  int count=0;
 
  for (int xx=x; xx < x+ blocksize; xx++) {
    for (int yy=y; yy< y +blocksize; yy++) {
      r += red( img.get(xx, yy) );
      g += green( img.get(xx, yy));
      b += blue( img.get(xx, yy));
      count++;
    }
  }
  return color( r/count, g/count, b/count);
}
 
void draw() {
  endRecord();
}

```

---

<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 6, 2020, 6:17pm UTC](https://discourse.processing.org/t/how-can-i-get-this-halftone-effect-on-a-folder-containing-images-and-then-export-them-to-another-folder/23711/4 "2020-09-06T18:17:59Z")

</div>

and the halftone images I want them to resemble those in the image above
