xxxxxxxxxx
/*-----------------------------
L-System Curves
Written by Travis McDaniel
February 29th - March 7th, 2017
mcdaniel.639@osu.edu
Program that draws tree-like patterns of curves
in a radial around the center of the canvas.
-----------------------------*/
//Library imports
//import processing.pdf.*;
//Global Variable Declaration
float strokeW = 6;
int imageCounter =0;
void setup()
{
size(4800, 4800);
background(255);
noFill();
stroke(0);
strokeWeight(strokeW);
}
void draw()
{
//Variable Declaration
float pi = 3.14159265359;
float rotation = pi/32;
float r = 0;
//Start writing to PDF
//beginRecord(PDF, "Capture###.pdf");
//Reset Background and Origin
background(255);
translate(width/2,height/2);
noFill();
//Center circle
ellipse(0,0,width/20,height/20);
//Rotate around the center and draw curve trees
while (r < 2*pi)
{
//Center line
strokeWeight(6);
line(0,0,0,height/40);
//Make a tree
tree(0,0,strokeW);
//Rotate the canvas
r+=rotation;
rotate(rotation);
}
//Stop PDF recording
//endRecord();
//Check if 100 recordings have been made
//if (imageCounter>100)
//{
noLoop();
//}
//else
//{
//imageCounter++;
//saveFrame("Capture###.tif");
//}
}
/*------------------------
Draw a tree at point (x,y)
-------------------------*/
void tree(float x, float y, float weight)
{
//Check end of recursion condition
if (weight<0.5)
{
}
//Main procedure
else
{
//Variables
strokeWeight(weight);
weight = 4*weight/7; //So we don't recur indefinitely
float branches = random(2,4);
float[] xValues = new float[0];
float[] yValues = new float[0];
//Draw the curved trunk
float newX = x;
float newY = y;
beginShape();
for(int i = 0; i<10; i++)
{
xValues = append(xValues, newX);
yValues = append(yValues, newY);
curveVertex(newX,newY);
newX += random(-75,75);
newY += random(20,120);
}
endShape();
//Draw the branches off the main stem using recursion
int index=0;
while (branches>0)
{
index += 2;
tree(xValues[index],yValues[index],weight);
branches--;
}
}
}