-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLeaf_Object
29 lines (27 loc) · 891 Bytes
/
Leaf_Object
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
int nLeafPoints = 5;
float[] xOutline;
float[] yOutline;
void defineLeafOutline(){
xOutline = new float[nLeafPoints];
yOutline = new float[nLeafPoints];
for(int i=0; i<=nLeafPoints/2;i++){
xOutline[i] = 2*i/(float)(nLeafPoints);
yOutline[i] = (-pow((xOutline[i]-.5),2)+.25)*2;
if(i>0 && i<=nLeafPoints/2){
xOutline[nLeafPoints-i] = xOutline[i];
yOutline[nLeafPoints-i] = -yOutline[i];
}
}
}
float tempx;
float tempy;
//leafWidth is a fraction of leafLength
void drawLeaf(float x, float y, float leafLength, float leafWidth, float direction){
beginShape();
for(int i=0; i<xOutline.length;i++){
tempx = xOutline[i]*cos(direction)*leafLength-yOutline[i]*sin(direction)*leafWidth*leafLength;
tempy = xOutline[i]*sin(direction)*leafLength+yOutline[i]*cos(direction)*leafWidth*leafLength;
vertex(x+tempx,y+tempy);
}
endShape(CLOSE);
}