We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi I am new to processing and I am trying to create a shape (a rectangle with curved edges) and fill it with a pattern. I know I can probably fill it using a for loop, but that seemed a little daunting. The alternative approach I thought of is to use an image and fill the shape with that image; however, I can't seem to figure out how to fill out the curved edges.
void draw() {
background(#FFFAFA);
strokeWeight(5);
fill(255);
rect(70,60,800,470,0,105,105,0);
//resizes the image and fills a rectangle shape
PImage static1 = loadImage("static.jpg");
static1.resize(700, 463);
image(static1, 73, 64);
}
Answers
Please edit your post and format the code with CTRL-o.
First, do you know how to fill any shape with a pattern, like a simple rectangle?
beginShape()
/endShape()
andtexture()
PImage
/PGraphics
and amask()
createShape()
to make aPShape
and then use.setTexture()
(listed in the javadoc linked from the reference, not the reference)If you want a rectangle with curved edges and don't want to draw each straight line and curve of the shape "by hand", then you could use the 8-argument version of rect(), which supports rounded corners:
This might combine well with the "mask" approach -- make a rounded rect mask, then mask an image of your texture. But there are many ways of doing this....
Thanks for this response. I will give the mask approach a shot.
Great! Please share your results if it works for you -- or if you get stuck.
Thanks Jeremy for the response. I tried to create a basic rectangle using Vertex, and tried to use the Texture() function, but received an error stating that texture() isn't available with this renderer. Do you have a sample of making a rounded rect mask?
don't loadImage inside draw. it's not something you want to do 60 times a second. do it in setup() and use a global variable.
@mapspug --
For texture and a renderer error you may need to use size(x, y, P3D) to specify the P3D renderer.
For a sample of a mask, here is a simple example:
Here is the same example, with a rounded rect instead:
thanks you so much. This worked flawlessly thank you Jeremy