Skip to content

Instantly share code, notes, and snippets.

@kcsluis
Created July 11, 2019 02:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kcsluis/470bfa0a05da4135926ecd591c31ad96 to your computer and use it in GitHub Desktop.
Save kcsluis/470bfa0a05da4135926ecd591c31ad96 to your computer and use it in GitHub Desktop.
// rename ki image
// set iX and iY values to the dimensions of the image
int iX = 500;
int iY = 300;
float sY = 3.0;
// larger sY value = less vertical displacement
import processing.svg.*;
float[][] imageArray;
float kk;
int k, km, laterY, thisY, lastY;
boolean lineOn, inFront;
void setup() {
size(500,300);
smooth();
noFill();
stroke(0);
strokeWeight(0.5);
noLoop();
PImage ki = loadImage("fuji_ring15.png");
image(ki, 0, 0);
imageArray = new float[iX][iY];
}
void draw() {
int m = millis();
beginRecord(SVG, "test_" + m + ".svg");
initArray(imageArray);
//scale(2);
for(int y = 0; y < iY; y+=1) {
for(int x = 1; x < iX; x++) {
// get this Y position
thisY = y-int(imageArray[x][y]);
lastY = y-int(imageArray[x-1][y]);
inFront = true;
// check if this point is behind another line
for(int z = y+1; z < iY; z++) {
laterY = z-int(imageArray[x][z]);
if (laterY <= thisY) { // softer edges
inFront = false;
}
}
// at the beginning
if (x == 1) {
if (inFront == true) {
beginShape();
vertex(x,thisY);
lineOn = true;
}
}
// for any given point
if (inFront == true) {
if (lineOn == false) {
beginShape();
vertex(x-1,lastY);
// could potentially try [x-1][y-1] to get better line
vertex(x,thisY);
lineOn = true;
} else {
vertex(x,thisY);
}
} else {
if (lineOn == true) {
vertex(x,thisY);
endShape();
lineOn = false;
}
}
// at the end
if (x == iX-1) {
if (inFront == true) {
vertex(x,thisY);
endShape();
lineOn = false;
}
}
}
}
endRecord();
println("finished");
}
void initArray(float[][] imageArray) {
for (int y = 0; y < iY; y+=1) {
for (int x = 0; x < iX; x++) {
color c = get(x, y);
k = int(brightness(c));
km = int(map(k,0,255,0,3));
// if you want float
//kk = float(k);
//imageArray[x][y] = kk/10;
// if you want integer
imageArray[x][y] = k/sY; // divide y/integer for different pitch
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment