Loading...
Logo
Processing Forum
I've been working with Spline2D and BezierCurve2D in Toxiclibs. To draw them, I compute the vertices with a certain resolution and then draw them as a series of vertices, or as a Polygon with ToxiclibsSupport, as it's done in the examples.

The problem is that, with variable segment lengths, either I found the resolution to be too small (I see the angles) or too high (the stroke is not smooth). That's especially noticeable if you have to export to a PDF vector file, where instead of having a nice bezier with control points you end up with a series of straight lines.

I haven't looked at the Processing implementation, but I wonder if there's any way to render this curves smoothly, like ellipse(), arc() or curveVertex() do in Processing.

thanks!

Replies(4)

Have you looked at the examples in this folder:

Examples/Contributed Libraries/toxiclibscore/splines

?
Yes, of course. I'll try to be more clear: I know how to draw different kinds of curved lines with ToxicLibs, but I don't know if there's any way to render them as smoothly as the default curved shapes in Processing. 

For example, a simple bezier with Processing and   Toxiclibs:

The blue one is not as smooth because it's rendered as a series of small straight lines. That's more clear when we export to vector and open in Illustrator:


Is there a way to render the red way from toxiclibs? Or should I extend ToxiclibsSupport to do it? Can anyone link me to the Processing implementation that does that?

This is the code I used to create the lines (it uses some functions of toxiclibs 0021, but the result is the same with splines or other classes). I might be missing something...
Copy code
  1. void setup()
  2. {
  3.   size(600, 400);
  4.   background(255);
  5.   smooth();

  6.   // create bezier points
  7.   ArrayList<Vec2D>points = new ArrayList();
  8.   for (int i=0; i<4; i++) points.add(new Vec2D(75 + i*150, random(350)));

  9.   beginRecord(PDF, "test.pdf"); 

  10.   // draw them processing style
  11.   strokeWeight(2);
  12.   stroke(255, 0, 0);
  13.   bezier(points.get(0).x, points.get(0).y, points.get(1).x, points.get(1).y, points.get(2).x, points.get(2).y, points.get(3).x, points.get(3).y);

  14.   // draw them toxiclibs style
  15.   translate(0, 50);
  16.   stroke(0, 0, 255);
  17.   BezierCurve2D curve = new BezierCurve2D(points);
  18.   LineStrip2D line = curve.toLineStrip2D(20); 
  19.   beginShape();
  20.   for (Vec2D v: line.getVertices()) vertex(v.x, v.y);
  21.   endShape();

  22.   endRecord();

  23.   // show points
  24.   strokeWeight(1);
  25.   stroke(0);
  26.   noFill();
  27.   for (Vec2D p: points) ellipse(p.x, p.y, 10, 10);
  28.   endRecord();
  29. }

Hello araidz, line 25:
Copy code
  1. for (Vec2D v: line.getVertices()) curveVertex(v.x, v.y);

I think, that will help you.

Darius
Looks like to me ToxiclibsSupport doesn't have curve drawing functionality.  So I think either you try higher resolution (which isn't working for you?) or you need to interpolate the curve yourself or using curveVertex() as darius suggests.