
Patrick B. answered 06/28/21
Math and computer tutor/teacher
Here is exactly what you are looking for.
This comes from the textbook:
title= The Waite Group's Object-Oriented Programming in Turbo C++
author = Robert LaFore
ISBN 1-878739-06-9
9-781878-739063
Publisher: Waiter Group Press 200 Tamal Plaza Corte Madera,CA 94925
pages 631-638
It uses the Borland C++ compiler
I transcribed the source code for you. Here it is:
-----------------------------------------------------------------------------------
#include <graphics.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <conio.h>
const int X0=320; //center of screen
const int Y0=240;
const float PI = 3.14159;
const int NUME=30; //numerator of probability
const int DENOM=100; //denominator of probability
const int NUMBER=7; //number of leaves per branch
const float rad=3.0; //radius
const float DELTHETA = 0.1; //change in angle theta in radians
const int SEGS=60; //max line segments per branch
const int REDUX=3; //how many divisions per line
const int MIN=1; //min # of line segments
class cluster
{
public:
void display(int size, int x, int y);
};
class tendril
{
public:
void display(int size, float theta, int x, int y);
};
void cluster::display(int size, int x0, int y0)
{
if (kbhit())
exit(0);
for (int i=0; i<NUMBER; i++) // for each tedril
{
float theta = i * 2 * PI/NUMBER;
int x = x0, y=y0;
moveto(x,y);
tedtril t;
t.display(size, theta,x,y);
}
}
void tendril::display( int size, float theta, int x, int y)
{
for (int j=0; j<size; j++)
{
int chng = ( random(DENOM)<NUME) ? -1 : 1; //left or right
theta = theta + chng*DELTHETA; //new angle
x = x + RAD*sin(theta); // x and y of next point
y = y + RAD*cos(theta);
if (size<4) setcolor(RED);
else if (size<13) setcolor(GREEN);
else if (size<40) setcolor(LIGHTGREEN);
else setcolor(YELLOW);
lineto(x,y); //draws the line
if (size > MIN) //if tedril is long enough, makes a new cluster
{
cluster c;
int newsize = size / REDUX; //but smaller than before
c.display(newsize,x,y); //displays it
}
}
}
void main()
{
int driver,mode;
dirver = VGA;
mode = VGAHI;
initgraph(&driver,&mode,"\\tc\\bgi"); // <---- will have to change this path to driver
randomize();
int x=X0, y=y0;
int size= SEGS;
cluster c;
c.display(size,x,y);
getch();
closegraph();
}