Hello,
I am trying to create a cascade of expanding curves that go in any direction based on an input angle. At the moment I have it working using ofDrawCurve, but only along the y-axis. The function takes in an x and y coordinate (xpos, ypos) and builds the curve from that point.
I have been able to rotate the x & y endpoints of the curve, but have been unable to figure out how to rotate the control points, px & py.
The test output looks like this. Essentially I’d like to have these curves shoot off in any arbitrary direction. I have a feeling there’s a simpler or easier way to do this, but I’m still new to oF so any pointers would be appreciated!
void ofApp::drawWaves (float xpos, float ypos, float pitch, float angle) {
// Define starting wave width
float curveWidth = ofGetWindowWidth() / widthDivisor;
// Iterator value to keep track of where the loop is
int curveNum = 0;
// For loop that iterates through y values to create cascading curves
// Goes through the height of the window
for (int y = 0; y < ofGetWindowHeight(); y += pitch) {
// Increment iterator value.
curveNum += 1;
// Define beginning and end coordinates of curve, Test points only along y-axis
//float x1 = xpos - curveWidth;
//float y1 = ypos + y;
//float x2 = xpos + curveWidth;
//float y2 = ypos + y;
// Control points to determine the depth of the curve, Test points only along y-axis
//float px1 = x1;
//float py1 = ypos + y - curveDepth;
//float px2 = x2;
//float py2 = ypos + y - curveDepth;
// Define beginning and end coordinates of curve
float x1 = xpos - cos(angle)*curveWidth;
float y1 = ypos - sin(angle)*curveWidth;
float x2 = xpos + cos(angle)*curveWidth;
float y2 = ypos + sin(angle)*curveWidth;
// Control points to determine the depth of the curve
float px1 = x1 - 2*curveDepth*sin(angle/2);
float py1 = y1 + cos(angle)*curveDepth;
float px2 = x2 - 2*curveDepth*sin(angle/2);
float py2 = y2 + cos(angle)*curveDepth;
// Define color. Cascade through RGB.
if (curveNum % 3 == 0) {
ofSetColor(0, 0, 255);
}
else if (curveNum % 3 == 1) {
ofSetColor(255, 0, 0);
}
else {
ofSetColor(0, 255, 0);
}
// Draw curve without fill
ofNoFill();
ofSetCurveResolution(curveResolution);
ofDrawCurve(px1, py1, x1, y1, x2, y2, px2, py2);
// Increase the width of the curve for the next iteration
curveWidth += widthIncrementer;;
}
}
Thank you for any help!