We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi,
I'm starting with Geomerative and I would like to draw some objects inside a shape.
I'm trying to use the contains() method, but I didn't completely understand how that works. When I'm trying to use it, only two points over the contour line passed the tests.
You can find a minimal working example here below.
Thanks for your kind help,
Rufone.
===
import geomerative.*;
RFont rfont;
String myText = "D";
RShape gShape;
//----------------SETUP---------------------------------
void setup() {
size(800, 600, P3D);
background(100);
lights();
// init geomerative and get font
RG.init(this);
rfont = new RFont("FreeSans.ttf", 400, CENTER);
translate(width/2, height/2, 0);
// we want Isometric 45 degrees view
//ortho();
//rotateX(PI/3);
//rotateZ(-PI/3);
//CONFIGURE SEGMENT LENGTH AND MODE
//SETS THE SEGMENT LENGTH BETWEEN TWO POINTS ON A SHAPE/FONT OUTLINE
RCommand.setSegmentLength(10);//ASSIGN A VALUE OF 10, SO EVERY 10 PIXELS
RCommand.setSegmentator(RCommand.UNIFORMLENGTH);
//RCommand.setSegmentator(RCommand.CUBICBEZIERTO);
//RCommand.setSegmentator(RCommand.ADAPTATIVE);
//get grouped lettershapes from RFont
gShape = rfont.toShape(myText);
stroke(0);
gShape.draw();
drawEllipsesInRMesh();
}
//----------------DRAW---------------------------------
void draw() {
// we have to set the same space transformations as in setup()
// otherwise objects are printed displaced
//translate(width/2, height/2, 0);
//drawEllipsesInRMesh();
}
// Draw objects inside the RShape
void drawEllipsesInRMesh() {
float xspace = width/100.0; // If you want 100 rows per screen
float yspace = height/100.0; // If you want 100 cols per screen
for(int x=0; x<width; x+=xspace) {
for(int y=0; y<height; y+=yspace) {
float xF = float(x);
float yF = float(y);
boolean isInShape = gShape.contains(new RPoint(xF, yF));
if (isInShape) {
println("x,y,isIN: "+x+","+y+","+isInShape);
// draw your object at point x, y
ellipse (xF,yF,20,20);
}
}
}
}
Answers
Ok, solved!
[see picture attached below]
My bad: I was using the wrong coordinates for x,y in the for loop. I added a function to get the bounding box of the shape, and used the min,max of the bounding box for x,y ranges. Now everything works!
Updated code attached below.
===