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:
size(650, 650, P3D);
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?
Here is an example using the existing
PImage img1, img2;
//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.fill(0, 0, 255); // Look this up in the references
pg.circle(50, 50, 100);
// 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);
Look up all the tutorials and references related to the example:
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?
This tutorial discusses renderers including PGraphics:
There are tutorials and references for PShape as well.
Another example from @jeremydouglass :
I can’t add more to this topic…