void drawTree(double x, double y, double r, double theta, int depth) { if (depth < MAX_DEPTH) { double growth = randomReal(0.1, 0.4); setColor(TREE_COLORS[depth]); GPoint branchPt = drawPolarLine(x, y, r * growth, theta); int numChildren = randomInteger(2, 8); for (int i = 0; i < numChildren; i++) { double thetaPrime = theta + randomReal(-45, +45); drawTree(branchPt.getX(), branchPt.getY(), (1.0 - growth) * r, thetaPrime, depth + 1); } } }
GPoint GDrawingSurface::drawPolarLine(const GPoint& p0, double r, double theta) { return drawPolarLine(p0.getX(), p0.getY(), r, theta); }