<?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>The Art of Nathan Selikoff &#187; Code Sketches</title> <atom:link href="http://nathanselikoff.com/category/code-sketches/feed" rel="self" type="application/rss+xml" /><link>http://nathanselikoff.com</link> <description>Mathematical systems, crafted in code, generating complex &#38; lyrical images full of movement &#38; energy</description> <lastBuildDate>Tue, 24 Jan 2012 17:30:47 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>Filaments</title><link>http://nathanselikoff.com/698/code-sketches/filaments</link> <comments>http://nathanselikoff.com/698/code-sketches/filaments#comments</comments> <pubDate>Wed, 24 Nov 2010 03:16:36 +0000</pubDate> <dc:creator>nathan</dc:creator> <category><![CDATA[Code Sketches]]></category> <guid
isPermaLink="false">http://nathanselikoff.com/?p=698</guid> <description><![CDATA[Recently I read about, and then watched, Casey Reas' Process Compendium 2004-2010 on Creative Applications Network. I loved the way he characterized a generative system: "An Element is a simple machine that is comprised of a Form and one or more Behaviors. A Process defines an environment for Elements and determines how the relationships between the Elements are visualized." This sketch could be described in this paradigm as follows:]]></description> <content:encoded><![CDATA[<p><script type="application/processing">PVector pt, pt0, pt1, pt2, pt3;
float speed = 1,
      noiseScale = 100, // higher makes the noise affect the position more
      noiseDiv = 50, // higher is less noise
      outerSteps = 620, // fewer makes the points on the edges rotate faster
      yOffset = 180,
      sinFreq = 0.01,
      sinAmp = 50,
      colorFreq = 0.002,
      bgAlpha = 0.0, // make non-zero to fade out screen; for whatever reason values below 0.004 won't fade back the screen
      strokeWt = 0.25;
color fgColor, bgColor;
int pass = 0; // keep track of how many passes across the screen we've made
void setup() {
  size(620, 360);
  pt = new PVector(0, height/2, 0);
  pt0 = new PVector(0, 0, 0);
  pt1 = new PVector(width, 0, 0);
  pt2 = new PVector(width, height, 0);
  pt3 = new PVector(0, height, 0);
  smooth();
  colorMode(RGB, 1.0);
  // have to set color values after changing the colorMode
  fgColor = color(0, 1.0, 0, 0.2);
  bgColor = color(0, 0, 0);
  // clear the screen to black initially
  background(0);
}
void draw() {
  // draw a rectangle over the whole screen to fade back the image if desired
  fill(bgColor, bgAlpha);
  noStroke();
  rect(0, 0, width, height);
  // draw the lines from the edges to the generator
  stroke(fgColor);
  strokeWeight(strokeWt);
  line(pt.x, pt.y, pt0.x, pt0.y);
  line(pt.x, pt.y, pt1.x, pt1.y);
  line(pt.x, pt.y, pt2.x, pt2.y);
  line(pt.x, pt.y, pt3.x, pt3.y);
  // update the color
  //fgColor = color(0, (sin(frameCount * colorFreq) + 1) * 0.5, 0, alpha(fgColor));
  // update the position of the "generator" - a sin wav with added noise in speed and position
  pt.x = pt.x + speed * noise(frameCount / noiseDiv);
  if (pt.x > width) {
    pt.x = 0;
    pass++;
    // if the color is green, set it to black; if it's black, set it to green
    if (green(fgColor) == 1.0)
      fgColor = color(0, 0, 0, alpha(fgColor));
    else
      fgColor = color(0, 1.0, 0, alpha(fgColor));
  }
  pt.y = yOffset + (noise(frameCount / noiseDiv) - 0.5) * noiseScale + sin(frameCount*sinFreq) * sinAmp;
  // update the positions of the points on the edges so they circle around
  pt0.x = (pt0.x + (width/outerSteps)*speed) % width;
  pt1.y = (pt1.y + (height/outerSteps)*speed) % height;
  pt2.x -= (width/outerSteps)*speed;
  if (pt2.x < 0)
    pt2.x = width;
  pt3.y -= (height/outerSteps)*speed;
  if (pt3.y < 0)
    pt3.y = height;
}</script></p><p>Recently I read about, and then watched, <a
href="http://reas.com/texts/processcompendium.html">Casey Reas&#8217; Process Compendium 2004-2010 on Creative Applications Network</a>. I loved the way he characterized a generative system:</p><blockquote><p>An Element is a simple machine that is comprised of a Form and one or more Behaviors. A Process defines an environment for Elements and determines how the relationships between the Elements are visualized.</p><p><a
href="http://reas.com/texts/processcompendium.html">http://reas.com/texts/processcompendium.html</a></p></blockquote><p>The above sketch could be described in this paradigm as follows:</p><p>Forms<br
/> F1: Point<br
/> F2: Line</p><p>Behaviors<br
/> B1: Move horizontally across the screen<br
/> B2: Move vertically according to a sin function<br
/> B3: Adjust speed and position according to a noise function<br
/> B4: Move along an edge of the screen</p><p>Elements<br
/> E1: F1 + B1 + B2 + B3<br
/> E2: F1 + B4<br
/> E3: E1 + E2</p><p>Screen captures and source code below&#8230; most of the parameters are at the top of the code and fun to play with, so please feel free to experiment, and leave me a comment if you do. Made with <a
href="http://processing.org/">Processing</a> and presented on this page with <a
href="http://processingjs.org/">Processing.js</a>.</p><p><a
href="http://nathanselikoff.com/files/2010/11/filaments_0.jpg"><img
class="alignnone size-full wp-image-700" title="filaments_0" src="http://nathanselikoff.com/files/2010/11/filaments_0.jpg" alt="" width="620" height="360" /></a></p><p><a
href="http://nathanselikoff.com/files/2010/11/filaments_1.jpg"><img
class="alignnone size-full wp-image-701" title="filaments_1" src="http://nathanselikoff.com/files/2010/11/filaments_1.jpg" alt="" width="620" height="360" /></a></p><p><a
href="http://nathanselikoff.com/files/2010/11/filaments_2.jpg"><img
class="alignnone size-full wp-image-702" title="filaments_2" src="http://nathanselikoff.com/files/2010/11/filaments_2.jpg" alt="" width="620" height="360" /></a></p><p><a
href="http://nathanselikoff.com/files/2010/11/filaments_3.jpg"><img
class="alignnone size-full wp-image-703" title="filaments_3" src="http://nathanselikoff.com/files/2010/11/filaments_3.jpg" alt="" width="620" height="360" /></a></p><p><a
href="http://nathanselikoff.com/files/2010/11/filaments_4.jpg"><img
class="alignnone size-full wp-image-706" title="filaments_4" src="http://nathanselikoff.com/files/2010/11/filaments_4.jpg" alt="" width="620" height="360" /></a></p><p><a
href="http://nathanselikoff.com/files/2010/11/filaments_5.jpg"><img
class="alignnone size-full wp-image-705" title="filaments_5" src="http://nathanselikoff.com/files/2010/11/filaments_5.jpg" alt="" width="620" height="360" /></a></p><p><a
href="http://nathanselikoff.com/files/2010/11/filaments_6.jpg"><img
class="alignnone size-full wp-image-704" title="filaments_6" src="http://nathanselikoff.com/files/2010/11/filaments_6.jpg" alt="" width="620" height="360" /></a></p><p><a
href="http://nathanselikoff.com/files/2010/11/filaments_7.jpg"><img
class="alignnone size-full wp-image-707" title="filaments_7" src="http://nathanselikoff.com/files/2010/11/filaments_7.jpg" alt="" width="620" height="360" /></a></p><p><div
class="code processing"><h4 class="cHead"><span><a
href="http://www.processing.org">processing</a> code</span></h4><div
class="cBody"><div
class="lines"> 01<br
/>02<br
/>03<br
/>04<br
/>05<br
/>06<br
/>07<br
/>08<br
/>09<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</div><pre><span Class="KEY">PVector</span> pt, pt0, pt1, pt2, pt3;
<span Class="KEY">float</span> speed = 1,
      noiseScale = 100, <span Class="COM">// higher makes the <span Class="KEY">noise</span> affect the position more
</span>      noiseDiv = 50, <span Class="COM">// higher is less <span Class="KEY">noise</span>
</span>      outerSteps = 620, <span Class="COM">// fewer makes the points on the edges <span Class="KEY">rotate</span> faster
</span>      yOffset = 180,
      sinFreq = 0.01,
      sinAmp = 50,
      colorFreq = 0.002,
      bgAlpha = 0.0, <span Class="COM">// make non-zero to fade out <span Class="KEY">screen</span>; <span Class="KEY">for</span> whatever reason values below 0.004 won't fade back the <span Class="KEY">screen</span>
</span>      strokeWt = 0.25;
<span Class="KEY"><span Class="KEY">color</span></span> fgColor, bgColor;
<span Class="KEY">int</span> pass = 0; <span Class="COM">// keep track of how many passes across the <span Class="KEY">screen</span> we've made
</span>
<span Class="KEY">void</span> <span Class="KEY">setup</span>() {
  <span Class="KEY">size</span>(620, 360);
  pt = <span Class="KEY">new</span> <span Class="KEY">PVector</span>(0, <span Class="STR">height</span>/2, 0);
  pt0 = <span Class="KEY">new</span> <span Class="KEY">PVector</span>(0, 0, 0);
  pt1 = <span Class="KEY">new</span> <span Class="KEY">PVector</span>(<span Class="STR">width</span>, 0, 0);
  pt2 = <span Class="KEY">new</span> <span Class="KEY">PVector</span>(<span Class="STR">width</span>, <span Class="STR">height</span>, 0);
  pt3 = <span Class="KEY">new</span> <span Class="KEY">PVector</span>(0, <span Class="STR">height</span>, 0);
  <span Class="KEY">smooth</span>();
  <span Class="KEY">colorMode</span>(RGB, 1.0);
  <span Class="COM">// have to <span Class="KEY">set</span> <span Class="KEY"><span Class="KEY">color</span></span> values after changing the <span Class="KEY">colorMode</span>
</span>  fgColor = <span Class="KEY"><span Class="KEY">color</span></span>(0, 1.0, 0, 0.2);
  bgColor = <span Class="KEY"><span Class="KEY">color</span></span>(0, 0, 0);
  <span Class="COM">// clear the <span Class="KEY">screen</span> to black initially
</span>  <span Class="KEY">background</span>(0);
}
<span Class="KEY">void</span> <span Class="KEY">draw</span>() {
  <span Class="COM">// <span Class="KEY">draw</span> a rectangle over the whole <span Class="KEY">screen</span> to fade back the <span Class="KEY">image</span> <span Class="KEY">if</span> desired
</span>  <span Class="KEY">fill</span>(bgColor, bgAlpha);
  <span Class="KEY">noStroke</span>();
  <span Class="KEY">rect</span>(0, 0, <span Class="STR">width</span>, <span Class="STR">height</span>);
  <span Class="COM">// <span Class="KEY">draw</span> the lines from the edges to the generator
</span>  <span Class="KEY">stroke</span>(fgColor);
  <span Class="KEY">strokeWeight</span>(strokeWt);
  <span Class="KEY">line</span>(pt.x, pt.y, pt0.x, pt0.y);
  <span Class="KEY">line</span>(pt.x, pt.y, pt1.x, pt1.y);
  <span Class="KEY">line</span>(pt.x, pt.y, pt2.x, pt2.y);
  <span Class="KEY">line</span>(pt.x, pt.y, pt3.x, pt3.y);
  <span Class="COM">// update the <span Class="KEY"><span Class="KEY">color</span></span>
</span>  <span Class="COM">//fgColor = <span Class="KEY"><span Class="KEY">color</span></span>(0, (<span Class="KEY">sin</span>(<span Class="KEY">frameCount</span> * colorFreq) + 1) * 0.5, 0, <span Class="KEY">alpha</span>(fgColor));
</span>
  <span Class="COM">// update the position of the <span Class="STR">&quot;generator&quot;</span> - a <span Class="KEY">sin</span> wav with added <span Class="KEY">noise</span> in speed and position
</span>  pt.x = pt.x + speed * <span Class="KEY">noise</span>(<span Class="KEY">frameCount</span> / noiseDiv);
  <span Class="KEY">if</span> (pt.x &gt; <span Class="STR">width</span>) {
    pt.x = 0;
    pass++;
    <span Class="COM">// <span Class="KEY">if</span> the <span Class="KEY"><span Class="KEY">color</span></span> is <span Class="KEY">green</span>, <span Class="KEY">set</span> it to black; <span Class="KEY">if</span> it's black, <span Class="KEY">set</span> it to <span Class="KEY">green</span>
</span>    <span Class="KEY">if</span> (<span Class="KEY">green</span>(fgColor) == 1.0)
      fgColor = <span Class="KEY"><span Class="KEY">color</span></span>(0, 0, 0, <span Class="KEY">alpha</span>(fgColor));
    <span Class="KEY">else</span>
      fgColor = <span Class="KEY"><span Class="KEY">color</span></span>(0, 1.0, 0, <span Class="KEY">alpha</span>(fgColor));
  }
  pt.y = yOffset + (<span Class="KEY">noise</span>(<span Class="KEY">frameCount</span> / noiseDiv) - 0.5) * noiseScale + <span Class="KEY">sin</span>(<span Class="KEY">frameCount</span>*sinFreq) * sinAmp;
  <span Class="COM">// update the positions of the points on the edges so they circle around
</span>  pt0.x = (pt0.x + (<span Class="STR">width</span>/outerSteps)*speed) % <span Class="STR">width</span>;
  pt1.y = (pt1.y + (<span Class="STR">height</span>/outerSteps)*speed) % <span Class="STR">height</span>;
  pt2.x -= (<span Class="STR">width</span>/outerSteps)*speed;
  <span Class="KEY">if</span> (pt2.x &lt; 0)
    pt2.x = <span Class="STR">width</span>;
  pt3.y -= (<span Class="STR">height</span>/outerSteps)*speed;
  <span Class="KEY">if</span> (pt3.y &lt; 0)
    pt3.y = <span Class="STR">height</span>;
}</pre></div><div
class="cFoot"> <a
href="http://www.anthonymattox.com/code_formatter">code formatter</a></div></div></p> ]]></content:encoded> <wfw:commentRss>http://nathanselikoff.com/698/code-sketches/filaments/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Code Sketches Category Description</title><link>http://nathanselikoff.com/321/category-description/code-sketches-category-description</link> <comments>http://nathanselikoff.com/321/category-description/code-sketches-category-description#comments</comments> <pubDate>Sun, 04 Apr 2010 01:33:44 +0000</pubDate> <dc:creator>nathan</dc:creator> <category><![CDATA[Category Description]]></category> <category><![CDATA[Code Sketches]]></category> <guid
isPermaLink="false">http://nathanselikoff.com/?p=321</guid> <description><![CDATA[Less than fully formed ideas, periodic digital sketches, proofs of concept, and code as creative process. More coming soon.]]></description> <content:encoded><![CDATA[<p>Less than fully formed ideas, periodic digital sketches, proofs of concept, and code as creative process. More coming soon.</p> ]]></content:encoded> <wfw:commentRss>http://nathanselikoff.com/321/category-description/code-sketches-category-description/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Fibonacci Spiral</title><link>http://nathanselikoff.com/279/code-sketches/fibonacci-spiral-sketch_dec21b</link> <comments>http://nathanselikoff.com/279/code-sketches/fibonacci-spiral-sketch_dec21b#comments</comments> <pubDate>Sun, 28 Mar 2010 21:44:19 +0000</pubDate> <dc:creator>nathan</dc:creator> <category><![CDATA[Code Sketches]]></category> <guid
isPermaLink="false">http://nathanselikoff.com/?p=279</guid> <description><![CDATA[I am fascinated by the Fibonacci (Golden) Spiral, and love the geometric construction, which is mimicked and expanded in this Processing sketch.]]></description> <content:encoded><![CDATA[<p>I am fascinated by the Fibonacci (Golden) Spiral, and love the geometric construction, which is mimicked and expanded in this Processing sketch.</p><div
id="attachment_363" class="wp-caption alignnone" style="width: 244px"><img
class="size-full wp-image-363" src="http://nathanselikoff.com/files/2010/03/fibonacci-golden-spiral.jpg" alt="Fibonacci Spiral by Nathan Selikoff. 2010. Image capture from Processing sketch." width="234" height="145" /><p
class="wp-caption-text">Fibonacci Spiral by Nathan Selikoff. 2010. Image capture from Processing sketch.</p></div><p>While developing an earlier concept for my website redesign, I created this version of the Fibonacci Spiral, with subtle coloration and fading arcs and squares. Make sure you stare at it for a little while to see the change!</p><p><div
id="sketch_dec21a_container" class="wp-caption" style="padding:4px 0;">  <script type="text/javascript"
	src="http://www.java.com/js/deployJava.js"></script> <script type="text/javascript">/*  */
  var attributes = { code:'sketch_dec21a.class',
                         archive: '/files/processing/sketch_dec21a/applet/sketch_dec21a.jar',
                         width:611, height:378 } ;
      var parameters = { };
      var version = '1.5';
      deployJava.runApplet(attributes, parameters, version);
      /* ]]&gt; */</script> <noscript><div> <!--[if !IE]> --> <object
classid="java:sketch_dec21a.class"
type="application/x-java-applet"
archive="/files/processing/sketch_dec21a/applet/sketch_dec21a.jar"
width="611" height="378"
standby="Loading Processing software..." ><param
name="archive" value="/files/processing/sketch_dec21a/applet/sketch_dec21a.jar" /><param
name="mayscript" value="true" /><param
name="scriptable" value="true" /><param
name="image" value="loading.gif" /><param
name="boxmessage" value="Loading Processing software..." /><param
name="boxbgcolor" value="#FFFFFF" /><param
name="test_string" value="outer" /> <!--<![endif]--> <object
classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
codebase="http://java.sun.com/update/1.6.0/jinstall-6u18-windows-i586.cab"
width="611" height="378"
standby="Loading Processing software..."  ><param
name="code" value="sketch_dec21a" /><param
name="archive" value="/files/processing/sketch_dec21a/applet/sketch_dec21a.jar" /><param
name="mayscript" value="true" /><param
name="scriptable" value="true" /><param
name="image" value="loading.gif" /><param
name="boxmessage" value="Loading Processing software..." /><param
name="boxbgcolor" value="#FFFFFF" /><param
name="test_string" value="inner" /><p> <strong> This browser does not have a Java Plug-in. <br
/> <a
href="http://www.java.com/getjava" title="Download Java Plug-in"> Get the latest Java Plug-in here. </a> </strong></p> </object> <!--[if !IE]> --> </object> <!--<![endif]--></div> </noscript></div></p><p><div
class="code processing"><h4 class="cHead"><span><a
href="http://www.processing.org">processing</a> code</span></h4><div
class="cBody"><div
class="lines"> 01<br
/>02<br
/>03<br
/>04<br
/>05<br
/>06<br
/>07<br
/>08<br
/>09<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</div><pre><span Class="COM">// large version
</span><span Class="COM">// <span Class="KEY">second</span> attempt at a fibonacci spiral
</span><span Class="COM">// first attempt was great, but used rotation,
</span><span Class="COM">// which is expensive and imprecise
</span><span Class="COM">// here's the beginning of the fibonacci sequence...
</span><span Class="COM">// 0, 1, 1, 2, 3, 5, 8
</span>
<span Class="KEY">void</span> <span Class="KEY">setup</span>() {
  <span Class="KEY">size</span>(611, 378);
  <span Class="KEY">smooth</span>();
  <span Class="KEY">frameRate</span>(30);
}
<span Class="KEY">int</span>[] s = <span Class="KEY">new</span> <span Class="KEY">int</span>[3];
<span Class="KEY">int</span> tmp, phase;
<span Class="KEY">float</span> speed;
<span Class="KEY">void</span> <span Class="KEY">draw</span>() {
  <span Class="COM">// clear the <span Class="KEY">screen</span> to a nice <span Class="KEY">green</span>
</span>  <span Class="KEY">background</span>(228, 236, 215);
  <span Class="COM">// initialize variables
</span>  s[0] = 0;
  s[1] = 0; <span Class="COM">// first number of the fibonacci sequence
</span>  s[2] = 1; <span Class="COM">// <span Class="KEY">second</span> number of the fibonacci sequence
</span>  phase = 0; <span Class="COM">// simple counter; use <span Class="KEY">this</span> to apply fx to the boxes linearly
</span>  speed = 0.01; <span Class="COM">// speed of the effects
</span>
  <span Class="COM">// <span Class="KEY">set</span> the origin at the end of the spiral
</span>  <span Class="KEY">translate</span>(442, 272);
  <span Class="COM">// flip vertically to <span Class="KEY">match</span> my logo
</span>  <span Class="KEY">scale</span>(1.0, -1.0);
  <span Class="KEY">rotate</span>(<span Class="STR">PI</span>);
  <span Class="COM">// <span Class="KEY">this</span> <span Class="KEY">loop</span> constructs the spiral
</span>  <span Class="COM">// basically, draw a square of side s,
</span>  <span Class="COM">// rotate 90deg, calculate the new s0 and s,
</span>  <span Class="COM">// move up s0 + s, and repeat...
</span>  <span Class="KEY">while</span> (s[2] &lt; 611) {
    <span Class="COM">// use a <span Class="KEY">sin</span> function to give us some nice undulating effects
</span>    <span Class="KEY">float</span> wave = <span Class="KEY">sin</span>((<span Class="KEY">frameCount</span> + phase*20) * speed) + 1.0;
    <span Class="COM">// styles <span Class="KEY">for</span> the arcs
</span>    <span Class="KEY">fill</span>(0, 0, wave * 64, 10); <span Class="COM">// undulating transparent black <span Class="KEY">fill</span>
</span>    <span Class="KEY">stroke</span>(255, wave * 255); <span Class="COM">// undulating white <span Class="KEY">stroke</span>
</span>
    <span Class="COM">// <span Class="KEY">draw</span> the quarter-circles inside the squares
</span>    <span Class="COM">// <span Class="KEY">set</span> the <span Class="KEY">stroke</span> weight to 2 <span Class="KEY">for</span> the <span Class="KEY">arc</span> that makes the spiral
</span>    <span Class="KEY">if</span> (phase % 4 == 0) <span Class="KEY">strokeWeight</span>(2); <span Class="KEY">else</span> <span Class="KEY">strokeWeight</span>(1);
    <span Class="KEY">arc</span>(s[2], s[2], 2*s[2], 2*s[2], <span Class="STR">PI</span>, 3*<span Class="STR">PI</span>/2.0);
    <span Class="KEY">if</span> (phase % 4 == 1) <span Class="KEY">strokeWeight</span>(2); <span Class="KEY">else</span> <span Class="KEY">strokeWeight</span>(1);
    <span Class="KEY">arc</span>(0, s[2], 2*s[2], 2*s[2], -<span Class="STR">PI</span>/2.0, 0);
    <span Class="KEY">if</span> (phase % 4 == 2) <span Class="KEY">strokeWeight</span>(2); <span Class="KEY">else</span> <span Class="KEY">strokeWeight</span>(1);
    <span Class="KEY">arc</span>(0, 0, 2*s[2], 2*s[2], 0, <span Class="STR">PI</span>/2.0);
    <span Class="KEY">if</span> (phase % 4 == 3) <span Class="KEY">strokeWeight</span>(2); <span Class="KEY">else</span> <span Class="KEY">strokeWeight</span>(1);
    <span Class="KEY">arc</span>(s[2], 0, 2*s[2], 2*s[2], <span Class="STR">PI</span>/2.0, <span Class="STR">PI</span>);
    <span Class="COM">// styles <span Class="KEY">for</span> the squares
</span>    <span Class="KEY">noFill</span>();
    <span Class="KEY">stroke</span>(255, 255, 255, 255);
    <span Class="KEY">strokeWeight</span>(1);
    <span Class="COM">// <span Class="KEY">draw</span> the square
</span>    <span Class="KEY">rect</span>(0, 0, s[2], s[2]);
    <span Class="COM">// calculate the next number in the fibonacci sequence
</span>    tmp = s[2];
    s[2] += s[1];
    s[0] = s[1];
    s[1] = tmp;
    <span Class="COM">// <span Class="KEY">translate</span> to <span Class="KEY">get</span> in position <span Class="KEY">for</span> the next square
</span>    <span Class="KEY">switch</span>(phase % 4) {
      <span Class="KEY">case</span> 0:
        <span Class="KEY">translate</span>(s[1], 0);
      <span Class="KEY">break</span>;
      <span Class="KEY">case</span> 1:
        <span Class="KEY">translate</span>(-s[0], s[1]);
      <span Class="KEY">break</span>;
      <span Class="KEY">case</span> 2:
        <span Class="KEY">translate</span>(-s[2], -s[0]);
      <span Class="KEY">break</span>;
      <span Class="KEY">case</span> 3:
        <span Class="KEY">translate</span>(0, -s[2]);
      <span Class="KEY">break</span>;
    }
    phase++;
  }
}</pre></div><div
class="cFoot"> <a
href="http://www.anthonymattox.com/code_formatter">code formatter</a></div></div></p><p><a
href="http://en.wikipedia.org/wiki/Golden_ratio">Φ</a></p> ]]></content:encoded> <wfw:commentRss>http://nathanselikoff.com/279/code-sketches/fibonacci-spiral-sketch_dec21b/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
