Created
April 15, 2011 06:37
Revisions
-
nbqx revised this gist
Apr 15, 2011 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,7 @@ #!/usr/bin/env node //http://vimeo.com/22429969 var fs = require('fs'); var spawn = require('child_process').spawn; -
nbqx created this gist
Apr 15, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,54 @@ #!/usr/bin/env node var fs = require('fs'); var spawn = require('child_process').spawn; var cap = "/path/to/cap.jpg"; var glt = "/path/to/cap_glitch.jpg"; function changeDesktopPicture(){ var scrt = (function(){/* tell application "Finder" set org to POSIX file "/path/to/cap.jpg" as string set desktop picture to file org set pic to POSIX file "/path/to/cap_glitch.jpg" as string set desktop picture to file pic end tell */}).toString().replace(/^.*?\n/,'').replace(/\n.*?$/,''); var doing = spawn('osascript',['-e',scrt]); } function glitch(f){ var v = (Math.random()>0.5)? 0.95 : Math.random()*1.5; var file = f; var buf = fs.readFileSync(file); for(var i=0; i<buf.length; i++){ if(Math.random()>v){ if(buf[i]==18){ if(Math.random()>0.5){ buf[i] = Math.floor(Math.random()*10); }else{ buf[i] = buf[i+1]; } } } } return buf } function capture(){ var cmd = spawn('screencapture',['-W','-tjpeg',cap]); cmd.on('exit',function(){ var buf = glitch(cap); fs.writeFile(glt,buf,function(err){ if(err) throw err; changeDesktopPicture(); }); }); } capture();