Emeline Liu

   About       Resume       Archive       Feed   


Tiles

This is how I taught myself how popMatrix and pushMatrix works. There are a multiple of different effects that can be achieved by varying a couple things:.

  • number of sides on the polygons
  • size of polygons
  • rotation directions
  • rotation speed
  • alpha transparency level of the polygon fill

One


float num1, num2, n1, n2, angle;
void setup()
{
  size(400,400);
  num1=11;
  num2=11;
  angle = 0;
  rectMode(CENTER);
}

void draw()
{
  background(255, 55);
  n1 = width/num1;
  n2 = height/num2;
  for (int j=0; j<=num2; j++){
	for (int i=0; i<=num1; i++){
	  pushMatrix();
	  noStroke();
	  fill(0, 50);
	  translate(n1*i, n2*j);
	  //Change this for the variations
	  if ((i*j)%2==0) {
		rotate(angle);
		//Change the number of sides and size
		polygon(0,0,20,5);
	  }
	  else {
		rotate(angle*-1);
		polygon(0, 0, 40, 5);
	  }
	  popMatrix();
	}
  }
  angle+=0.02;
}

//Function to create a polygon
void polygon(float x, float y, float radius, int npoints) {
  float angle = TWO_PI / npoints;
  beginShape();
  for (float a = 0; a < TWO_PI; a += angle) {
	float sx = x + cos(a) * radius;
	float sy = y + sin(a) * radius;
	vertex(sx, sy);
  }
  endShape(CLOSE);
}	
	

Two

Three

Four