Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Re : Dinamically setting the points of a bezierVertex in a PShape

$
0
0
thanks that's helpful.  the bit about having access to the original vertices and not the 20 new ones was clear from your first post.  my bad on not getting that and providing a useless answer.  still, thanks for taking the time to re-explain.  maybe helpful for others.

your comment about what you wish to do when you have the bezier verts (make it bigger w/o scale) was helpful in answering my question whether or not the number of vertices will stay the same.  It sounds like they will stay the same and if that is so, then the idea i have is to use either an array or even better, a class.  

create a Heart class that takes an array of bezier coordinates when it's created and stores them as an array called bezierVertices (or bezVerts, etc) as one of it's properties.  then you could create your own class function called getBezVertices() and have access to them that way.  Here's an untested example of what i'm talking about, I've never used PShapes so that part of the code may be extra incorrect.
  1. class Heart {
  2.       float[][] bezierVertices;
  3.       PShape shape;
  4.       
  5.       Heart(float[][] bezVs) {
  6.             bezierVerticies = bezVs;
  7.             shape = createShape();
  8.       }

  9.       void display(){
  10.             //all the yummy goodness you already wrote to display the heart
  11.       }

  12.       float[][] getBezierVertices(){
  13.             return this.bezierVerticies;
  14.       }

  15.       float[] getBezierVertex(int i){
  16.             return this.bezierVerticies[i];
  17.       }
  18.       
  19.       void setBezierVertex(int i, float nx, float ny){
  20.             this.bezierVertices[i][0] = nx;
  21.             this.bezierVertices[i][1] = ny;
  22. }

or, if you had a 2D heartBezVertices array which had the coordinates of the vertices, then you could change the values in the elements of the array and multiply them by a scale factor.  however, i'm not sure this would be much more efficient than just adding a scale factor to your current code.  here's an example, scale factor not included because i imagine that in some cases it has to be pos and others neg.
  1. //float b/c you have fractions
  2. float[][] heartBezVerts = { {heartSize/2, heartSize*0.15}, 
  3.                                       {heartSize*0.5, -heartSize*0.05}, 
  4.                                       {heartSize*0.9, heartSize*0.05}, 
  5.                                       {heartSize*0.5, heartSize*0.4},
  6.                                       {heartSize/2, heartSize*0.15},
  7.                                       {heartSize*0.5, -heartSize*0.05}, 
  8.                                       {heartSize*0.1, heartSize*0.05}, 
  9.                                       {heartSize*0.5, heartSize*0.4}  }

  10.         myShape = createShape();
  11.         myShape.beginShape();
  12.         myShape.vertex (heartBezVerts[0][0], heartBezVerts[0][1]);

  13.         myShape.bezierVertex(heartBezVerts[1][0], heartBezVerts[1][1]
  14.                                           heartBezVerts[2][0]heartBezVerts[2][1]
  15.                                           heartBezVerts[3][0]heartBezVerts[3][1]);

  16.         myShape.vertex(heartBezVerts[4][0] * s, heartBezVerts[4][1] * s);

  17.         myShape.bezierVertex(heartBezVerts[5][0]heartBezVerts[5][1]
  18.                                           heartBezVerts[6][0]heartBezVerts[6][1]
  19.                                           heaheartBezVerts[7][0]heartBezVerts[7][1]);
  20.         myShape.endShape();

Viewing all articles
Browse latest Browse all 1768

Trending Articles