<?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>kasperkamperman.com&#187; Blog &#8211; kasperkamperman.com</title>
	<atom:link href="http://www.kasperkamperman.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kasperkamperman.com</link>
	<description>Kasper Kamperman designs and creates interactive and responsive media applications for exhibitions, interior and events. He works as a teacher in the field of Art and Technology</description>
	<lastBuildDate>Fri, 23 Jul 2010 15:06:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>MediaLAB Amsterdam : U-turm &#8211; Scryption</title>
		<link>http://www.kasperkamperman.com/blog/medialab-amsterdam/</link>
		<comments>http://www.kasperkamperman.com/blog/medialab-amsterdam/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 23:03:54 +0000</pubDate>
		<dc:creator>kasperkamperman</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Teaching]]></category>

		<guid isPermaLink="false">http://www.kasperkamperman.com/?p=897</guid>
		<description><![CDATA[In the <a href="http://medialab.hva.nl/">MediaLAB Amsterdam</a> (Lab of the Applied University of Amsterdam) I've supervised a few project teams to help them find the right technical solutions for their projects. I'd like to highlight two of them. 


Related posts:<ol><li><a href='http://www.kasperkamperman.com/blog/computer-vision/computervision-framedifferencing/' rel='bookmark' title='Permanent Link: Computer Vision : Frame differencing'>Computer Vision : Frame differencing</a></li>
<li><a href='http://www.kasperkamperman.com/blog/arduino-unity-serial-communication/' rel='bookmark' title='Permanent Link: Arduino &#8211; Unity serial communication'>Arduino &#8211; Unity serial communication</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>In the <a href="http://medialab.hva.nl/">MediaLAB Amsterdam</a> (Lab of the Applied University of Amsterdam) I&#8217;ve supervised a few project teams to help them find the right technical solutions for their projects. I&#8217;d like to highlight two of them. </p>
<h2><a href="http://uturm.medialab.hva.nl/">U-turm</a></h2>

<a href="http://www.kasperkamperman.com/wordpress_kk/wp-content/gallery/post-images/u_turm_concept.jpg" title="" rel="lightbox[singlepic71]" >
	<img class="ngg-singlepic ngg-right" src="http://www.kasperkamperman.com/wordpress_kk/index.php?callback=image&amp;pid=71&amp;width=200&amp;height=&amp;mode=" alt="u_turm_concept" title="u_turm_concept" />
</a>

An interactive projection for the closing ceremony of the <a href="http://www.eculturefair2010.eu/project/medialab-u-turm-project">E-culture fair</a>, as part of the cultural capital of Europe Ruhr 2010. Dance on the facade of the Dortmunder U. In collaboration with producer <a href="http://janscholte.nl/">Jan Scholte</a> and the artist <a href="http://www.magdatt.nl">Matthias Oostrik</a>.<br/><br/></p>
<p>The U-turm team made an interactive projection on the Dortmunder-U tower. When a person steps on one of the stages their silhouette appears on one of the windows of the building. Depending on how the person moves the silhouette can move to other windows, leaving a trace where it has already been before. If two or more silhouettes meet on the same window there will be some creative content coming out, symbolizing the new use of the building as cultural hotspot.</p>
<p>The installation uses Quart Composer the generate the visuals. I&#8217;ve helped Joost Buijs (responsible for the technical part) finding some different motion tracking solutions for Quartz Composer.<br/><br/>Tested options were :</p>
<ul>
<li><a href="http://v002.info/?page_id=28">v002 Optical Flow 2.0.2</a> : uses a lot of processing power, so a big framerate drop. </li>
<li><a href="http://www.msavisuals.com/webcam_piano">Webcam piano by Memo Akten</a> : worked good, but didn&#8217;t invite for dancing too much. </li>
<li><a href="http://kineme.net/release/CVTools/0.2">Kineme CVTools plugin</a> : used in the end, saves a lot of processing power by checking only certain points.</li>
</ul>
<p>The team did a good job to find and test the right way of interaction. Its a really powerful and intuitive concept I&#8217;m curious how its going to look on the big building.  </p>
<p><object width="554" height="312"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=12035666&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=12035666&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=0d616c&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="554" height="312"></embed></object>
<hr/>
<h2><a href="http://scryption.medialab.hva.nl">Scryption &#8211; Google mirror.</a></h2>
<p>The team of Scryption made a mirror that shows your digital identity. The concept was based on the theories of Marshall McLuhans ideas. From their concept document :</p>
<blockquote><p>
You enter the area and you will see two different mirrors in front of you. You will be directed to type in your name. The left mirror is just an ordinary mirror that shows the real you. The left one shows up the pictures that appear on Google when doing a search query on your name. This mirror shows you the digital you, the identity that is created by the internet (incl. other people) and by yourself. You will then be able to play with your digital shape since there are sensors installed that react on your movement. A picture is uploaded to the net. </p>
<p>The installation fits to the debate around technological determinism. As McLuhan puts it, “We shape our tools and our tools shape us”. But also that the medium is the message since a mirror always confronts you with yourself. And sometimes you see something you didn’t expect to see.</p></blockquote>
<p><a href="http://www.saromedia.nl/">Saro van Cleynenbreugel</a> was responsible for the technical part. Together with him and project coach <a href="http://www.tovernoot.nl">Iris Douma</a> we&#8217;ve decided to make the installation with <a href="http://www.processing.org">Processing</a>. I like Processing because of the ease of code sharing (mail some code and run it directly). However in the end Processing seemed a bit to slow for the task. Especially blending a camera silhouette with images and text cost a lot frames. Maybe next time I would choose and suggest <a href="http://www.openframeworks.cc">OpenFrameWorks</a> for an installation like this. In the end the application ran at 20 fps, so we couldn&#8217;t complain. Due some problems with a Nightvision camera (warning: exposure settings don&#8217;t work in that mode), there was some trouble to make a nice looking silhouette. </p>

<a href="http://www.kasperkamperman.com/wordpress_kk/wp-content/gallery/post-images/screenshot-scryption.jpg" title="" rel="lightbox[singlepic70]" >
	<img class="ngg-singlepic ngg-center" src="http://www.kasperkamperman.com/wordpress_kk/index.php?callback=image&amp;pid=70&amp;width=556&amp;height=&amp;mode=" alt="screenshot-scryption" title="screenshot-scryption" />
</a>

<p>Libraries used :</p>
<ul>
<li><a href="http://www.superduper.org/processing/fullscreen_api/">Fullscreen library</a></li>
<li><a href="http://ubaa.net/shared/processing/opencv/">OpenCV library</a></li>
<li><a href="http://www.shiffman.net/teaching/nature/box2d-processing/">Box2D library</a></li>
</ul>


<p>Related posts:<ol><li><a href='http://www.kasperkamperman.com/blog/computer-vision/computervision-framedifferencing/' rel='bookmark' title='Permanent Link: Computer Vision : Frame differencing'>Computer Vision : Frame differencing</a></li>
<li><a href='http://www.kasperkamperman.com/blog/arduino-unity-serial-communication/' rel='bookmark' title='Permanent Link: Arduino &#8211; Unity serial communication'>Arduino &#8211; Unity serial communication</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.kasperkamperman.com/blog/medialab-amsterdam/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visuals by code</title>
		<link>http://www.kasperkamperman.com/blog/visuals-by-code/</link>
		<comments>http://www.kasperkamperman.com/blog/visuals-by-code/#comments</comments>
		<pubDate>Mon, 17 May 2010 11:40:36 +0000</pubDate>
		<dc:creator>kasperkamperman</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Teaching]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[generative art]]></category>
		<category><![CDATA[processing]]></category>
		<category><![CDATA[toxic libs]]></category>
		<category><![CDATA[visuals by code]]></category>
		<category><![CDATA[vvvv]]></category>

		<guid isPermaLink="false">http://www.kasperkamperman.com/?p=328</guid>
		<description><![CDATA[Some resources I’ve mentioned in the lecture of 'visuals by code'. An overview of toolkits you can use to design and make graphical work by writing code, some examples and a view useful books. 


Related posts:<ol><li><a href='http://www.kasperkamperman.com/blog/medialab-amsterdam/' rel='bookmark' title='Permanent Link: MediaLAB Amsterdam : U-turm &#8211; Scryption'>MediaLAB Amsterdam : U-turm &#8211; Scryption</a></li>
<li><a href='http://www.kasperkamperman.com/blog/computer-vision-blob-tracking-face-detection/' rel='bookmark' title='Permanent Link: Computer Vision : Blob tracking &#8211; Face detection'>Computer Vision : Blob tracking &#8211; Face detection</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Some resources I&#8217;ve mentioned in the lecture of visuals by code.</p>
<p>A lot of interactive tools like Flash and Processing serve well to make visual effects. By using relative simple scripts ( re-use and play ! ) you can create complex and cool looking visuals. Most tools let you export the material to image sequences or even video. Make use of them even for non-interactive stuff. Try some examples to create some genenerative art yourself.Lets start using your creativity and start playing, &#8216;remixing&#8217; and mashing up some code. </p>
<p>Toolkits :</p>
<ul>
<li><a href="http://www.processing.org">processing.org</a></li>
<li><a href="http://developer.apple.com/graphicsimaging/quartz/">quartz composer (osx)</a></li>
<li><a href="http://www.hypeframework.org/">hype framework (Flash)</a></li>
<li><a href="http://www.nodebox.net/">Nodebox (Python, nodebased)</a></li>
<li><a href="http://www.vvvv.org">vvvv (nodebased, windows)</a></li>
<li><a href="http://sourceforge.net/projects/nodekit/">Tagtool/Nodekit (windows)</a></li>
<li><a href="http://aeexpressions.blogspot.com/2006/07/lesson-1-basics.html">after effects expressions</a></li>
<li><a href="http://www.openframeworks.cc/">OpenFrameworks (c++)</a></li>
<li><a href="http://libcinder.org/">Cinder framework (c++)</a></li>
</ul>
<p>Code examples, libraries, inspiration :</p>
<ul>
<li><a href="http://www.fxguide.com/article473.html">sc/4 : realtime compositing</a> by <a href="http://www.minivegas.co.uk/">Minivegas</a></li>
<li><a href="http://www.memo.tv/lab">memo.tv</a></li>
<li><a href="http://kineme.net/">kineme.net (quartz)</a></li>
<li><a href="http://www.levitated.net/daily/index.html">levitated : Jared Tarbell</a></li>
<li><a href="http://www.apple.com/pro/profiles/joshuadavis/">Joshua Davis</a></li>
<li><a href="http://incubator.quasimondo.com/">incubator : Mario Klingemann</a></li>
<li><a href="http://code.google.com/p/toxiclibs/">toxic libs ( processing libraries examples</a></li>
<li><a href="http://www.processing.org/learning/">processing learning section</a></li>
<li><a href="http://www.brendandawes.com/sketches/redux/">cinema redux : Bredan Dawes (2004)</a></li>
<li><a href="http://www.yooouuutuuube.com/v/?width=160&amp;height=160&amp;yt=pAwR6w2TgxY&amp;flux=0&amp;direction=bottom_left">yooouuutuuube.com : David Kraftsow 2009 | Alice ( Fagottron )</a></li>
</ul>
<p>Books :</p>
<p><iframe class="amazon_iframe" src="http://rcm-de.amazon.de/e/cm?t=kasperkamperm-21&amp;o=3&amp;p=8&amp;l=as1&amp;asins=1590593146&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;m=amazon&amp;lc1=0e8290&amp;bc1=FFFFFF&amp;bg1=FFFFFF&amp;f=ifr" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>
<iframe class="amazon_iframe" src="http://rcm-de.amazon.de/e/cm?t=kasperkamperm-21&amp;o=3&amp;p=8&amp;l=as1&amp;asins=0262182629&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;m=amazon&amp;lc1=0e8290&amp;bc1=FFFFFF&amp;bg1=FFFFFF&amp;f=ifr" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>
<iframe class="amazon_iframe" src="http://rcm-de.amazon.de/e/cm?t=kasperkamperm-21&amp;o=3&amp;p=8&amp;l=as1&amp;asins=1590594290&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;m=amazon&amp;lc1=0e8290&amp;bc1=FFFFFF&amp;bg1=FFFFFF&amp;f=ifr" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>
<iframe class="amazon_iframe" src="http://rcm-de.amazon.de/e/cm?t=kasperkamperm-21&amp;o=3&amp;p=8&amp;l=as1&amp;asins=1590597915&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;m=amazon&amp;lc1=0e8290&amp;bc1=FFFFFF&amp;bg1=FFFFFF&amp;f=ifr" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe></p>
<p>Above 20 euro no shipping costs to the Netherlands and Germany !</p>


<p>Related posts:<ol><li><a href='http://www.kasperkamperman.com/blog/medialab-amsterdam/' rel='bookmark' title='Permanent Link: MediaLAB Amsterdam : U-turm &#8211; Scryption'>MediaLAB Amsterdam : U-turm &#8211; Scryption</a></li>
<li><a href='http://www.kasperkamperman.com/blog/computer-vision-blob-tracking-face-detection/' rel='bookmark' title='Permanent Link: Computer Vision : Blob tracking &#8211; Face detection'>Computer Vision : Blob tracking &#8211; Face detection</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.kasperkamperman.com/blog/visuals-by-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Arduino Flash communication AS3 &#8211; Messenger</title>
		<link>http://www.kasperkamperman.com/blog/arduino-flash-communication-as3-messenger/</link>
		<comments>http://www.kasperkamperman.com/blog/arduino-flash-communication-as3-messenger/#comments</comments>
		<pubDate>Thu, 13 May 2010 21:52:41 +0000</pubDate>
		<dc:creator>kasperkamperman</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.kasperkamperman.com/?p=857</guid>
		<description><![CDATA[Example how to setup serial communication between Flash and Arduino in combination with the Messenger library for Arduino. This is usefull if you want to use Arduino in a different way than as a sensorbox (if you want that check out the As3glue Firmata combination in my other post).


Related posts:<ol><li><a href='http://www.kasperkamperman.com/blog/arduino/arduino-flash-communication/' rel='bookmark' title='Permanent Link: Arduino Flash communication AS2'>Arduino Flash communication AS2</a></li>
<li><a href='http://www.kasperkamperman.com/blog/arduino/arduino-flash-communication-as3/' rel='bookmark' title='Permanent Link: Arduino Flash communication AS3 &#8211; As3Glue bundle'>Arduino Flash communication AS3 &#8211; As3Glue bundle</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Example how to setup serial communication between Flash and Arduino in combination with the Messenger library for Arduino. You can send whatever you want between Arduino and Flash (if you only want to receive data from inputs and set outputs it better to use <a href="http://www.kasperkamperman.com/blog/arduino/arduino-flash-communication-as3/">Firmata / As3Glue combination</a>). </p>
<p>For receiving of data on the Arduino I&#8217;ll choose the <a href="http://www.arduino.cc/playground/Code/Messenger">Messenger library</a>. It has some nice simple functions and gives you the opportunity to check if a string is fully received (a &#8216;carriage return&#8217; is send by Flash at the end of a serial message in the SerialPort class) by Arduino. Of course you can write your own serial protocol. You can find some thoughts about it at the Todbot blog : <a href="http://todbot.com/blog/2009/07/30/arduino-serial-protocol-design-patterns/">Arduino serial protocol design patterns</a>.</p>
<p>You can send data to the serial port with the <a href="http://arduino.cc/en/Serial/Print">Serial.print()</a> and <a href="http://arduino.cc/en/Serial/Println">Serial.println()</a> commands.</p>
<p>Included is the SerialPort class for Flash that makes it easy to send and receive serial data from/to the Arduino. I&#8217;ve modified the original (from <a href="http://www.tinker.it/blog/">tinker.it</a>) so it supports start and stop characters. As a stop character &#8216;carriage return&#8217; is used (&#8216;\r&#8217;, or char(13)) that is send when you do Serial.println(); from Arduino. </p>
<p>I advise using a start character (not used in the example below) as well, because sometimes (especially when sending on a high datarate) characters at the beginning if the string can get lost. </p>
<p>The download contains SerialPort.as and example_messenger.fla (CS3).  </p>
<p>Download : <a class="download" href='http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/05/flash-arduino-as3-messenger.zip'>flash-arduino-as3-messenger</a></p>
<h2>Step by step guide for Messenger library communication</h2>
<ul>
<li>Download the <a href="http://www.arduino.cc/playground/Code/Messenger">Messenger library</a> and install it in your <em>Arduino/libraries/</em> folder ( you can find it by default in your documents folder ). Restart Arduino if it was running. </li>
<li>
Go to <em>File > Examples > Messenger > basic_communication</em>.</li>
<li>Change
<div class="codecolorer-container arduino default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="arduino codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066;">Serial</span>.<span style="color: #202020;">begin</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">115200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>to</p>
<div class="codecolorer-container arduino default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="arduino codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066;">Serial</span>.<span style="color: #202020;">begin</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">57600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>if you use my Serialproxy setup instructions from my tutorial ( see <a href="http://www.kasperkamperman.com/blog/arduino/arduino-flash-communication-as3/">Arduino &#8211; Flash communication AS3 &#8211; AS3Glue bundle</a> ). </li>
<li>Change
<div class="codecolorer-container arduino default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="arduino codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> interval <span style="color: #339933;">=</span> <span style="color: #0000dd;">20</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>to</p>
<div class="codecolorer-container arduino default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="arduino codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> interval <span style="color: #339933;">=</span> <span style="color: #0000dd;">40</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>for more stability</li>
<li>Upload the Sketch to the Arduino.</li>
<li>Configure Serialproxy for your Arduino board and run it.</li>
<li>Open example_messenger.fla and run it.</li>
<li>If everything went fine you&#8217;ll see the led on pin 13 blinking and 6 balls, controlled by the analog inputs, moving on the screen.</li>
</ul>
<h2>Example_messenger code</h2>
<pre>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6699cc; font-weight: bold;">var</span> receivedValues<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #009900; font-style: italic;">// Arduino connection</span><br />
<br />
<span style="color: #3f5fbf;">/* SerialPort(localhost, netport, start character, stop character)<br />
&nbsp; &nbsp;for more stability use a startcharacter so you can check if a message is complete<br />
&nbsp; &nbsp;default stop character is carriage return '\r' <br />
&nbsp; &nbsp;A carriage return is send by the Arduino command Serial.println();<br />
*/</span><br />
<br />
<span style="color: #6699cc; font-weight: bold;">var</span> arduino<span style="color: #000066; font-weight: bold;">:</span>SerialPort = <span style="color: #0033ff; font-weight: bold;">new</span> SerialPort<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;127.0.0.1&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">5331</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
arduino<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">DataEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">DATA</span><span style="color: #000066; font-weight: bold;">,</span> onArduinoData <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
arduino<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">connect</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #009900; font-style: italic;">// Setup a timer to send data to the Arduino</span><br />
<span style="color: #009900; font-style: italic;">// The timer object calls the timerEvent function 20 times a second (every 50ms)</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">timer</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Timer</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">500</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #004993;">timer</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;timer&quot;</span><span style="color: #000066; font-weight: bold;">,</span> timerEvent<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #004993;">timer</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #009900; font-style: italic;">// toggle variable that is switched by the timer from true to false and back</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> toggle<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>= <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #339966; font-weight: bold;">function</span> timerEvent<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <br />
<span style="color: #000000;">&#123;</span> &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// change toggle boolean to the opposite</span><br />
&nbsp; &nbsp; toggle = <span style="color: #000066; font-weight: bold;">!</span>toggle<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>toggle == <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span> <span style="color: #009900; font-style: italic;">// make ledPin 13 HIGH - onboard led on </span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//arduino.send(&quot;on&quot;); // For Messenger checkString example</span><br />
&nbsp; &nbsp; &nbsp; arduino<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">send</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;13 1&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// For Messenger basic_communication example</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">else</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span> <span style="color: #009900; font-style: italic;">// make ledPin 13 LOW - onboard led off</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//arduino.send(&quot;off&quot;); // For Messenger checkString example</span><br />
&nbsp; &nbsp; &nbsp; arduino<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">send</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;13 0&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> &nbsp;<span style="color: #009900; font-style: italic;">// For Messenger basic_communication example</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; When you have a certain amount of values it will be smart to keep them<br />
&nbsp; &nbsp; in an array (so you only modify the array indexes that change.<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; You can convert an array to a character seperated string (space character for <br />
&nbsp; &nbsp; Messenger library) with the join function.<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; Example :<br />
&nbsp; &nbsp; var sendValues:Array = new Array(2,4,8,16,32,64,128);<br />
&nbsp; &nbsp; arduino.send(sendValues.join(&quot; &quot;));<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; */</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #009900; font-style: italic;">// add some balls to the stage to display incoming analog values</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> ballArray = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>i<span style="color: #000066; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">6</span><span style="color: #000066; font-weight: bold;">;</span>i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span> &nbsp; <br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> ball<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MovieClip</span> = <span style="color: #0033ff; font-weight: bold;">new</span> Ball<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; ballArray<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = ball<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; ball<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span> = ball<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span> = <span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; ball<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; ball<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000;">&#40;</span>i<span style="color: #000066; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">60</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>ball<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #009900; font-style: italic;">// Called when data is received from the Arduino</span><br />
<span style="color: #339966; font-weight: bold;">function</span> onArduinoData<span style="color: #000000;">&#40;</span> event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">DataEvent</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
<span style="color: #000000;">&#123;</span> &nbsp; <br />
&nbsp; &nbsp; <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;received string : &quot;</span><span style="color: #000066; font-weight: bold;">,</span> event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #3f5fbf;">/* The values from Arduino Messenger are space seperated values. We will <br />
&nbsp; &nbsp; &nbsp; &nbsp;store each value in the receivedValues array. &nbsp; &nbsp;<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; receivedValues = event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">split</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot; &quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// change the y position of the balls on stage </span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>i<span style="color: #000066; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">6</span><span style="color: #000066; font-weight: bold;">;</span>i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span> <span style="color: #6699cc; font-weight: bold;">var</span> mc = ballArray<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; mc<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = receivedValues<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">350</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">1023</span><span style="color: #000066; font-weight: bold;">;</span>&nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span> &nbsp; <br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
</pre>


<p>Related posts:<ol><li><a href='http://www.kasperkamperman.com/blog/arduino/arduino-flash-communication/' rel='bookmark' title='Permanent Link: Arduino Flash communication AS2'>Arduino Flash communication AS2</a></li>
<li><a href='http://www.kasperkamperman.com/blog/arduino/arduino-flash-communication-as3/' rel='bookmark' title='Permanent Link: Arduino Flash communication AS3 &#8211; As3Glue bundle'>Arduino Flash communication AS3 &#8211; As3Glue bundle</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.kasperkamperman.com/blog/arduino-flash-communication-as3-messenger/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Arduino &#8211; Unity serial communication</title>
		<link>http://www.kasperkamperman.com/blog/arduino-unity-serial-communication/</link>
		<comments>http://www.kasperkamperman.com/blog/arduino-unity-serial-communication/#comments</comments>
		<pubDate>Wed, 12 May 2010 21:45:43 +0000</pubDate>
		<dc:creator>kasperkamperman</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://www.kasperkamperman.com/?p=850</guid>
		<description><![CDATA[Control parameters in Unity with sensors connected to the Arduino and control actuators connected to Arduino from Unity.


Related posts:<ol><li><a href='http://www.kasperkamperman.com/blog/arduino/arduino-flash-communication-as3/' rel='bookmark' title='Permanent Link: Arduino Flash communication AS3 &#8211; As3Glue bundle'>Arduino Flash communication AS3 &#8211; As3Glue bundle</a></li>
<li><a href='http://www.kasperkamperman.com/blog/arduino-flash-communication-as3-messenger/' rel='bookmark' title='Permanent Link: Arduino Flash communication AS3 &#8211; Messenger'>Arduino Flash communication AS3 &#8211; Messenger</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Art &#038; Technology student Tiuri de Jong did a project on Arduino and Unity communication. The goal was (and still is) to create an easy workflow and tutorial on how to connect Arduino with Unity (free version). Due the serial implementation in the Mac OSX version of Unity, this part still doesn&#8217;t work. Suggestions and contributions are welcome on the <a href="http://code.google.com/p/unity-arduino-serial-connection/">project page</a>. </p>
<blockquote><h2>Project: unity-arduino with serial connection</h2>
<p>This project uses Unity (which uses C# and JavaScript scripting), the Arduino and/or SerialProxy to connect the Arduino to Unity. Thus allowing custom hardware to be linked to Unity (in real-time).</p>
<p>The link is established in Windows using the Mono implementation of System.IO.Ports.</p>
<p>For Mac/OSX users, I&#8217;ve made an implementation that uses SerialProxy because direct serial connection doesn&#8217;t work on the mac. The problem is, though, that the SerialProxy implementation doesn&#8217;t seem to work either. </p></blockquote>
<p>Links:</p>
<ul>
<li><a href="http://code.google.com/p/unity-arduino-serial-connection/">Unity-Arduino serial-connection</a>  on Google code</li>
<li><a href="http://unity3d.com/">Unity : Game Development Tool</a></li>
<li>
<a href="http://www.arduino.cc">Arduino</a></li>
</ul>


<p>Related posts:<ol><li><a href='http://www.kasperkamperman.com/blog/arduino/arduino-flash-communication-as3/' rel='bookmark' title='Permanent Link: Arduino Flash communication AS3 &#8211; As3Glue bundle'>Arduino Flash communication AS3 &#8211; As3Glue bundle</a></li>
<li><a href='http://www.kasperkamperman.com/blog/arduino-flash-communication-as3-messenger/' rel='bookmark' title='Permanent Link: Arduino Flash communication AS3 &#8211; Messenger'>Arduino Flash communication AS3 &#8211; Messenger</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.kasperkamperman.com/blog/arduino-unity-serial-communication/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Computer Vision : Blob tracking &#8211; Face detection</title>
		<link>http://www.kasperkamperman.com/blog/computer-vision-blob-tracking-face-detection/</link>
		<comments>http://www.kasperkamperman.com/blog/computer-vision-blob-tracking-face-detection/#comments</comments>
		<pubDate>Thu, 29 Apr 2010 13:04:44 +0000</pubDate>
		<dc:creator>kasperkamperman</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Computer Vision]]></category>

		<guid isPermaLink="false">http://www.kasperkamperman.com/?p=825</guid>
		<description><![CDATA[In this 'Computer Vision' article you can read about <strong>Blob detection</strong> and <strong>Face detection</strong>. I've included some video's to give you an idea about the techniques and links to the most relevant code examples.


Related posts:<ol><li><a href='http://www.kasperkamperman.com/blog/computer-vision/computervision-framedifferencing/' rel='bookmark' title='Permanent Link: Computer Vision : Frame differencing'>Computer Vision : Frame differencing</a></li>
<li><a href='http://www.kasperkamperman.com/blog/flash-code/as3-apply-bitmap-filters-to-a-webcam-image/' rel='bookmark' title='Permanent Link: Flash AS3 : Apply bitmap filters to a webcam image'>Flash AS3 : Apply bitmap filters to a webcam image</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>A blobs is a certain object that represents a certain area of a frame. Blobs can be different things like: hands, faces, balls, ir-lights. They are identified because they differ from other pixels in the frame.<br/><br/> Tracking is identifying blobs that change over time. In multi-touch tables, based on computer vision with a webcam, your fingertips are the blobs that are tracked. Every blob will act as a &#8216;mouse pointer&#8217;. </p>
<p><em>Blob Detection test by samkeene :</em>
<p><a href="http://www.kasperkamperman.com/blog/computer-vision-blob-tracking-face-detection/"><em>Click here to view the embedded video.</em></a></p></p>
<p>Max Meinders made a good description of all the processing steps involved in Blob tracking :<br/>
<a href="http://vid.acqda.nl/index.php?page=general">Max Meinders &#8211; videotracking</a>.</p>
<table>
<tr>
<th>Tool/Language</th>
<th>Resource</th>
</tr>
<tr>
<td>AS3</td>
<td><a href="http://play.blog2t.net/fast-blob-detection/">Fast blob detection in Flash by Tomek</a></td>
</tr>
<tr>
<td>Application</td>
<td><a href="http://ccv.nuigroup.com/">Community Core Vision / Tbeta by the NUI Group Community</a><br/>
  Can communicate by TUIO, OSC, XML protocols with other software.
  </td>
</tr>
<tr>
<td>OF (c++)</td>
<td><a href="http://code.google.com/p/peoplevision/">CYA: People Vision Software</a></td>
</tr>
<tr>
<td>Processing</td>
<td><a href="http://ubaa.net/shared/processing/opencv/opencv_blobs.html">OpenCV library for Processing</a> by Stéphane Cousot and Douglas Edric Stanley.</td>
</tr>
</table>
<p><br/></p>
<h2>Face detection</h2>
<p>OpenCV also supports the recognition of special characteristics in an image and use those as a blob. Face detection a tecnique to recognize things that look like a face in an image. It doesn&#8217;t recognize a certain face ( although thats possible, see Image recognition ), but it detects facial features. </p>
<p><em>Face Detection with Processing by Pedro Amado </em>
<p><a href="http://www.kasperkamperman.com/blog/computer-vision-blob-tracking-face-detection/"><em>Click here to view the embedded video.</em></a></p></p>
<p>Face detection works with classifiers. You can learn the computer characteristics of an object. So OpenCV can detect other objects as well, as long you have a classifier file for it. </p>
<p>Keywords : <a href="http://www.google.com/search?q=%22Haar+Classifier%22">Haar Classifier</a>, <a href="http://www.google.com/search?q=%22Viola+Jones+object+detection+framework%22">Viola Jones object detection framework</a>, <a href="http://www.google.nl/search?q=cascade+classifier">cascade classifiers</a>. </p>
<table>
<tr>
<th>Tool/Language</th>
<th>Resource</th>
</tr>
<tr>
<td>AS3</td>
<td><a href="http://blog.inspirit.ru/?p=416">Viola-Jones object detection by Eugene Zatepyakin</a></td>
</tr>
<tr>
<td>AS3</td>
<td><a href="http://www.quasimondo.com/archives/000687.php ">Optimizing Flash Based Face Detection by Mario Klingemann</a>
  </td>
</tr>
<tr>
<td>Processing libary</td>
<td><a href="http://ubaa.net/shared/processing/opencv/opencv_detect.html">OpenCV detect</a> Can detect faces, profiles and bodies.</td>
</tr>
</table>
<p><br/>
Tomek made a nice example where he tracks faces in the &#8216;Black and White&#8217; video of Michael Jackson in realtime in Flash ( you can tried it yourself to with a webcam ) : <a href="http://play.blog2t.net/realtime-as3-face-and-eye-detection-with-michael-jackson/">Machines are looking for Michael Jackson</a>. </p>


<p>Related posts:<ol><li><a href='http://www.kasperkamperman.com/blog/computer-vision/computervision-framedifferencing/' rel='bookmark' title='Permanent Link: Computer Vision : Frame differencing'>Computer Vision : Frame differencing</a></li>
<li><a href='http://www.kasperkamperman.com/blog/flash-code/as3-apply-bitmap-filters-to-a-webcam-image/' rel='bookmark' title='Permanent Link: Flash AS3 : Apply bitmap filters to a webcam image'>Flash AS3 : Apply bitmap filters to a webcam image</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.kasperkamperman.com/blog/computer-vision-blob-tracking-face-detection/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Computer Vision : Frame differencing</title>
		<link>http://www.kasperkamperman.com/blog/computer-vision/computervision-framedifferencing/</link>
		<comments>http://www.kasperkamperman.com/blog/computer-vision/computervision-framedifferencing/#comments</comments>
		<pubDate>Fri, 23 Apr 2010 22:51:21 +0000</pubDate>
		<dc:creator>kasperkamperman</dc:creator>
				<category><![CDATA[Computer Vision]]></category>

		<guid isPermaLink="false">http://www.kasperkamperman.com/?p=804</guid>
		<description><![CDATA[In this 'Computer Vision' article you can read something about the <strong>Frame Differencing</strong> technique. I've included some video's to give you an idea about the technique and some links the most relevant code examples. 


Related posts:<ol><li><a href='http://www.kasperkamperman.com/blog/computer-vision-blob-tracking-face-detection/' rel='bookmark' title='Permanent Link: Computer Vision : Blob tracking &#8211; Face detection'>Computer Vision : Blob tracking &#8211; Face detection</a></li>
<li><a href='http://www.kasperkamperman.com/blog/flash-code/as3-apply-bitmap-filters-to-a-webcam-image/' rel='bookmark' title='Permanent Link: Flash AS3 : Apply bitmap filters to a webcam image'>Flash AS3 : Apply bitmap filters to a webcam image</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Frame differencing is a technique where the computer checks the difference between two video frames. If the pixels
have changed there apparently was something changing in the image (moving for example).
Most techniques work with some blur and threshold, to distict real movement from noise. Because frame could differ
too when light conditions in a room change ( and camera auto focus, brightness correction etc. ).  </p>
<p>Below an example of the difference filter in the <a href="http://ubaa.net/shared/processing/opencv/">OpenCV library</a> for Processing. You can do the same in Flash with the <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/BlendMode.html#DIFFERENCE">Difference Blendmode</a>.</p>
<p><a href="http://www.kasperkamperman.com/blog/computer-vision/computervision-framedifferencing/"><em>Click here to view the embedded video.</em></a></p>
<p>You can move objects to area&#8217;s where most of the motion is happening, like in the Pong example of Ostrich :
<a href="http://www.flashfeathers.com/feathers/samples/ostrich/samplecursors.html">Ostrich two cursors example</a> </p>
<p>Or you can make some hotspots in your image and check the amount of motion in those. A nice example to get the idea is the <a href="http://www.memo.tv/webcam_piano">webcam piano</a> from Memo Akten (implemented in Quartz Composer and Processing) :</p>
<p><a href="http://www.kasperkamperman.com/blog/computer-vision/computervision-framedifferencing/"><em>Click here to view the embedded video.</em></a></p>
<p>Or you can do other creative things with it (video by <a href="http://www.okgo.net/2010/01/20/wtf-video-remix-project/">WTF? by OK Go</a>, <a href="http://www.msavisuals.com/xmas2009">example code in Processing by Memo Akten</a>) :</p>
<p><a href="http://www.kasperkamperman.com/blog/computer-vision/computervision-framedifferencing/"><em>Click here to view the embedded video.</em></a></p>
<h2>Code examples and tutorials</h2>
<table>
<tr>
<th>Tool/Language</th>
<th>Resource</th>
</tr>
<tr>
<td>AS3</td>
<td><a href="http://ostrichflash.wordpress.com/">Ostrich Flash (Flash feathers)</a></td>
</tr>
<tr>
<td>AS3</td>
<td><a href="http://blog.soulwire.co.uk/code/actionscript-3/webcam-motion-detection-tracking/">Webcam motion detection by Soulwire</a></td>
</tr>
<tr>
<td>AS2</td>
<td><a href="http://www.adobe.com/devnet/flash/articles/webcam_motion_print.html">Webcam Motion Detection by Guy Watson</a></td>
</tr>
<tr>
<td>Processing</td>
<td><a href="http://www.memo.tv/webcam_piano_with_processing_v0_1">Webcam Piano by Memo Akten</a></td>
</tr>
<tr>
<td>Processing</td>
<td><a href="http://andybest.net/2009/02/processing-opencv-tutorial-2-bubbles/">Poping Bubbles with OpenCV library by Andy Best</a></td>
</tr>
<tr>
<td>Processing</td>
<td><a href="http://processing.org/learning/library/framedifferencing.html">Frame differencing code example by Golan Levin</a></td>
</tr>
</table>
<p><br/>If you only want to detect if there is a certain amount of motion in front of a webcam, you can use the activityHandler and <a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/media/Camera.html#activityLevel">activityLevel</a> parameters in Flash. See my example on bitmap filters where i use it the apply a red filter when there is movement :<br/>
<a href="http://www.kasperkamperman.com/blog/flash-code/as3-apply-bitmap-filters-to-a-webcam-image/">Flash AS3 : Apply bitmap filters to a webcam image</a></p>


<p>Related posts:<ol><li><a href='http://www.kasperkamperman.com/blog/computer-vision-blob-tracking-face-detection/' rel='bookmark' title='Permanent Link: Computer Vision : Blob tracking &#8211; Face detection'>Computer Vision : Blob tracking &#8211; Face detection</a></li>
<li><a href='http://www.kasperkamperman.com/blog/flash-code/as3-apply-bitmap-filters-to-a-webcam-image/' rel='bookmark' title='Permanent Link: Flash AS3 : Apply bitmap filters to a webcam image'>Flash AS3 : Apply bitmap filters to a webcam image</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.kasperkamperman.com/blog/computer-vision/computervision-framedifferencing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Arduino Flash communication AS3 &#8211; As3Glue bundle</title>
		<link>http://www.kasperkamperman.com/blog/arduino/arduino-flash-communication-as3/</link>
		<comments>http://www.kasperkamperman.com/blog/arduino/arduino-flash-communication-as3/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 16:36:18 +0000</pubDate>
		<dc:creator>kasperkamperman</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.kasperkamperman.com/?p=789</guid>
		<description><![CDATA[Video tutorial on how to setup communication between Arduino and Flash ( Actionscript 3.0 ) with Firmata, As3Glue and Serialproxy. You can download a bundle with examples and the libraries/software. 


Related posts:<ol><li><a href='http://www.kasperkamperman.com/blog/arduino/arduino-flash-communication/' rel='bookmark' title='Permanent Link: Arduino Flash communication AS2'>Arduino Flash communication AS2</a></li>
<li><a href='http://www.kasperkamperman.com/blog/arduino-flash-communication-as3-messenger/' rel='bookmark' title='Permanent Link: Arduino Flash communication AS3 &#8211; Messenger'>Arduino Flash communication AS3 &#8211; Messenger</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.kasperkamperman.com/blog/arduino/arduino-flash-communication-as3/"><em>Click here to view the embedded video.</em></a></p>
<p>I&#8217;ve created a Flash monitor application with As3Glue to make it easier to start with Flash Arduino communication.</p>
<p>Glue is an ActionScript 3.0 library that enables communication between Flash and Arduino boards with Firmata. Since Flash cannot interface the serial port directly we&#8217;ll use Serialproxy in between. Serialproxy converts incoming serial data the XMLsocket data. </p>
<p>The monitor is useful to check if all the connections are working good. You can monitor directly all the sensors and actuators connected to your Arduino board. </p>
<p>The example code file is a start point to program your own things controlled by Arduino. </p>
<p>Included files :</p>
<ul>
<li><a href="http://code.google.com/p/as3glue/ ">AS3Glue</a> files ( .net.eriksjodin.arduino )</li>
<li><a href="http://code.google.com/p/tinkerit/wiki/TinkerProxy">Tinkerproxy osx</a> ( renamed to serproxy )</li>
<li><a href="http://cote.cc/blog/serialproxy-v014-can-use-com-ports-above-9">Serialproxy windows</a> ( renamed to serproxy )</li>
<li>as3glue_standalone_monitor.fla</li>
<li>as3glue_program-example.fla</li>
</ul>
<p>The Firmata library is included with Arduino itself. Make sure you use Arduino 018, because the Firmata library included in version 017 is not stable. </p>
<p>Update (12-05-10, v1.3): I&#8217;ve updated the code for the support of two servo motors (pin 9 and pin 10). </p>
<p>Download the zip-file : <a class="download" href='http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/05/arduino_as3glue_bundle_v14.zip'>arduino_as3glue_bundle_v1.4</a></p>
<p><a href="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/screenshot_as3-example.jpg">
<img src="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/screenshot_as3-example.jpg" alt="" title="screenshot_as3-example" width="550" height="671" class="alignnone size-full wp-image-793" /></a></p>


<p>Related posts:<ol><li><a href='http://www.kasperkamperman.com/blog/arduino/arduino-flash-communication/' rel='bookmark' title='Permanent Link: Arduino Flash communication AS2'>Arduino Flash communication AS2</a></li>
<li><a href='http://www.kasperkamperman.com/blog/arduino-flash-communication-as3-messenger/' rel='bookmark' title='Permanent Link: Arduino Flash communication AS3 &#8211; Messenger'>Arduino Flash communication AS3 &#8211; Messenger</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.kasperkamperman.com/blog/arduino/arduino-flash-communication-as3/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Flash AS3 : Apply bitmap filters to a webcam image</title>
		<link>http://www.kasperkamperman.com/blog/flash-code/as3-apply-bitmap-filters-to-a-webcam-image/</link>
		<comments>http://www.kasperkamperman.com/blog/flash-code/as3-apply-bitmap-filters-to-a-webcam-image/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 21:52:13 +0000</pubDate>
		<dc:creator>kasperkamperman</dc:creator>
				<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.kasperkamperman.com/?p=769</guid>
		<description><![CDATA[Simple ( beginner-intermediate ) Flash Actionscript 3.0 code example on how to apply a bitmap filter on a webcam image. Also image rotation and simple motion detection ( activityLevel ) is included. 



Related posts:<ol><li><a href='http://www.kasperkamperman.com/blog/computer-vision/computervision-framedifferencing/' rel='bookmark' title='Permanent Link: Computer Vision : Frame differencing'>Computer Vision : Frame differencing</a></li>
<li><a href='http://www.kasperkamperman.com/blog/arduino-flash-communication-as3-messenger/' rel='bookmark' title='Permanent Link: Arduino Flash communication AS3 &#8211; Messenger'>Arduino Flash communication AS3 &#8211; Messenger</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Simple ( beginner-intermediate ) Flash AS3code example on how to apply a bitmap filter on a webcam image. Also image rotation and simple motion detection ( activityLevel ) is included. </p>
<p>You can make a Photobooth of this script as well. Mark Knol wrote an ImageSaver class that sends a .jpg or .png picture of a Display element to a simple PHP script that stores it on a webserver :<br/>
<a href="http://blog.stroep.nl/2008/08/as3-imagesaver-class-v10/">Stroep.nl AS3 ImageSaver Class</a>.</p>
<p>You need a webcam and give Flashplayer access to the camera to see the example below :</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_camera-example_856589321"
			class="flashmovie"
			width="400"
			height="300">
	<param name="movie" value="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/camera-example.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/camera-example.swf"
			name="fm_camera-example_856589321"
			width="400"
			height="300">
	<!--<![endif]-->
		
<p><a href="http://get.adobe.com/flashplayer/"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p><br/>
For more in-depth information see the following subjects in the Flash Actionscript 3.0 reference :</p>
<ul>
<li><a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/filters/package-detail.html">filters</a></li>
<li><a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/display/BitmapData.html">bitmapdata </a></li>
<li><a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/media/Camera.html">camera</a></li>
</ul>
<h2>The code ( copy-paste directly in a new Flash project in the Actions &#8211; Frame. )</h2>
<pre>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #3f5fbf;">/*<br />
Example how to detect motion in a webcam image and to apply a color filter <br />
and/or rotation. <br />
<br />
www.kasperkamperman.com - 10-03-2010<br />
*/</span><br />
<br />
<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">fps</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">25</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// frames per second you want to grab and display</span><br />
<br />
<span style="color: #6699cc; font-weight: bold;">var</span> cam<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Camera</span><span style="color: #000066; font-weight: bold;">;</span><br />
cam = <span style="color: #004993;">Camera</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getCamera</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
cam<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">setMode</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">640</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">480</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #004993;">fps</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #6699cc; font-weight: bold;">var</span> video<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Video</span><span style="color: #000066; font-weight: bold;">;</span><br />
video = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Video</span><span style="color: #000000;">&#40;</span>cam<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">,</span> cam<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
video<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">attachCamera</span><span style="color: #000000;">&#40;</span>cam<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #009900; font-style: italic;">// motion detector ------------------------------------------------</span><br />
cam<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">setMotionLevel</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">30</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// level 30, timer 500ms</span><br />
cam<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">ActivityEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ACTIVITY</span><span style="color: #000066; font-weight: bold;">,</span> activityHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #009900; font-style: italic;">// variable to store movement ( use later to apply the filter )</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> imageMovement<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span> <br />
<br />
<span style="color: #339966; font-weight: bold;">function</span> activityHandler<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">ActivityEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <br />
<span style="color: #000000;">&#123;</span> &nbsp;<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">activating</span> == <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; imageMovement = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;movement above threshold. Level :&quot;</span><span style="color: #000066; font-weight: bold;">+</span>cam<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">activityLevel</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp;<span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; imageMovement = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;no movement. Level :&quot;</span><span style="color: #000066; font-weight: bold;">+</span>cam<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">activityLevel</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp;<span style="color: #000000;">&#125;</span> &nbsp; &nbsp;<br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #009900; font-style: italic;">// --- filter ---------------------------------------------------------</span><br />
<br />
<span style="color: #009900; font-style: italic;">// filter green/blue components ( leave red)</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> redFilterMatrix<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
redFilterMatrix = redFilterMatrix<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">concat</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// red</span><br />
redFilterMatrix = redFilterMatrix<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">concat</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// green</span><br />
redFilterMatrix = redFilterMatrix<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">concat</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// blue</span><br />
redFilterMatrix = redFilterMatrix<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">concat</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// alpha</span><br />
<br />
<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">filter</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">ColorMatrixFilter</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">ColorMatrixFilter</span><span style="color: #000000;">&#40;</span>redFilterMatrix<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #009900; font-style: italic;">// --- BitmapData ------------------------</span><br />
<br />
<span style="color: #009900; font-style: italic;">// make a BitmapData object on which you can draw to video</span><br />
<span style="color: #009900; font-style: italic;">// ( exchange width/height when you want to rotate the image )</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> bmd<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">BitmapData</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">BitmapData</span><span style="color: #000000;">&#40;</span>cam<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">,</span>cam<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #009900; font-style: italic;">// rectangle and pointer for applying filter</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">rect</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Rectangle</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> bmd<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">,</span> bmd<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> point<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Point</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #6699cc; font-weight: bold;">var</span> canvasBitmap<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Bitmap</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Bitmap</span><span style="color: #000000;">&#40;</span>bmd<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// link BitmapData to Bitmap </span><br />
<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>canvasBitmap<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900; font-style: italic;">// add Bitmap to stage</span><br />
<br />
<span style="color: #009900; font-style: italic;">// --- rotate camera image ---------------------------------------------------</span><br />
<br />
<span style="color: #6699cc; font-weight: bold;">var</span> rotateMatrix<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Matrix</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Matrix</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
rotateMatrix<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">rotate</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PI</span> <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">90</span> <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">360</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
rotateMatrix<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">translate</span><span style="color: #000000;">&#40;</span>cam<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #009900; font-style: italic;">// --- Timer to refresh the image --------------------------------------------</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> refreshTimer<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Timer</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Timer</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1000</span><span style="color: #000066; font-weight: bold;">/</span><span style="color: #000000; font-weight:bold;">25</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">// 1000ms / 25fps</span><br />
refreshTimer<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
refreshTimer<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">TimerEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TIMER</span><span style="color: #000066; font-weight: bold;">,</span> imageRefresh<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #339966; font-weight: bold;">function</span> imageRefresh<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span> &nbsp; &nbsp;<span style="color: #009900; font-style: italic;">// draw video on BitmapData</span><br />
&nbsp; &nbsp; &nbsp;bmd<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">draw</span><span style="color: #000000;">&#40;</span>video<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp;<span style="color: #009900; font-style: italic;">// draw video rotated on BitmapData ( don't forget to change BitmapData to </span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #009900; font-style: italic;">// the right size ) and comment the bmd.draw(video) line. </span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #009900; font-style: italic;">//bmd.draw(video, rotateMatrix);</span><br />
&nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp;<span style="color: #009900; font-style: italic;">// apply the red filter when there is enough image movement</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>imageMovement==<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span> bmd<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">applyFilter</span><span style="color: #000000;">&#40;</span>bmd<span style="color: #000066; font-weight: bold;">,</span><span style="color: #004993;">rect</span><span style="color: #000066; font-weight: bold;">,</span>point<span style="color: #000066; font-weight: bold;">,</span><span style="color: #004993;">filter</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>&nbsp; &nbsp; <br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
</pre>


<p>Related posts:<ol><li><a href='http://www.kasperkamperman.com/blog/computer-vision/computervision-framedifferencing/' rel='bookmark' title='Permanent Link: Computer Vision : Frame differencing'>Computer Vision : Frame differencing</a></li>
<li><a href='http://www.kasperkamperman.com/blog/arduino-flash-communication-as3-messenger/' rel='bookmark' title='Permanent Link: Arduino Flash communication AS3 &#8211; Messenger'>Arduino Flash communication AS3 &#8211; Messenger</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.kasperkamperman.com/blog/flash-code/as3-apply-bitmap-filters-to-a-webcam-image/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Processing ControlP5 library example 2 : Style and setValue</title>
		<link>http://www.kasperkamperman.com/blog/processing-code/controlp5-library-example2/</link>
		<comments>http://www.kasperkamperman.com/blog/processing-code/controlp5-library-example2/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 20:50:22 +0000</pubDate>
		<dc:creator>kasperkamperman</dc:creator>
				<category><![CDATA[Processing]]></category>

		<guid isPermaLink="false">http://www.kasperkamperman.com/?p=728</guid>
		<description><![CDATA[In this follow up article (Processing ControlP5 example 1) an example on how to style (font, color) the ControlP5 interface elements and how to set their values, so you can use them also to monitor variables. 


Related posts:<ol><li><a href='http://www.kasperkamperman.com/blog/processing-code/controlp5-library-example1/' rel='bookmark' title='Permanent Link: Processing ControlP5 library example 1 : user interface'>Processing ControlP5 library example 1 : user interface</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>In this example you&#8217;ll see how to style the GUI that you&#8217;ve made with the ControlP5 library ( see first article : <a href="http://www.kasperkamperman.com/blog/processing-code/controlp5-library-example1/">Processing ControlP5 library example 1 : user interface</a> for the basics. ) </p>
<div id="attachment_733" class="wp-caption alignnone" style="width: 390px"><a href="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/controlP5-interface-basic2.jpg"><img src="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/controlP5-interface-basic2.jpg" alt="" title="controlP5-interface-basic2" width="380" height="305" class="size-full wp-image-733" /></a><p class="wp-caption-text">controlP5 styling interface elements</p></div>
<p>View the sketch in action at <a href="http://www.openprocessing.org/visuals/?visualID=8113">openprocessing.org</a>.<br/>
Download the zip-file ( with all the examples ) : <a class="download" href='http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/controlP5-examples.zip'>controlP5-examples.zip</a></p>
<p>This example is pretty straight forward. You give some style the controlP5 object with the &#8217;setControlFont&#8217; and &#8217;setColor&#8230;.&#8217; methods. </p>
<p>In the controlEvent function we use the values of some control elements to control the value of others. The setValue method is useful when you want to monitor variables in a visual way. </p>
<ul>
<li>Slider1 controls Slider2.</li>
<li>Bang1 sets Toggle1 to 1 (on/true).</li>
<li>Button1 sets Toggle1 to 0 (off/false).</li>
<li>Numberbox1 controls Knob1.</li>
</ul>
<pre>
<div class="codecolorer-container processing default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br /></div></td><td><div class="processing codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #777755;">// ControlP5 Example 2 : Style UI elements and setValue</span><br />
<span style="color: #777755;">// ControlP5 by Andreas Schlegel : http://www.sojamo.de/libraries/controlP5/</span><br />
<br />
<span style="color: #996600;">import</span> controlP5.<span style="color: #000000;">*;</span><br />
ControlP5 controlP5<span style="color: #000000;">;</span><br />
<br />
<span style="color: #993300; font-weight: bold;">void</span> <span style="color: #996600;">setup</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; <span style="color: #996600;">size</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">300</span>,<span style="color: #000000;">260</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; <span style="color: #996600;">smooth</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; <br />
&nbsp; controlP5 = <span style="color: #996600;">new</span> ControlP5<span style="color: #000000;">&#40;</span><span style="color: #996600;">this</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #777755;">// change the default font to Verdana</span><br />
&nbsp; <span style="color: #993300; font-weight: bold;">PFont</span> p = <span style="color: #996600;">createFont</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;Verdana&quot;</span>,<span style="color: #000000;">9</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span> <br />
&nbsp; controlP5.<span style="color: #000000;">setControlFont</span><span style="color: #000000;">&#40;</span>p<span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #777755;">// change the original colors</span><br />
&nbsp; controlP5.<span style="color: #000000;">setColorForeground</span><span style="color: #000000;">&#40;</span>0xffaa0000<span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; controlP5.<span style="color: #000000;">setColorBackground</span><span style="color: #000000;">&#40;</span>0xff660000<span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; controlP5.<span style="color: #000000;">setColorLabel</span><span style="color: #000000;">&#40;</span>0xffdddddd<span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; controlP5.<span style="color: #000000;">setColorValue</span><span style="color: #000000;">&#40;</span>0xffff88ff<span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; controlP5.<span style="color: #000000;">setColorActive</span><span style="color: #000000;">&#40;</span>0xffff0000<span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #777755;">// add the elments ( see example 1 for the parameters )</span><br />
&nbsp; controlP5.<span style="color: #000000;">addBang</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;bang1&quot;</span>,<span style="color: #000000;">10</span>,<span style="color: #000000;">10</span>,<span style="color: #000000;">20</span>,<span style="color: #000000;">20</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span> &nbsp; &nbsp;<br />
&nbsp; controlP5.<span style="color: #000000;">addButton</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;button1&quot;</span>,<span style="color: #000000;">1</span>,<span style="color: #000000;">70</span>,<span style="color: #000000;">10</span>,<span style="color: #000000;">60</span>,<span style="color: #000000;">20</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span> &nbsp;<br />
&nbsp; controlP5.<span style="color: #000000;">addToggle</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;toggle1&quot;</span>,<span style="color: #996600;">false</span>,<span style="color: #000000;">170</span>,<span style="color: #000000;">10</span>,<span style="color: #000000;">20</span>,<span style="color: #000000;">20</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span> &nbsp; &nbsp;<br />
&nbsp; controlP5.<span style="color: #000000;">addSlider</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;slider1&quot;</span>,<span style="color: #000000;">0</span>,<span style="color: #000000;">255</span>,<span style="color: #000000;">128</span>,<span style="color: #000000;">10</span>,<span style="color: #000000;">80</span>,<span style="color: #000000;">10</span>,<span style="color: #000000;">100</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; <br />
&nbsp; Slider s = controlP5.<span style="color: #000000;">addSlider</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;slider2&quot;</span>,<span style="color: #000000;">0</span>,<span style="color: #000000;">255</span>,<span style="color: #000000;">128</span>,<span style="color: #000000;">70</span>,<span style="color: #000000;">80</span>,<span style="color: #000000;">100</span>,<span style="color: #000000;">10</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; <span style="color: #777755;">// change sliderMode of the Slider object. The default is Slider.FIX</span><br />
&nbsp; s.<span style="color: #000000;">setSliderMode</span><span style="color: #000000;">&#40;</span>Slider.<span style="color: #000000;">FLEXIBLE</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span> <br />
&nbsp; &nbsp; <br />
&nbsp; controlP5.<span style="color: #000000;">addKnob</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;knob1&quot;</span>,<span style="color: #000000;">0</span>,<span style="color: #000000;">360</span>,<span style="color: #000000;">0</span>,<span style="color: #000000;">70</span>,<span style="color: #000000;">120</span>,<span style="color: #000000;">50</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; <br />
&nbsp; Numberbox n = controlP5.<span style="color: #000000;">addNumberbox</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;numberbox1&quot;</span>,<span style="color: #000000;">50</span>,<span style="color: #000000;">170</span>,<span style="color: #000000;">120</span>,<span style="color: #000000;">60</span>,<span style="color: #000000;">14</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; <span style="color: #777755;">// change Multiplier of the Numberbox ( default is 1 )</span><br />
&nbsp; n.<span style="color: #000000;">setMultiplier</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">30</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #993300; font-weight: bold;">void</span> <span style="color: #996600;">draw</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <br />
&nbsp; <span style="color: #996600;">background</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span> &nbsp;<span style="color: #777755;">// background black</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #993300; font-weight: bold;">void</span> controlEvent<span style="color: #000000;">&#40;</span>ControlEvent theEvent<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #996600;">if</span><span style="color: #000000;">&#40;</span>theEvent.<span style="color: #000000;">isController</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #996600;">print</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;control event from : &quot;</span>+theEvent.<span style="color: #000000;">controller</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">name</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; &nbsp; <span style="color: #996600;">println</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;, value : &quot;</span>+theEvent.<span style="color: #000000;">controller</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">value</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #777755;">// clicking on bang1 sets toggle1 value to 1 (true) &nbsp; &nbsp; &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #996600;">if</span><span style="color: #000000;">&#40;</span>theEvent.<span style="color: #000000;">controller</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">name</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>==<span style="color: #ff0000;">&quot;bang1&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;controlP5.<span style="color: #000000;">controller</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;toggle1&quot;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">setValue</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span> &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #777755;">// clicking on button1 sets toggle1 value to 0 (false)</span><br />
&nbsp; &nbsp; <span style="color: #996600;">if</span><span style="color: #000000;">&#40;</span>theEvent.<span style="color: #000000;">controller</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">name</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>==<span style="color: #ff0000;">&quot;button1&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;controlP5.<span style="color: #000000;">controller</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;toggle1&quot;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">setValue</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span> &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #777755;">// dragging slider1 changes the value of slider2</span><br />
&nbsp; &nbsp; <span style="color: #996600;">if</span><span style="color: #000000;">&#40;</span>theEvent.<span style="color: #000000;">controller</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">name</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>==<span style="color: #ff0000;">&quot;slider1&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;controlP5.<span style="color: #000000;">controller</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;slider2&quot;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">setValue</span><span style="color: #000000;">&#40;</span>theEvent.<span style="color: #000000;">controller</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">value</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #777755;">// changing the value of numberbox1 turns knob1</span><br />
&nbsp; &nbsp; <span style="color: #996600;">if</span><span style="color: #000000;">&#40;</span>theEvent.<span style="color: #000000;">controller</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">name</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>==<span style="color: #ff0000;">&quot;numberbox1&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;controlP5.<span style="color: #000000;">controller</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;knob1&quot;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">setValue</span><span style="color: #000000;">&#40;</span>theEvent.<span style="color: #000000;">controller</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">value</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; <span style="color: #000000;">&#125;</span> &nbsp;<br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&lt;</span>/pre<span style="color: #000000;">&gt;</span></div></td></tr></tbody></table></div>


<p>Related posts:<ol><li><a href='http://www.kasperkamperman.com/blog/processing-code/controlp5-library-example1/' rel='bookmark' title='Permanent Link: Processing ControlP5 library example 1 : user interface'>Processing ControlP5 library example 1 : user interface</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.kasperkamperman.com/blog/processing-code/controlp5-library-example2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Processing ControlP5 library example 1 : user interface</title>
		<link>http://www.kasperkamperman.com/blog/processing-code/controlp5-library-example1/</link>
		<comments>http://www.kasperkamperman.com/blog/processing-code/controlp5-library-example1/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 08:18:48 +0000</pubDate>
		<dc:creator>kasperkamperman</dc:creator>
				<category><![CDATA[Processing]]></category>

		<guid isPermaLink="false">http://www.kasperkamperman.com/?p=722</guid>
		<description><![CDATA[The controlP5 library for Processing makes it easy to add knobs and buttons to your Processing applications. In this article an example how to add some interface elements (buttons, sliders etc.) and how to listen to their events. 


Related posts:<ol><li><a href='http://www.kasperkamperman.com/blog/processing-code/controlp5-library-example2/' rel='bookmark' title='Permanent Link: Processing ControlP5 library example 2 : Style and setValue'>Processing ControlP5 library example 2 : Style and setValue</a></li>
<li><a href='http://www.kasperkamperman.com/blog/flash-code/as3-apply-bitmap-filters-to-a-webcam-image/' rel='bookmark' title='Permanent Link: Flash AS3 : Apply bitmap filters to a webcam image'>Flash AS3 : Apply bitmap filters to a webcam image</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>ControlP5 is a GUI and controller library for Processing. You can easy add controllers to your program. You can <a href="http://www.sojamo.de/libraries/controlP5/">download the ControlP5 library at the site of Andreas Schlegel</a>. After downloading und unpacking you can copy the library in the &#8216;libraries&#8217; subfolder of the Processing sketches folder. </p>
<p>The library comes with a lot of examples, but it lacks a bit an overview how to use different elements together. In this article and example an overview of some basic GUI elements and how you can handle their events. </p>
<p>See the sketch in action at <a href="http://www.openprocessing.org/visuals/?visualID=8108">openprocessing.org</a>.<br/>
Download the zip-file ( with all the examples ) : <a class="download" href='http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/controlP5-examples.zip'>controlP5-examples.zip</a></p>
<div id="attachment_725" class="wp-caption alignnone" style="width: 390px"><a href="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/controlP5-interface-basic.jpg"><img src="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/controlP5-interface-basic.jpg" alt="" title="controlP5-interface-basic" width="380" height="305" class="size-full wp-image-725" /></a><p class="wp-caption-text">controlP5 basic interface elements</p></div>
<table>
<tr>
<th>Element</th>
<th>Description</th>
</tr>
<tr>
<td><a href="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/controlP5-bang.gif"><img src="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/controlP5-bang.gif" alt="" title="controlP5-bang" width="140" height="70" class="alignnone size-full wp-image-735" /></a></td>
<td><strong>Bang : A bang controller triggers an event when pressed.</strong><br/>
  parameters  : name, x, y, width, height<br/>
  <code class="codecolorer processing default"><span class="processing">controlP5.<span style="color: #000000;">addBang</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;bang1&quot;</span>,<span style="color: #000000;">10</span>,<span style="color: #000000;">10</span>,<span style="color: #000000;">20</span>,<span style="color: #000000;">20</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span></span></code>
  </td>
</tr>
<tr>
<td><a href="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/controlP5-button.gif"><img src="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/controlP5-button.gif" alt="" title="controlP5-button" width="140" height="70" class="alignnone size-full wp-image-736" /></a></td>
<td><strong>Button : A button executes after release.</strong><br/>
parameters : name, value (float), x, y, width, height<br/>
<code class="codecolorer processing default"><span class="processing">controlP5.<span style="color: #000000;">addButton</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;button1&quot;</span>,<span style="color: #000000;">1</span>,<span style="color: #000000;">70</span>,<span style="color: #000000;">10</span>,<span style="color: #000000;">60</span>,<span style="color: #000000;">20</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span></span></code>
</td>
</tr>
<tr>
<td><a href="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/controlP5-toggle1.gif"><img src="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/controlP5-toggle1.gif" alt="" title="controlP5-toggle" width="140" height="70" class="alignnone size-full wp-image-748" /></a></td>
<td><strong>Toggle : A toggle can have two states, true and false. Where true has the value 1 and false is 0.</strong><br/>
 parameters  : name, default value (boolean), x, y, width, height<br/>
 <code class="codecolorer processing default"><span class="processing">controlP5.<span style="color: #000000;">addToggle</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;toggle1&quot;</span>,<span style="color: #996600;">false</span>,<span style="color: #000000;">170</span>,<span style="color: #000000;">10</span>,<span style="color: #000000;">20</span>,<span style="color: #000000;">20</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span></span></code>
</td>
</tr>
<tr>
<td><a href="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/controlP5-slider.gif"><img src="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/controlP5-slider.gif" alt="" title="controlP5-slider" width="140" height="70" class="alignnone size-full wp-image-739" /></a></td>
<td><strong>Slider : A slider is either used horizontally or vertically. When the width is bigger, you get a horizontal slider. When the height is bigger, you get a vertical slider.</strong><br/>
parameters : name, minimum, maximum, default value (float), x, y, width, height
<code class="codecolorer processing default"><span class="processing">controlP5.<span style="color: #000000;">addSlider</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;slider2&quot;</span>,<span style="color: #000000;">0</span>,<span style="color: #000000;">255</span>,<span style="color: #000000;">128</span>,<span style="color: #000000;">70</span>,<span style="color: #000000;">80</span>,<span style="color: #000000;">100</span>,<span style="color: #000000;">10</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span></span></code>
</td>
</tr>
<tr>
<td><a href="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/controlP5-knob.gif"><img src="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/controlP5-knob.gif" alt="" title="controlP5-knob" width="140" height="70" class="alignnone size-full wp-image-737" /></a></td>
<td><strong>Knob : A round turning dial knob. Counts from 0-360 degrees.</strong><br/>
 parameters :name, minimum, maximum, default value (float, x, y, diameter<br/>
 <code class="codecolorer processing default"><span class="processing">controlP5.<span style="color: #000000;">addKnob</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;knob1&quot;</span>,<span style="color: #000000;">0</span>,<span style="color: #000000;">360</span>,<span style="color: #000000;">0</span>,<span style="color: #000000;">70</span>,<span style="color: #000000;">120</span>,<span style="color: #000000;">50</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span></span></code>
</td>
</tr>
<tr>
<td><a href="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/controlP5-numberbox.gif"><img src="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/controlP5-numberbox.gif" alt="" title="controlP5-numberbox" width="140" height="70" class="alignnone size-full wp-image-738" /></a></td>
<td><strong>NumberBox : Box that displays a number. You can change the value by click and hold in the box and drag the mouse up and down.</strong><br/>
parameters : name, default value (float), x, y,  width, height<br/>
<code class="codecolorer processing default"><span class="processing">controlP5.<span style="color: #000000;">addNumberbox</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;numberbox1&quot;</span>,<span style="color: #000000;">50</span>,<span style="color: #000000;">170</span>,<span style="color: #000000;">120</span>,<span style="color: #000000;">60</span>,<span style="color: #000000;">14</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span></span></code>
</td>
</tr>
</table>
<h2>variables and setup</h2>
<pre>
<div class="codecolorer-container processing default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br /></div></td><td><div class="processing codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #777755;">// ControlP5 Example 1 : Basic UI elements</span><br />
&nbsp;<br />
<span style="color: #996600;">import</span> controlP5.<span style="color: #000000;">*;</span> &nbsp; &nbsp;<span style="color: #777755;">// import controlP5 library</span><br />
ControlP5 controlP5<span style="color: #000000;">;</span> &nbsp; <span style="color: #777755;">// controlP5 object</span><br />
<br />
<span style="color: #777755;">// array to store 7 colors that can be changed by the different </span><br />
<span style="color: #777755;">// user interface elements</span><br />
<span style="color: #993300; font-weight: bold;">color</span> <span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> colors = <span style="color: #996600;">new</span> <span style="color: #993300; font-weight: bold;">color</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">7</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">;</span> <br />
<br />
<span style="color: #993300; font-weight: bold;">void</span> <span style="color: #996600;">setup</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; <span style="color: #996600;">size</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">330</span>,<span style="color: #000000;">260</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; <span style="color: #996600;">smooth</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; controlP5 = <span style="color: #996600;">new</span> ControlP5<span style="color: #000000;">&#40;</span><span style="color: #996600;">this</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #777755;">// description : a bang controller triggers an event when pressed. </span><br />
&nbsp; <span style="color: #777755;">// parameters &nbsp;: name, x, y, width, height</span><br />
&nbsp; controlP5.<span style="color: #000000;">addBang</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;bang1&quot;</span>,<span style="color: #000000;">10</span>,<span style="color: #000000;">10</span>,<span style="color: #000000;">20</span>,<span style="color: #000000;">20</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; <span style="color: #777755;">// description : a button executes after release</span><br />
&nbsp; <span style="color: #777755;">// parameters &nbsp;: name, value (float), x, y, width, height</span><br />
&nbsp; controlP5.<span style="color: #000000;">addButton</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;button1&quot;</span>,<span style="color: #000000;">1</span>,<span style="color: #000000;">70</span>,<span style="color: #000000;">10</span>,<span style="color: #000000;">60</span>,<span style="color: #000000;">20</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #777755;">// description : a toggle can have two states, true and false</span><br />
&nbsp; <span style="color: #777755;">// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; where true has the value 1 and false is 0.</span><br />
&nbsp; <span style="color: #777755;">// parameters &nbsp;: name, default value (boolean), x, y, width, height</span><br />
&nbsp; controlP5.<span style="color: #000000;">addToggle</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;toggle1&quot;</span>,<span style="color: #996600;">false</span>,<span style="color: #000000;">170</span>,<span style="color: #000000;">10</span>,<span style="color: #000000;">20</span>,<span style="color: #000000;">20</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #777755;">// description : a slider is either used horizontally or vertically.</span><br />
&nbsp; <span style="color: #777755;">// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width is bigger, you get a horizontal slider</span><br />
&nbsp; <span style="color: #777755;">// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height is bigger, you get a vertical slider. &nbsp;</span><br />
&nbsp; <span style="color: #777755;">// parameters &nbsp;: name, minimum, maximum, default value (float), x, y, width, height</span><br />
&nbsp; controlP5.<span style="color: #000000;">addSlider</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;slider1&quot;</span>,<span style="color: #000000;">0</span>,<span style="color: #000000;">255</span>,<span style="color: #000000;">128</span>,<span style="color: #000000;">10</span>,<span style="color: #000000;">80</span>,<span style="color: #000000;">10</span>,<span style="color: #000000;">100</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; controlP5.<span style="color: #000000;">addSlider</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;slider2&quot;</span>,<span style="color: #000000;">0</span>,<span style="color: #000000;">255</span>,<span style="color: #000000;">128</span>,<span style="color: #000000;">70</span>,<span style="color: #000000;">80</span>,<span style="color: #000000;">100</span>,<span style="color: #000000;">10</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #777755;">// description : round turning dial knob</span><br />
&nbsp; <span style="color: #777755;">// parameters &nbsp;: name, minimum, maximum, default value (float, x, y, diameter</span><br />
&nbsp; controlP5.<span style="color: #000000;">addKnob</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;knob1&quot;</span>,<span style="color: #000000;">0</span>,<span style="color: #000000;">360</span>,<span style="color: #000000;">0</span>,<span style="color: #000000;">70</span>,<span style="color: #000000;">120</span>,<span style="color: #000000;">50</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #777755;">// parameters : name, default value (float), x, y, &nbsp;width, height</span><br />
&nbsp; controlP5.<span style="color: #000000;">addNumberbox</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;numberbox1&quot;</span>,<span style="color: #000000;">50</span>,<span style="color: #000000;">170</span>,<span style="color: #000000;">120</span>,<span style="color: #000000;">60</span>,<span style="color: #000000;">14</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
</pre>
<h2>The draw() loop</h2>
<p>In the draw loop you don&#8217;t have to do anything with the controlP5 elements, since you&#8217;ve added them already in the setup() function. In the draw-loop the rectangles are draw, with the color value from the colors[] array. The values in the colors[] array are modified by the controller events. </p>
<pre>
<div class="codecolorer-container processing default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="processing codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993300; font-weight: bold;">void</span> <span style="color: #996600;">draw</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <br />
&nbsp; <span style="color: #996600;">background</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span> &nbsp;<span style="color: #777755;">// background black</span><br />
&nbsp; <br />
&nbsp; <span style="color: #777755;">// draw 7 squares and use as a fill color the colors from the colors array</span><br />
&nbsp; <span style="color: #996600;">for</span><span style="color: #000000;">&#40;</span><span style="color: #993300; font-weight: bold;">int</span> i=<span style="color: #000000;">0</span><span style="color: #000000;">;</span>i<span style="color: #000000;">&lt;</span><span style="color: #000000;">7</span><span style="color: #000000;">;</span>i++<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #777755;">// loop through colors array</span><br />
&nbsp; &nbsp; <span style="color: #996600;">stroke</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">255</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; &nbsp; <span style="color: #996600;">fill</span><span style="color: #000000;">&#40;</span>colors<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #777755;">// use color to fill</span><br />
&nbsp; &nbsp; <span style="color: #996600;">rect</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">10</span>+<span style="color: #000000;">&#40;</span>i<span style="color: #000000;">*</span><span style="color: #000000;">45</span><span style="color: #000000;">&#41;</span>,<span style="color: #000000;">210</span>,<span style="color: #000000;">40</span>,<span style="color: #000000;">40</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span> &nbsp;<span style="color: #777755;">// draw rectangle</span><br />
&nbsp; <span style="color: #000000;">&#125;</span> &nbsp;<br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
</pre>
<h2>controlEvent</h2>
<p>The function controlEvent is an event listener for all the user elements. In this case we only want to listen to controller events (  <code class="codecolorer processing default"><span class="processing"><span style="color: #996600;">if</span><span style="color: #000000;">&#40;</span>theEvent.<span style="color: #000000;">isController</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span></span></code> ). By getting the name (  <code class="codecolorer processing default"><span class="processing">theEvent.<span style="color: #000000;">controller</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">name</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span></span></code> ) and the value (  <code class="codecolorer processing default"><span class="processing">theEvent.<span style="color: #000000;">controller</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">value</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span></span></code> ) of the event we can program some logic ( if/else ) and change some variables in Processing ( in this case the values in the color[] array ). </p>
<pre>
<div class="codecolorer-container processing default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br /></div></td><td><div class="processing codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993300; font-weight: bold;">void</span> controlEvent<span style="color: #000000;">&#40;</span>ControlEvent theEvent<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; <span style="color: #777755;">/* events triggered by controllers are automatically forwarded to <br />
&nbsp; &nbsp; &nbsp;the controlEvent method. by checking the name of a controller one can <br />
&nbsp; &nbsp; &nbsp;distinguish which of the controllers has been changed.<br />
&nbsp; */</span> <br />
&nbsp;<br />
&nbsp; <span style="color: #777755;">/* check if the event is from a controller otherwise you'll get an error<br />
&nbsp; &nbsp; &nbsp;when clicking other interface elements like Radiobutton that don't support<br />
&nbsp; &nbsp; &nbsp;the controller() methods<br />
&nbsp; */</span><br />
&nbsp; <br />
&nbsp; <span style="color: #996600;">if</span><span style="color: #000000;">&#40;</span>theEvent.<span style="color: #000000;">isController</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #996600;">print</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;control event from : &quot;</span>+theEvent.<span style="color: #000000;">controller</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">name</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; &nbsp; <span style="color: #996600;">println</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;, value : &quot;</span>+theEvent.<span style="color: #000000;">controller</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">value</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #996600;">if</span><span style="color: #000000;">&#40;</span>theEvent.<span style="color: #000000;">controller</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">name</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>==<span style="color: #ff0000;">&quot;bang1&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; colors<span style="color: #000000;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">&#93;</span> = colors<span style="color: #000000;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">&#93;</span> + <span style="color: #993300; font-weight: bold;">color</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">40</span>,<span style="color: #000000;">40</span>,<span style="color: #000000;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #996600;">if</span><span style="color: #000000;">&#40;</span>colors<span style="color: #000000;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">255</span><span style="color: #000000;">&#41;</span> colors<span style="color: #000000;">&#91;</span><span style="color: #000000;">0</span><span style="color: #000000;">&#93;</span> = <span style="color: #993300; font-weight: bold;">color</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">40</span>,<span style="color: #000000;">40</span>,<span style="color: #000000;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span> &nbsp; &nbsp;<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #996600;">if</span><span style="color: #000000;">&#40;</span>theEvent.<span style="color: #000000;">controller</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">name</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>==<span style="color: #ff0000;">&quot;button1&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; colors<span style="color: #000000;">&#91;</span><span style="color: #000000;">1</span><span style="color: #000000;">&#93;</span> = colors<span style="color: #000000;">&#91;</span><span style="color: #000000;">1</span><span style="color: #000000;">&#93;</span> + <span style="color: #993300; font-weight: bold;">color</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">40</span>,<span style="color: #000000;">0</span>,<span style="color: #000000;">40</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #996600;">if</span><span style="color: #000000;">&#40;</span>colors<span style="color: #000000;">&#91;</span><span style="color: #000000;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">255</span><span style="color: #000000;">&#41;</span> colors<span style="color: #000000;">&#91;</span><span style="color: #000000;">1</span><span style="color: #000000;">&#93;</span> = <span style="color: #993300; font-weight: bold;">color</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">40</span>,<span style="color: #000000;">0</span>,<span style="color: #000000;">40</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #996600;">if</span><span style="color: #000000;">&#40;</span>theEvent.<span style="color: #000000;">controller</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">name</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>==<span style="color: #ff0000;">&quot;toggle1&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #996600;">if</span><span style="color: #000000;">&#40;</span>theEvent.<span style="color: #000000;">controller</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">value</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>==<span style="color: #000000;">1</span><span style="color: #000000;">&#41;</span> colors<span style="color: #000000;">&#91;</span><span style="color: #000000;">2</span><span style="color: #000000;">&#93;</span> = <span style="color: #993300; font-weight: bold;">color</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">0</span>,<span style="color: #000000;">255</span>,<span style="color: #000000;">255</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #996600;">else</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; colors<span style="color: #000000;">&#91;</span><span style="color: #000000;">2</span><span style="color: #000000;">&#93;</span> = <span style="color: #993300; font-weight: bold;">color</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">0</span>,<span style="color: #000000;">0</span>,<span style="color: #000000;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #996600;">if</span><span style="color: #000000;">&#40;</span>theEvent.<span style="color: #000000;">controller</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">name</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>==<span style="color: #ff0000;">&quot;slider1&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; colors<span style="color: #000000;">&#91;</span><span style="color: #000000;">3</span><span style="color: #000000;">&#93;</span> = <span style="color: #993300; font-weight: bold;">color</span><span style="color: #000000;">&#40;</span>theEvent.<span style="color: #000000;">controller</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">value</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>,<span style="color: #000000;">0</span>,<span style="color: #000000;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #996600;">if</span><span style="color: #000000;">&#40;</span>theEvent.<span style="color: #000000;">controller</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">name</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>==<span style="color: #ff0000;">&quot;slider2&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; colors<span style="color: #000000;">&#91;</span><span style="color: #000000;">4</span><span style="color: #000000;">&#93;</span> = <span style="color: #993300; font-weight: bold;">color</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">0</span>,theEvent.<span style="color: #000000;">controller</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">value</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>,<span style="color: #000000;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #996600;">if</span><span style="color: #000000;">&#40;</span>theEvent.<span style="color: #000000;">controller</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">name</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>==<span style="color: #ff0000;">&quot;knob1&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; colors<span style="color: #000000;">&#91;</span><span style="color: #000000;">5</span><span style="color: #000000;">&#93;</span> = <span style="color: #993300; font-weight: bold;">color</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">0</span>,<span style="color: #000000;">0</span>,theEvent.<span style="color: #000000;">controller</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">value</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #996600;">if</span><span style="color: #000000;">&#40;</span>theEvent.<span style="color: #000000;">controller</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">name</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>==<span style="color: #ff0000;">&quot;numberbox1&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; colors<span style="color: #000000;">&#91;</span><span style="color: #000000;">6</span><span style="color: #000000;">&#93;</span> = <span style="color: #993300; font-weight: bold;">color</span><span style="color: #000000;">&#40;</span>theEvent.<span style="color: #000000;">controller</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">value</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span> <br />
&nbsp; &nbsp; <br />
&nbsp; <span style="color: #000000;">&#125;</span> &nbsp;<br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
</pre>


<p>Related posts:<ol><li><a href='http://www.kasperkamperman.com/blog/processing-code/controlp5-library-example2/' rel='bookmark' title='Permanent Link: Processing ControlP5 library example 2 : Style and setValue'>Processing ControlP5 library example 2 : Style and setValue</a></li>
<li><a href='http://www.kasperkamperman.com/blog/flash-code/as3-apply-bitmap-filters-to-a-webcam-image/' rel='bookmark' title='Permanent Link: Flash AS3 : Apply bitmap filters to a webcam image'>Flash AS3 : Apply bitmap filters to a webcam image</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.kasperkamperman.com/blog/processing-code/controlp5-library-example1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert AVCHD to other codecs for more fluent editing</title>
		<link>http://www.kasperkamperman.com/blog/video-compression/convert-avchd-to-other-codecs-for-more-fluent-editing/</link>
		<comments>http://www.kasperkamperman.com/blog/video-compression/convert-avchd-to-other-codecs-for-more-fluent-editing/#comments</comments>
		<pubDate>Sun, 07 Mar 2010 14:36:24 +0000</pubDate>
		<dc:creator>kasperkamperman</dc:creator>
				<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://www.kasperkamperman.com/?p=698</guid>
		<description><![CDATA[The AVCHD codec is a very processor intensive codec. A lot of computers have problem displaying and editing 1080i video ( resolution 1920 by 1080 ) video. When editing video its important to have fast and smooth playback. You can also apply and preview effects a lot faster when not working with AVCHD. In this article some options to convert AVCHD to DV to work with AVCHD in a more fluent way. 


Related posts:<ol><li><a href='http://www.kasperkamperman.com/blog/video-compression/encode-hd-video-for-vimeo-or-youtube-media-encoder-cs4/' rel='bookmark' title='Permanent Link: Encode HD video for Vimeo or YouTube ( Media Encoder CS4 )'>Encode HD video for Vimeo or YouTube ( Media Encoder CS4 )</a></li>
<li><a href='http://www.kasperkamperman.com/blog/video-compression/rendering_hd_ae_cs3/' rel='bookmark' title='Permanent Link: Render HD and SD movies for Vimeo with After Effects CS3'>Render HD and SD movies for Vimeo with After Effects CS3</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>The AVCHD codec is a very processor intensive codec. A lot of computers have problem displaying and editing 1080i video ( resolution 1920 by 1080 ) video. When editing video its important to have fast and smooth playback. You can also apply and preview effects a lot faster when not working with AVCHD. In this article some options to convert AVCHD to DV to work with AVCHD in a more fluent way. </p>
<p>In all the examples I use AVCHD 1080i50 ( PAL 25 fps ) as the source material. </p>
<h2>Convert to SD (Standard Definition) video ( 720 x 576 )</h2>
<p>If your end-product is a standard DVD, this is the way to go. Of course you&#8217;ll lose quality ( less pixels ) and you have to use more disk space ( less compression ). </p>
<p>The DV codec the most common codec for SD. Most videotools and encoders support this codec.
Below the settings for MediaEncoder CS4. </p>
<p><a href="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/cs4-me-export-DV-widescreen.jpg"><img src="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/cs4-me-export-DV-widescreen.jpg" alt="" title="cs4-me-export-DV-widescreen" width="414" height="759" class="alignnone size-full wp-image-701" /></a></p>
<p>You can also download the <a href="https://eww.pavc.panasonic.co.jp/pro-av/support/desk/e/download.htm#avchd">AVCHD transcoder from Panasonic</a> (windows only) if you have a Panasonic camera. Make sure you keep the directory structure of your smartmedia card, since it doesn&#8217;t recognize single .MTS files. </p>
<p><a href="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/panasonic-avchd-transcoder.jpg"><img src="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/panasonic-avchd-transcoder.jpg" alt="" title="panasonic-avchd-transcoder" width="442" height="138" class="alignnone size-full wp-image-702" /></a></p>
<p>Another alternative (Mac only) is to import your material (again keep the structure of your smartmedia card) in iMovie. It will convert it to video with the Apple Intermediate codec and a resolution of 960 by 540 pixels ( slightly better then 720 x 576 ). Counterpart is that the Apple Intermediate Codec isn&#8217;t available for Windows, so you cannot play it back under Windows. </p>
<div id="attachment_704" class="wp-caption alignnone" style="width: 427px"><a href="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/imovie8_importhd.jpg"><img src="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/imovie8_importhd.jpg" alt="" title="imovie8_importhd" width="417" height="105" class="size-full wp-image-704" /></a><p class="wp-caption-text">Import the material as 960 x 540.</p></div>
<div id="attachment_703" class="wp-caption alignnone" style="width: 424px"><a href="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/imovie8_revealinfinder.jpg"><img src="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/imovie8_revealinfinder.jpg" alt="" title="imovie8_revealinfinder" width="414" height="313" class="size-full wp-image-703" /></a><p class="wp-caption-text">Right click on the video in the event library > 'Reveal in Finder'</p></div>
<h2>Convert to Motion JPEG format anamorphic ( 1440 x 1080 )</h2>
<p>If you want to keep the 1080i quality you can convert to the Motion JPEG A codec. Its a light intra frame compression format ( DCT compression like the DV codec ) and it supports HD resolution interlaced material. This codec is also used in some broadcast facilities to store HD content. </p>
<p>I chose for a pixel aspect ratio of 1.333 (HD anamorphic 1080) to keep the filesize down, and make playback more fluent. You can alter the quality to a higher value, but keep in mind that the datarate and the filesize get bigger really quick ( so editing gets less fluent ). </p>
<p>You could also use this codec for storing an project in high quality for archiving purposes, since its impossible to store HD edits in the AVCHD codec with CS4. </p>
<p><a href="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/cs4-me-MJPEGA-export.jpg"><img src="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/cs4-me-MJPEGA-export.jpg" alt="" title="cs4-me-MJPEGA-export" width="414" height="749" class="alignnone size-full wp-image-705" /></a></p>
<div id="attachment_707" class="wp-caption alignnone" style="width: 370px"><a href="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/cs4-me-mpjegA-options.jpg"><img src="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/cs4-me-mpjegA-options.jpg" alt="" title="cs4-me-mpjegA-options" width="360" height="186" class="size-full wp-image-707" /></a><p class="wp-caption-text">Codec Settings</p></div>
<h2>Offline editing, Proxy video</h2>
<p>If you want to keep the original quality you could first edit with a lower quality movie ( convert to an SD movie with one of the techniques mentioned before ) and then replace that with the original HD version. </p>
<p>A workflow is explained here :
<a href="http://www.associatedcontent.com/article/2345722/quickly_edit_hd_video_in_adobe_premiere.html?cat=15">Quickly Edit HD Video in Adobe Premiere Pro with Proxy Video</a></p>


<p>Related posts:<ol><li><a href='http://www.kasperkamperman.com/blog/video-compression/encode-hd-video-for-vimeo-or-youtube-media-encoder-cs4/' rel='bookmark' title='Permanent Link: Encode HD video for Vimeo or YouTube ( Media Encoder CS4 )'>Encode HD video for Vimeo or YouTube ( Media Encoder CS4 )</a></li>
<li><a href='http://www.kasperkamperman.com/blog/video-compression/rendering_hd_ae_cs3/' rel='bookmark' title='Permanent Link: Render HD and SD movies for Vimeo with After Effects CS3'>Render HD and SD movies for Vimeo with After Effects CS3</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.kasperkamperman.com/blog/video-compression/convert-avchd-to-other-codecs-for-more-fluent-editing/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Encode HD video for Vimeo or YouTube ( Media Encoder CS4 )</title>
		<link>http://www.kasperkamperman.com/blog/video-compression/encode-hd-video-for-vimeo-or-youtube-media-encoder-cs4/</link>
		<comments>http://www.kasperkamperman.com/blog/video-compression/encode-hd-video-for-vimeo-or-youtube-media-encoder-cs4/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 14:31:41 +0000</pubDate>
		<dc:creator>kasperkamperman</dc:creator>
				<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://www.kasperkamperman.com/?p=657</guid>
		<description><![CDATA[Media Encoder CS4 comes with a few standard presets, however they contain not always the best settings. In this article you will find the optimal export/encoding options you can make voor YouTube/Vimeo HD quality movies. 


Related posts:<ol><li><a href='http://www.kasperkamperman.com/blog/video-compression/rendering_hd_ae_cs3/' rel='bookmark' title='Permanent Link: Render HD and SD movies for Vimeo with After Effects CS3'>Render HD and SD movies for Vimeo with After Effects CS3</a></li>
<li><a href='http://www.kasperkamperman.com/blog/video-compression/convert-avchd-to-other-codecs-for-more-fluent-editing/' rel='bookmark' title='Permanent Link: Convert AVCHD to other codecs for more fluent editing'>Convert AVCHD to other codecs for more fluent editing</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>In this article you will find the optimal export/encoding options you can make voor YouTube/Vimeo HD quality movies. Media Encoder CS4 comes with a few standard presets, however they contain not always the best settings. In this article I assume that your source material is PAL video ( 25 frames a second ).</p>
<p>If you have the newest ME ( Media Encoder ) you&#8217;ll have a YouTube Widescreen HD preset. I started modifying this one. Make sure you select H.264 as the video format. </p>
<h2>Video settings ( video tab )</h2>
<p><a href="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/cs4-me-YouTubeWideCustom_videotab.jpg"><img src="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/cs4-me-YouTubeWideCustom_videotab.jpg" alt="" title="cs4-me-YouTubeWideCustom_videotab" width="420" height="537" class="size-full wp-image-658" /></a></p>
<table>
<tr>
<th>Setting</th>
<th>Explanation</th>
</tr>
<tr>
<td>TV Standard : NTSC/PAL</td>
<td>doesn&#8217;t matter for web video. Don&#8217;t click it however since it will change the Frame Width/Height values to SD video size.</td>
</tr>
<tr>
<td>Frame Width/Height : 1280 x 720</td>
<td>HD 720p resolution. If you cannot set this witdh and height, please check if the Level ( see below ) is set to 3.2.</td>
</tr>
<tr>
<td>Frame Rate [fps] : 25</td>
<td>Same rate as the source material you&#8217;re encoding ( to check open the file in Quicktime and press CMD+I ( osx ) to see the frame rate properties.<br/>Choose 25 fps when you encode PAL video, choose 30 fps when you encode NTSC video.</td>
</tr>
<tr>
<td>Field Order: None (Progressive)</td>
<td>Always choose None(progressive) for web video (since it doesn&#8217;t support interlacing). ME CS4 will automatically de-interlace interlaced source material.</td>
</tr>
<tr>
<td>Pixel Aspect Ratio: Square Pixels</td>
<td>Always square pixels for web video.</td>
</tr>
<tr>
<td>Profile : High</td>
<td>The &#8216;High Profile&#8217; has better compression methods, so it gives a better quality ( but uses more computer power as well ).</td>
</tr>
<tr>
<td>Level : 3.2</td>
<td>This H.264 Level supports a resolution of 1280&#215;720. <a href="http://en.wikipedia.org/wiki/H.264/MPEG-4_AVC#Levels">Wikipedia</a> gives a good overview of the different H.264/AVC Levels.</td>
</tr>
<tr>
<td>Bitrate Encoding</td>
<td>Choose &#8216;VBR, 2 Pass&#8217; for better encoding efficiency ( better quality for the same filesize ). If you want faster encoding pick &#8216;VBR, 1 Pass&#8217;.</td>
</tr>
<tr>
<td>Target Bitrate</td>
<td>The average bitrate the encoder can use in Mega bits per second. This multiplied by the time gives an indication of the file size.<br/>One minute of video with this setting would be :<br/>
5 Mbps * 60s = 300 Mbps. 300Mbps/8 ( from bits to bytes ) = 37.5 Mb.</td>
</tr>
<tr>
<td>Maximum Bitrate</td>
<td>The encoder can use a higher bitrate for difficult parts in a video image ( lots of movement, noise) to improve the quality. This implies directly that other &#8217;simple&#8217; parts are encoded with a lower bitrate than the average bitrate.</td>
</tr>
</table>
<h2>Audio settings ( audio tab )</h2>
<p><a href="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/cs4-me-YouTubeWideCustom_audiotab.jpg"><img src="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/cs4-me-YouTubeWideCustom_audiotab.jpg" alt="" title="cs4-me-YouTubeWideCustom_audiotab" width="420" height="397" class="alignnone size-full wp-image-676" /></a></p>
<p>In the audiotab you don&#8217;t have to make a lot of changes. The audio codec used in combination with H264 is AAC ( Advanced Audio Coding ). Depending your demands you can change stereo to mono ( a bitrate of 64 kbps would be sufficient then ), when you want good quality stereo music it&#8217;s better to choose 128kbps or higher ( the higher the bitrate, the better the quality ). </p>
<p>Use 44.1 kHz as an audio bitrate, 48 kHz ( most camera&#8217;s record with this frequency ) can give distorted audio playback with YouTube/Vimeo now and then. </p>
<h2>Export settings summary</h2>
<p><a href="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/cs4-me-YouTubeWideCustom_export.jpg"><img src="http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/03/cs4-me-YouTubeWideCustom_export.jpg" alt="" title="cs4-me-YouTubeWideCustom_export" width="420" height="261" class="alignnone size-full wp-image-681" /></a></p>
<p>Look at the settings in the Export summary and compare them with the summary above. Make changes when necessary.<br/><br/>
To save this preset you can press the disk icon next to the preset name ( automatically changes to Custom when you changed an existing preset ). </p>
<h2>Final note</h2>
<p>The encoded video will be re-encoded in Vimeo or YouTube. However with these settings you have good quality HD movie as reference and for archive purposes. </p>


<p>Related posts:<ol><li><a href='http://www.kasperkamperman.com/blog/video-compression/rendering_hd_ae_cs3/' rel='bookmark' title='Permanent Link: Render HD and SD movies for Vimeo with After Effects CS3'>Render HD and SD movies for Vimeo with After Effects CS3</a></li>
<li><a href='http://www.kasperkamperman.com/blog/video-compression/convert-avchd-to-other-codecs-for-more-fluent-editing/' rel='bookmark' title='Permanent Link: Convert AVCHD to other codecs for more fluent editing'>Convert AVCHD to other codecs for more fluent editing</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.kasperkamperman.com/blog/video-compression/encode-hd-video-for-vimeo-or-youtube-media-encoder-cs4/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Adobe Premiere CS4 Cheat Sheet mac</title>
		<link>http://www.kasperkamperman.com/blog/video-compression/adobe-premiere-cs4-cheat-sheet-mac/</link>
		<comments>http://www.kasperkamperman.com/blog/video-compression/adobe-premiere-cs4-cheat-sheet-mac/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 17:14:48 +0000</pubDate>
		<dc:creator>kasperkamperman</dc:creator>
				<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://www.kasperkamperman.com/?p=648</guid>
		<description><![CDATA[Overview with the most useful keyboard shortcuts for Premiere CS4 (Mac). 


No related posts.]]></description>
			<content:encoded><![CDATA[<p>Adobe released a nice shortcut look-up application called &#8220;Adobe Shortcut App for Creative Suite&#8221;. Really useful but the included Cheat Sheet doesn&#8217;t show the most necessary shortcuts. </p>
<p>So I&#8217;ve decided to make a new Cheat Sheet with the ( in my opinion ) most useful keyboard shortcuts for Premiere CS4 (Mac). </p>
<p>Download : <a href='http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/02/Adobe-Premiere-CS4-Cheat-Sheet.pdf'>Adobe Premiere CS4 Cheat Sheet</a></p>
<p>Go to : <a href=" http://www.adobe.com/cfusion/marketplace/index.cfm?event=marketplace.offering&#038;offeringid=15241&#038;marketplaceid=1">Adobe Shortcut App ( air application )</a> </p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.kasperkamperman.com/blog/video-compression/adobe-premiere-cs4-cheat-sheet-mac/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Arduino programming &#8211; Manual and links</title>
		<link>http://www.kasperkamperman.com/blog/arduino/arduino-programming-manual/</link>
		<comments>http://www.kasperkamperman.com/blog/arduino/arduino-programming-manual/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 09:29:58 +0000</pubDate>
		<dc:creator>kasperkamperman</dc:creator>
				<category><![CDATA[Arduino]]></category>

		<guid isPermaLink="false">http://www.kasperkamperman.com/?p=634</guid>
		<description><![CDATA[Download the Arduino programming notebook. 


Related posts:<ol><li><a href='http://www.kasperkamperman.com/blog/arduino/arduino-programming-map-and-smooth/' rel='bookmark' title='Permanent Link: Arduino Programming &#8211; Map and smooth values'>Arduino Programming &#8211; Map and smooth values</a></li>
<li><a href='http://www.kasperkamperman.com/blog/arduino/arduino-programming-interval/' rel='bookmark' title='Permanent Link: Arduino Programming &#8211; Interval'>Arduino Programming &#8211; Interval</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>To get started with programming for the Arduino you can download or buy a print version of the excellent programming notebook at lulu.com. There is also a Dutch translation that you can find on <a href="http://www.arduino.nu">www.arduino.nu</a>. </p>
<p>Download the &#8220;Arduino programming notebook&#8221; by Brian Evans at lulu.com :
<a href="http://www.lulu.com/product/download/arduino-programming-notebook/3524028">Arduino programming notebook</a></p>
<p>Download de &#8220;Arduino programmeer manual&#8221;
Nederlandse vertaling door A. Companje van <a href="http://www.arduino.nu">arduino.nu</a> :
<a href="http://www.arduino.nu/download/Arduino%20manual%201_0%20NL.pdf">Arduino programmeer manual</a></p>
<p>The Arduino website has good information to help you get started. See
<a href="http://arduino.cc/en/Guide/HomePage">Getting started with Arduino</a>.</p>
<p>Next to that watch use the code examples in the Arduino IDE and use the <a href="http://arduino.cc/en/Reference/HomePage">Arduino reference</a>.
The Arduino playground has more advanced information  and the <a href="http://www.arduino.cc/playground/">Arduino playground</a> at <a href="http://www.arduino.cc/">arduino.cc</a>. </p>
<p>General programming tips :</p>
<ol>
<li>Learn by doing</li>
<li>Make simple things</li>
<li>Combine simple things to make complex things</li>
<li>Print code for a better overview</li>
</ol>


<p>Related posts:<ol><li><a href='http://www.kasperkamperman.com/blog/arduino/arduino-programming-map-and-smooth/' rel='bookmark' title='Permanent Link: Arduino Programming &#8211; Map and smooth values'>Arduino Programming &#8211; Map and smooth values</a></li>
<li><a href='http://www.kasperkamperman.com/blog/arduino/arduino-programming-interval/' rel='bookmark' title='Permanent Link: Arduino Programming &#8211; Interval'>Arduino Programming &#8211; Interval</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.kasperkamperman.com/blog/arduino/arduino-programming-manual/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Arduino Programming &#8211; HSB to RGB</title>
		<link>http://www.kasperkamperman.com/blog/arduino/arduino-programming-hsb-to-rgb/</link>
		<comments>http://www.kasperkamperman.com/blog/arduino/arduino-programming-hsb-to-rgb/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 00:48:52 +0000</pubDate>
		<dc:creator>kasperkamperman</dc:creator>
				<category><![CDATA[Arduino]]></category>

		<guid isPermaLink="false">http://www.kasperkamperman.com/?p=623</guid>
		<description><![CDATA[Control a RGB led with Hue, Saturation and Brightness (HSB / HSV ).


Related posts:<ol><li><a href='http://www.kasperkamperman.com/blog/arduino/arduino-programming-state-change/' rel='bookmark' title='Permanent Link: Arduino Programming &#8211; State change'>Arduino Programming &#8211; State change</a></li>
<li><a href='http://www.kasperkamperman.com/blog/arduino/arduino-programming-interval/' rel='bookmark' title='Permanent Link: Arduino Programming &#8211; Interval'>Arduino Programming &#8211; Interval</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Control a RGB led with Hue, Saturation and Brightness (HSB / HSV ). </p>
<p>Level : beginner with Arduino. ( Basic knowledge of programming principles like if/else and variables  ). </p>
<p>Download the Arduino ( .pde ) files : <a class="download" href='http://www.kasperkamperman.com/wordpress_kk/wordpress_uploads/2010/01/arduino_HSB_to_RGB.zip'>arduino_HSB_to_RGB.zip</a></p>
<p>HSB_to_RGB.pde :</p>
<pre>
<div class="codecolorer-container arduino default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br /></div></td><td><div class="arduino codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">/* &nbsp;<br />
&nbsp; Control a RGB led with Hue, Saturation and Brightness (HSB / HSV )<br />
<br />
&nbsp; Hue is change by an analog input. <br />
&nbsp; Brightness is changed by a fading function. <br />
&nbsp; Saturation stays constant at 255<br />
<br />
&nbsp; getRGB() function based on &lt;http://www.codeproject.com/miscctrl/CPicker.asp&gt; &nbsp;<br />
&nbsp; dim_curve idea by Jims<br />
<br />
&nbsp; created 05-01-2010 by kasperkamperman.com<br />
*/</span><br />
<br />
<span style="color: #808080; font-style: italic;">/* <br />
&nbsp; dim_curve 'lookup table' to compensate for the nonlinearity of human vision.<br />
&nbsp; Used in the getRGB function on saturation and brightness to make 'dimming' look more natural. <br />
&nbsp; Exponential function used to create values below : <br />
&nbsp; x from 0 - 255 : y = round(pow( 2.0, x+64/40.0) - 1) &nbsp; <br />
*/</span><br />
<br />
<span style="color: #993333;">const</span> <span style="color: #993333;">byte</span> dim_curve<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">3</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">3</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">3</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">3</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">3</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">3</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">3</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000dd;">3</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">3</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">3</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">3</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">3</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">3</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">3</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">4</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">4</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">4</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">4</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">4</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">4</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">4</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">4</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">4</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000dd;">4</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">4</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">4</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">5</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">5</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">5</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">5</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">5</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">5</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">5</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">5</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">5</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">5</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">6</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">6</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">6</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000dd;">6</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">6</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">6</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">6</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">6</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">7</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">7</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">7</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">7</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">7</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">7</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">7</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">8</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">8</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">8</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">8</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000dd;">8</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">8</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">9</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">9</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">9</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">9</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">9</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">9</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000dd;">10</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">10</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">10</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">10</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">10</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">11</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">11</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">11</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000dd;">11</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">11</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">12</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">12</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">12</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">12</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">12</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">13</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">13</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">13</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">13</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">14</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">14</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">14</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">14</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">15</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000dd;">15</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">15</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">16</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">16</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">16</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">16</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">17</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">17</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">17</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">18</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">18</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">18</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">19</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">19</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">19</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">20</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000dd;">20</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">20</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">21</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">21</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">22</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">22</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">22</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">23</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">23</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">24</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">24</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">25</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">25</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">25</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">26</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">26</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000dd;">27</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">27</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">28</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">28</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">29</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">29</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">30</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">30</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">31</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">32</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">32</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">33</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">33</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">34</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">35</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">35</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000dd;">36</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">36</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">37</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">38</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">38</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">39</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">40</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">40</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">41</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">42</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">43</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">43</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">44</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">45</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">46</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">47</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000dd;">48</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">48</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">49</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">50</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">51</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">52</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">53</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">54</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">55</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">56</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">57</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">58</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">59</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">60</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">61</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">62</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000dd;">63</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">64</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">65</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">66</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">68</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">69</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">70</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">71</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">73</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">74</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">75</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">76</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">78</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">79</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">81</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">82</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000dd;">83</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">85</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">86</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">88</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">90</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">91</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">93</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">94</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">96</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">98</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">99</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #0000dd;">101</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">103</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">105</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">107</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">109</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000dd;">110</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">112</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">114</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">116</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">118</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">121</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">123</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">125</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">127</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">129</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">132</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">134</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">136</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">139</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">141</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">144</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000dd;">146</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">149</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">151</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">154</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">157</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">159</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">162</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">165</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">168</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">171</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">174</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">177</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">180</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">183</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">186</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">190</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000dd;">193</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">196</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">200</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">203</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">207</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">211</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">214</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">218</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">222</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">226</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">230</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">234</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">238</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">242</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">248</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">255</span><span style="color: #339933;">,</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #993333;">const</span> <span style="color: #993333;">int</span> sensorPin <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> &nbsp;<span style="color: #666666; font-style: italic;">// pin the potmeter is attached too</span><br />
<span style="color: #993333;">const</span> <span style="color: #993333;">int</span> ledPinR &nbsp; <span style="color: #339933;">=</span> <span style="color: #0000dd;">9</span><span style="color: #339933;">;</span> &nbsp;<span style="color: #666666; font-style: italic;">// pwm pin with red led</span><br />
<span style="color: #993333;">const</span> <span style="color: #993333;">int</span> ledPinG &nbsp; <span style="color: #339933;">=</span> <span style="color: #0000dd;">10</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// pwm pin with green led</span><br />
<span style="color: #993333;">const</span> <span style="color: #993333;">int</span> ledPinB &nbsp; <span style="color: #339933;">=</span> <span style="color: #0000dd;">11</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// pwm pin with blue led</span><br />
<br />
<span style="color: #993333;">int</span> sensorVal <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// store the value coming from the sensor</span><br />
<span style="color: #993333;">int</span> fadeVal &nbsp; <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// value that changes between 0-255</span><br />
<span style="color: #993333;">int</span> fadeSpeed <span style="color: #339933;">=</span> <span style="color: #0000dd;">4</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 'speed' of fading</span><br />
<br />
<span style="color: #666666; font-style: italic;">// getRGB function stores RGB values in this array</span><br />
<span style="color: #666666; font-style: italic;">// use these values for the red, blue, green led. </span><br />
<span style="color: #993333;">int</span> rgb_colors<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <br />
<br />
<span style="color: #993333;">int</span> hue<span style="color: #339933;">;</span><br />
<span style="color: #993333;">int</span> saturation<span style="color: #339933;">;</span><br />
<span style="color: #993333;">int</span> brightness<span style="color: #339933;">;</span><br />
<br />
<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <br />
&nbsp; <span style="color: #000066;">pinMode</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">9</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">OUTPUT</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000066;">pinMode</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">10</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">OUTPUT</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000066;">pinMode</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">11</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">OUTPUT</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000066;">Serial</span>.<span style="color: #202020;">begin</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">57600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> &nbsp;<span style="color: #009900;">&#123;</span> <br />
<br />
&nbsp; sensorVal <span style="color: #339933;">=</span> <span style="color: #000066;">analogRead</span><span style="color: #009900;">&#40;</span>sensorPin<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">// fade from 0 - 255 and back with a certain speed &nbsp; </span><br />
&nbsp; fadeVal <span style="color: #339933;">=</span> fadeVal <span style="color: #339933;">+</span> fadeSpeed<span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// change fadeVal by speed</span><br />
&nbsp; fadeVal <span style="color: #339933;">=</span> <span style="color: #000066;">constrain</span><span style="color: #009900;">&#40;</span>fadeVal<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp;<span style="color: #666666; font-style: italic;">// keep fadeVal between 0 and 255</span><br />
<br />
&nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>fadeVal<span style="color: #339933;">==</span><span style="color: #0000dd;">255</span> <span style="color: #339933;">||</span> fadeVal<span style="color: #339933;">==</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// change from up&gt;down or down-up (negative/positive)</span><br />
&nbsp; <span style="color: #009900;">&#123;</span> fadeSpeed <span style="color: #339933;">=</span> <span style="color: #339933;">-</span>fadeSpeed<span style="color: #339933;">;</span> &nbsp;<br />
&nbsp; <span style="color: #009900;">&#125;</span> &nbsp;<br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">// set HSB values</span><br />
&nbsp; hue &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #339933;">=</span> <span style="color: #000066;">map</span><span style="color: #009900;">&#40;</span>sensorVal<span style="color: #339933;">,</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1023</span><span style="color: #339933;">,</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">359</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// hue is a number between 0 and 360</span><br />
&nbsp; saturation <span style="color: #339933;">=</span> <span style="color: #0000dd;">255</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// saturation is a number between 0 - 255</span><br />
&nbsp; brightness <span style="color: #339933;">=</span> fadeVal<span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// value is a number between 0 - 255</span><br />
<br />
&nbsp; getRGB<span style="color: #009900;">&#40;</span>hue<span style="color: #339933;">,</span>saturation<span style="color: #339933;">,</span>brightness<span style="color: #339933;">,</span>rgb_colors<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #666666; font-style: italic;">// converts HSB to RGB</span><br />
<br />
&nbsp; <span style="color: #000066;">analogWrite</span><span style="color: #009900;">&#40;</span>ledPinR<span style="color: #339933;">,</span> rgb_colors<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">// red value in index 0 of rgb_colors array</span><br />
&nbsp; <span style="color: #000066;">analogWrite</span><span style="color: #009900;">&#40;</span>ledPinG<span style="color: #339933;">,</span> rgb_colors<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">// green value in index 1 of rgb_colors array</span><br />
&nbsp; <span style="color: #000066;">analogWrite</span><span style="color: #009900;">&#40;</span>ledPinB<span style="color: #339933;">,</span> rgb_colors<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">// blue value in index 2 of rgb_colors array</span><br />
<br />
&nbsp; <span style="color: #000066;">delay</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">20</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// delay to slow down fading</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #993333;">void</span> getRGB<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> hue<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> sat<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> val<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> colors<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <br />
&nbsp; <span style="color: #808080; font-style: italic;">/* convert hue, saturation and brightness ( HSB/HSV ) to RGB<br />
&nbsp; &nbsp; &nbsp;The dim_curve is used only on brightness/value and on saturation (inverted).<br />
&nbsp; &nbsp; &nbsp;This looks the most natural. &nbsp; &nbsp; &nbsp;<br />
&nbsp; */</span><br />
<br />
&nbsp; val <span style="color: #339933;">=</span> dim_curve<span style="color: #009900;">&#91;</span>val<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; sat <span style="color: #339933;">=</span> <span style="color: #0000dd;">255</span><span style="color: #339933;">-</span>dim_curve<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">255</span><span style="color: #339933;">-</span>sat<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #993333;">int</span> r<span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #993333;">int</span> g<span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #993333;">int</span> b<span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #993333;">int</span> base<span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>sat <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// Acromatic color (gray). Hue doesn't mind.</span><br />
&nbsp; &nbsp; colors<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>val<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; colors<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>val<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; colors<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>val<span style="color: #339933;">;</span> &nbsp;<br />
&nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> &nbsp;<span style="color: #009900;">&#123;</span> <br />
<br />
&nbsp; &nbsp; base <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">255</span> <span style="color: #339933;">-</span> sat<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> val<span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;&gt;</span><span style="color: #0000dd;">8</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span>hue<span style="color: #339933;">/</span><span style="color: #0000dd;">60</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; r <span style="color: #339933;">=</span> val<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; g <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>val<span style="color: #339933;">-</span>base<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>hue<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #0000dd;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span>base<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; b <span style="color: #339933;">=</span> base<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; r <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>val<span style="color: #339933;">-</span>base<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">60</span><span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span>hue<span style="color: #339933;">%</span><span style="color:#800080;">60</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #0000dd;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span>base<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; g <span style="color: #339933;">=</span> val<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; b <span style="color: #339933;">=</span> base<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; r <span style="color: #339933;">=</span> base<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; g <span style="color: #339933;">=</span> val<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; b <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>val<span style="color: #339933;">-</span>base<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span>hue<span style="color: #339933;">%</span><span style="color:#800080;">60</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #0000dd;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span>base<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #0000dd;">3</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; r <span style="color: #339933;">=</span> base<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; g <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>val<span style="color: #339933;">-</span>base<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">60</span><span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span>hue<span style="color: #339933;">%</span><span style="color:#800080;">60</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #0000dd;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span>base<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; b <span style="color: #339933;">=</span> val<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #0000dd;">4</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; r <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>val<span style="color: #339933;">-</span>base<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span>hue<span style="color: #339933;">%</span><span style="color:#800080;">60</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #0000dd;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span>base<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; g <span style="color: #339933;">=</span> base<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; b <span style="color: #339933;">=</span> val<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #0000dd;">5</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; r <span style="color: #339933;">=</span> val<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; g <span style="color: #339933;">=</span> base<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; b <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>val<span style="color: #339933;">-</span>base<span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">60</span><span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span>hue<span style="color: #339933;">%</span><span style="color:#800080;">60</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #0000dd;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span>base<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; colors<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>r<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; colors<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>g<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; colors<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>b<span style="color: #339933;">;</span> <br />
&nbsp; <span style="color: #009900;">&#125;</span> &nbsp; <br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
</pre>


<p>Related posts:<ol><li><a href='http://www.kasperkamperman.com/blog/arduino/arduino-programming-state-change/' rel='bookmark' title='Permanent Link: Arduino Programming &#8211; State change'>Arduino Programming &#8211; State change</a></li>
<li><a href='http://www.kasperkamperman.com/blog/arduino/arduino-programming-interval/' rel='bookmark' title='Permanent Link: Arduino Programming &#8211; Interval'>Arduino Programming &#8211; Interval</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.kasperkamperman.com/blog/arduino/arduino-programming-hsb-to-rgb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
