// Flower generation - Jeff Clark, Aug 23rd, 2006 // This application is based on the one found online at http://rpi.edu/~mcdonk/code/flower/ . // The source is hacked together but has some interesting ideas. // Set bCreateOne = true; in the setup function to get a flower when first run. // Uncomment the MousePressed() method to make a new one on a click. int maxle, maxra, lightd, lvar, la, darkd, dvar, da, maxbright, brightvar, sa, basehu, inithuvar, huvar; float minbend, edgevar, maxedgevar, edgemem, stepinc, wot, hot, steple, edgememp1, petalsperlevel, dHairSparseness; float edgeWidth; float fExternalHue; boolean bCreateOne; float fHue1, fHue2, fHue3; float[] toRect(float ra, float th) { float[] ou={sin(th)*ra,cos(th)*ra}; return ou; } void setup() { int iMrg = 30; int iHgt = 20; framerate(5); randomSeed(0); background(255); size(400,400); setParms(); bCreateOne = false; fExternalHue = 128; fHue1 = 0; fHue2 = 160; fHue3 = 40; } void setParms() { wot=width/2; hot=height/2; colorMode(HSB); maxle=(int)random(3,10); //layers of petals maxra=(int)random(120,160); //initial radius edgevar=random(50,200); //velocity on random edge variance, low values -> smoother edges maxedgevar=random(10,60); //max edge deviation edgemem=random(300,600); //memory for the edge randomness, low values -> really jagged but depends on edgevar lightd=(int)random(5,15); //light distance lvar=(int)random(5,20); //light randomness variance la=(int)random(5,20); //light alpha multiplier darkd=(int)random(10,20); //(int)random(10,20); //dark distance dvar=(int)random(10,20); //dark randomness variance da=(int)random(8,18); //dark alpha multiplier dHairSparseness = 0;//.75;//random(0,1); // lower values - > less hair maxbright=240;//(int)random(200,240); //maximum brightness of petals brightvar=0;//120;//150;//(int)random(50,150); //maxbright-brightvar is the brightness at the center sa=240;//(int)random(180,255); //saturation basehu=128; //color center inithuvar=128; //color variance huvar=(int)random(5,25); //step variance stepinc=.0015; steple=maxra/maxle; edgememp1=edgemem+1; //for speed edgeWidth = random(.80,1); if(random(0,1) < .8) edgeWidth = 1; edgeWidth = .95; //minbend=random(.05,.80); //random(.65,.80); //"bend" on petals (1=circles) minbend=random(.00,.70); //"bend" on petals (1=circles) } void CreateRose(float fh1, float fh2, float fh3, float fSat, float fBrightness, float fHairiness, float fEdgeVariance, float fMinBend, int iLevels, int iRandomseed) { //background(iback); randomSeed(iRandomseed); setParms(); fHue1 = fh1; fHue2 = fh2; fHue3 = fh3; sa = (int)fSat; brightvar = (int) fBrightness; maxle = iLevels; dHairSparseness = fHairiness; edgevar = 50 + 150 * fEdgeVariance; minbend = fMinBend; bCreateOne = true; } void CreateRose(int iback) { //background(iback); setParms(); fHue1 = iback; fHue2 = fHue3 = fHue1; bCreateOne = true; } void draw() { //if(IsNewText()) if(bCreateOne) { background(255); rose(); bCreateOne = false; } } void mousePressed() { /* setParms(); fHue1 = nonGreenRandomHue(); fHue2 = nonGreenRandomHue(); fHue3 = fHue1; maxle=(int)random(3,5); //layers of petals bCreateOne = true; */ } float nonGreenRandomHue() { float hu = random(0,255); // eliminate green while(hu > 42 && hu < 110) { hu = random(0,255); } return hu; } /* void mouseReleased() { noLoop(); } */ void rose() { translate(wot,hot); /* float hu = random(basehu-inithuvar,basehu+inithuvar); // eliminate green while(hu > 42 && hu < 110) { hu = random(basehu-inithuvar,basehu+inithuvar);; } */ float hu = fExternalHue; for(float le=0;le