Before the generated image, I used Photoshop and grayscaled it, and after that, cutting out the unnecessary background, then getting the right brightness level.
After making the adjusted image, I coded it. I have not backed up my code, and I transferred to a new PC since the old one got broke. Fortunately, one of my codes is uploaded as an image, so I'll recreate it and post it later.
I made a PImage for the adjusted image, and using <PImage>.get(x, y) allows you to get the color for the specified pixel in the image. It uses the color class though, and turning it into a number needs to extract one of the color channels: the functions red(), green(), blue() do this, that's why I made it grayscale. The extracted numbers make the period and amplitude of the art. For loops, vertex(x, y) and its related functions are nice here. During the generation, one part of the wave was a bit off, and so I stretched out some of the pixels in MS Paint. There was a little bit of trial and error until the results were right. :)
EDIT: I realize I turned this into a Processing 3 explanation. I hope you will understand this, thank you!
This doesn't explain the stitching of the "frequency pixels", i.e. why the horizontal lines are connected.
Given the size of the pixel and knowing the frequency corresponding to any particular gray scale pixel, one could calculate the required phase of the sine wave for a particular frequency pixel so that the picture contains continuous waves and not just a bunch of disconnected wave segments.
The map(...) function in this tweaked source code is missing, and it's a little bit asymmetrical (there is an out-of-bounds wave on the topmost of the output image, where in the bottommost, there is none). Nice rework on the code by the way. :)
I took out the map as a first step to allowing any sized source image. My new code sizes the output canvas to the same aspect ratio as the input image and used bilinear interpolation to allow for better up or down sampling of the source image.
The trick is to add a settings() function. You can then open the source image before calling size() on the output canvas. If you do the size in the setup() function it must be the first call.
I have been wanting to jump into generative art for a while. Thanks for the inspiration!
Ok, i put here the gif version (is the same as the other except that it create the gif)
float decel(float x) { // as an easing function
return 1-(x-1)*(x-1);
}
float step = 66.0f;
float wavePeriod = 4f;
PGraphics pg;
int widthOut = 0;
int heightOut = 0;
void setup() {
background(255);
size(750, 750, P2D);
PImage img = loadImage("image.png");
widthOut = img.width;
heightOut = img.height;
pg = createGraphics(widthOut, heightOut);
float lastX = 0;
pg.beginDraw();
pg.strokeWeight(2);
pg.noFill();
for (float y=0.0; y<step; y++) {
float l = 0;
pg.beginShape(LINES);
for (float x=lastX; x<widthOut * wavePeriod; x++) {
float xx=x/wavePeriod;
// using this version will generate a squished image due to using map(...) in line 26
// color c = img.get(int(xx),int(y*height/50.0));
color c = img.get(int(xx), int(map(y*heightOut/step, 0, heightOut, step, heightOut-step)));
l += (255-red(c))/255/wavePeriod; // period of the wave
// 5*decel(m) sets the amplitude of the wave
// map(...) sets the position of the wave
float m = (255-red(c))/255.0; // separate it from an increasing variable (l)
if (alpha(c) == 0)
m = 0;
pg.vertex(xx, map((y+0.5)*heightOut/step, 0, heightOut, step, heightOut-step)+sin(l*PI/2.0)*5*decel(m));
}
}
pg.endShape();
PImage outImg = pg.get();
outImg.save("image-edit.png");
if (widthOut > 750 || heightOut > 750)
if (widthOut > heightOut)
outImg.resize(750, 0);
else
outImg.resize(0, 750);
image(outImg, 0, 0);
thread("createGifFrames");
}
// This happens as a separate thread and can take as long as it wants
void createGifFrames() {
pg.noStroke();
pg.fill(255);
for (int endX = widthOut - 3; endX > 0; endX -= 3)
{
pg.rect(endX, 0, widthOut - endX, heightOut);
pg.get().save("gif/gif-" + nf(endX, 4) + ".png");
}
}
I used a p5js version of this script in the line art modifier for my experiment https://www.openartmix.com/. There is an "i" icon where I give attribution. OP would love to get your thoughts on the project.
Looks good! I like how you can put multiple widgets and the image processes pretty nicely. One thing I hope for in the "Line Art" widget is the ability to adjust the number of lines, stroke width, and the amplitude and period of the wave. :)
So having this image open causes my computer to emit an audible, although faint, high pitched buzzing sound. Zooming in and out changes the frequency. It has never done that with anything else before.
Edit: And scrolling through it changes the harmonic content of the sound! My computer probably constantly makes faint sound rendering the screen but it's probably so chaotic it just sounds like noise. This super ordered image is actually making it give off a sound with pitch information!
I have been informed this is called coil whine. Neat!
My link is to a reddit post with a screenshot of the generated image being used in an ad, the style seems very similar. The comments seem impressed with the code at least!
I'm pretty sure it would already have been reported and removed by YouTube by now. The generated image is basically a behind view of a woman on top of a man with this exact line wave style, I wouldn't be concerned about checking it out unless you're really anti nude images.
46
u/d_ynamic Apr 25 '20
Source code: here
Set a 750x750 grayscale image named
image.pngbeside it! Output will be saved asimage-edit.png13
u/hidden_machinery Apr 25 '20
Cool! How did you implement this?
8
u/reality_boy Apr 26 '20
I cleaned up the source on this to make it more readable and easier to tweak. Great work on the original code by the way.
2
u/Jaeger1987 Apr 25 '20 edited Apr 26 '20
Hi, Your work is simply fantastic!
I just edit your code so it can handle images of different sizes (and you can edit which lines step if you want), if you are interested I can send it!
EDIT: I had that if a pixel has 0 alpha (is totally transparent) the code it handle as it is a white pixel.
2
u/garygeo Jun 20 '20 edited Jun 20 '20
I used a p5js version of this script in the line art modifier for my experiment https://www.openartmix.com/. There is an "i" icon where I give attribution. OP would love to get your thoughts on the project.
9
u/j_lyf Apr 25 '20
It's amazing how the human eye adds detail that isn't even there
4
u/StatikDynamik Apr 25 '20 edited Apr 25 '20
So having this image open causes my computer to emit an audible, although faint, high pitched buzzing sound. Zooming in and out changes the frequency. It has never done that with anything else before.
Edit: And scrolling through it changes the harmonic content of the sound! My computer probably constantly makes faint sound rendering the screen but it's probably so chaotic it just sounds like noise. This super ordered image is actually making it give off a sound with pitch information!
I have been informed this is called coil whine. Neat!
2
u/electricity-wizard Apr 25 '20
This is what pictures look like in the time domain
1
u/jrgroats May 02 '20
Ahaha is this (NSFW) YouTube ad using your code?
1
u/databayou Apr 25 '20
This is so cool! Thanks for sharing
1
u/astritmalsia Apr 25 '20
This looks so cool, but how do I run this script or how it works so I can create a similar image ?
1
u/schnautzi Apr 25 '20
I love the simplicity of this method, would be cool to have a real time shader for this!
1
u/csgbroseph Apr 25 '20
wow this is incredible! i’ve seen lots of processing sketches that abstract images by contrast but this is so smooth
1
u/PrecursorNL Apr 25 '20
If we turn these waves into sound.. what would it sound like?
1
u/leecharles_ Oct 08 '20
What would be the result if you were to sum the lines vertically?