Geomerative - fitting text inside arbitrary shapes?

OK I explored a bit more would something like this be acceptable?

import geomerative.*;

RShape shape;
RShape rect;

void setup(){
  size(600, 600, P2D);
  RG.init(this);
  RG.setPolygonizer(RG.ADAPTATIVE);
  shape = RG.getRect(100,100,100,50);
}

void draw(){
  fill(255);
  rect = RShape.createRectangle(mouseX, mouseY, 10, 10);
  shape.draw(this);
  if (shape.contains(rect.getCentroid())){
    fill(255, 0, 0);
  }
  else{
    fill(255);
  }
  rect.draw(this);
}

OR

import geomerative.*;

RShape bounds;
RShape my_rect;

void setup() {
  size(600, 600);
  RG.init(this);
  RG.setPolygonizer(RG.ADAPTATIVE);
  bounds = RG.getRect(105, 105, 95, 45);
}

void draw() {
  fill(255);
  my_rect = RShape.createRectangle(mouseX, mouseY, 10, 10);
  rect(100, 100, 100, 50);
  if (inBounds(my_rect)){
    fill(255, 0, 0);
  } else {
    fill(255);
  }
  my_rect.draw(this);
}

boolean inBounds(RShape shp) {
  RPoint[] pts = shp.getPoints();
  for (int i = 0; i < pts.length; i++) {
    if (!bounds.contains(pts[i]))
    { 
      return false;
    }
  }
  return true;
}

For something a bit more sophisticated.

2 Likes