how can i build this with tissue and servos?
class Flower {
float xC,yC;
int leafcount;
color col;
float luminance;
float lineColor;
int factor;
int showLeafs = 1;
Leaf[] leafs;
Flower() {
col = changeColor();
}
public void setLeafs(int amount) {
leafcount = amount;
leafs = new Leaf[leafcount];
addLeafs();
}
void addLeafs() {
float angle = 360/leafcount;
float l = width/2;//random(factor*1.5,factor*1.85);
float w = width/6;//random(factor*0.75,factor*1.25);
float factorX = random(2,3);
float factorY = random(2);
float x1 = w/factorX;
float y1 = l/factorX;
float x2 = factorX*w/factorX;
float y2 = factorY*l/factorX;
for(int i=0;i<leafcount;i++) {
leafs[i] = new Leaf(xC,yC,i,angle);
leafs[i].setDimension(l,w);
leafs[i].setBezier(x1,y1,x2,y2);
leafs[i].setDetail(leafcount);
leafs[i].setColor(this.col);
leafs[i].setLineColor(this.lineColor);
leafs[i].setLuminance(this.luminance);
}
}
public void setLuminance(float lum) {
this.luminance = lum;
}
public void setLineColor(float lc) {
this.lineColor = lc;
}
public void setPosition(float x_, float y_) {
xC = x_;
yC = y_;
}
public void render()
{
stroke(this.lineColor, this.luminance);
fill(this.col, this.luminance);
pushMatrix();
for(int i=0;i<leafcount;i++) {
leafs[i].renderLines();
}
popMatrix();
pushMatrix();
if (showLeafs <= leafcount) {
for(int i=0;i<showLeafs;i++) {
leafs[i].render(true);
}
showLeafs++;
} else {
showLeafs = 0;
delay(1500);
this.randomize();
}
popMatrix();
ellipse(0,0,10,10);
//scale(random(-100,100));
}
void randomize() {
this.setLeafs((int)random(3,13));
//this.setLuminance((int)random(110,240));
this.setLuminance(255);
this.setColor(this.changeColor());
if ( flipflop ) {
this.setLineColor(0);
} else {
this.setLineColor(255);
}
flipflop = !flipflop;
}
public void renderLeaf()
{
float old;
leafs[0].xpos = 0;
leafs[0].ypos = 0;
old = leafs[0].luminance;
leafs[0].luminance = 255;
leafs[0].render(false);
leafs[0].luminance = old;
}
color changeColor() {
color from = color(random(70,255),random(70,255),random(70,255),90);
color to = color(random(255),random(255),random(255),90);
col = lerpColor(from, to, 90);
return col;
}
color setColor(color c) {
col = c;
return c;
}
}
//import processing.opengl.*;
//import javax.media.opengl.*;
//import com.processinghacks.arcball.*;
int w = 4;
int h = 4;
int factor = 150;
int [] flowercolors; //Array to store sampled flower colours (this could be an ArrayList)
int numFlowers = 1; // Always set = 1
Flower[] elements;
int [] showFlower;
boolean flipflop = false;
PFont myFont;
void setup() {
size(600,600);
//ArcBall arcball = new ArcBall(this);
noCursor();
smooth();
loop();
//String[] fontList = PFont.list();
//println(fontList);
// Set the font and its size (in units of pixels)
myFont = createFont("arial",12,false);
elements = new Flower[numFlowers];
showFlower = new int[numFlowers];
int count = 0;
for(int i=0;i<numFlowers;i++) {
this.showFlower[count] = 0;
elements[count] = new Flower();
elements[count].factor = this.factor;
// elements[count].setLuminance((int)random(110,240));
elements[count].setLuminance(255);
if ( flipflop ) {
elements[count].setLineColor(0);
} else {
elements[count].setLineColor(255);
}
flipflop = !flipflop;
elements[count].setLeafs((int)random(3,13));
//elements[count].setPosition(random(width),random(height));
elements[count].setPosition(width/2,height/2);
count++;
}
println("Added .." + count);
}
void draw(){
smooth();
background(255);
int show = (int)random(numFlowers);
renderFlower(show);
this.showFlower[show] = 1;
delay (560);
}
void renderFlower(int count) {
pushMatrix();
translate(elements[count].xC,elements[count].yC);
elements[count].render();
popMatrix();
textFont(myFont, 14);
stroke(0);
fill(255);
rect(0,0,elements[count].leafs[0].w/2 + 30, elements[count].leafs[0].l/2);
textAlign(LEFT);
fill(0);
stroke(elements[count].lineColor);
text(elements[count].leafcount + "x " + elements[count].leafs[0].angle + "°",
10,14);
elements[count].renderLeaf();
}
/*
void keyPressed() { // Press a key to save the data
saveFrame("flowers-########.jpg");
}*/
public class Leaf {
float xpos;
float ypos;
float angle;
float unitsize;
int detail;
float luminance;
float lineColor;
// Basic quantity descriptors
float l; // maximum length
float w; // maximum width
float a; // area
float h; // Convex hull
float p; // perimeter
// Dimensionless shape factors
float c; // Compactness
float r; // Roundness
float e; // Elongation
float g; // Roughness
// Bezier descriptors
float dx1 = 0;
float dy1 = 0;
float dx2 = 0;
float dy2 = 0;
int index;
color col;
Leaf(float x, float y, int i, float rotation) {
this.xpos = x;
this.ypos = y;
this.index = i;
this.p = 360;
angle = rotation;
unitsize = angle*2;
//render();
};
void setDimension(float l_, float w_) {
this.h = l_;
this.l = l_;
this.w = w_;
this.a = l*w;
this.shapeFactors();
}
void setBezier(float x1, float y1, float x2, float y2) {
this.dx1 = x1;
this.dy1 = y1;
this.dx2 = x2;
this.dy2 = y2;
}
void setColor(color c) {
this.col = c;
}
void setLineColor(float c) {
this.lineColor = c;
}
public void setLuminance(float lum) {
this.luminance = lum;
}
void setDetail(int d) {
detail = d;
}
void shapeFactors() {
this.c = 4*PI*this.a/(this.p*this.p);
this.r = 4*this.a/(PI*(this.l*this.l));
this.e = this.w/this.l;
this.r = this.h/this.p;
}
void renderLines() {
this.shapeFactors();
xpos = 0;
ypos = 0;
rotate(radians(angle));
stroke(128, 128);
line(0,0,0,this.l + 20);
ellipse(0,this.l,3,3);
}
void render(boolean rot) {
this.shapeFactors();
xpos = 0;
ypos = 0;
stroke(this.lineColor, this.luminance);
fill(this.col, this.luminance);
beginShape(POLYGON);
// http://www.openprocessing.org/visuals/?visualID=2123
// #0
curveVertex(xpos,ypos);
curveVertex(xpos,ypos);
// #1
curveVertex(xpos+dx1,ypos+dy1);
// #2
curveVertex(xpos+dx2,ypos+dy2);
// #3
curveVertex(xpos,ypos+l);
//curveVertex(xpos,ypos+l);
// #4
curveVertex(xpos-dx2,ypos+dy2);
// #5
curveVertex(xpos-dx1,ypos+dy1);
// #6
curveVertex(xpos,ypos);
curveVertex(xpos,ypos);
if (rot) {
rotate(radians(angle));
} else {
translate(w/4+10,30);
scale(0.25);
}
endShape();
stroke(128,128);
// anchors
ellipse(dx1,dy1,3,3);
ellipse(dx2,dy2,3,3);
ellipse(-dx1,dy1,3,3);
ellipse(-dx2,dy2,3,3);
/******
// bounding rect
//stroke(this.lineColor, 75);
fill(this.col, 75);
rect(0,0,w,l);
rect(0,0,-w,l);
// leaf middle line
//line(0,0,0,this.l + 20);
// ** servo control
// outer vertex
// 1 servos needed
// X/Y Servo
line(xpos,ypos,xpos+dx2,ypos+dy2); // hypothenuse
line(xpos,ypos,xpos-dx2,ypos+dy2); // hypothenuse
// outer lines hypothenuse
line(xpos,this.l,xpos+dx2,ypos+dy2); // hypothenuse
line(xpos,this.l,xpos-dx2,ypos+dy2); // hypothenuse
// inner vertex
// 2 servos needed
// X/Y Servo
line(xpos,this.l,xpos-dx1,ypos+dy1); // hypothenuse
line(xpos,this.l,xpos+dx1,ypos+dy1); // hypothenuse
line(xpos,ypos,xpos+dx1,ypos+dy1); // hypothenuse
line(xpos,ypos,xpos-dx1,ypos+dy1); // hypothenuse
// Width Servo
line(0,dy1,dx1,dy1);
line(0,dy1,-dx1,dy1);
*/
//fill(this.col, this.luminance - 50);
//line(xpos,ypos,xpos,ypos+l);
};
};
OpenProcessing is an online community platform devoted to sharing and discussing Processing sketches in a collaborative, open-source environment.
Download Processing
Terms of Service
To contact, send an email to:

See the feedback forum and vote!
Follow OpenProcessing on Twitter.
All sketches are licensed under Creative Commons Attribution-Share Alike 3.0.
Syntax highlighting and Processing brush under LGPL 3.
All the source code is licensed under Creative Commons GNU GPL.
Comments engine by Scriptsmill Comments Script.


