I am thinking of doing a project that traces a rose curve. I think I know the equasions for rose curves (yay internet) but I am not sure how to write it in OF as a draw.
These are called parametric ecuations or cuves http://en.wikipedia.org/wiki/Parametric-equation , and that is beacuse they depend on just one parameter t.
This one is in polar coodinates, which describes all the plane with a radius r and an angle tetha http://en.wikipedia.org/wiki/Polar-coordinate-system
The rule for translation to Cartesian coordinates (the one OF undestands) is:
x=r cos(tetha);
y=r sin(tetha);
== edit, I wrote this up and forgot to hit post yesterday and I’m doing it now anyways even though someone else already explained it and probably better than myself
The equation just looks like this:
p = amp*cos(petals*radian); // do the polar coordinates
x = x0+p*cos(radian); // Cartesian i.e. x/y coords
y = y0+p*sin(radian); // Cartesian i.e. x/y coords
This draws the rose over several frames:
void testApp::setup() {
prevx = prevy = degree = radian = x = y = 0.0f;
amp = 300; // size of the rose
x0 = y0 = 400; // this becomes the center
petals = 12; // number of petals
ofSetFrameRate(30);
ofSetBackgroundAuto(false);
ofBackground(122, 122, 122);
}
void testApp::draw() {
if (degree<=360) {
radian = PI/180*(degree);
p = amp*cos(6*radian); //do the polar coordinates
x = x0+p*cos(radian); // convert to Cartesian
y = y0+p*sin(radian); // convert to Cartesian
ofLine(prevx, prevy, x, y); // draw
prevx = x;
prevy = y;
degree++;
} else {
degree = 0;
ofBackground(122, 122, 122);
}
}