import processing.net.*; // Forest // based on L-system Classes // Built by blprnt for FlashBelt 2005 // blprnt@blprnt.com Tree[] tree = new Tree[20];//5]; Turtle gTurtle = new Turtle(); int gBgcolour = 255; float gStemred = 0; float gStemgreen = 0; float gStemblue = 0; float gStemalpha = 70; boolean gDoColourSwitch = false; boolean gWhiteToBlack = true; float gXness = 0.5; float gYness = 0.5; float gWind = 0.1; float gBranchThinkness = 1.0, gBranchMax = 1.0, gBranchMin = 100.0; float gLRDifference = 0.0; float gAnglechange = 0; float gGlobalAngleNess = 1; int INTERPOLATE_LINEAR = 0; int INTERPOLATE_EASEOUT = 1; int STATE_START = 0; int STATE_GROWING = 1; int STATE_GROWN = 2; int STATE_SHRINKING = 3; int gState = STATE_GROWN;//START; float TREE_GROWTH_RATE = 2.5; float SOUND_LEVEL_TO_WIND = 0.05; float SOUND_SENSITIVITY = 0.05; float[] gAngle_step_array = {0.0, 15.0, 30.0, 45.0, 60.0, 75.0, 90.0, 105.0, 120.0, 135.0, 150.0, 165.0, 180.0, -165.0, -150.0, -135.0, -120.0, -105.0, -90.0, -75.0, -60.0, -45.0, -30.0, -15.0 }; int gAngle_step_index = 2; int gAngle_step_next_index = 3; Interpolate gInter = new Interpolate(0, 0, 0, 0); boolean gUseSoundLevel = true; public int gVolL, gVolR; void setup() { size(400, 400, P3D); framerate(25); background(gBgcolour); gAnglechange = gAngle_step_array[gAngle_step_index]; for (int i = 0; i < tree.length; i++) { tree[i] = new Tree(); } noCursor(); }; void draw() { // clear the background background(gBgcolour); // if (!gReactive) { gBranchThinkness = 1.0; gLRDifference = 0.0; gBranchMax = 1.0; gBranchMin = 100.0; // } // draw all trees for (int i = 0; i < tree.length; i++) { tree[i].draw(); } if (gDoColourSwitch) { doColourSwitch(); } if (!gInter.getFinished()) { gInter.step(); gAnglechange = gInter.getValue(); } }; void doColourSwitch() { float distance = -1; float multiple = 0.1;//25; if (gWhiteToBlack) { distance = - gBgcolour; gBgcolour += (distance * multiple); distance = 255 - gStemred; gStemred += (distance * multiple); distance = 255 - gStemgreen; gStemgreen += (distance * multiple); distance = 255 - gStemblue; gStemblue += (distance * multiple); } else { distance = 255 - gBgcolour; gBgcolour += (distance * multiple); distance = - gStemred; gStemred += (distance * multiple); distance = - gStemgreen; gStemgreen += (distance * multiple); distance = - gStemblue; gStemblue += (distance * multiple); } float absChange = abs(distance); if (absChange < 5) { gDoColourSwitch = false; gWhiteToBlack = !gWhiteToBlack; if(gStemred < 5) { gStemred = 0; gStemgreen = 0; gStemblue = 0; } else { gStemred = 255; gStemgreen = 255; gStemblue = 255; } } else { } } //-------------------------------------------------------------- // mouse and key event handlers //-------------------------------------------------------------- void mousePressed() { }; void mouseMoved() { gXness = float(mouseX) / float(width); gYness = float(mouseY) / float(height); } void keyPressed() { } void keyReleased() { if (key == '0') { gState = STATE_START; } if (key == '1') { gState = STATE_GROWING; } if (key == '2') { gState = STATE_GROWN; } if (key == '3') { gState = STATE_SHRINKING; } if (key == 'b' || key == 'B') { gDoColourSwitch = true; } if (key == 'i' || key == 'I') { gBgcolour = 255 - gBgcolour; gStemred = 255 - gStemred; gStemgreen = 255 - gStemgreen; gStemblue = 255 - gStemblue; } // reset if (key == ' ') { for (int i = 0; i < tree.length; i++) { tree[i] = new Tree(); } } if (key == ',') { gInter.setValue(gAnglechange); gInter.setStartValue(gAnglechange); if (gAngle_step_index > 0) { gInter.setEndValue( gAngle_step_array[--gAngle_step_index]); } else { gInter.setEndValue( gAngle_step_array.length - 1 ); gAngle_step_index = gAngle_step_array.length - 1; } gInter.setTotalFrames(10); gInter.setCurrentFrame(0); gInter.setType(INTERPOLATE_LINEAR); gInter.start(); } if (key == '.') { gInter.setValue(gAnglechange); gInter.setStartValue(gAnglechange); if (gAngle_step_index < gAngle_step_array.length - 1) { gInter.setEndValue( gAngle_step_array[++gAngle_step_index]); } else { gInter.setEndValue( 0 ); gAngle_step_index = 0; } float sv = gInter.getStartValue(); float ev = gInter.getEndValue(); gInter.setTotalFrames(10); gInter.setCurrentFrame(0); gInter.setType(INTERPOLATE_LINEAR); gInter.start(); } if (key == CODED) { // wind on UP and DOWN // could do gust key - some sort of easeing eq? if (keyCode == UP) { gWind += 0.05; } if (keyCode == DOWN) { gWind -= 0.05; } // println("keyCode = " + keyCode + ", LEFT = " + LEFT + ", SHIFT = " + SHIFT); if (keyCode == LEFT) { this.gAnglechange++; } if (keyCode == RIGHT) { this.gAnglechange--; } } }