We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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
Did you figure this problem out?
Try this:
Kf
That github repo hasn't changed in 6 years.
It's also not the original, just someone's sketchbook directory that they've committed to github.
The original afaik is here: https://github.com/leebyron/mesh
And he still hasn't fixed the bug in MPolygon...
@digitalmartyn -- that sounds like a job for... forking the original repo!
already done, includes the fix. https://github.com/acdean/mesh
(i should update the readme)
@koogs <:-P
great - solved. thanks so much