[net.graphics] right arms {fractal code}

rich@sdcc13.UUCP (rich) (07/06/85)

in response to the discussion on fractals
in net.graphics:

(no flames for posting this to two groups please, it is short)
/*
 * This is a simple fractal curve based on the making of a fractal
 * snoflake. I cant post the snoflake since i did not author
 * the code to it. By manipulating the side() {
 *                                  side (.....);
 *                                  side (.....);
 *                                  side (.....);
 *                                             }
 *
 *      theme you can build up most of the 2-d objects in
 * Mandelbrotts` book plus much much more. (this is one of those
 * mores). 
 *    This will run on a sun workstation, or by modifying the
 *                    line_rel_2 (dx, dy);
 * line, to draw relative vectors on your graphics device, it
 * will draw there. This particular `fractal` will look real
 * nice if you have a polygon fill routine which can handle
 * this mesh of relative vectors. 
 *    
 *   I chose this particular picture because i liked it an i
 * was suprised by it. If you wish to understand why it
 * works read 'the fractal geometry of nature' , of course.
 * A lot of credit for helping get started on this goes to
 * Jim Hutchinson ( hutch@sdcsvax).
 * 
 *   I`ll take those right arms now.
 *  
 *           -rich
 *   ihnp4--\                                        
 *   decvax--\	
 *   akgua----\
 *   dcdwest---\
 *   somewhere--\
 *   ucbvax-------- sdcsvax -- sdcc3 --rich
 *   
 */   

#define SQRT2		1.41421
#define PI		3.1415927
#define PIO4		(PI / 4.0)
#define TWOPIO3		(2.0 * PI / 3.0)
#define PIO3		(PI / 3.0)
#define PIO2		(PI / 2.0)
#define TWOPI		(2.0 * PI)
#define MOD(a,b)	while(a > b) a -= b

#include <math.h>
#include <usercore.h>

main () {
    double  length = 45.0;
    double  angle = PIO2;
    double  depth = 0.75;

    nice_shape (length, angle, depth)
}


side (size, min, angle)
double  size,
        min,
        angle;
{
    if (size <= min)
	plot_line (size, angle);
    else {
	size /= 3.0;
	side (size, min, angle + PI);
	side (size, min, angle + PI / 2.0);
    }
}

nice_shape (len, angle, depth)
double  len,
        angle,
        depth;
{
    side (len, depth, angle);
    side (len * 100, depth * 2.0, angle + PIO2);
    side (len, depth, -angle);
    side (len * 100, depth * 2.0, angle - PIO2);
}



/*
 *	Plot a line by length and angle from current position
 */

plot_line (length, angle)
double  length,
        angle;
{
    double  dx,
            dy;

    MOD (angle, TWOPI);

    dx = length * cos (angle);
    dy = length * sin (angle);

    line_rel_2 (dx, dy);
}