Introduction: Laser-Cut Screen From a Photograph

In this project, you'll start with a digital image and use Processing to convert it into a grid of circles (similar to a halftone image) that can be used to make a laser-cut screen. Processing outputs a PDF file, which I import into Adobe Illustrator to use with the laser cutter.

The full sketch is available here.

Step 1: Create a Processing Sketch and Choose a Photo

If you haven't already downloaded and installed Processing, you can get it here.

First create a new Processing sketch and save it. Then, inside of the sketch's folder, create a new folder called "data". Place the photo you want to use inside the data folder.

Back in your Processing file, start by importing the library to handle creating pdf files.

import processing.pdf.*;

Declare the following variables:

String myFile = "myImage.jpg";
PImage pic;  
int w, h;

Step 2: Resize the Photo in Setup

Load the image and set the variables w and h to the image dimensions.

pic = loadImage(myFile); 

h = pic.height;
w = pic.width;

Then resize the image so that it's 150 pixels on it's longest side. Note that in resize(), using the 0 automatically resizes the second dimension while maintaining the original image's proportions.

Eventually, we're going to look at each pixel of the input image and use it's brightness to set the size of the output circle. In the code, I've set it up so that the output circles vary from 0 to 10 pixels wide with 5 pixels of space between them. This means that the output image will be 15 times as large as the image we start with. So we need to start with a relatively small image.

if( w > h){
    pic.resize(150,0); 
  } else if (h > w) {
    pic.resize(0,150);
  } else if (h == w){
    pic.resize(150,150);
  }

Set the output dimensions.

size(2250,2250);

And set up the PDF file. This will be your output file. It will automatically save to your Processing sketch's folder. If you want to rename it, simply replace "dotPic.pdf" with your own filename.

beginRecord(PDF, "dotPic.pdf");

Note that if you re-run the program, it will overwrite the file that was created last time. If you want to run the program multiple times and save the different outputs, you can change the filename each time to avoid overwriting previous outputs.

So, the entire program at this point looks like this:

import processing.pdf.*;<br>
PImage pic;
String myFile = "myImage.jpg";
int w, h;
void setup(){
  pic = loadImage(myFile);
  h = pic.height;
  w = pic.width;
  if( w > h){
    pic.resize(150,0); 
  } else if (h > w) {
    pic.resize(0,150);
  } else if (h == w){
    pic.resize(150,150);
  }
  size(2250,2250);
  beginRecord(PDF, "dotPic.pdf"); 
}

Step 3: Convert to Grayscale and Calculate Image Brightness

Inside the draw() function, set up your drawing parameters. I used stroke weight of .001 and red color to draw, because those are the settings for the laser cutter I used. If your laser cutter settings are different, you can adjust accordingly.

background(255); 
noLoop();
noFill();
strokeWeight(.001);
stroke(255,0,0);

Next, load the pixels of the image and loop through them. Get the red, green and blue values for each pixel, and use the formula 0.21*r + 0.72*g + 0.07*b to convert the colors to a greyscale value.

Map the greyscale value to a size between 0 and the maximum circle size you want - here I'm using 10 pixels.

Finally, draw a circle, adding an additional 5 pixels as a spacer between each circle.

pic.loadPixels();<br>   for (int y = 0; y < pic.height; y++) {
    for (int x = 0; x < pic.width; x++) {
      int loc = x + y*pic.width;
      float r = red(pic.pixels[loc]);
      float g = green(pic.pixels[loc]);
      float b = blue(pic.pixels[loc]);
      float c = (0.21*r + 0.72*g + 0.07*b);
      float size = map(c, 0, 255, 0, 10);
      ellipse(x*15, y*15, size, size);
    }
   }

Then complete the save to PDF operation with endRecord();

endRecord();

So the entire draw loop is:

void draw(){<br>  background(255);
  noLoop();
  noFill();
  strokeWeight(.001);
  stroke(255,0,0);
  pic.loadPixels();
   for (int y = 0; y < pic.height; y++) {
    for (int x = 0; x < pic.width; x++) {
      int loc = x + y*pic.width;
      float r = red(pic.pixels[loc]);
      float g = green(pic.pixels[loc]);
      float b = blue(pic.pixels[loc]);
      float c = (0.21*r + 0.72*g + 0.07*b);
      float size = map(c, 0, 255, 0, 10);
      ellipse(x*15, y*15, size, size);
    }
   }
  
  endRecord();
}

Step 4: Import PDF Into Illustrator

The code is also available here.

With your image in the data folder, run the program. Then check the sketch's folder and you should find the PDF output.

Open the PDF in Illustrator and save it as an Illustrator file for using with the laser cutter.