<?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>toxiclibs &#187; generative</title>
	<atom:link href="http://toxiclibs.org/tag/generative/feed/" rel="self" type="application/rss+xml" />
	<link>http://toxiclibs.org</link>
	<description>Building blocks for computational design</description>
	<lastBuildDate>Tue, 20 Dec 2011 17:03:34 +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>simutils-0001: Diffusion limited aggregation</title>
		<link>http://toxiclibs.org/2010/02/new-package-simutils/</link>
		<comments>http://toxiclibs.org/2010/02/new-package-simutils/#comments</comments>
		<pubDate>Sat, 20 Feb 2010 11:44:16 +0000</pubDate>
		<dc:creator>toxi</dc:creator>
				<category><![CDATA[simutils]]></category>
		<category><![CDATA[3d]]></category>
		<category><![CDATA[diffusion]]></category>
		<category><![CDATA[dla]]></category>
		<category><![CDATA[generative]]></category>
		<category><![CDATA[octree]]></category>
		<category><![CDATA[particles]]></category>
		<category><![CDATA[rulebased]]></category>

		<guid isPermaLink="false">http://toxiclibs.org/?p=190</guid>
		<description><![CDATA[A few days ago I published some updates to all five existing main packages and also bundled up some other classes from existing projects into a new package, called simutils. As the name indicates, these new classes deal with the simulation of some fairly basic processes inspired by nature, but each of them exhibits some [...]]]></description>
			<content:encoded><![CDATA[<p>A few days ago I published some updates to all five existing main packages and also bundled up some other classes from existing projects into a new package, called <strong>simutils</strong>. As the name indicates, these new classes deal with the simulation of some fairly basic processes inspired by nature, but each of them exhibits some emergent behaviours which can be (and have been) used for a wide variety of design tasks from 3D printed sculptures to generative music. To help you get started, the package also contains two or three Processing demos for each process showing basic usage patterns. The three processes implemented so far are explained in more detail in this &amp; <a href="http://toxiclibs.org/2010/02/simutils-grayscott/">the next</a> few upcoming posts. Let&#8217;s start with&#8230;</p>
<p><img class="alignnone size-full wp-image-220" title="brownian_sunflow" src="http://toxiclibs.org/wp-content/uploads/2010/02/brownian_sunflow.jpg" alt="brownian motion" width="680" height="382" /></p>
<h2>Diffusion limited aggregation</h2>
<p><a href="http://en.wikipedia.org/wiki/Diffusion-limited_aggregation" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Diffusion-limited_aggregation?referer=');">Diffusion limited aggregation</a>, DLA in short, is a theoretical process describing the clustering of particles through a process of diffusion, like a random walk/<a href="http://en.wikipedia.org/wiki/Brownian_motion" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Brownian_motion?referer=');">Brownian motion</a>. Inspired by the work of <a href="http://www.andylomas.com" onclick="pageTracker._trackPageview('/outgoing/www.andylomas.com?referer=');">Andy Lomas</a> with this process, in 2006 I set out to implement DLA myself from scratch, in order to apply it to structures and literally grow objects not made out of triangles/polygons. At the same time I&#8217;d also just discovered the possibilities of <a href="http://toxi.co.uk/blog/2006_12_01_archive.htm" onclick="pageTracker._trackPageview('/outgoing/toxi.co.uk/blog/2006_12_01_archive.htm?referer=');">rendering huge point clouds with Sunflow</a>, which seemed the perfect combination to explore this all further. By March &#8217;07 I had a system in place which allowed me to grow type and have used it for a commission to produce the &#8220;New Shoots&#8221; title sequence for Channel4.</p>
<p><img class="alignnone size-large wp-image-207" title="New Shoots (still)" src="http://toxiclibs.org/wp-content/uploads/2010/02/456471284_95dc1b9b45_o-680x382.png" alt="" width="680" height="382" /></p>
<p>The basic premise of a DLA simulation is the slow formation of complex structures through the (random) movement of single particles. Once a particle comes close to an existing one, it attaches itself and a new particle is spawned in a sphere around a previous particle. The process then repeats, slowly filling up the simulation space. If the random walk ever takes a particle passed a certain escape radius, the search is restarted with a different initial direction until another particle is hit. Because particles are usually very tiny, a large number of them and even more iterations are required for even very simple structures to emerge. For example, <a href="http://www.flickr.com/photos/toxi/456487319/in/set-72157600200636464/" onclick="pageTracker._trackPageview('/outgoing/www.flickr.com/photos/toxi/456487319/in/set-72157600200636464/?referer=');">the final frame of the New Shoots sequence</a> consisted of 4.5 million particles, whereas the structure for the image below has a &#8220;mere&#8221; 645,000&#8230;</p>
<p><img class="alignnone size-large wp-image-196" title="dlatest_spiral2" src="http://toxiclibs.org/wp-content/uploads/2010/02/dlatest_spiral2-680x382.png" alt="" width="680" height="382" /></p>
<h3>Finding the needle in the haystack</h3>
<p>Searching for particle collisions in sets of such size linearly is super slow &amp; cumbersome, so to make the process more efficient, my version of DLA is using the <a href="http://toxiclibs.org/docs/core/toxi/geom/PointOctree.html">PointOctree</a> class from the core package. This class is recursively (and on-demand) subdividing the simulation space into smaller, nested cubes, which are stored as <a href="http://en.wikipedia.org/wiki/Octree" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Octree?referer=');">tree structure</a>. When new particles are added by the DLA process they&#8217;re also being attached to the leaf nodes of the octree. When the next particle is searching for collisions with existing particles, these can then be found very quickly by querying the octree based on local search criteria using these 2 methods:</p>
<pre class="brush:java">PointOctree octree = new PointOctree(new Vec3D(-50,-50,50),100);
List&lt;Vec3D&gt; points; // in Java
java.util.List points; // in Processing, no support for generics!

// search within a sphere (i.e. all points within a certain distance)
Sphere boundingSphere = new Sphere(new Vec3D(),1);
points = octree.getPointsWithinSphere(boundingSphere); // or
points = octree.getPointsWithinSphere(origin, radius);

// search within an axis-aligned bounding box
AABB boundingBox = AABB.fromMinMax(new Vec3D(-1, -1, -1), new Vec3D(1, 1, 1));
points = octree.getPointsWithinBox(boundingBox);</pre>
<p>For more usage information about the octree also see the <a href="http://code.google.com/p/toxiclibs/source/browse/trunk/toxiclibs/examples/sim/DLASpiral/DLASpiral.pde" onclick="pageTracker._trackPageview('/outgoing/code.google.com/p/toxiclibs/source/browse/trunk/toxiclibs/examples/sim/DLASpiral/DLASpiral.pde?referer=');">DLASpiral</a> demo (the screenshot below also shows the adaptive structure of the octree) and the <a href="http://code.google.com/p/toxiclibs/source/browse/#svn/trunk/toxiclibs/examples/core/OctreeDemo" onclick="pageTracker._trackPageview('/outgoing/code.google.com/p/toxiclibs/source/browse/_svn/trunk/toxiclibs/examples/core/OctreeDemo?referer=');">OctreeDemo</a> of the core package&#8230;</p>
<p>In the future I&#8217;ll probably refactor this current dependency on the <code>PointOctree</code> class and have the <code>DLA</code> merely depend on a more generic <code>SpatialTree</code> interface, which then can also be implemented by other tree types, e.g. a <a href="http://en.wikipedia.org/wiki/Kd-tree" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Kd-tree?referer=');">kD tree</a>. To compensate, the DLA class so far has an extension point of sorts to allow custom <code>PointOctree</code> sub-classes to be used. In this case you&#8217;ll simply have to also sub-class <code>DLA</code> and overwrite the <code>createOctree</code> method to return an instance of your custom <code>PointOctree</code>.</p>
<p><img class="alignnone size-full wp-image-192" title="DLASpiral004" src="http://toxiclibs.org/wp-content/uploads/2010/02/DLASpiral004.png" alt="" width="680" height="362" /></p>
<h3>Guided growth</h3>
<p>In the above screenshot you can also see the blue spiral shape guideline directing the growth of the particles. These guidelines can either be individual line segments or points lists, e.g. sourced from a <a href="http://toxiclibs.org/docs/core/toxi/geom/Spline3D.html">Spline3D</a> instance or computed otherwise. When passing in a list of points, they&#8217;re connected into successive line segments internally. At least one line segment is required for the DLA process to function and you&#8217;d combine the 2 classes like this:</p>
<pre class="brush:java">// define a spline
Spline3D spline = new Spline3D();
spline.add(new Vec3D()).add(new Vec3D(0,-50,0)).add(new Vec3D(50,0,50)).add(new Vec3D(0,50,0));
DLAGuideLines guides = new DLAGuideLines();
guides.addCurveStrip(spline.computeVertices(8));

// setup DLA in a cubic space of 100 units edge length (always centred around (0,0,0))
DLA dla = new DLA(100);
// assign guideline(s)
dla.setGuideLines(guides);
</pre>
<p>The moment the guidelines are attached, each line segment is sampled at a high resolution and the computed points added to a second octree kept by the <code>DLA</code> class. It&#8217;s these points which are shown in the above screenshot (although only 10% of them are displayed)&#8230;</p>
<p><iframe title="YouTube video player" class="youtube-player" type="text/html" width="680" height="382" src="http://www.youtube.com/embed/yDIh3PVq3RE" frameborder="0" allowFullScreen="true"> </iframe></p>
<h3>Order of growth</h3>
<p>By default the growth of the entire particle system will be in the same order as the guideline segments have been added, however you&#8217;re free to change this by means of custom <a href="http://java.sun.com/javase/6/docs/api/java/util/Comparator.html" onclick="pageTracker._trackPageview('/outgoing/java.sun.com/javase/6/docs/api/java/util/Comparator.html?referer=');">Compatators</a>. The <a href="http://code.google.com/p/toxiclibs/source/browse/trunk/toxiclibs/src.sim/toxi/sim/dla/DLAGuideLines.java" onclick="pageTracker._trackPageview('/outgoing/code.google.com/p/toxiclibs/source/browse/trunk/toxiclibs/src.sim/toxi/sim/dla/DLAGuideLines.java?referer=');">DLAGuideLines</a> class is storing <a href="http://code.google.com/p/toxiclibs/source/browse/trunk/toxiclibs/src.sim/toxi/sim/dla/DLASegment.java" onclick="pageTracker._trackPageview('/outgoing/code.google.com/p/toxiclibs/source/browse/trunk/toxiclibs/src.sim/toxi/sim/dla/DLASegment.java?referer=');">DLASegment</a> instances in a sorted <a href="http://java.sun.com/javase/6/docs/api/java/util/TreeSet.html" onclick="pageTracker._trackPageview('/outgoing/java.sun.com/javase/6/docs/api/java/util/TreeSet.html?referer=');">TreeSet</a>. The order of this set can be defined by defining a custom comparator implementation when creating the guidelines and so any possible growth order can be designed/defined. The example below defines one which enforces a bottom-up growth (assuming positive Y is up):</p>
<pre class="brush:java">// define comparator
// (this how to do in Processing, which doesn't support generics...
// in plain Java you'd compare Line3D instance directly
// without the need for casting from Object)
class BottomUpOrder implements Comparator {
  public int compare(Object a, Object b) {
    float ya=((Line3D)a).getMidPoint().y;
    float yb=((Line3D)b).getMidPoint().y;
    if (ya&lt;yb) return -1;
    if (ya&gt;yb) return 1;
    return 0;
  }
}

// now use the comparator for the guidelines
DLAGuideLines guides = new DLAGuideLines(new BottomUpOrder());
</pre>
<p>The next release of this package will contain a few more of those&#8230;</p>
<h3>Parameters of growth</h3>
<p>The final requirement for the whole process to start is a set of configuration parameters. Of these there are many and so they&#8217;re encapsulated in their own class. To use them they&#8217;re simply passed to the DLA like:</p>
<pre class="brush:java">// use default configuration
dla.setConfig(new DLAConfiguration());
</pre>
<p>The default configuration has the following values, also briefly described below:</p>
<pre class="brush:java">// threshold distance below which a particle attaches itself to an older one
float snapDistance = 1.8f;
// threshold distance to attach to a curve/guideline particle
float curveAttachDistance = 2;

// max. radius of the sphere in which a new particle is spawned around a previous one
float spawnRadius = 12;
// max. radius of the sphere when the particle's random walk is interrupted/restarted
float escapeRadius = 36;
// actual size of the particles (currently assumed to be uniform for entire system)
float particleRadius = 0.25f;
// stickiness factor, only 10% of all attachments will be successful
float stickiness = 0.1f;
// using guidelines the growth can be forced into a certain direction
// this parameter defines the impact strength of this direction
// if 0.0 particles grow in all directions, 1.0 = actual segment direction is used
float curveAlign = 0.74f;

// percentage amount to progress along segments after each new particle
float curveSpeed = 0.00045f;
// velocity of the random particle walk
float searchSpeed = snapDistance * 0.66f;
// turn speed when particle changes direction
float particleSpeed = 0.001f;

// progress speed when scanning guidelines to build octree
float guideLineDensity = 0.1;

// chance for existing/already processed segments to continue growing
// evaluated before spawning each new particle
float continousGrowthRatio = 0.1f;
</pre>
<h3>Why a library?</h3>
<p>Whereas this is setup creates very interesting structures (especially when rendered in Sunflow), my idea for this library was not necessarily to have everyone replicate this specific look over &amp; over again, but provide the means to focus more on exploring the actual growth process, to customize it and use it as driver for creating new structures in which the actual particles are only present indirectly/secondary. One key feature for that matter are events emitted by the DLA class at key moments of the process. The <a href="http://code.google.com/p/toxiclibs/source/browse/trunk/toxiclibs/src.sim/toxi/sim/dla/DLAEventListener.java" onclick="pageTracker._trackPageview('/outgoing/code.google.com/p/toxiclibs/source/browse/trunk/toxiclibs/src.sim/toxi/sim/dla/DLAEventListener.java?referer=');">DLAEventListener</a> interface defines the following 3 event hooks:</p>
<pre class="brush:java">public interface DLAEventListener {

    void dlaAllSegmentsProcessed(DLA dla);

    void dlaNewParticleAdded(DLA dla, Vec3D p);

    void dlaSegmentSwitched(DLA dla, DLASegment s);
}
</pre>
<p>You can subscribe to these events by either creating your own class implementing this interface or sub-classing the also supplied <a href="http://code.google.com/p/toxiclibs/source/browse/trunk/toxiclibs/src.sim/toxi/sim/dla/DLAEventAdapter.java" onclick="pageTracker._trackPageview('/outgoing/code.google.com/p/toxiclibs/source/browse/trunk/toxiclibs/src.sim/toxi/sim/dla/DLAEventAdapter.java?referer=');">DLAEventAdapter</a> (in case you don&#8217;t want to react to all of them):</p>
<pre class="brush:java">class MyDLAListener extends DLAEventAdapter {

  // only get notified when growth is complete
  public  void dlaAllSegmentsProcessed(DLA dla) {
     System.out.println("done");
  }
}

DLA dla=new DLA(100);
// attach listener
dla.addListener(new MyDLAListener());
</pre>
<p>Alternatively, listening to &#8220;new particle&#8221; events allows you to construct elaborate structures not just from particles, but use particle positions to deposit small meshes or use <a href="http://toxiclibs.org/category/volumeutils/">volumeutils</a> to draw with a <code>VolumetricBrush</code> at these positions&#8230; There&#8217;re endless possibilities for further exploration and I hope some of you are excited enough to explore them! If so have fun &amp; share it!</p>
<p><a href="http://www.flickr.com/photos/toxi/tags/dla/" onclick="pageTracker._trackPageview('/outgoing/www.flickr.com/photos/toxi/tags/dla/?referer=');">Some more of my own earlier explorations into this field are on flickr.</a></p>
<p><img class="alignnone size-large wp-image-210" title="dlatest_spiral" src="http://toxiclibs.org/wp-content/uploads/2010/02/dlatest_spiral-680x382.png" alt="" width="680" height="382" /></p>
]]></content:encoded>
			<wfw:commentRss>http://toxiclibs.org/2010/02/new-package-simutils/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Re-inventing the wheel</title>
		<link>http://toxiclibs.org/2010/01/re-inventing-the-wheel/</link>
		<comments>http://toxiclibs.org/2010/01/re-inventing-the-wheel/#comments</comments>
		<pubDate>Sun, 17 Jan 2010 02:44:50 +0000</pubDate>
		<dc:creator>toxi</dc:creator>
				<category><![CDATA[core]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Usage]]></category>
		<category><![CDATA[generative]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[searchspace]]></category>
		<category><![CDATA[spline]]></category>
		<category><![CDATA[symmetry]]></category>
		<category><![CDATA[variation]]></category>

		<guid isPermaLink="false">http://toxiclibs.org/?p=141</guid>
		<description><![CDATA[Firstly, massive thanks are in order for such a storming positive reception of this new site &#8211; I really hope this will become a good resource for everyone interested in the fields these libs are addressing and I will try to update everyone (and everything) as often as I can. In the near future that [...]]]></description>
			<content:encoded><![CDATA[<p>Firstly, massive thanks are in order for such a storming positive reception of this new site &#8211; I really hope this will become a good resource for everyone interested in the fields these libs are addressing and I will try to update everyone (and everything) as often as I can. In the near future that will include a bit of future gazing, but today I&#8217;ve been re-inventing the wheel, literally&#8230;</p>
<p><a href="http://www.flickr.com/photos/toxi/4280317234/" onclick="pageTracker._trackPageview('/outgoing/www.flickr.com/photos/toxi/4280317234/?referer=');"><img class="alignnone size-full wp-image-147" title="wheel12" src="http://toxiclibs.org/wp-content/uploads/2010/01/wheel12.jpg" alt="wheel 12 spokes" width="680" height="525" /></a></p>
<p>I&#8217;ve been working on some designs for custom made wheels for a potential installation project. The aim is to lasercut some light-weight &amp; good looking acrylic wheels and so I&#8217;ve been literally searching for a few candidate solutions, which allow me to cut out large pieces of material from inside the wheel to keep the weight down whilst still being sturdy enough (thankfully the load on them will be minimal so I can skip the structural analysis).</p>
<p>Not wanting to do this exploration/hike manually, I opted for the Processing PDF output route and have written this little tool below to show me my options (at least some of them) and also tweak them easily.</p>
<p>Apart from Processing, the tool also makes use of these 3 classes from the <a href="http://toxiclibs.org/docs/core/">toxiclibscore</a> package:</p>
<h2>Vec2D</h2>
<p>This class, alongside its sibling Vec3D, is likely one of the most used classes of the entire library. Since 1.0 Processing has its own vector class too now, but Vec2D/3D are far more feature complete, implement a <a href="http://en.wikipedia.org/wiki/Fluent_interface" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Fluent_interface?referer=');">fluent interface</a> for more legible code when dealing with complex vector maths and <em>can</em> be faster too (especially for 2D, but also by helping you to avoid temporary object creation). Furthermore Vec2D also has support for polar coordinates (Vec3D has spherical as equivalent) which was very helpful for building the tool below:</p>
<p>Normally, you&#8217;d specify a Cartesian point with:</p>
<pre class="brush:java">Vec2D v = new Vec2D(x, y);</pre>
<p>However, if we want to interpret our vector as polar coordinates, we&#8217;re using the x component to specify the radius and the y component as rotation angle. To convert the vector back into Cartesian space (e.g. our screen) we can use the <code>.toCartesian()</code> method&#8230;</p>
<pre class="brush:java">Vec2D v = new Vec2D(radius, theta).toCartesian();</pre>
<p>In a similar manner, you can also transform a Cartesian point into polar coordinates:</p>
<pre class="brush:java">// here we 1st create a copy of v and then convert that one
Vec2D p = v.copy().toPolar();</pre>
<p>To see this basic usage pattern in more context, take a closer look at the <code>drawHoles(</code>) method below (lines 114-134) or check out the <a href="http://code.google.com/p/toxiclibs/source/browse/trunk/toxiclibs/examples/core/PolarUnravel/PolarUnravel.pde" onclick="pageTracker._trackPageview('/outgoing/code.google.com/p/toxiclibs/source/browse/trunk/toxiclibs/examples/core/PolarUnravel/PolarUnravel.pde?referer=');">PolarUnravel demo</a> bundled with the core lib.</p>
<h2>Spline2D</h2>
<p>Each cut-out shape in the wheel is created from a simple spline shape, specified using only 4 points. As mentioned above, these anchor points are specified using (initially) polar coordinates and the Spline2D class is then computing control points (handles) for each of these given points automatically. As user you can also specify tightness &amp; subdivisions for the computed curve vertices in between. While the lack of direct manual control over the spline handles might be a shortcoming in some situations, I generally found it easier to work with this automated version, especially when working with long curves and not only single bezier segments.</p>
<p>The next release of the library will also add a decimator method to this class which will enable the sampling of the curve at a uniform interval (i.e. all successive points of the returned list have the same distance (within a tolerance), regardless of curvature). This feature comes from the <a href="http://code.google.com/p/toxiclibs/source/browse/trunk/toxiclibs/src.physics/toxi/physics/ParticlePath.java" onclick="pageTracker._trackPageview('/outgoing/code.google.com/p/toxiclibs/source/browse/trunk/toxiclibs/src.physics/toxi/physics/ParticlePath.java?referer=');">ParticlePath</a> class briefly described in the <a href="http://toxiclibs.org/2010/01/happy-2010/">Happy 2010 post</a>.</p>
<p>Computing symmetrical handles for the curve endpoints is another still outstanding feature, but currently low priority (unless someone has got a patch ready for that ;)</p>
<p>The next image shows the 4 anchor points of each spline shape in green and all other computed vertices in pink.</p>
<p><a href="http://www.flickr.com/photos/toxi/4280635396/" onclick="pageTracker._trackPageview('/outgoing/www.flickr.com/photos/toxi/4280635396/?referer=');"><img src="http://toxiclibs.org/wp-content/uploads/2010/01/wheelspline-e1263695654792.png" alt="wheel with highlighted spline vertices" title="wheelspline" width="680" height="680" class="alignnone size-full wp-image-180" /></a></p>
<h2>UnitTranslator</h2>
<p>This class is the sole, lonely member of the <code>toxi.math.conversion</code> package, but is especially useful for those of you using Processing for digital fabrication or creating printed outputs. It provides the following conversion methods, making it trivial to e.g produce PDF outputs at the right physical dimensions (without trial &amp; error):</p>
<ul>
<li><code>millisToPixels(double mm, int dpi)</code> &#8211; Converts millimeters into pixels.</li>
<li><code>millisToPoints(double mm)</code> &#8211; Converts millimeters into PostScript points.</li>
<li><code>pixelsToInch(int pix, int dpi)</code> &#8211; Converts pixels into inches.</li>
<li><code>pixelsToMillis(int pix, int dpi)</code> &#8211; Converts pixels into millimeters.</li>
<li><code>pixelsToPoints(int pix, int dpi)</code> &#8211; Converts pixels into points.</li>
<li><code>pointsToMillis(double pt)</code> &#8211; Converts points into millimeters.</li>
<li><code>pointsToPixels(double pt, int dpi)</code> &#8211; Converts points into pixels.</li>
</ul>
<p>In the demo below, we&#8217;re using it to specifiy the wheel radius and drill holes in mm and then automatically calculate the required window size in pixels. In that case we&#8217;re however not using <code>millisToPixels()</code>, but <code>millisToPoints()</code> because PDF units are in points which are interpreted as 1 pixel (at 72 dpi)&#8230;</p>
<h2>The Wheel tool</h2>
<p>Just copy &#038; paste the code below into Processing and hit <em>Run</em> to fill up your hard disk (kidding, by default it only generates 120 different small PDF files/variations). The variations are created by iterating over all permutations of 4 parameters: number of symmetry steps, inset radius, core radius, alternate core radius.</p>
<pre class="brush:java">/**
 * Generative wheel designs utilizing Vec2D polar coordinates,
 * splines and unit conversion. By default each design is exported as
 * PDF &#038; PNG file, but can be turned off by setting the doExport flag to false.
 *
 * Usage: if export is enabled simply run &#038; wait until all permutations
 * have been generated. Else press 'x' to activate next permutation or
 * use - / = to adjust the ARC_WIDTH parameter which defines the
 * size of the cutouts.
 *
 * (c) 2010 Karsten Schmidt, PostSpectacular Ltd.
 *
 * More info: http://toxiclibs.org/2010/01/re-inventing-the-wheel/
 * Source code licensed under GPL v3.0. See http://www.gnu.org/licenses/gpl.html
 */

import processing.pdf.*;

import toxi.geom.*;
import toxi.math.conversion.*;

// bleed in mm
int BLEED = 6;

// wheel radii &#038; document size
float R = (float)UnitTranslator.millisToPoints(370 / 2);
float W = 2 * R + 2 * (float)UnitTranslator.millisToPoints(BLEED);
float EMPTY_CORE_SIZE = (float)UnitTranslator.millisToPoints(5);

// start number of main segments
int NUM_SEGMENTS = 3;

// normalized parameters
float INSET_RADIUS = 0.8f;
float OFFSET = 0.1f;
float CORE_RADIUS = 0.15f;
float ALTCORE_RADIUS = 0.3f;
float ARC_WIDTH = 0.4f;

// optional mounting holes
int NUM_DOTS = 18;
float DOT_RADIUS = 0.97f;
float DOTSIZE = (float)UnitTranslator.millisToPoints(2);

// number of subdivisions for spline vertex computation
int SPLINE_SUBDIV = 20;

// flag for PDF &#038; PNG export of all permutations
boolean doExport = true;

public void setup() {
  size((int) W, (int) W);
  // turn off automatic redraws when not exporting
  if (!doExport) {
    noLoop();
  }
}

public void draw() {
  String frameID =
    "wheel-" + NUM_SEGMENTS + "-" + nf(INSET_RADIUS, 1, 2) + "-"
    + nf(ALTCORE_RADIUS, 1, 2) + "-"
    + nf(CORE_RADIUS, 1, 2) + "-" + nf(ARC_WIDTH, 1, 2);
  println(frameID);
  if (doExport) {
    beginRecord(PDF, "out/" + frameID + ".pdf");
  }
  background(255);
  noStroke();
  fill(0);
  translate(width / 2, height / 2);
  ellipseMode(RADIUS);
  ellipse(0, 0, R, R);
  fill(255);
  ellipse(0, 0, EMPTY_CORE_SIZE, EMPTY_CORE_SIZE);
  // main holes
  drawHoles((INSET_RADIUS + OFFSET) * R, CORE_RADIUS * R, (INSET_RADIUS
    + OFFSET + CORE_RADIUS)
    / 2 * R, ARC_WIDTH, 0, NUM_SEGMENTS);
  if (CORE_RADIUS &gt;= 0.5) {
    drawHoles(CORE_RADIUS * 0.85f * R, 0.2f * R,
    (CORE_RADIUS * 0.85f + 0.2f) / 2 * R, ARC_WIDTH, 0,
    NUM_SEGMENTS);
  }
  // small cutouts
  drawHoles(INSET_RADIUS * R, ALTCORE_RADIUS * R,
  (INSET_RADIUS + ALTCORE_RADIUS) / 2 * R, ARC_WIDTH / 2, PI
    / NUM_SEGMENTS, NUM_SEGMENTS);
  if (ALTCORE_RADIUS &gt;= 0.5) {
    drawHoles(ALTCORE_RADIUS * 0.85f * R, 0.3f * R,
    (ALTCORE_RADIUS * 0.85f + 0.3f) / 2 * R, ARC_WIDTH / 2, PI
      / NUM_SEGMENTS, NUM_SEGMENTS);
  }
  // drill holes
  drawDots(NUM_DOTS, DOT_RADIUS * R, DOTSIZE);
  if (doExport) {
    endRecord();
    saveFrame("png/" + frameID + ".png");
    nextPermutation();
  }
}

void drawDots(int num, float radius, float s) {
  float delta = TWO_PI / num;
  for (int i = 0; i &lt; num; i++) {
    Vec2D p = new Vec2D(radius, i * delta).toCartesian();
    ellipse(p.x, p.y, s, s);
  }
}

void drawHoles(float outerR, float innerR, float centerR, float radiusWidth, float thetaOffset, int num) {
  radiusWidth *= PI / num;
  Spline2D s = new Spline2D();
  // define point in polar coordinates, then convert them
  Vec2D p = new Vec2D(outerR, 0).toCartesian();
  Vec2D a = new Vec2D(outerR, radiusWidth).toCartesian();
  Vec2D b = new Vec2D(centerR, radiusWidth).toCartesian();
  Vec2D c = new Vec2D(innerR, 0).toCartesian();
  Vec2D d = new Vec2D(centerR, -radiusWidth).toCartesian();
  Vec2D e = new Vec2D(outerR, -radiusWidth).toCartesian();
  // add points to spline &#038; compute
  s.add(p).add(a).add(b).add(c).add(d).add(e).add(p);
  java.util.List verts = s.computeVertices(SPLINE_SUBDIV);
  float delta = TWO_PI / num;
  for (int i = 0; i &lt; num; i++) {
    pushMatrix();
    rotate(i * delta + thetaOffset);
    drawPath(verts);
    popMatrix();
  }
}

void drawPath(java.util.List verts) {
  beginShape();
  for (Iterator i = verts.iterator(); i.hasNext();) {
    Vec2D v = (Vec2D) i.next();
    vertex(v.x, v.y);
  }
  endShape();
}

public void keyPressed() {
  if (key == 'x') {
    nextPermutation();
  } else if (key == '-') {
    ARC_WIDTH -= 0.02;
  } else if (key == '=') {
    ARC_WIDTH += 0.02;
  }
  redraw();
}

void nextPermutation() {
  CORE_RADIUS += 0.2;
  if (CORE_RADIUS &gt;= INSET_RADIUS) {
    CORE_RADIUS = 0.15f;
    ALTCORE_RADIUS += 0.2f;
    if (ALTCORE_RADIUS &gt;= INSET_RADIUS) {
      ALTCORE_RADIUS = 0.3f;
      INSET_RADIUS += 0.1f;
      if (INSET_RADIUS &gt; 0.8) {
        NUM_SEGMENTS++;
        INSET_RADIUS = 0.8f;
        if (NUM_SEGMENTS &gt; 12) {
          exit();
        }
      }
    }
  }
}
</pre>
<p>Finally, below are some more images of variations created with this tool (<a href="http://www.flickr.com/photos/toxi/sets/72157623224570676/" onclick="pageTracker._trackPageview('/outgoing/www.flickr.com/photos/toxi/sets/72157623224570676/?referer=');">see the full size &#038; set on flickr</a>):</p>
<p><a href="http://www.flickr.com/photos/toxi/4280053262/" title="wheel3_all by toxi, on Flickr" onclick="pageTracker._trackPageview('/outgoing/www.flickr.com/photos/toxi/4280053262/?referer=');"><img src="http://farm3.static.flickr.com/2680/4280053262_5e0676cd13.jpg" width="350" height="500" alt="wheel3_all" /></a></p>
<p><a href="http://www.flickr.com/photos/toxi/4279310563/" title="wheel5_all by toxi, on Flickr" onclick="pageTracker._trackPageview('/outgoing/www.flickr.com/photos/toxi/4279310563/?referer=');"><img src="http://farm5.static.flickr.com/4021/4279310563_ca5ed79d6c.jpg" width="350" height="500" alt="wheel5_all" /></a></p>
<p><a href="http://www.flickr.com/photos/toxi/4280055796/" title="wheel8_all by toxi, on Flickr" onclick="pageTracker._trackPageview('/outgoing/www.flickr.com/photos/toxi/4280055796/?referer=');"><img src="http://farm3.static.flickr.com/2758/4280055796_f43663fc20.jpg" width="350" height="500" alt="wheel8_all" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://toxiclibs.org/2010/01/re-inventing-the-wheel/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Ginger section</title>
		<link>http://toxiclibs.org/2010/01/ginger-section/</link>
		<comments>http://toxiclibs.org/2010/01/ginger-section/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 22:21:08 +0000</pubDate>
		<dc:creator>toxi</dc:creator>
				<category><![CDATA[Community]]></category>
		<category><![CDATA[Showcase]]></category>
		<category><![CDATA[volumeutils]]></category>
		<category><![CDATA[3d]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[contour]]></category>
		<category><![CDATA[generative]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[volumetric]]></category>

		<guid isPermaLink="false">http://toxiclibs.postspectacular.com/?p=61</guid>
		<description><![CDATA[It&#8217;s always still a nice surprise to spot other people&#8217;s experiments with these libraries in the wild. Just came across this beautiful example of using volumeutils by mariusz0z0Bydgoszczy, a cross section of an imaginary plant. Unfortunately no further info is available about the actual growth process, though it looks like a semi-random particle walk or [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s always still a nice surprise to spot other people&#8217;s experiments with these libraries in the wild. Just came across this beautiful example of using <a href="/category/volumeutils">volumeutils</a> by <a href="http://www.youtube.com/user/mariusz0z0Bydgoszczy" onclick="pageTracker._trackPageview('/outgoing/www.youtube.com/user/mariusz0z0Bydgoszczy?referer=');">mariusz0z0Bydgoszczy</a>, a cross section of an imaginary plant. Unfortunately no further info is available about the actual growth process, though it looks like a semi-random particle walk or <a href="http://en.wikipedia.org/wiki/Diffusion-limited_aggregation" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Diffusion-limited_aggregation?referer=');">DLA</a> method.</p>
<p><iframe title="YouTube video player" class="youtube-player" type="text/html" width="680" height="382" src="http://www.youtube.com/embed/Gqu-2n2hidg" frameborder="0" allowFullScreen="true"> </iframe></p>
<p>I especially like the amount &amp; colours of the contour layers used to visualize different densities. A similar (only in principle) thought also lead to the concept for the <a href="/2009/12/va-decode-generative-identity/">V&amp;A Decode Identity</a> completed recently. Just create a VolumetricSpace instance, use one of the preset VolumetricBrushes (or create your own one through sub-classing), use it to manipulate the &#8220;density&#8221; in the space and then pass the space instance to a IsoSurface to turn it into a TriangleMesh. Et voila! <a href="http://code.google.com/p/toxiclibs/source/browse/trunk/toxiclibs/examples/volume/VolumeBrush/VolumeBrush.pde" onclick="pageTracker._trackPageview('/outgoing/code.google.com/p/toxiclibs/source/browse/trunk/toxiclibs/examples/volume/VolumeBrush/VolumeBrush.pde?referer=');">Example code</a> for this basic approach comes with the <a href="http://code.google.com/p/toxiclibs/downloads/list" onclick="pageTracker._trackPageview('/outgoing/code.google.com/p/toxiclibs/downloads/list?referer=');">volumeutils library download</a>.</p>
<p><strong>UPDATE:</strong> There&#8217;s also an older, alternative version which is using sensor inputs to control its growth (so maybe the above process is related or even the same)&#8230;</p>
<p><iframe src="http://player.vimeo.com/video/7594282" width="680" height="382" frameborder="0"></iframe></p>
<blockquote><p>&#8220;this rhizome grows only if PIR sensor doesn&#8217;t detect movement [either nobody is in the room, or you stay still] amount of light measured by photocell influences branches girth. in this way, resulting form is a diagram of changing environmental conditions.&#8221;</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://toxiclibs.org/2010/01/ginger-section/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

