xxxxxxxxxx
35
// The Nature of Code
// Daniel Shiffman
// http://natureofcode.com
// Cantor Set
// Renders a simple fractal, the Cantor Set
function setup() {
createCanvas(640, 640);
background(255);
// Call the recursive function
strokeWeight(2);
cantor(10, 10, 620);
}
function draw() {
// No need to loop
noLoop();
}
function cantor(x, y, length) {
//{!1} Stop at 1 pixel!
if (length > 8) {
line(x, y, x + length, y);
textAlign(CENTER);
textSize(24);
text("A", x + length / 2, y + 24);
text("B", x + 1.5*length, y + 24);
text("B", x - 0.5*length, y + 24);
cantor(x, y + 100, length / 3);
cantor(x + (2 * length) / 3, y + 100, length / 3);
}
}