Jeff Thompson | Blog

Archive for the ‘Processing’ tag

How Many Lines of Code Did You Write This Year?

Filling out my pre-tenure paperwork (blech) I started to wonder.  I sure wasn’t going to count them by hand, so I wrote a Processig sketch bash script to find out.  Result: 208 sketches for a total of 20,944 lines or 590,670 characters!  (2010: 232 sketches, 19,786 lines, 563,083 characters; 2012 so far: 9 sketches, 879 lines, 27,533 characters)

UPDATE:
The previous version used a Processing sketch to find the information, which seemed poetic.  However, it seems that Java doesn’t do file handling very cleanly (curse you File variable).  As I went to bed, it seemed a bash script would be much cleaner and likely faster, so I got up today and wrote one.  Sorry Windows users, this is likely Mac/Linux only.  You can still download the Processing sketch and try it yourself.

#!/bin/bash
# Jeff Thompson | www.jeffreythompson.org

# enter the year you're looking for and the path to your Processing sketchbook
lookFor="pde"											# file extension to look (period optional)
yearCreated="2011"										# year to look at
pathToCheck="/Users/jeffthompson/Documents/Processing"	# where to look
# pathToCheck=$HOME										# alternatively, look everywhere (may be VERY slow)
dateRange="01-Jan-$yearCreated"							# set date to the first of the year we're looking for

echo ""
echo "HOW MANY LINES OF CODE DID YOU WRITE THIS YEAR?"
echo -e "Path:\t\t$pathToCheck"
echo -e "Extension:\t$lookFor"
echo -e "Year:\t\t$yearCreated"

# note: we don't need the . in front of the extension since * will match all preceeding characters
find $pathToCheck -type f -name \*$lookFor -newermt "$dateRange" -and -not -newermt "$dateRange +12 month"> "$lookFor_files.txt"
fileCount=$(wc -l < "$lookFor_files.txt")

lineCount=0
charCount=0
while read line; do
	lines=$(wc -l < $line)		# count lines in the file
	let "lineCount += lines"
	chars=$(wc -c < $line)		# count characters
	let "charCount += chars"
done < "$lookFor_files.txt"

rm "$lookFor_files.txt"			 # be nice and delete the working file (optional)
echo -e "Result:\t   ${fileCount} files, ${lineCount} lines, ${charCount} characters"
exit

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!

[ download the sketch here ]

 

 

January 26th, 2012 at 10:44 am

Voronoi Video

Further experiment with Voronoi Diagrams, Processing, ffmpeg, and video (Max/MPS-ers may recognize the classic bball.mov source file).

January 24th, 2012 at 4:37 pm

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.

[ view the source code here ]

January 22nd, 2012 at 9:55 pm

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.

January 4th, 2012 at 7:48 pm

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.

January 3rd, 2012 at 3:13 pm

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.

January 3rd, 2012 at 10:50 am

Random Hexadecimal Colors, Sorted

December 31st, 2011 at 12:24 pm

Tagged with , ,

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.

December 27th, 2011 at 9:34 pm

Tagged with , , ,

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

 


December 11th, 2011 at 6:15 pm