<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: cantor code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 25 Jul 2008 15:16:00 GMT</pubDate>
    <description>DZone Snippets: cantor code</description>
    <item>
      <title>Cantor's Sets with Processing</title>
      <link>http://snippets.dzone.com/posts/show/5102</link>
      <description>This simple Processing programme generates the &lt;a href="http://en.wikibooks.org/wiki/Fractals/Cantor's_Set"&gt;Cantor's Sets&lt;/a&gt; fractal.&lt;br /&gt;&lt;br /&gt;Images are generated randomly, but tend to look like &lt;a href="http://scvalex.deviantart.com/art/Cantor-s-Sets-76451637"&gt;this&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;int setHeight = 60;&lt;br /&gt;color setColour = color(184 + random(-40, 40),&lt;br /&gt;                        124 + random(-40, 40),&lt;br /&gt;                        124 + random(-40, 40));&lt;br /&gt;int wid = 600;&lt;br /&gt;&lt;br /&gt;void setup() {&lt;br /&gt;  size(wid, (int)((log(wid) / log(3) + 1) * (setHeight + 5)));&lt;br /&gt;  background(0);&lt;br /&gt;  smooth();&lt;br /&gt;  &lt;br /&gt;  cantorSet(10, 10, width - 20, setColour);&lt;br /&gt;  &lt;br /&gt;  save("cantorSet.png");&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;float rnd(float x) {&lt;br /&gt;  return x + random(-20, 20);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void brushRect(int x, int y, int w, int h) {&lt;br /&gt;  for (int i = 0; i &lt; h; ++i) {&lt;br /&gt;    float r = random(3);&lt;br /&gt;    strokeWeight(r);&lt;br /&gt;    float downpull = random(h / 4);&lt;br /&gt;    float shudder = random(-2, 2);&lt;br /&gt;    line(x + shudder, y + i, x + w - shudder, y + i + downpull);&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void cantorSet(int y, int offX, int wid, color col) {&lt;br /&gt;  if ((y &gt; height - 10) || (wid &lt; 1))&lt;br /&gt;    return;&lt;br /&gt;&lt;br /&gt;  stroke(col);&lt;br /&gt;  brushRect(offX, y, wid, setHeight);&lt;br /&gt;  //fill(col);&lt;br /&gt;  //rect(offX, y, wid, setHeight);&lt;br /&gt;  &lt;br /&gt;  color newCol = color(rnd(red(col)), rnd(green(col)),&lt;br /&gt;                      rnd(blue(col)));&lt;br /&gt;  cantorSet(y + setHeight + 5, offX, wid / 3, newCol);&lt;br /&gt;  cantorSet(y + setHeight + 5, offX + wid*2/3, wid / 3, newCol);&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 04 Feb 2008 11:08:31 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5102</guid>
      <author>scvalex (Alexandru Scvortov)</author>
    </item>
  </channel>
</rss>
