Saturday, August 2, 2008

Daisey Function Code



If you play with the code and enter different values in the daisy function's parameter's you might find the results a bit strange. The reason for this is the way the original daisy is drawn. Because we are using pushMatrix(); and popMatrix(); the daisy is being moved relative to it's original position within the window. The original position is the center of the window. When using these functions it's better to draw the shape at the top left of the window, this way all changes are relative to the point 0, 0.

If you want you could try to modify the daisy function so it draws the daisy at the top left corner of the window, then see how much easier it is to position.

If none of what I am saying makes sense than I recommend cutting and pasting this code into processing and using the daisy function to draw some daisy's.


void setup () {
size (500,500);
background (13,121,43);
ellipseMode (CENTER);
smooth ();
}

void draw () {
daisy(-50, -150, 0, 1);
daisy(-150, -150, 0, 1.6);
daisy(600, 75, 1.5, 1);
daisy(400, 5, 1, .4);
}

void daisy(int x, int y, float r, float scale) {
pushMatrix();
translate(x, y);
scale(scale, scale);

rotate(r);


//this part draws the daisy
stroke (100, 255, 0);
strokeWeight(4);
line(250, 250, 350, 500);
stroke (0);
strokeWeight(1);
fill (255);
ellipse (250, 200, 100, 150);
ellipse (300, 250, 150, 100);
ellipse (250, 300, 100, 150);
ellipse (200, 250, 150, 100);
fill (220, 160, 0);
ellipse (250,250,100,80);
popMatrix();

}

No comments: