/**
* Constants
* (A-Z) Draw forward; (a-z) Not drawing; (f) Forward; (+) Turn left; (-) Turn right
* (^) Turn up; (_) Turn down; (\) Bank left; (/) Bank right
* ( [ ) Save current transformation; ( ] ) Call last saved transformation
* Mouse left button = rotate view
* Mouse right button = zoom view
* Mouse midle button = pan view
* Code writen by Bojan Mitrovic,
* Faculty of Architecture, Belgrade 2009.,
* Generic Explorations Lab.
*/
import java.awt.TextField;
import java.awt.Panel;
import java.awt.Label;
// Camera
float cx,cy,cz,ax,ay,az;
float ex = 0;
float ey = 0;
// UI
TextField variables = new TextField("F",5);
TextField rules = new TextField("F=F+F++F+F",20);
TextField initialState = new TextField("F",5);
TextField angleX = new TextField("30",3);
TextField angleY = new TextField("30",3);
TextField angleZ = new TextField("60",3);
TextField lineLength = new TextField("40",3);
TextField lineWidth = new TextField("3",1);
TextField startColor = new TextField("000000",4);
TextField endColor = new TextField("000000",4);
TextField ni = new TextField("3",3);
TextField bgColor = new TextField("FFFFFF",4);
Panel UI = new Panel();
Panel UI1 = new Panel();
Panel UI2 = new Panel();
//initial
color ccc = color(#ffffff);
String r;
String drawForward = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String noDraw = "abcdefghijklmnopqrstuvwxyz";
void setup() {
size(640,480,P3D);
//UI.setLayout(new FlowLayout(FlowLayout.CENTER));
UI.add(new Label("Variables:"));
UI.add(variables);
UI.add(new Label(" Rules:"));
UI.add(rules);
UI.add(new Label(" Initial state:"));
UI.add(initialState);
UI1.add(new Label("Angle X, Y & Z:"));
UI1.add(angleX);
UI1.add(angleY);
UI1.add(angleZ);
UI1.add(new Label(" Line length:"));
UI1.add(lineLength);
UI1.add(new Label(" Iterations:"));
UI1.add(ni);
UI2.add(new Label("Line width:"));
UI2.add(lineWidth);
UI2.add(new Label("Start color:"));
UI2.add(startColor);
UI2.add(new Label("End color:"));
UI2.add(endColor);
UI2.add(new Label("Background color:"));
UI2.add(bgColor);
this.add(UI);
this.add(UI1);
this.add(UI2);
perspective();
}
void draw() {
// Prepare scene
try {
ccc = color(unhex(bgColor.getText()));
} catch(NumberFormatException eee) {
ccc = color(#ffffff);
}
background(ccc);
strokeWeight(float(lineWidth.getText()));
// Center camera
translate(width/2,height/2,0);
// Camera transformation
translate(cx,cy,cz);
rotateX(radians(ax));
rotateY(radians(ay));
rotateZ(radians(az));
evaluateString();
// Interpretate String
float ll = float(lineLength.getText());
float lrx = radians(float(angleX.getText()));
float lry = radians(float(angleY.getText()));
float lrz = radians(float(angleZ.getText()));
for(int i=0;i1) {
l = arrRule[1];
}
}
c=c+l;
}
r=c;
}
//println(r);
loop();
}
// Camera handling
void mousePressed() {
ex = mouseX;
ey = mouseY;
if (mouseButton == LEFT) {
}
else if (mouseButton == RIGHT) {
}
else {
}
}
void mouseDragged()
{
if (mouseButton == LEFT) {
noLoop();
az += (ex-mouseX)*0.25;
ax += (ey-mouseY)*0.25;
ex = mouseX;
ey = mouseY;
loop();
}
else if (mouseButton == RIGHT) {
cz += (ex-mouseX);
cz += (ey-mouseY);
ex = mouseX;
ey = mouseY;
loop();
}
else {
noLoop();
cx -= ex-mouseX;
cy -= ey-mouseY;
ex = mouseX;
ey = mouseY;
loop();
}
}
void keyPressed() {
if (key == CODED) {
if (keyCode == UP) {
cy += 1;
}
else if (keyCode == DOWN) {
cy -= 1;
}
else if (keyCode == LEFT) {
cx += 1;
}
else if (keyCode == RIGHT) {
cx -= 1;
}
}
}