Bezier curve drawn using de Casteljau's algorithm, showing tangents.
I used Ching-Kuang Shene's
Computing with Geometry notes to help write the sketch.
This is actually an uniform rational B-spline (URBS) but can easily be converted to a NURBS (just use a non-uniform knot vector). See the Bezier example for a simpler piece of code using the same principle.
Click for a new surface.
This sketch shows the mathematics to create a Bezier curve. More control points can be added.
This is an implementation of an emergent Voronoi diagram, following an algorithm presented in programming.architecture by Paul Coates. It adapts the algorithm slightly to give a good convergence. Coates simply says "move away from the nearest node", which is wonderfully elegant!
Click for another pattern.
All-to-all particle spring system. Click to jiggle the particles.
Simple demo of a chain of particles strung together
Simple particle-spring demo. Click to restart.
A flock of Reynolds' boids. These boids use three rules to cohere, maintain separation and align themselves with each other.
A simple swarming algorithm for flies that (a) cohere and (b) avoid being too close to each other
A moving agent in a scene
Click the mouse to toggle between a fixed camera and a camera attached to the agent
Press a key to reset
Left-click to grow the tree, right-click to start again.
This is a third recursive tree example. This time, the main aim is to demonstrate the use of a scene graph in the Node class, but the Item class in rules.pde also builds on the L-system rules seen in previous examples.
This illustrates growing a tree using an L-system-like rule. For this example, I have kept the code simple.
Left-click to grow the tree, and right-click to start afresh. Do not click too quickly as you can run out of memory quickly!
Everyone has a recursive tree, this is mine. Click for a new tree.
A glider in Conway's game of life, 2D glider. This is a basic implementation to make the coding as transparent as possible.
A 1-D cellular automata using Wolfram's enumeration schema.
BZ reaction in <200 chars. Wait a while to see the swirls shown in the thumbnail emerge.
My previous trials with standard algorithms failed to fit 200 chars: the sketch needed to play to Processing's strengths. So here filter "diffuses" reagents and blend "reacts" them. The six panes are necessary to the process: vertically, each pane records levels of three reagents, horizontally, the panes act as a buffer for levels at the next time step.
(Uses the size trick, thanks dotlassie, but most of all, thanks Ben and Casey!)
This is a demo genetic algorithm.
I hope it can be taken apart and put to good use!
The algorithm attempts to maximise the square of the side lengths while minimising the volume of a box.
Better solutions are at the top right.
Click to restart.
This is a problem that a number of AAC students address each year: attempting to fit a regular mesh to a NURBS surface. This code gives the basics of moving points on a mesh covering a NURBS surface by changing their u,v coordinates as a starter. For more involved solutions, see for example
Martha Tsigkari, 2006, Tessellation of Arbitrarily Shaped Objects.
Click for a new surface.
A number of people have asked me how to access the z-buffer, especially now that g.zbuffer can no longer be accessed directly*, so this is a little demo to retrieve the real world depth at the mouse location.
You may need to click on this sketch to start the z-buffer read out working.
* You need to cast g to a PGraphics3D object
This is an attempt at creating some sand ripples or dunes by blowing a "wind" across a brightness level.
I'm not sure the mechanism is quite right, but it has the kind of effect I wanted...
(I'm having difficulty with this running on Opera on the Mac. Seems to be fine on Safari, Firefox or a PC. It should settle to look like the thumbnail after a short period.)
Instructions: left-click to test, and right-click (or ctrl+click on a Mac) to train.
This is a standard feedforward network with a single hidden layer.
The demo identifies handwritten numbers. The data are originally from the National Institute of Standards and Technology (USA). I used the MNIST processed versions available from
Yann LeCun and
Corinna Cortes.
After about 10 or so training clicks, the net should do a fairly good job of recognising numbers.
This is the same algorithm as the simple Belousov-Zhabotinsky reaction I posted previously, just using hue rather than brightness to display the amount of substrate "A" present, and with a modified parameter. It takes a little longer to get into producing the spiral waves.
For details about how it works, I've written a short implementation note:
BZ reaction implementation note (pdf)
This is a variation of DLA called 'ballistic aggregation', where particles are fired in a straight line at the aggregation. I have included a couple of tricks to speed it up: particles are fired from a distance of twice the maximum radius of the aggregation, and the angle is restricted according to where these could possibly adjoin the aggregation, otherwise it should be fairly straight-forward.
Enjoy!
This is a dynamic equilibrium equation for cellular automata which works on the principle of a Belousov-Zhabotinsky-like reaction. To make how it works clearer, I have separated the CA values into three concentrations of components 'a', 'b' and 'c'.
I have written a short implementation note for further details available here:
BZ reaction implementation note (pdf)