Archive for January, 2012
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!
UPDATE:
While I really don’t know why, the previous sketch seems to break with a Java IOException error. It appears that ffmpeg can’t be found, but the solution is simple: specify the path to your ffmpeg install. For example:
/usr/local/bin/ffmpeg filename.mov etc...
The “-c:v” option to specify the codec is also updated to “-vcodec” and “-acodec”
[ download the updated sketch here ]
Every Possible Radio Callsign
KAAA, KAAB, KAAC, KAAD, KAAE, KAAF, KAAG, KAAH, KAAI, KAAJ, KAAK, KAAL, KAAM, KAAN, KAAO, KAAP, KAAQ, KAAR, KAAS, KAAT, KAAU, KAAV, KAAW, KAAX, KAAY, KAAZ, KABA, KABB, KABC, KABD, KABE, KABF, KABG, KABH, KABI, KABJ, KABK, KABL, KABM, KABN, KABO, KABP, KABQ, KABR, KABS, KABT, KABU, KABV, KABW, KABX, KABY, KABZ, KACA, KACB, KACC, KACD, KACE, KACF, KACG, KACH, KACI, KACJ, KACK, KACL, KACM, KACN, KACO, KACP, KACQ, KACR, KACS, KACT, KACU, KACV, KACW, KACX, KACY, KACZ, KADA, KADB, KADC, KADD, KADE, KADF, KADG, KADH, KADI, KADJ, KADK, KADL, KADM, KADN, KADO, KADP, KADQ, KADR, KADS, KADT, KADU, KADV, KADW, KADX, KADY, KADZ, KAEA, KAEB, KAEC, KAED, KAEE, KAEF, KAEG, KAEH, KAEI, KAEJ, KAEK...
Thinking about which callsign to unnoficially assign ourselves for the microbroadcasting project at Drift Station, I thought “how many possible combinations of the four-letter callsign can there be?” The answer is 17,576 for both east (prefix of W) and west (prefix of K) of the Mississippi; the list was generated using TextMechanic.com’s great tools.
[ download the entire list as a .csv file here or as a text file (can be viewed in your browser) ]
How Voronoi Diagrams Work
Lots of time thinking about Voronoi Diagrams this week; click image for full-size or here for a high-res PDF.
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.









Video Still

Via: The Office, season 6, episode 20, 12’38″
Notebook Paper Animated GIF
Waterfall GIF

Spending (some) of the afternoon looking at animated GIFs.
Sound Invisibility

Fantastically-interesting project detailed at Physics World – Martin Wegener, Nicolas Stenger, and Manfred Wilhelm of the Karlsruhe Institute of Technology in Germany built the device above which can cloak objects from sound waves. The rings around the center are filled with soft plastic and an object to be cloaked is placed in the center hole. Because of the design of the rings, sound waves approaching the object are bent and re-emerge on the other side exactly as they came in. There are no acoustic reflections off the object whatsoever.
Via: Physics World (thanks Stephen Shingler)


