<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Scott builds Software &#187; images</title>
	<atom:link href="http://scottpenberthy.com/tag/images/feed/" rel="self" type="application/rss+xml" />
	<link>http://scottpenberthy.com</link>
	<description>Musings on iPhone, Flash and the Cloud</description>
	<lastBuildDate>Tue, 28 Jun 2011 05:02:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>&quot;Photobooth&quot; Images in Flash and JavaScript</title>
		<link>http://scottpenberthy.com/2009/01/24/photobooth-images-in-flash-and-javascript/</link>
		<comments>http://scottpenberthy.com/2009/01/24/photobooth-images-in-flash-and-javascript/#comments</comments>
		<pubDate>Sat, 24 Jan 2009 10:58:48 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[images]]></category>
		<category><![CDATA[photobooth]]></category>

		<guid isPermaLink="false">http://scottpenberthy.com/?p=160</guid>
		<description><![CDATA[I've been working on a handy utility in Flash and JavaScript that will let you morph images, videos, and webcams like Photobooth.  Each effect is specified as a "preset" specified as a text string or external file.  No Flash programming required.]]></description>
			<content:encoded><![CDATA[<div style="text-align:center">
<div style="float:right">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="216" height="270" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="name" value="TestDriver" /><param name="bgcolor" value="#869ca7" /><param name="align" value="middle" /><param name="src" value="http://scottpenberthy.com/meshdemo/TestDriver.swf" /><embed type="application/x-shockwave-flash" width="216" height="270" src="http://scottpenberthy.com/meshdemo/TestDriver.swf" align="middle" bgcolor="#869ca7" name="TestDriver"></embed></object></p>
<p>Photoboothed with &#8220;presets&#8221;</p>
</div>
<div style="float:left">
<img src="http://scottpenberthy.com/meshdemo/obama.jpg"></p>
<p>Source image</p>
</div>
</div>
<p><br clear="both"/></p>
<p>My kids love to play with Photobooth on the Mac.  The fish eye, pinch, punch, squeeze, Andy Warhol, and other looks provide countless sources of fun and amusement.</p>
<p>I&#8217;ve been working on a handy utility in Flash that will let you morph images, videos, and webcams like Photobooth.  Each effect is specified as a &#8220;preset.&#8221;  A preset is a set of mathematical constraints and parameter values specified in an external character string, often stored in a file.  I think the idea was first used in the Milkdrop music visualizer in the late 90&#8217;s.  I&#8217;m not sure.</p>
<p>Anyway, I&#8217;ve written a preset compiler in Flash that turns these equations into bytecodes for a custom, finely tuned virtual machine.  The virtual machine operates much like an HP calculator, a stack machine with numerous functions.</p>
<p>I then created a 2d mesh and exposed several values at each vertex.  Each of these values can be manipulated by the presets.  They include the texture location (u,v), the screen location (x,y), rotation (rot), scaling (sx,sy), translation (dx,dy), a nonlinear zoom (zoom, zoom_exp), and a sinusoidal warping technique (warp, warp_exp, warp_scale).  You can also specify the &#8220;current&#8221; values of (u,v) as (u_t,v_t).  I also cache the polar coordinates of the vertex as (ang,rad).  These names are borrowed from Milkdrop&#8230;</p>
<p>Finally, I wrapped it all together by placing the 2d mesh on a sprite, loading a preset, then running it every frame, at every vertex.  For fun I pass along the current time as a &#8220;time&#8221; value.</p>
<p>Here are some simple presets.  The first one is a fisheye effect, repeating the ImageMagick trick in Flash.</p>
<pre lang="c">rs=pow(rad,2.5)/2;
u=2+time*0.5-rs*cos(ang);
v=2+time*0.5-rs*sin(ang);
u_t=u;
v_t=v;</pre>
<p>This next preset will gradually shrink the source image over time.  Once it shrinks, Flash wraps around and fills the empty space as one would expect on a graphics card:</p>
<pre lang="c">sx=1.0-time/4;
sy=1.0-time/4</pre>
<p>I was playing with Zoom a bit here.  This neat effect appears to stretch the image like taffy from the center, oscillating back and forth in time:</p>
<pre lang="c">zoom=max(1,1.0+sin(time*0.31415)*rad)</pre>
<p>Another trick with the zoom exponent, one that also oscillates:</p>
<pre lang="c">where=sin(time*3.1415);
zoom=1.0+2*rad;
zoom_exp=1.0+where*0.5;</pre>
<p>This is a mashup effect that shifts, rotates, and zooms over time in a variety of ways:</p>
<pre lang="c">dx=sin(time);
dy=cos(time);
rot=time*1.57;
zoom=1.0-0.8*sin(time*2.675);
zoom_exp=3</pre>
<p>In the end, I use the identity function to map the current (u_t,v_t) to the original (u,v)</p>
<pre lang="c">u_t=u;
v_t=v</pre>
<p>Soon I plan to release the code.  You&#8217;ll use JavaScript to specify the preset and source image, video or webcam.  Flash will do all the math.  Voila!  Photobooth in Flash and JavaScript (well, almost).  Suggestions welcome!</p>
]]></content:encoded>
			<wfw:commentRss>http://scottpenberthy.com/2009/01/24/photobooth-images-in-flash-and-javascript/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

