Access an array in a class. (MPolygon)

I have successfully created a convex hull around a randomly placed circle and box.

However, since i want the filled shape to be a gradient i want to create a PShape using the vertex coords. So i need to access the coords from the MPolygon class from the Mesh library.

I can't figure out how to pull the array of coordinates of the hull from the class:

Code here:

import megamu.mesh.*;

int offSetX, offSetY;
int circleNum = 50;
int size = circleNum + 4;
int loc = 0;

size(600, 600);
background(255);
strokeWeight (5);

float[][] points = new float[size][2];


//CIRCLE
float radius=100;
offSetX = round(random(radius, width-radius));
offSetY = round(random(radius, height-radius));

float angle=TWO_PI/(float)circleNum;
for (int i=0; i<circleNum; i++) {

  points[loc][0] = ((radius*sin(angle*i)))+offSetX;
  points[loc][1] = ((radius*cos(angle*i)))+offSetY;
  point (points[loc][0], points[loc][1]);
  loc++;
}



//BOX
offSetX = round(random(radius, width-radius));
offSetY = round(random(radius, height-radius));


radius=150;
angle=TWO_PI/(float)8;
for (int i=1; i<8; i+=2) {

  points[loc][0] = ((radius*sin(angle*i)))+offSetX;
  points[loc][1] = ((radius*cos(angle*i)))+offSetY;
  point (points[loc][0], points[loc][1]);
  loc++;
}


///create the hull
Hull myHull = new Hull( points );

//draw the hull
strokeWeight (1);
MPolygon myRegion = myHull.getRegion();
//fill(255, 0, 0);
//noFill();
//myRegion.draw(this);


/// CREATE THE VERTEX SHAPE WITH COLOR AT EACH POINT
//beginShape();
//fill(255, 0, 0);
//vertex(0, 0);
//endShape();

The MPolygon code is this: https://github.com/gotascii/processing/blob/master/libraries/mesh/source/MPolygon.java

Answers

Sign In or Register to comment.