Hi All
I am a professional artist from Norfolk, UK.
I am trying to make some high definition stencils and stumbled across a chaps website that gave some info and details on processing and a script that he had made with help from others here and based on similar code. His zip file can be download here:
https://paolocirio.net/work/hd-stencils/SCRIPT_HD_STENCILS_Open_March_2015.zip
This file includes the script and instructions.
However, I am a dimbo when it comes to programming code and despite getting processing, spending hours and hours creating errors in scripts, I have got nowhere.
Please can someone help.
Its a very short script and I would think quite simple to you clever chaps and chapeses.
It basically is meant to create a pdf file that laser cutters can read, with lots of shapes on that the cutter cuts out. These are tiny holes, although Im not sure how you determine the hole sizes.
The script is designed for use by being able to create a pdf file for each colour channel, from CYMK image files, but I dont even need that, I just want to be able to create one file, not one for each channel. Im just looking to make this HD stencil from a basic greyscale or midtone.
Creating the image is easy for me, not a problem
But altering this code, even with the line tips, is impossible.
I dont know where to add my file, how to change sizes, how to attach various files etc, code changes to point to my image etc. I suspect a lot of the lines can be removed (especially since I only need one colour channel).
I will paste the script below but there are some supporting files that go with it at the link above. These appear to be the files that tell the script the hole shapes etc.
If someone could create a version of this script for me that assumes an image file called āuntitled.jpgā or something, with dimensions of 800x600 then at least I can perhaps pick through it and understand it better. If there are any other lines/parameters that I need to be aware of and that I can change please highlight them, then I can try and work it out. But a basic A4 size image with fine holes from loading a single image is enough to create my stencil I think
Once again thank you, I will donate or send a piece of art to my life savers!
Best Regards
Phil Daniels
Oh heres the script:
/*******************************************************************************
High Definition Stencils
http://paolocirio.net/work/hd-stencils/
Stencils made with the laser cutter for spray paint.
Created and invented by Paolo Cirio between 2011-2015
The script in Processing as well as the technique invented for this project are released in Open Source
with Attribution-NonCommercial-ShareAlike CC BY-NC-SA This license lets others remix, tweak, and build upon
your work non-commercially as long as they credit you and license their new creations under the identical terms.
http://creativecommons.org/licenses/by-nc-sa/4.0/deed.en_US
Script adapted from: Daniel Shiffman -Example 16-8: Brightness mirror
/********************************************************************************/
//////////////////////////////////////////////////////////////////////////////////
// Load system variables and libraries
import processing.pdf.*;
PImage img;
PShape pointShape;
int cols, rows, imgScale, minDot, offSet, offsetX, offsetY;
int marginY, marginX, centX, centY, holderSize, holderPos, numbDots;
String filename, channel, pinhole;
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
// Configure values to crate the vector files of the stencils
void setup() {
// SET INPUT FILE NAME
// It must be a JPG, filename will be composed by name color channel + .jpg
filename = "Untitled-1_";
// SET COLOR CHANNEL for OFFSET and OUTPUT FILE
// Case Sensitive, from Photoshop name files splitting channels
// Cyan, Magenta, Yellow, Black.
channel = "Yellow";
// Set shapte PINHOLES
// Triangle, Circle, Square, Star
pinhole = "Triangle";
// SET RESOLUTION
imgScale = 25;
// Size of each cell in the grid - smaller numb increases resolution
// 15 quite too high res. very slow
// 20 with all the ones tested _GOOD_
// 30 very big and fast
// 5 - 4 makes better resolution
// 11 good for text and logos
// SET MIN. SIZE Shapes
minDot = 0;
// originally 0.5 the minum size it draws / smaller numb increases resolution
// for TXT can be 1 / for Pictures can be 0.8
// 0.2mm minimum cut shape size
// Set frame for stencil holders
marginX= 137; // 2,5 cm
marginY= 548; // 10 cm
holderSize= 7;
holderPos = 40;
// SET Offset between color channel
// Automatic setting are fine, no panic.
offSet = imgScale/2;
offsetX=offsetY=0;
if(channel=="Cyan") offsetX =+ offSet;
else if(channel=="Magenta") offsetX =- offSet;
else if(channel=="Yellow") offsetY =+ offSet;
else if(channel=="Black") offsetY =- offSet;
//////////////////////////////////////////////////////////////////////////////////
// RUN MAN RUN !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//////////////////////////////////////////////////////////////////////////////////
// Creates laser cut templates from CMYK channels for spray painting.
// Uses imported shape or of built-in options.
pointShape = loadShape("shape" + pinhole + ".svg");
// pointShape = loadShape("shapeSquare.svg");
// Set INPUT and OUTPUT FILES
img = loadImage( filename + channel + ".jpg");
size(img.width+marginX,img.height+marginY);
centX=(marginX/2);
centY=(marginY/2);
cols = (width-marginX)/imgScale;
rows = (height-marginY)/imgScale;
// smooth();
beginRecord(PDF, filename + channel + ".pdf");
////////////////////////////////////////////////////
// Create the hole holder for the stencil at the edge of them
ellipseMode(RADIUS);
stroke(255, 0, 0);
strokeWeight(0.13333); //1pt = 1.3333px => 0.1pt = 0.13333px
noFill();
ellipse( holderPos, holderPos, holderSize, holderSize);
ellipse( ((img.width+marginX)-(holderPos+holderSize)), holderPos, holderSize, holderSize);
ellipse( holderPos, ((img.height+marginY)-holderPos-holderSize), holderSize, holderSize);
ellipse( ((img.width+marginX)-(holderPos+holderSize)), ((img.height+marginY)-holderPos-holderSize), holderSize, holderSize);
// image(img,0,0);
// background(255);
img.loadPixels();
//img.filter(GRAY);
//img.filter(POSTERIZE, 12);
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
// pixel-wise
int x = i*imgScale;
int y = j*imgScale;
// Reversing x to mirror the image
// In order to mirror the image, the column is reversed with the following formula:
// mirrored column = width - column - 1
// int loc = (img.width - i - 1) + j*img.width;
int loc = x + y*img.width;
// Each rect is colored with a size determined by brightness
color c = img.pixels[loc];
// A rectangle size is calculated as a function of the pixel's brightness.
// A bright pixel is a large rectangle, and a dark pixel is a small one.
float sz = (((brightness(c))/255.0)*imgScale*1.1); //this equation may be adjusted for different shapes
// place something in any case to avoid null spots?
//if(sz < 1) sz = sz * 0.5;
// print(sz);
if(sz > minDot){
////////////////////////////////////////////////////
// Option with drawing the rectacle
//rectMode(CENTER);
//fill(c);
//fill(0);
//noStroke();
//noFill();
//stroke(255, 0, 0);
//strokeWeight(0.13333); //1pt = 1.3333px => 0.1pt = 0.13333px
//rect(centX + x + offsetX + imgScale/2, centY + y + offsetY + imgScale/2, sz, sz);
////////////////////////////////////////////////////
// Option with placing the shape pinhole
shapeMode(CENTER);
shape(pointShape, centX + x + offsetX + imgScale/2, centY + y + offsetY + imgScale/2, sz, sz);
// Counting for log data
numbDots++;
}
}
}
// Print logs
print(numbDots);
endRecord(); //MUST be present when beginRecord() is used
}
void draw() {
}