bioscribble
YaBB Newbies
Offline
Posts: 11
curvePoint and curveVertex commands
Feb 4th , 2006, 8:06pm
I want to find points along the entire length of a curve, and there doesn't seem to be a way to do this using the curvePoints command. Currently, curvePoints only accepts four variables, with the inside two measured as being on the curve, and the outside acting only as control handles. This means that the values curvePoints returns are all between my middle two variables. How can I find values between my first two variables or my last two variables? The way I can get those parts of the spline to draw is by including the first and last curveVertex() twice, but there doesn't seem to be a similar 'hack' to get the values of points on those curves. I want to eventually add mouse control to the following "seaweed" generator, which is why I don't want to clip the ends of the curve or leave long threads trailing. Thanks for any suggestions. class Seaweed{ //instance properties float x1; float y1; float x2; float y2; float x3; float y3; float x4; float y4; float w; int branches = 12; //constructor Seaweed(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, float w){ this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2; this.x3 = x3; this.y3 = y3; this.x4 = x4; this.y4 = y4; this.w = w; createStem(); createWebbing(); createBranches(); } float getFirstX(){ return x1; } float getFinalX(){ return x4; } float getFirstY(){ return y1; } float getFinalY(){ return y4; } void createStem(){ stroke(150,60,40); strokeWeight(1); beginShape(LINE_STRIP); curveVertex(x1, y1); curveVertex(x1, y1); curveVertex(x2, y2); curveVertex(x3, y3); curveVertex(x4, y4); curveVertex(x4, y4); endShape(); } void createBranches(){ stroke(150,60,40); strokeWeight(1); float centrality = 1; float centerX = curvePoint(x1,x2,x3,x4,.5); float centerY = curvePoint(y1,y2,y3,y4,.5); for (int i = 0; i < branches; i++) { float t = i / float(branches); float x = curvePoint(x1, x2, x3, x4, t); float y = curvePoint(y1, y2, y3, y4, t); centrality = 1 - dist(x,y,centerX,centerY)/dist(x2,y2,centerX,centerY); line(x, y, x+w*(centrality), y); line(x, y, x-w*(centrality), y); } } void createWebbing(){ fill(200,50,60,127); noStroke(); float centrality = 1; float centerX = curvePoint(x1,x2,x3,x4,.5); float centerY = curvePoint(y1,y2,y3,y4,.5); beginShape(POLYGON); curveVertex(x1,y1); for (int i = 0; i < branches; i++) { float t = i / float(branches); float x = curvePoint(x1, x2, x3, x4, t); float y = curvePoint(y1, y2, y3, y4, t); centrality = 1 - dist(x,y,centerX,centerY)/dist(x2,y2,centerX,centerY); curveVertex(x+w*centrality,y); } curveVertex(x3,y3); curveVertex(x4,y4); endShape(); beginShape(POLYGON); curveVertex(x1,y1); for (int i = 0; i < branches; i++) { float t = i / float(branches); float x = curvePoint(x1, x2, x3, x4, t); float y = curvePoint(y1, y2, y3, y4, t); centrality = 1 - dist(x,y,centerX,centerY)/dist(x2,y2,centerX,centerY); curveVertex(x-w*centrality,y); } curveVertex(x3,y3); curveVertex(x4,y4); endShape(); } }