Fiveagon
Generative Code Art with Processing
One to many. blendMode(SCREEN);

One to many. blendMode(SCREEN);

blendMode(SUBTRACT);

blendMode(SUBTRACT);

I figure it’s faster to translate the PGraphics than copying the RShape and then translating. The reason the texture jumps around is because the center point of my shape is different at any point of the rotation.

PImage createBlendTexture(RShape userShape, PImage userTexture, int userMode) {
  int w = ceil(userShape.getWidth());
  int h = ceil(userShape.getHeight());
  PGraphics blendGraphics = createGraphics(w, h);
  
  RPoint graphicsCenter = new RPoint(w/2.0, h/2.0);
  RPoint shapeCenter = userShape.getCenter();
  graphicsCenter.sub(shapeCenter);

  blendGraphics.beginDraw();
  blendGraphics.hint(ENABLE_STROKE_PURE);
  blendGraphics.translate(graphicsCenter.x, graphicsCenter.y);
  userShape.draw(blendGraphics);
  blendGraphics.resetMatrix();  // blendMode() does some funky stuff without this
  blendGraphics.blendMode(userMode);
  blendGraphics.image(userTexture, 0, 0);
  blendGraphics.endDraw();

  return blendGraphics.get();
}

I figure it’s faster to translate the PGraphics than copying the RShape and then translating. The reason the texture jumps around is because the center point of my shape is different at any point of the rotation.

PImage createBlendTexture(RShape userShape, PImage userTexture, int userMode) {
  int w = ceil(userShape.getWidth());
  int h = ceil(userShape.getHeight());
  PGraphics blendGraphics = createGraphics(w, h);
  
  RPoint graphicsCenter = new RPoint(w/2.0, h/2.0);
  RPoint shapeCenter = userShape.getCenter();
  graphicsCenter.sub(shapeCenter);

  blendGraphics.beginDraw();
  blendGraphics.hint(ENABLE_STROKE_PURE);
  blendGraphics.translate(graphicsCenter.x, graphicsCenter.y);
  userShape.draw(blendGraphics);
  blendGraphics.resetMatrix();  // blendMode() does some funky stuff without this
  blendGraphics.blendMode(userMode);
  blendGraphics.image(userTexture, 0, 0);
  blendGraphics.endDraw();

  return blendGraphics.get();
}
Yes! Another way to texture. Here’s the basic idea for using PGraphics.blendMode().

PImage createBlendTexture(RShape userShape, PImage userTexture, int userMode) {
  RShape copyShape = new RShape(userShape);
  int w = ceil(copyShape.getWidth());
  int h = ceil(copyShape.getHeight());
  PGraphics blendGraphics = createGraphics(w, h);

  blendGraphics.beginDraw();
  blendGraphics.hint(ENABLE_STROKE_PURE);
  copyShape.centerIn(blendGraphics);
  copyShape.translate(w/2.0, h/2.0);
  copyShape.draw(blendGraphics);
  blendGraphics.blendMode(userMode);
  blendGraphics.image(userTexture, 0, 0);
  blendGraphics.endDraw();

  return blendGraphics.get();
}

Yes! Another way to texture. Here’s the basic idea for using PGraphics.blendMode().

PImage createBlendTexture(RShape userShape, PImage userTexture, int userMode) {
  RShape copyShape = new RShape(userShape);
  int w = ceil(copyShape.getWidth());
  int h = ceil(copyShape.getHeight());
  PGraphics blendGraphics = createGraphics(w, h);

  blendGraphics.beginDraw();
  blendGraphics.hint(ENABLE_STROKE_PURE);
  copyShape.centerIn(blendGraphics);
  copyShape.translate(w/2.0, h/2.0);
  copyShape.draw(blendGraphics);
  blendGraphics.blendMode(userMode);
  blendGraphics.image(userTexture, 0, 0);
  blendGraphics.endDraw();

  return blendGraphics.get();
}
I finally learned how to texture any RShape (from Geomerative) using PGraphics and PImage.mask():

void maskTexture(RShape maskShape, PImage textureImage) {
  int w = (int) maskShape.getWidth();
  int h = (int) maskShape.getHeight();
  PGraphics maskGraphics = createGraphics(w, h);

  maskGraphics.beginDraw();
  maskShape.draw(maskGraphics);
  maskGraphics.endDraw();

  RPoint topLeft = maskShape.getTopLeft();
  int x = (int) topLeft.x;
  int y = (int) topLeft.y; 
  PImage textureCrop = textureImage.get(x, y, w, h);
  textureCrop.mask(maskGraphics);

  image(textureCrop, x, y);
}

This is the basic idea, though you’ll have to play with the coordinates depending on where you draw your shape and where you want the texture. And, of course, you don’t have to use Geomerative to use this technique. Just draw to a PGraphics.

I finally learned how to texture any RShape (from Geomerative) using PGraphics and PImage.mask():

void maskTexture(RShape maskShape, PImage textureImage) {
  int w = (int) maskShape.getWidth();
  int h = (int) maskShape.getHeight();
  PGraphics maskGraphics = createGraphics(w, h);

  maskGraphics.beginDraw();
  maskShape.draw(maskGraphics);
  maskGraphics.endDraw();

  RPoint topLeft = maskShape.getTopLeft();
  int x = (int) topLeft.x;
  int y = (int) topLeft.y; 
  PImage textureCrop = textureImage.get(x, y, w, h);
  textureCrop.mask(maskGraphics);

  image(textureCrop, x, y);
}

This is the basic idea, though you’ll have to play with the coordinates depending on where you draw your shape and where you want the texture. And, of course, you don’t have to use Geomerative to use this technique. Just draw to a PGraphics.