/**
a little flower and bee sketch
by Guru
*/
Flower f;
void setup() {
size(300,300);
smooth();
noCursor();
f = new Flower( 150, 100, 5, color( 255, 0, 0));
}
void draw() {
background(120,120,255);
f.draw();
noStroke();
fill( 120,255,120);
rect( 0, 200, width, 100);
bee();
}
float rot = 0;
void bee() {
pushMatrix();
translate( mouseX, mouseY );
if (( pmouseX != mouseX || pmouseY != mouseY ) && (abs(pmouseX - mouseX) + abs(pmouseY - mouseY) > 1)) {
float d = float( mouseY - pmouseY) / float( mouseX - pmouseX ) ;
boolean flip = mouseX < pmouseX;
float new_rot = atan( d ) + ( flip ? PI : 0 );
float ease = 0.3;
if ( abs(new_rot - rot) < PI ) {
rot += ( new_rot - rot ) * ease;
} else {
rot += ( (2 * PI + new_rot) - rot ) * ease;
}
}
rotate(rot);
stroke(255,80);
fill(255,60);
ellipse(-2,-10,10,15);
fill(255,255,0);
noStroke();
ellipse(0,0,20,10);
strokeWeight(3);
stroke(0);
line(-6,-4,-6,3);
line(0,-5,0,4);
line(6,-4,6,3);
fill(0);
ellipse(10,0,5,5);
strokeWeight(1);
line(6,3,8,7);
line(4,3,5,7);
stroke(255,80);
fill(255,60);
ellipse(2,-10,10,15);
popMatrix();
}
public class Flower {
float x;
float s;
float pedals;
color c;
public Flower( float x, float s, float pedals, color c ) {
this.x = x;
this.s = s;
this.pedals = pedals;
this.c = c;
}
void draw() {
stroke( 0,255,0);
strokeWeight(3);
line( x, 200, x, 200 - s );
fill( 0, 245, 0);
float peds = 20 * s / 100;
bezier( x, 200, x, 200 - s/3, x , 200 - s/3, x + peds, 200 - s/2 );
bezier( x, 200, x+peds, 200 - s/4, x + peds, 200 - s/4, x + peds, 200 - s/2 );
line( x, 200, x + peds, 200 - s/2);
float ps = 80 * s / 100;
fill( c );
noStroke();
for( int i = 0; i < pedals; i++) {
pushMatrix();
translate( x-1, 200 - s );
rotate( radians( i * 360 / pedals ));
ellipse( ps / 4, 0, ps / 2 , ps / pedals );
popMatrix();
}
fill(255,255,0);
ellipse( x, 200-s, ps/pedals,ps/pedals);
}
}