Filling a PShape

I’d like to be able to generate an arbitrary shape and fill it with a simple pattern.
Drawing the shape is easy - something like this would do:

void setup(){
  size(650, 650, P3D);
  smooth(8);
   translate(200, 200);
   beginShape();
   vertex(random(100),random(100));
   vertex(random(100), random(100));
   vertex(random(100), random(100));
   vertex(random(100),random(100));
   endShape();
   
}

However, if I wanted to fill in that shape with small blue strokes of circles, I would have no idea where to start. Can anyone direct me towards some code or a tutorial that would help?

Thanks!

Hello,

Here is an example using the existing circle() shape:

PImage img1, img2;
PGraphics pg;

void setup()
  {
  size(300, 300);
  //img1 = loadImage("https://processing.org/img/processing-web.png");
  img1 = loadImage("https://raw.githubusercontent.com/processing/processing-website/main/content/examples/Basics/Image/LoadDisplayImage/data/moonwalk.jpg");
  
  img2 = createImage(100, 100, RGB);
  img2 = img1.get(360, 100, 100, 100);
  
  pg = createGraphics(100, 100);
  pg.beginDraw();
  //pg.background(0);
  pg.noStroke();
  pg.fill(0, 0, 255); // Look this up in the references
  pg.circle(50, 50, 100);
  pg.endDraw();
  
  // The "pg image" is masking the "img2 image"
  img2.mask(pg); //Look this up in the references 
  
  background(255, 128, 0, 255);
  image(img2, 100, 100);
  noLoop();
  }

Look up all the tutorials and references related to the example:

image

You will have to use createShape() to create a shape with your vertices to replace the circle() shape in the example with your shape.

This may also be of interest:

:)

Thanks, GLV - I will definitely take a closer look at masking functions in the documentation.
I am curious, though: is there another method where new drawings/shapes can be made according to the bounds of an existing shape? In the masking approach, it seems that we use transparency to reveal a back layer - but if I wanted to have many different types of “fills”, with many different types of shapes - I think this might prove difficult. I could be wrong, though - I am new to this.

Ah - it looks like this “texture” mode might be what I’m after.
Is it possible to take a generated set of drawn shapes and use it as a texture, though?

I have been working with PShapes - but I believe they need to be PGraphics in order to be converted into PImages so that they might be used as a texture. Is that accurate?
My understanding is that PShapes cannot be converted into PGraphics - essentially, we’re talking about a difference between vectors and pixels - but certainly, I can’t be the first person looking to create textures on shapes using basic geometry?

Hello,

This tutorial discusses renderers including PGraphics:

Reference:

There are tutorials and references for PShape as well.

Another example from @jeremydouglass :
https://forum.processing.org/two/discussion/18710/filling-shapes-with-a-pattern.html

I can’t add more to this topic…

:)