Loading...
Logo
Processing Forum
Hi everyone, 

I've looked around the forums, and so far I have not been able to find a relevant solution to my problem.  I'm working on a program that generates an Alexander Calder image when typing "alexander calder mobile."

When using curveVertex within beginShape, I continue to get a sharp non-curved corner where the shape is closed.  Does anyone know how to maintain a continually curved shape?


This is a sample of my code, but I could post more if that would help.
Copy code
  1. void shape16(){
  2.   beginShape();
  3.   curveVertex( 270.0, 296.0 );
  4.   curveVertex( 270.0, 296.0 );
  5.   curveVertex( 272.0, 269.0 );
  6.   curveVertex( 360.0, 213.0 );
  7.   curveVertex( 394.0, 299.0 );
  8.   curveVertex( 270.0, 296.0 );
  9.   scale(.25);
  10.   fill(255,0,0);
  11.   noStroke();
  12. endShape();
  13. }
Thank you for any assistance!

Replies(2)

I tried various improvements, and found out it looks better if you push the starting point a bit away from the next point, and if you add an intermediary final point.
Test code:
Copy code
  1. void setup()
  2. {
  3.   size(400, 400);
  4.   smooth();
  5. //  scale(4);
  6.   shape16();
  7. }
  8.  
  9. void shape16(){
  10.   float[] points =
  11.   {
  12.     300.0, 302.0, // Start a little lower and to the right
  13.     270.0, 296.0,
  14.     272.0, 269.0,
  15.     360.0, 213.0,
  16.     394.0, 299.0,
  17.     350.0, 308.0, // Intermediary lower point
  18.   };
  19. //  scale(.25);
  20.   fill(255,0,0);
  21.   noStroke();
  22.   beginShape();
  23.   for (int i = 0; i < points.length; i += 2)
  24.   {
  25.     curveVertex(points[i], points[i + 1]);
  26.   }
  27.   // Loop on the start
  28.   curveVertex(points[0], points[1]);
  29.   // Twice give a better result!
  30.   curveVertex(points[0], points[1]);
  31.   endShape();
  32.   noFill();
  33.   stroke(#008888, 100);
  34.   for (int i = 0; i < points.length; i += 2)
  35.   {
  36.     ellipse(points[i], points[i + 1], 5, 5);
  37.   }
  38. }
Note: using an array of points allows to quickly and easily visualize the points (the ellipses I added). You can even make only one function and pass it the array and a color as parameters.

I found that using curveVertex() is delicate and can lead to curious results in some cases (like the path reversing and making a sharp corner).
Perhaps because I am used to vector drawing programs like Illustrator, Corel DRAW! or Inkscape, I prefer bezierVertex(), whose control points can be hard to master, but leading to more consistent / logical / expected results.
Moreover, there are tools for the PDE allowing to draw such curve and to convert them directly to code.
You can also check with it: don't duplicate the 1st point, and add the 2nd and 3rd points before ending the shape:

Copy code
  1. void shape16() {

  2.   beginShape();
  3.   curveVertex( 270.0, 296.0 );
  4.   curveVertex( 272.0, 269.0 );
  5.   curveVertex( 360.0, 213.0 );
  6.   curveVertex( 394.0, 299.0 );

  7.   // 1st point, closing the form
  8.   curveVertex( 270.0, 296.0 );

  9.   // 2nd and 3rd points
  10.   curveVertex( 272.0, 269.0 );
  11.   curveVertex( 360.0, 213.0 );

  12.   scale(.25);
  13.   fill(255,0,0);
  14.   noStroke();
  15.   endShape();
  16. }

This trick works for me for all shapes I draw with curveVertex.