String FILENAME = "Morris2c_toggleInput"; // UPDATE THIS!! import processing.pdf.*; import processing.opengl.*; import processing.video.*; import blobDetection.*; Capture cam; PrintWriter dataOutput; ///////////////////////////////////////////////// Blobs b; Line l []; Plant plantList []; ArrayList a; Attributes FlowerParent, PetalChild, BranchParent, StemParent, LeafChild; //Attributes ground; Butterfly bfly; int lineCount; float MAX_DIST =12;//4;//40 float sinLUT[]; int ARRAY_LENGTH= 360;//int((360.0/SINCOS_PRECISION)); ////// int newPlantCounter = 0; int newPlantTarget = int (random (190, 250)); ///////////////////////////////////////////////////////////////// /////////// DEFINE A SET OF STRINGS ///////////////////////////// String [] stemString = { "SSSSSS*"};// "SSSSSSSE*", "SSSSSSSSSE*", "SSSSSSSSSSSE*"};//"SE*"; String [] branchString = { "SSNLSSSNLSSSNLSE*", "SSSSNLSSSSSSNLSSSE*"};//"SE", "FNLFFNLF*" }; //"SE"}; String [] leafString = { "FF*", "FF*"};// "F+l-lFF*", "F+l-lFFF*"}; String [] flowerString = { "FNp*"}; String [] petalString = { "FFFF*", "FFFF*"}; /////////////////////////////////////////////////////////// String [] segArray = { "FBFBF", "FFBF", "FFF"}; String [] endArray = { "F2LFL*", "Fff*"} ;//"ff...............................................................................................P*"}; //////////////////DEFINE A NEW PLANT SPEC : PLANT 2////// String [] stemString2 = { "SSSSSS*"};// "SSSSSSSE*", "SSSSSSSSSE*", "SSSSSSSSSSSE*"};//"SE*"; String [] branchString2 = { "SSNLSSSNLSSSNLSE*", "SSSSNLSSSSSSNLSSSE*"};//"SE", "FNLFFNLF*" }; //"SE"}; String [] leafString2 = { "FF*", "FF*"};// "F+l-lFF*", "F+l-lFFF*"}; String [] flowerString2 = { "FNp*"}; String [] petalString2 = { "FFFF*", "FFFF*"}; String [] segArray2 = { "FBFBF", "FFBF", "FFF"}; String [] endArray2 = { "F2LFL*", "Fff*"} ; /////////// DEFINE A SET OF COLOURS //////////////////////////// color l1 = color (216, 235, 35);//(47, 140, 20); // light color l2 = color (60, 80, 0); //(122, 155, 0);//(47, 60, 20); // dark color f1 = color (235, 237, 228);//(223, 217, 217);//(35, 90, 152);//(132,105,206); color f2 = color (219, 202, 117);//(244, 250, 225);//(256, 100, 160); //(256, 0, 0); //(49,21,237); color stem1 = color (20, 35, 0); color stem2 = color (6, 6, 0); /////////////////////////////////////////////// //float leafAngle = 12; int MAXDEPTH =3;/// SETS A LIMIT ON THE NUMBER OF SUB-BRANCHES (RECURSION) float UNIT_LENGTH = 60*0.78; // USE THIS TO CONTROL THE OVERALL SIZE OF ALL THE ELEMENTS RELATIVE TO EACH OTHER //int SEG_LENGTH = 60;// 30 80 60; // seg length = time * radius ///////////////////////////////////////////////// boolean record; int filecount; // number of screen grabs /////////////////////////////////////////////////// int petalNum; int petalSpan; int leafNum; float stemSineLength, stemSineStart, stemWidth; //////////////////////////////////////////////////// Attributes ground = new Attributes (); color bground = color (256, 256, 256);//(242, 256, 238 );//(180, 180, 25);//(170, 180, 100); color colorBground, colorBgroundDark ; //red(l2), green (l2), blue (l2); //color (232, 242, 230); // colorued background int count= 0; boolean flowerspin = false;// false; // give flowers and random angle (true) or not (false); //////////////////////////////////////////////////////////////////// Vector3D plantLoc; float plantAngle; String repeatType = "RANDOM_EDGES";//"TILE_CONTINUOUS"; // can be "RANDOM", "CENTRE", "BASE" or "TILE1" (a continuous tile) or "TILE2" (tiles from opposite side) String inputSource = "MOUSE"; // or MOUSE or CAMERA to toggle between different elements to respond to.. ////////////////////////////////////////////////// ////////////////////////////////////////////////// String date = day () + ":" + month () + ":" + year (); String time = hour () + "." + minute (); String foldername = date + "_" + time; /////////////////////////////////////////////////////////////// boolean printdata = false; /// output data ?? boolean sketchMode = false; boolean fillMode = true; // if fillMode = false: show as wireframe boolean light = false; ////////////////////////////////////////////////// /////////////////////////////////////////////// void captureEvent(Capture cam){ cam.read(); //newFrame = true; } ////////////// void setup () { //size (900, 600, OPENGL); //size (758, 650, OPENGL); // 10 x 8 ratio (1: 1.167) size (1100, 500, OPENGL); // web size (factored by 0.78) (1400, 650, OPENGL);// //size (1200, 900, OPENGL); // 4: 3 /// OTHER SIZES FOR THIS RATIO: 759x650 // 817x700 // 875x750 // frameRate (80); hint (DISABLE_DEPTH_TEST);// this works!! background (bground); ellipseMode (CENTER); if (inputSource == "CAMERA") { println (Capture.list ()); String s = "IIDC FireWire Video";//"MXV330i";//"SN9C201+MI0360 WebCam"; // cam = new Capture(this, 40*1, 30*1,s); // parent, width, height, name, fps cam = new Capture(this, 40*1, 30*1); // parent, width, height, name, fps } /////////////////////////////////////////////////// colorMode (HSB, 100); colorBground = color ( hue (l1), 30, 95); // H S = 5, B = 95 colorBgroundDark = color (hue (l2), 85, 6); //(15, 20, 79); //color (hue (l1), 85, 10); // HSB // DARK colorMode (RGB, 255); bground = colorBgroundDark; if (printdata) { outputFileData (); } ////// FILL SINE LUT ///////////////////////////// sinLUT=new float[ARRAY_LENGTH]; for (int i = 0; i < ARRAY_LENGTH; i++) { sinLUT[i] = sin (radians (i)); } /////////////////////////////////////// l = new Line [10000]; leafNum = 2; petalNum = 8;//6 petalSpan = 360; // degrees span stemWidth = 6; stemSineStart = 90; stemSineLength = 90; /////CREATE NEW FLOWER AND PETAL OBJECTS (as Parent and Child) ////////// /// SET UNIT LENGTH OF FLOWER - SO IT CAN BE INHERITED AND CHANGED BY PETAL // PARAMETERS = (type, stringArray, color1, color2, petalNum, petalAngle, lo, hi, maxWidth, unitLength randomSpin? FlowerParent = new Attributes ("flower", flowerString, f1, f2, petalNum, petalSpan/petalNum, 0, 0, 30, UNIT_LENGTH*.3, flowerspin); BranchParent = new Attributes ("branch", branchString, l1, l2, leafNum, 90, 120, 140 , stemWidth, UNIT_LENGTH*.25, false); StemParent = new Attributes ("stem", stemString, l1, l2, leafNum, 90, 120, 280, stemWidth, UNIT_LENGTH*.9, false); // PARAMETERS = (Parent, type, string, sineStart, sineLength, minWidth, maxWidth, deviation, SHAPENOISE, unitLegnth PetalChild = new Attributes (FlowerParent, "petal", petalString, 0, 190, 4, 0, 3, 10, 0); LeafChild = new Attributes (BranchParent, "leaf", leafString, 0, 180, 2, 16, 0, 6, UNIT_LENGTH*.8);// shapenoise 7?/ /////////////////////////////////////////////////////////////////////////////// /////CREATE A ARRAY OF PLANTS //////////////////////////////////////////// Vector3D startPlantLoc = new Vector3D (random (width-50)+25, height+10); plantList = new Plant [1]; plantList[0] = new Plant (StemParent, BranchParent, LeafChild, FlowerParent, PetalChild, startPlantLoc); // lo, hi, petalCount, leafAngle, petalAngle //plantList[1] = new Plant (StemParent, BranchParent, LeafChild, FlowerParent, PetalChild); // lo, hi, petalCount, leafAngle, petalAn // plantList[1] = new Plant (Stem, Branch, Leaf, Flower, Petal, 20, 300, 4, 45, 12); // lo, hi, petalCount //////////////////////////////////////////// //Vector3D loc = new Vector3D (200, height/4, 0); setPlantLoc(0); Target t = new Target (plantList[0], plantList[0].Stem, plantLoc, plantAngle, 0, 0); // loc, angle, string, parent // depth a = new ArrayList (); a.add (t); ///////////////////////////////////// //bfly = new Butterfly (); //////////////////////////////// if (printdata) { dataOutput.close(); // Finishes the data file } b = new Blobs (); } ////////////////////////////////////////////// void draw () { //background (c1, 20); background (bground); // (bground); newPlantCounter ++; // println (newPlantCounter); if (newPlantCounter%newPlantTarget == 0) { //println ("NEW PLANT"); createNewPlant (); newPlantTarget = int (random (150, 250)); newPlantCounter = 1; } //////////////////////////////////////// if (record) { beginRaw (PDF, foldername + "/" + foldername + "_" + FILENAME + "_" + filecount+".pdf"); fill (bground); /// PRINT WITH TRANSPARENT BACKGROUND (NO RECT ()) rect (0, 0, width, height); // remove this to print on transparent background.. } ///////////////////////////////// if (inputSource == "CAMERA") { b.goBlobs (); } ////////////////////////////////// if (fillMode == false) { strokeWeight (0.2); stroke (100, 100, 100);//(24, 54, 126, 90); //(0, 0, 0, 90); noFill (); } else { noStroke(); } ////LIGHTS ////////////////////// //directionalLight(126, 126, 126, 0, 0, -1); //spotLight(235, 191, 232, width, height/2, 300, -2, 0, -1, PI/2, 2); if (light) { pointLight (256, 256, 256, 30, 30, 20); // (red (l1), green (l1), blue (l1), 35, 40, 36); //(35, 191, 232, 35, 40, 36); ambientLight (256, 256, 256); //(red(l1), green (l1), blue (l1)); //(35, 191, 232);//(150, 14, 142);//(102, 240, 120); // rgb } /////////////////////////////// for (int i=1; i<=lineCount; i++) { // Line l = (Line) lines.get (i); //l.run (); l[i].run (); } /////////////////////////// for (int i=0; iwidth) { x=0; plantAngle = 0; } if (y<0) { y =height; plantAngle = 270; } if (y>height) { y = 0; plantAngle = 90; } ///////////////////////////////// plantLoc = new Vector3D (x,y); } } //////////////////////////////////////////////////////////// void outputFileData () { dataOutput = createWriter (foldername + "/" +"data.txt");// ("data.txt"); dataOutput.println (FILENAME); dataOutput.println (date + " " + time); dataOutput.println (); dataOutput.println ("MAX_DIST: " + MAX_DIST); dataOutput.println ("UNIT_LENGTH: " + UNIT_LENGTH); dataOutput.println ("flowerspin: " + flowerspin); dataOutput.println ("repeatType: " + repeatType); dataOutput.println ("UNIT_LENGTH: " + UNIT_LENGTH); dataOutput.println ("colorBground: r:" + red (colorBground) + " g:" + green (colorBground) + " b:" + blue (colorBground)); for (int i=0; i