How to fill a shape with a generated pattern?

edited May 2017 in Questions about Code

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

Sign In or Register to comment.