FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Suggestions
   Software Suggestions
(Moderator: fry)
   accessing component segments of LINE_STRIP shape
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: accessing component segments of LINE_STRIP shape  (Read 386 times)
forkinsocket

forkinsockt WWW
accessing component segments of LINE_STRIP shape
« on: Jan 24th, 2003, 5:14pm »

i would like to know if it is possible to access the component segments of a curve constructed as a LINE_STRIP shape.
 
such a feature would be useful in drawing lines (and curves) in real time, and altering the quality of a given line (via strokewidth or opacity) as it is being drawn.
 
an illustration of this concept, constructed in flash:
http://forkinsocket.com/sketchy/18.01.2003.html
 
to accomplish this in flash, i implemented catmull-rom in actionscript; should i do the same in p5?
 
fry


WWW
Re: accessing component segments of LINE_STRIP sha
« Reply #1 on: Jan 24th, 2003, 5:45pm »

it's a good suggestion.. i'd been wanting to add an evaluator so that this can be done more programmatically inside the graphics engine, since it's something i use often for my own stuff. (the discussion of curves from the other board makes it clear that folks are interested in this..)  
 
for the time being, here's the code for the 2D version of the curve evaluators (one for catmull-rom the other for beziers), which breaks into 20 segments, which you could pack into an array or deal with more directly. the 20 isn't ideal, but useful performance-wise.  
 
Code:
 private void bezier_segment(float x1, float y1, float x2, float y2,  
    float x3, float y3, float x4, float y4) {
    float xplot1 = -0.142625f*x1 + 0.135375f*x2 + 0.007125f*x3 + 0.000125f*x4;
    float xplot2 =  0.014250f*x1 - 0.027750f*x2 + 0.012750f*x3 + 0.000750f*x4;
    float xplot3 = -0.000750f*x1 + 0.002250f*x2 - 0.002250f*x3 + 0.000750f*x4;
 
    float yplot1 = -0.142625f*y1 + 0.135375f*y2 + 0.007125f*y3 + 0.000125f*y4;
    float yplot2 =  0.014250f*y1 - 0.027750f*y2 + 0.012750f*y3 + 0.000750f*y4;
    float yplot3 = -0.000750f*y1 + 0.002250f*y2 - 0.002250f*y3 + 0.000750f*y4;
 
    vertex(x1, y1);
    for (int j = 0; j < 20; j++) {
 x1 += xplot1; xplot1 += xplot2; xplot2 += xplot3;
 y1 += yplot1; yplot1 += yplot2; yplot2 += yplot3;
 vertex(x1, y1);
    }
  }
 
 
  private void curve_segment(float x1, float y1,  
        float cx1, float cy1,
        float cx2, float cy2,  
        float x2, float y2) {
 
    float xplot1 = (-0.0225625020f* x1 + -0.0060624960f*cx1 +  
       0.0298125020f*cx2 + -0.0011875001f*x2);
    float xplot2 = ( 0.0046250005f* x1 + -0.0113750010f*cx1 +  
       0.0088749990f*cx2 + -0.0021250000f*x2);
    float xplot3 = (-3.7500003E-4f* x1 +  0.0011250000f*cx1 +  
      -0.0011250000f*cx2 +  3.7500003E-4f*x2);
 
    float yplot1 = (-0.0225625020f* y1 + -0.0060624960f*cy1 +  
       0.0298125020f*cy2 + -0.0011875001f*y2);
    float yplot2 = ( 0.0046250005f* y1 + -0.0113750010f*cy1 +  
       0.0088749990f*cy2 + -0.0021250000f*y2);
    float yplot3 = (-3.7500003E-4f* y1 +  0.0011250000f*cy1 +  
      -0.0011250000f*cy2 +  3.7500003E-4f*y2);
 
    vertex(cx1, cy1);
    for (int j = 0; j < 20; j++) {  
 cx1 += xplot1; xplot1 += xplot2; xplot2 += xplot3;
 cy1 += yplot1; yplot1 += yplot2; yplot2 += yplot3;
 vertex(cx1, cy1);
    }
  }

 
have fun..
 
Pages: 1 

« Previous topic | Next topic »