You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
That sounds really cool so I wanted to give it a quick try ;)
Turned out I can abuse my TSP solver to make dithers. I actually didn't know my particular implementation was good enough to do so until I tried.
For the color one, I simply split the image into 4 channels (CMYK) and run dither and TSP on each. Each "pixel" is divided into 4 (2x2) for each thread so the stitches don't stack at the exact same point.
The code is super simple:
importprocessing.embroider.*;
PEmbroiderGraphicsE;
voiddot(floatx, floaty){
E.beginRawStitches();
E.rawStitch(x,y);
E.rawStitch(x+1,y+1);
E.endRawStitches();
}
voiddot(PVectorp){
dot(p.x,p.y);
}
// Floyd Steinberg ditherArrayList<PVector> dither(PImageim){
ArrayList<PVector> pts = newArrayList<PVector>();
float[] tmp = newfloat[im.width*im.height];
im.loadPixels();
for (inti= 0; i < im.height; i++) {
for (intj= 0; j < im.width; j++) {
floato = (im.pixels[i*im.width+j]&255) + tmp[i*im.width+j];
intn = o > 128 ? 255 : 0;
floatqe = o - n;
if(j<im.width -1){ tmp[ i *im.width+ j+1] += qe * 7.0/16.0; }
if(i<im.height-1){if(j!=0){tmp[(i+1)*im.width+ j-1] += qe * 3.0/16.0; }
tmp[(i+1)*im.width+ j ] += qe * 5.0/16.0;
if(j<im.width -1){ tmp[(i+1)*im.width+ j+1] += qe * 1.0/16.0; }}
if (n == 0){
pts.add(newPVector(j,i));
}
}
}
returnpts;
}
voidsetup(){
size(1024,1024);
smooth();
E = newPEmbroiderGraphics(this);
E.setPath(sketchPath("tsp-painting.vp3"));
PImageim = loadImage("cameraman.bmp");
ArrayList<PVector> pts = dither(im);
for (inti = 0; i < pts.size(); i++){
dot(pts.get(i).copy().mult(4));
}
E.optimize();
E.visualize(true,true,true);
E.endDraw();
}
voiddraw(){
}
OMG I am slain @LingDong- . Well this is great, because I was taking too long to get around to this anyway. Please push an Example into the examples/ directory and I'll clean it up.
Saving this one for me, just wanted to put it up so I could cross it off.
The text was updated successfully, but these errors were encountered: