/* BubbleTree * By Jacob Joaquin * * jacobjoaquin@gmail.com * Thumbuki http://www.thumbuki.com/ * * Copyright (C) 2008 Jacob Joaquin * License: GNU LESSER GENERAL PUBLIC LICENSE * http://www.gnu.org/licenses/lgpl.txt * * * Tested with Processing 0135 Beta. */ void setup() { size(500, 302); smooth(); noLoop(); } void draw() { background(0); fill(255, 128); noStroke(); /* Create two bubbleTrees */ bubbleTree(width * 0.618, height, 2, 8, 0.1, radians(-90), radians(30), 70); bubbleTree(width * 0.382 * 0.618, 0, 1, 6, 0.1, radians(90), radians(25), 70); } void bubbleTree(float lastX, float lastY, float minSegmentLength, float maxSegmentLength, float odds, float lastAngle, float spread, int numberOfSegmentsLeft) { float angle = ((random(1) - 0.5) * spread) + lastAngle; float length = random(1) * (maxSegmentLength - minSegmentLength) + minSegmentLength; float x1 = cos(angle) * length + lastX; float y1 = sin(angle) * length + lastY; ellipseMode(CENTER); ellipse((x1 + lastX) * 0.5, (y1 + lastY) * 0.5, length * 0.5, length * 0.5); if (numberOfSegmentsLeft > 1) { bubbleTree(x1, y1, minSegmentLength, maxSegmentLength, odds, angle, spread, numberOfSegmentsLeft - 1); if (Math.random() < odds) { bubbleTree(x1, y1, minSegmentLength, maxSegmentLength, odds, angle, spread, numberOfSegmentsLeft - 1); } } } void mousePressed() { redraw(); }