PageRenderTime 58ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/_site/2011/03/08/as-monty-python-said-and-now-for-something-completly-different.html

https://github.com/vicmaster/blog.crowdint.com
HTML | 256 lines | 209 code | 43 blank | 4 comment | 0 complexity | e96ebd121e9e69eb4f7b7bc19883eb84 MD5 | raw file
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  6. <title>Crowd Interactive Tech Blog :: As Monty Python said... "And Now For Something Completly Different"</title>
  7. <link rel="stylesheet" href="/stylesheets/screen.css?853991" type="text/css" media="screen, projection" />
  8. <link rel="stylesheet" href="/stylesheets/print.css" type="text/css" media="print" />
  9. <link rel="stylesheet" href="/stylesheets/styles.css?853991" type="text/css" media="screen" />
  10. <link rel="stylesheet" href="/stylesheets/skribit.css" type="text/css" media="screen" />
  11. <link rel="stylesheet" href="/stylesheets/syntax.css" type="text/css" media="screen" />
  12. <link rel="alternate" type="application/rss+xml" title="RSS Feed for blog.crowdint.com" href="http://feeds.feedburner.com/CrowdInteractiveTechBlog" />
  13. <link href='http://fonts.googleapis.com/css?family=Arvo' rel='stylesheet' type='text/css'>
  14. <!--[if lt IE 8]><link rel="stylesheet" href="css/blueprint/ie.css" type="text/css" media="screen, projection"><![endif]-->
  15. <script type="text/javascript">
  16. var _gaq = _gaq || [];
  17. _gaq.push(['_setAccount', 'UA-17527068-1']);
  18. _gaq.push(['_trackPageview']);
  19. (function() {
  20. var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  21. ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  22. var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  23. })();
  24. </script>
  25. </head>
  26. <body>
  27. <div class="container">
  28. <div id="empty-header">
  29. <a href="/" id="home-link"><img src="/images/logo_03.png" id="logoHead" width="227" height="74" alt="LogoHead" onclick="_gaq.push(['_trackEvent', 'header', 'logo']);"/></a>
  30. <ul id="navMenu">
  31. <li><a href="http://www.crowdint.com/" onclick="_gaq.push(['_trackEvent', 'header', 'home']);"><span>HOME</span></a></li>
  32. <li><a href="http://www.crowdint.com/projects" onclick="_gaq.push(['_trackEvent', 'header', 'projects']);"><span>PROJECTS</span></a></li>
  33. <li><a href="http://www.crowdint.com/services" onclick="_gaq.push(['_trackEvent', 'header', 'services']);"><span>SERVICES</span></a></li>
  34. <li class="selected"><span>BLOG</span></li>
  35. <li><a href="http://www.crowdint.com/about_us" onclick="_gaq.push(['_trackEvent', 'header', 'about_us']);"><span>ABOUT</span></a></li>
  36. <li><a href="http://www.crowdint.com/" onclick="_gaq.push(['_trackEvent', 'header', 'contact']);"><span>CONTACT</span></a></li>
  37. </ul>
  38. </div>
  39. <div class="span-24 append-bottom testGlow">
  40. <div class="round-top span-24">
  41. &nbsp;
  42. </div>
  43. <div id="white-body" class="span-24">
  44. <div class="left-side span-17">
  45. <div class="post prepend-1">
  46. <h1>As Monty Python said... "And Now For Something Completly Different"</h1>
  47. <p class="author">
  48. <span class="date"><b>Mar 08</b><br />2011</span>
  49. </p>
  50. <div class="body prepend-1 append-1">
  51. <div class="gravatar span-3"><img src="http://www.gravatar.com/avatar/89c6420fb99cb01bcf2e3502a7851da2" class="avatar" alt="Avatar" /></div>
  52. <p>Perhaps by reading this you may be wondering what is Processing.js?
  53. Well, <a href="http://processingjs.org/">Processing.js</a> is a JavaScript port of a visualization-oriented language based on Java with the same name Processing (or p5 for short) made by <a href="http://ejohn.org">John Resig</a>, the creator of jQuery.</p>
  54. <h3>First, a little history about p5.</h3>
  55. <p> It was developed by Ben Fry and Casey Reas and it was intended to help electronic arts and visual design communities learn the basis of computer programming in a visual context.</p>
  56. <p>And... what about Processing.js?</p>
  57. <p> Processing.js is the little sister project of the popular Processing visual programming language, but designed for the web.
  58. <strong>Processing.js helps you to make your data visualizations, digital art, interactive animations, educational graphs, video games, etc. work using web standards and without any plug-ins.</strong> You only write code using the Processing language, include it in your web page, and Processing.js does the rest. <em>It's not magic, but almost</em>.</p>
  59. <p> Originally developed by Ben Fry and Casey Reas, Processing started as an open source programming language based on Java to help the electronic arts and visual design communities learn the basics of computer programming in a visual context.
  60. <strong>Processing.js takes this to the next level</strong>, allowing Processing code to be run by <strong>any HTML5 compatible browser</strong>, including current versions of Firefox, Safari, Chrome, Opera, and even the upcoming Internet Explorer 9. <em>Processing.js brings the best of visual programming to the web, both for Processing and web developers</em>.</p>
  61. <p> Ok, so when or where could I use processing?, It's simple, for example: when you need to implement some animation or visual interaction without using Adobe's Flash, or when you want to make new interfaces (like using Arduino) or maybe if you want to put multimedia. That's why I like Processing.js.</p>
  62. <p> Well, first of all <strong>you'll need the Processing.js</strong> (which could be <a href="http://processingjs.org/content/download/processing-js-1.0.0/processing-1.0.0.min.js">downloaded here</a>), and <strong>include it on your page</strong>:</p>
  63. <div class="highlight"><pre><code class="html"><span class="nt">&lt;script </span><span class="na">src=</span><span class="s">&quot;processing-1.0.0.min.js&quot;</span><span class="nt">&gt;&lt;/script&gt;</span>
  64. </code></pre>
  65. </div>
  66. <p> Then, wherever you want to use it just put it inside a canvas element (note: of course it has to be HTML5 canvas, which I will speak on my next post).</p>
  67. <div class="highlight"><pre><code class="html"><span class="nt">&lt;canvas</span> <span class="na">data-processing-sources=</span><span class="s">&quot;MySuperDuperInteractionFile.pjs.&quot;</span><span class="nt">&gt;&lt;/canvas&gt;</span>
  68. </code></pre>
  69. </div>
  70. <p> <strong>Load your web page, and it will parse, translate, and run your sketch in the browser</strong>... Tadaaaa! =)</p>
  71. <p> In my experience, I've always hated those basic HELLO WORLD examples so here is a little example which you can try.
  72. I won't explain all the Processing language, this will just show you a little bouncing ball, nothing great because out there you can find lots of more complex examples.</p>
  73. <div class="highlight"><pre><code class="javascript"> <span class="kr">float</span> <span class="nx">frame</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="c1">// we start at frame 0</span>
  74. <span class="kr">float</span> <span class="nx">framerate</span> <span class="o">=</span> <span class="mi">24</span><span class="p">;</span> <span class="c1">// our &quot;sketch&quot; will have a framerate of 24 frames per second.</span>
  75. <span class="kr">int</span> <span class="nx">ball_x</span><span class="p">;</span> <span class="c1">// ball x coordinate</span>
  76. <span class="kr">int</span> <span class="nx">ball_y</span><span class="p">;</span> <span class="c1">// ball y coordinate</span>
  77. <span class="kr">int</span> <span class="nx">ball_radius</span> <span class="o">=</span> <span class="mi">20</span><span class="p">;</span> <span class="c1">// ball radius</span>
  78. <span class="k">void</span> <span class="nx">setup</span><span class="p">()</span> <span class="p">{</span>
  79. <span class="nx">size</span><span class="p">(</span><span class="mi">200</span><span class="p">,</span><span class="mi">200</span><span class="p">);</span> <span class="c1">// set draw area size</span>
  80. <span class="nx">frameRate</span><span class="p">(</span><span class="nx">framerate</span><span class="p">);</span> <span class="c1">// set animation framerate</span>
  81. <span class="nx">ball_x</span> <span class="o">=</span> <span class="nx">width</span><span class="o">/</span><span class="mi">2</span><span class="p">;</span> <span class="c1">// set the initial ball coordinates</span>
  82. <span class="nx">ball_y</span> <span class="o">=</span> <span class="nx">ball_radius</span><span class="p">;</span> <span class="c1">// set the initial ball coordinates</span>
  83. <span class="nx">stroke</span><span class="p">(</span><span class="err">#</span><span class="mi">003300</span><span class="p">);</span> <span class="c1">// set the default shape outline colour</span>
  84. <span class="nx">fill</span><span class="p">(</span><span class="err">#</span><span class="mi">0000</span><span class="nx">FF</span><span class="p">);</span> <span class="c1">// set the default shape fill colour</span>
  85. <span class="p">}</span>
  86. <span class="k">void</span> <span class="nx">draw</span><span class="p">()</span> <span class="p">{</span>
  87. <span class="nx">frame</span><span class="o">++</span><span class="p">;</span> <span class="c1">// note that we&#39;re one frame further than last time</span>
  88. <span class="kr">float</span> <span class="nx">bounce_height</span> <span class="o">=</span> <span class="nx">height</span><span class="o">/</span><span class="mi">2</span> <span class="o">*</span> <span class="nx">abs</span><span class="p">(</span><span class="nx">sin</span><span class="p">(</span><span class="nx">PI</span><span class="o">*</span><span class="nx">frame</span><span class="o">/</span><span class="nx">framerate</span><span class="p">));</span> <span class="c1">// compute the ball height for this frame</span>
  89. <span class="kr">float</span> <span class="nx">ball_height</span> <span class="o">=</span> <span class="nx">height</span> <span class="o">-</span> <span class="p">(</span><span class="nx">bounce_height</span><span class="o">+</span><span class="nx">ball_radius</span><span class="p">);</span> <span class="c1">// because the top of the screen is 0, and the bottom is &quot;height&quot;,</span>
  90. <span class="nx">background</span><span class="p">(</span><span class="err">#</span><span class="nx">FFFFEE</span><span class="p">);</span> <span class="c1">// clear the drawing area</span>
  91. <span class="nx">ball_y</span> <span class="o">=</span> <span class="p">(</span><span class="kr">int</span><span class="p">)</span> <span class="p">(</span><span class="nx">ball_height</span><span class="p">);</span> <span class="c1">// set the new ball y position</span>
  92. <span class="nx">ellipse</span><span class="p">(</span><span class="nx">ball_x</span><span class="p">,</span><span class="nx">ball_y</span><span class="p">,</span><span class="nx">ball_radius</span><span class="p">,</span><span class="nx">ball_radius</span><span class="p">);</span> <span class="c1">// draw the ball</span>
  93. <span class="p">}</span>
  94. </code></pre>
  95. </div>
  96. <p> What can we see here? If you noticed, we have three main sections, the global variables (nothing to say), the setup method which sets the configuration that will be used in our sketch and the draw method which well... will draw our sketch.</p>
  97. <p> Wait a minute, Sketch?, yeap... <em>sketches are the main way to use processing</em>.
  98. If you remember Adobe Flash you'll easy understand a sketch because it works similar, they are like small scenes which together make a movie, and just as happens in Processing, you can use several sketches to make more complex things.</p>
  99. <p> That's all folks! (for now).
  100. Hope you have enjoyed this small change, as someone said before: Ruby is not the first nor will be the last programming language, it is always good to have alternatives...</p>
  101. <p>
  102. <div class="tweet">
  103. <a href="http://twitter.com/share"
  104. class="twitter-share-button"
  105. data-text=""
  106. data-count="none"
  107. data-via="crowdint"
  108. data-related=":with">Tweet</a>
  109. <script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
  110. </div>
  111. <div class="right">
  112. <!-- Place this tag where you want the +1 button to render -->
  113. <g:plusone></g:plusone>
  114. <!-- Place this tag after the last plusone tag -->
  115. <script type="text/javascript">
  116. (function() {
  117. var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
  118. po.src = 'https://apis.google.com/js/plusone.js';
  119. var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  120. })();
  121. </script>
  122. </div>
  123. <br><br>
  124. <div class="left">
  125. <!-- http://www.facebook.com/pages/Crowd-Interactive/63293958828 -->
  126. <iframe src="http://www.facebook.com/plugins/like.php?href=http://blog.crowdint.com/2011/03/08/as-monty-python-said-and-now-for-something-completly-different.html" scrolling="no" frameborder="0" style="height: 62px; width: 100%" allowTransparency="true"></iframe>
  127. </div>
  128. </p>
  129. </div>
  130. <div class="author_box">
  131. <p><b>Author:</b> Carlos Mu単iz | carlos.muniz@crowdint.com</p>
  132. </div>
  133. <div class="nav_links span-16">
  134. <div class="previous span-8"><a href="/2011/03/02/how-to-make-your-models-look-lean.html"><< How to make your Models look lean</a></div>
  135. <div class="next span-8 last"><a href="/2011/03/14/Sinatra-the-green-way.html">Sinatra, the green way >></a></div>
  136. </div>
  137. </div>
  138. <div class="post prepend-1">
  139. <h1>Related Posts</h1>
  140. <ul class="archives">
  141. <li><span><b>08 Mar 2011</b></span> &raquo; <a href="/2011/03/08/as-monty-python-said-and-now-for-something-completly-different.html">As Monty Python said... "And Now For Something Completly Different"</a></li>
  142. <li><span><b>17 Nov 2010</b></span> &raquo; <a href="/2010/11/17/rack-basics-a-rack-introduction.html">Rack Basics - A Rack Introduction</a></li>
  143. <li><span><b>25 Feb 2011</b></span> &raquo; <a href="/2011/02/25/why-ruby.html">Why ruby?</a></li>
  144. <li><span><b>14 Jan 2011</b></span> &raquo; <a href="/2011/01/14/building-a-basic-dsl-to-create-callbacks-in-ruby.html">Building a basic DSL to create callbacks in Ruby</a></li>
  145. <li><span><b>30 Nov 2010</b></span> &raquo; <a href="/2010/11/30/rspec-for-really-newbies.html">RSpec for really newbies</a></li>
  146. </ul>
  147. <div id="disqus_thread"></div>
  148. <script type="text/javascript">
  149. /**
  150. * var disqus_identifier; [Optional but recommended: Define a unique identifier (e.g. post id or slug) for this thread]
  151. */
  152. // var disqus_developer = 1;
  153. (function() {
  154. var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
  155. dsq.src = 'http://crowdinttech.disqus.com/embed.js';
  156. (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
  157. })();
  158. </script>
  159. <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript=crowdinttech">comments powered by Disqus.</a></noscript>
  160. <a href="http://disqus.com" class="dsq-brlink">blog comments powered by <span class="logo-disqus">Disqus</span></a>
  161. </div>
  162. </div>
  163. <div class="right-side span-5 last prepend-1">
  164. <h1><a href="/">Blog Home</a></h1>
  165. <h1>About Crowd Interactive</h1>
  166. <p class="append-1 about">Crowd Interactive is a Ruby on Rails
  167. consultancy firm powered by a team of enthusiast engineers that love
  168. programming.We turn your ideas into web applications...<br/><a href="/about.html">Read More...</a></p>
  169. <h1>Our Favorite Sites</h1>
  170. <ul>
  171. <li><a href="http://www.crowdint.com">Crowd Interactive</a></li>
  172. <li><a href="http://www.magmarails.com">MagmaRails</a></li>
  173. <li><a href="http://rubyonrails.org">Ruby on Rails</a></li>
  174. <li><a href="http://ruby-lang.org">Ruby-Lang</a></li>
  175. <li><a href="http://github.com/crowdint">Github</a></li>
  176. </ul>
  177. <h1>Stuff we've built</h1>
  178. <ul>
  179. <li><a href="http://www.modcloth.com">ModCloth</a></li>
  180. <li><a href="http://www.creativeallies.com">Creative Allies</a></li>
  181. <li><a href="http://www.nameframe.com">Nameframe</a></li>
  182. <li><a href="http://github.com/crowdint/rails3-jquery-autocomplete">Rails3-jQuery-Autocomplete</a></li>
  183. <li><a href="http://github.com/crowdint/rankstar">rankstar</a></li>
  184. <li><a href="http://github.com/crowdint/blog.crowdint.com">This site's source code</a></li>
  185. </ul>
  186. <h1>Older Posts</h1>
  187. <ul>
  188. <li><a href="/archive.html">Archive</a></li>
  189. </ul>
  190. <iframe src="http://www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2Fpages%2FCrowd-Interactive%2F63293958828&amp;width=190&amp;colorscheme=light&amp;show_faces=true&amp;border_color&amp;stream=false&amp;header=false&amp;height=380px" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:190px; height:380px;" allowTransparency="true"></iframe>
  191. Site Powered by <a href="http://github.com/mojombo/jekyll">Jekyll</a>
  192. </div>
  193. </div>
  194. <div class="round-bottom span-24">
  195. &nbsp;
  196. </div>
  197. </div>
  198. </div>
  199. <div id="footer">
  200. <div class="copyContent" >
  201. <p class="copy">Copyright &copy; 2010, Crowd Interactive. All rights reserved.</p>
  202. </div>
  203. </div>
  204. <script type="text/javascript">
  205. var disqus_shortname = 'crowdinttech';
  206. (function () {
  207. var s = document.createElement('script'); s.async = true;
  208. s.src = 'http://disqus.com/forums/crowdinttech/count.js';
  209. (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
  210. }());
  211. </script>
  212. </body>
  213. </html>