Archive for the ‘Processing’ tag
Creating Video With Processing and FFMPEG

Max/MSP users: look familiar?
For the past week I have been wrangling with getting ffmpeg (the open-source, command line video utility) to run in a Processing sketch and preserve the hard edges of graphical and/or intentionally pixelly video. It now works!
Details are listed in the code itself, but it is most important to note that the codec is likely the most important factor in getting good quality. The “png” codec is great, but will create rather large files; mjpeg (MotionJPEG) also works well for graphics and hard edges (pixellated images, etc); H.264 is all-around good for photgraphic images.
The sketch below runs ffmpeg’s commands within Processing (as covered before) and exports a video from a series of still files. Processing’s built-in video library seems ok, but offers little in the way of control as compared to ffmpeg. Questions or suggestions are welcomed – feel free to use but please give credit!
Voronoi Video
Further experiment with Voronoi Diagrams, Processing, ffmpeg, and video (Max/MPS-ers may recognize the classic bball.mov source file).
Voronoi Diagrams of “Starry Night”

After getting very excited about Voronoi Diagrams and this post, I took a break from PHP to make what I think is essentially a custom image-compression algorithm. I’ve applied it to Van Gogh’s famous painting “Starry Night” at varying levels. The program, written in Processing, essentially looks at a pixel’s neighbors and if the colors are similar enough, it sets the neighbor’s value to the tested pixel. The above image is a allows for a difference of as much as 250 (very high compression/low similarity) and steps down in increments of 25 down to 25.









Random Walk: Square Root of Two
Following yesterday’s experiments with the Random Pi Walk (hat tip Alex Bellos), I’ve upped the ante. The above image is the decimal expansion of the square root of two, following the first one million digits. The data is thanks to Stan Kerr via Project Gutenberg. Each decimal digit 0-9 results in a change of direction of 36 degrees and, in this case, travels 3 pixels in that direction.
The resulting image is MUCH larger than the previous visualizations – click here for the full resolution version.
3d Random “Pi Walk”
Random walk based on the decimal expansion of pi (from the previous post), but this time in 3d space. Created using Processing and OpenGL.
Click on images for full-size.
Random “Pi Walk”

While John Venn is best-known for the Venn Diagram, Alex Bellos mentions Venn’s other invention in his quite-good book “Here’s Looking at Euclid” (page 231). Venn was the first to create a “random walk” or “drunk walk”. Using the decimal expansion of pi, each digit is seen as a cardinal direction. I’ve updated Venn’s experiment slightly (his ignored the numbers 8 and 9) – each number from 0-9 rotates the direction of movement by a factor of 36º and takes a step 20 pixels forward.
The above image is the first 1120 decimal places of pi, starting at the gray dot. Created using Processing.
Random Hexadecimal Colors, Sorted
Finished video based on experiments sorting hexadecimal colors. Watch on Vimeo here.
Sorting Hexadecimal Colors
I’m currently working on a poster/catalog for an upcoming curatorial project at the Bemis Underground and was thinking of using an image of sorted white noise on a television set. Grayscale white noise is actually pretty boring (so long as it’s actually close to random, the values will fall along a Gaussian curve), so I tried some other experiments.
Using hexadecimal color yielded some pretty interesting results. The above image is 1,296,000 random values that range from #000000-FFFFFF (0 - 16,777,215). A Processing sketch sorts those values numerically and fills the pixels of the image in order.
Click here, or on the image, for full-resolution.
Also of interest were Photoshop’s histograms of the color – I’ve not really looked at histograms much in the past, but these were really strange. Luminosity was, as I suspected, a Gaussian curve and RGB values were each close to a flat line. But overall “color” resulted in the above images. The top is the raw image, the one below after “Auto Color” correction: 8-bit fortress meets birthday cake.
Further Text Interpolation Experiments
Some more wrangling in Processing, some new results experimenting with interpolating texts. The problem with previous tests was that if the files aren’t the exact same length, remaining characters were simply dumped at the end of the resulting file. While character-accurate, it isn’t really an interpolation. Instead, this new version finds the ratio between the number of characters in the two texts. For example:
File one = 351,155 characters
File two = 194,138 characters
This makes the ratio between the two files ~2/1. The code reads two characters in the longer file, interpolates them, and then interpolates that result against a single character from the first file. Two examples are below using Shakespeare’s sonnet #51 and 117.
The sonnets interpolated using a ratio-interpolation:
lclanel slodij eigsnA otfe sdaceturtrd c dltrnIiamtrhnohddoascoar nioeoEaacehsh Oodsdi lhtoodrnion lrlaoosrfn Etosini Si iieintiItgsaIaonaniid hr maueccsiou Aneo ioEj hciefsmhsal hiimtrm gimstyaelaanr Aautlrd s otalige lfsr hdohinasucsouodleiahofoEo seooTnhsd rlhsd noirlh rononiiena lsaih TsrnOaauohcnieslaomtsa mtelaseriinirOtyaddnOooislta iococnoi fceutcpnlaons egn hocalo Inhs Rih tr whselr. olrrolcsrouatndrwsideaa Sohou s olsnoiatrhd rtdndisrrmtlrlrnihst Anhtordtiehte rt ctdau poloiducdaelnreoie ii fhco sfhevlnti aeHnaN ilhtleisce rotddcdo h se gordsnfhmtlai dTnlroiiremtso psf o
The text above, run through Microsoft Word’s spell-check:
cannel solid deigns often sdaceturtrd c dltrnIiamtrhnohddoascoar nioeoEaacehsh Odds lhtoodrnion lrlaoosrfn Eosin Si iieintiItgsaIaonaniid hr maueccsiou Anew ice hciefsmhsal hitter gimstyaelaanr Auld s totalize lifer hdohinasucsouodleiahofoEo soothed rills north rononiiena lash TsrnOaauohcnieslaomtsa mtelaseriinirOtyaddnOooislta rococo fceutcpnlaons egg horal Inns Rah try wheel. olrrolcsrouatndrwsideaa Shoo s olsnoiatrhd rtdndisrrmtlrlrnihst Anhtordtiehte rat coda poloiducdaelnreoie ii face sheltie ashcan ilhtleisce rotddcdo h se gordsnfhmtlai dTnlroiiremtso puff o
Text as Number
0.00000000010011110000000001100110000000000010000000000000011011010000000001111001000000000010000 0000000000110010000000000011101010000000001101100000000000110110000000000001000000000000001100010 0000000001100101000000000110000100000000011100100000000001100101000000000111001000000000001000000 0000000011101110000000001101000000000000110010100000000011011100000000000100000000000000110011000 0000000111001000000000011011110000000001101101000000000010000000000000011101000000000001101000000 0000001100101000000000110010100000000001000000000000001001001000000000010000000000000011100110000 0000011100000000000001100101000000000110010100000000011001000000000000111010000000000101010000000 0000110100100000000011011000000000001101100000000000010000000000000010010010000000000100000000000 0001110010000000000110010100000000011101000000000001110101000000000111001000000000011011100000000 0001011000000000000100000000000000110111100000000011001100000000000100000000000000111000000000000 0110111100000000011100110000000001110100000000000110100100000000011011100000000001100111000000000 0100000000000000110100100000000011100110000000000100000000000000110111000000000011011110000000000 1000000000000001101110000000000110010100000000011001010000000001100100000000000010111000000000010 1011100000000011010000000000001100101000000000110111000000000001000000000000001110011000000000111 0111000000000110100100000000011001100000000001110100000000000010000000000000011001010000000001111 0000000000001110100000000000111001000000000011001010000000001101101000000000110100100000000011101 0000000000011110010000000000100000000000000110001100000000011000010000000001101110000000000010000 0000000000111001100000000011001010000000001100101000000000110110100000000001000000000000001100010 0000000001110101000000000111010000000000001000000000000001110011000000000110110000000000011011110 0000000011101110000000000111111000000000100100100000000011011100000000000100000000000000111011100 0000000110100100000000011011100000000001100111000000000110010100000000011001000000000000100000000 0000001110011000000000111000000000000011001010000000001100101000000000110010000000000001000000000 0000011011100000000001101111000000000010000000000000011011010000000001101111000000000111010000000 0000110100100000000011011110000000001101110000000000010000000000000011100110000000001101000000000 0001100001000000000110110000000000011011000000000000100000000000000100100100000000001000000000000 0011010110000000001101110000000000110111100000000011101110000000000101100000000000101010000000000 0110100000000000011001010000000001110010000000000110010100000000011001100000000001101111000000000 1110010000000000110010100000000001000000000000001100100000000000110010100000000011100110000000001 1010010000000001110010000000000110010100000000001011000000000000100000000000000010100000000000011 0111100000000011001100000000000100000000000000111000000000000011001010000000001110010000000000110 0110000000000110010100000000011000110000000001110100000000000010011100000000011100110000000001110 1000000000000100000000000000110110000000000011011110000000001110110000000000110010100000000001000 0000000000011000100000000001100101000000000110100100000000011011100000000001100111000000000010000 0000000000110110100000000011000010000000001100100000000000110010100000000001010010000000001000010 0000000001110101000000000111010000000000001000000000000001101100000000000110111100000000011101100 0000000011001010000000000101100000000000010000000000000011001100000000001101111000000000111001000 0000000010000000000000011011000000000001101111000000000111011000000000011001010000000000101100000 0000000100000000000000111010000000000011010000000000001110101000000000111001100000000001000000000 0000011100110000000001101000000000000110000100000000011011000000000001101100000000000010000000000 0000110010100000000011110000000000001100011000000000111010100000000011100110000000001100101000000 0000100000000000000110110100000000011110010000000000100000000000000110101000000000011000010000000 0011001000000000001100101000000000010110100000000001000000000000000100000000000000010000000000000 0101010000000000011011110000000001110111000000000110000100000000011100100000000001100100000000000 1110011000000000010000000000000011101000000000001101000000000000110010100000000011001010000000000 1000000000000001001001000000000010011100000000011011000000000001101100000000000010000000000000011 1001000000000011101010000000001101110000000000010110000000000001000000000000001100001000000000110 1110000000000110010000000000001000000000000001100111000000000110100100000000011101100000000001100 1010000000000100000000000000110100000000000011010010000000001101101000000000010000000000000011011 0000000000011001010000000001100001000000000111011000000000011001010000000000100000000000000111010 000000000011011110000000000100000000000000110011100000000011011110000000000101110
I wrote a simple Processing sketch that returns binary values of characters from a split file (one letter per line), with an appended “0.” in front – this essentially makes this a single very complex number that holds all the information of the text. Above is Shakespeare’s 51st sonnet stored as a number.
Based on a thought in Gary William Flake’s “The Computational Beauty of Nature” (pg 21). As Flake describes it, “Now take a long number and put a zero and a decimal point in front of it. We’ve just translated one huge number into a rational number between 0 and 1. By placing this single point at exactly the right spot on the number line, we can store an unlimited amount of information.”
I think especially interesting is the idea that rather than the sonnet be translated to a number between 0 and a giant number (say 100 trillion, etc), the number is only between 0-1 but occupies a very specific point on the number line. The resulting number is unique and no other text has that exact value.
—
Source code:
BufferedReader reader;
String tempLine;
char c;
int numLines = 0;
PrintWriter writer;
void setup() {
try {
reader=createReader("Sonnet51_Split.txt");
writer = createWriter("TextAsData.txt");
writer.print("0.");
while ((tempLine = reader.readLine ()) != null) {
c = tempLine.charAt(0);
writer.print(binary(c));
}
writer.flush();
writer.close();
}
catch (IOException e) {
println("Error reading file!");
println(e);
}
exit();
}






