We are about to switch to a new forum software. Until then we have removed the registration on this forum.
HI- I would like to fill an ellipse with a generated pattern. I've been all over the internet and I found PShape class but can't figure out how to fill the PShape with a random and moving pattern, only with a solid fill. Thanks in advance, my code is below
//forked from Bárbara Almeida
int tile = 15;
int[][] m; //two dimensional array
color c0, c1, c2;
PShape ellipseShape;
void setup()
{
size(570, 570);
noStroke();
smooth(8);
//background(50);
ellipseShape = createShape(ELLIPSE,285,285,550,550);
newColor();
newPattern();
}
void draw()
{
//frameRate(240);
//shape(ellipseShape);
drawPattern();
saveFrame();
}
void newColor() //choose a random color
{
//c0 = color(#77540f);
// c1 = color(#f3fc5d);
c0 = color(random(255), random(255), random(255));
c1 = color(random(255), random(255), random(255));
c2 = color(random(255), random(255), random(255));
}
void newPattern() //create a matrix for the Truchet tiling
{
m = new int[width/tile][height/tile]; //create 2D matrix
for (int x = 0; x < width; x += tile)
{
for (int y = 0; y < height; y += tile)
{
m[x/tile][y/tile] = int(random(15));
}
}
}
void drawPattern()
{
//squares
for (int x = 0; x < width; x += tile)
{
for (int y = 0; y < height; y += tile)
{
if (m[x/tile][y/tile] == 0)
{
fill(c0);
}
else ellipseShape.fill(c1);
rect(x, y, tile, tile);
}
}
//circles
for (int x = 0; x < width + 5; x += tile)
{
for (int y = 0; y < height + 5; y += tile)
{
int s = 0;
if ((x+y)%2 == 0) // if remainder of x+y/2 = 0
{
fill(c0);
//s = -1;
}
else
{
fill(c1);
s = 1;
}
float d = map(noise(x/320.0, y/320.0, frameCount/100.0), 0.33, 0.66, -tile/2, tile/2);
// map (noise x,y,z = to be converted), lower bound of range, upper bound of range,
// lower bound of target, upper bound of target
ellipse(x, y, tile + s*d, tile + s*d);
}
}
}
Answers
Draw your own ellipse using sin and cos. Draw the pattern to an off screen image. Use the version of vertex () with x, y, u, v parameters
hi koogs, What does "draw the pattern to an off screen image" mean? Thank you for the response!
Check this: https://forum.processing.org/two/discussion/comment/77395/#Comment_77395
Kf
thank you, looks like a useful thread :)
@Sophi -- glad to hear it! Let us know here in this thread if you have any questions after trying those approaches.
Also, depending on the kind of pattern, an advanced approach is to use PShader:
https://processing.org/tutorials/pshader/