[Need help] How to build GUI?
in
Contributed Library Questions
•
1 years ago
How to build GUI with this script?
- import processing.opengl.*;
import java.text.*;
import lsystem.*;
import peasy.*;
PeasyCam cam;
Grammar grammar;
float distance =50;
int depth = 4;
float alph = radians(15); //rotateX
float beta = radians(15); //rotateY
float delta = radians(15); //rotateZ
String production = "";
void setup() {
size(900, 700, OPENGL);
configureOpenGL();
configureCamera();
setupGrammar();
noStroke();
}
void configureCamera(){
cam = new PeasyCam(this, 100);
cam.setMinimumDistance(100);
cam.setMaximumDistance(500);
}
void configureOpenGL(){
hint(ENABLE_OPENGL_4X_SMOOTH);
hint(DISABLE_OPENGL_ERROR_REPORT);
}
void setupGrammar(){
int generations = 5;
String axiom = "F";
grammar = new StochasticGrammar(this, axiom);
grammar.addRule('F', "GH[\\+F]F__[-_F]__[-_F]__[\\F]");
grammar.addRule('F', "GH_[\\+F]F[-_F]_[-_F]_[//F]");
grammar.addRule('F', "GH__[\\+F]_F[-_F][-_F][\\F]");
grammar.addRule('G', "GH");
production = grammar.createGrammar(generations);
distance *= pow(0.5, generations);
}
void draw() {
background(#ffffff);
lights();
render();
}
void render() {
translate(0, -50, 0); // center the plant empirically set looks OK to me
lightSpecular(0, 175, 0);
specular(0, 255, 0);
shininess(1.0);
CharacterIterator it = new StringCharacterIterator(production);
for (char ch = it.first(); ch != CharacterIterator.DONE; ch = it.next()) {
switch (ch) {
case 'F':
translate(0, distance/2, 0);
box(distance/9, distance, distance/9);
translate(0, distance/2, 0);
fill(0, 175, 0);
break;
case 'G':
translate(0, distance/2, 0);
box(distance/9, distance, distance/9);
translate(0, distance/2, 0);
break;
case 'H':
translate(0, distance/2, 0);
box(distance/9, distance, distance/9);
translate(0, distance/2, 0);
break;
case '+':
rotateX(alph);
break;
case '-':
rotateX(-alph);
break;
case '_':
rotateY(beta);
break;
case '^':
rotateY(-beta);
break;
case '\\':
rotateZ(delta);
break;
case '/':
rotateZ(-delta);
break;
case '[':
pushMatrix();
break;
case ']':
popMatrix();
break;
default:
System.err.println("character " + ch + " not in grammar");
}
}
}
1