Col­o­u­r­e­d Faces

by Matthew Chensee
  • Show Sketch
/** @peep sketchcode **/
 
void setup() {
  size(200, 200);
  background(204);
  crowd(20, 20, width-40, height-40, 40);
}
 
void crowd(int crowdX, int crowdY, int crowdWidth, int crowdHeight, int numFaces) {
  for (int f = 0; f < numFaces; f++) {
    int faceWidth = int(random(crowdWidth/12, crowdWidth/6));
    int faceHeight = int(random(crowdHeight/12, crowdHeight/6));
    int faceX = int(random(crowdX, crowdX+crowdWidth)) - faceWidth/2;
    int faceY = int(random(crowdY, crowdY+crowdHeight)) - faceHeight/2;
    int noseX = int(random(faceWidth/8, 7*faceWidth/8));
    int noseY = int(random(faceHeight/4, 3*faceHeight/4));
    int noseWidth = int(random(faceWidth/6, faceWidth/3));
    face(faceX, faceY, faceWidth, faceHeight, noseX, noseY, noseWidth);
  }
}
 
 
void face(int faceX, int faceY, int faceWidth, int faceHeight, int noseX, int noseY, int noseWidth) { 
  float a = random(0, 255);
  float b = random(0, 255);
  float c = random(0, 255);
  fill(a, b, c);
  rect(faceX, faceY, faceWidth, faceHeight);
  line(faceX+noseX, faceY, faceX+noseX, faceY+noseY); // Nose Bridge 
  line(faceX+noseX, faceY+noseY, faceX+noseX+noseWidth, faceY+noseY); // Nose 
  line(faceX+noseX+noseWidth, faceY+noseY, faceX+noseX+noseWidth, faceY+faceHeight); 
  int mouthY = (faceHeight+noseY)/2;
  int mouseWidth = noseWidth;
  line(faceX+noseX, faceY+mouthY, faceX+noseX+noseWidth, faceY+mouthY); // Mouth 
  int eyeY = noseY/2;
  int eyeSeparation = noseWidth/2;
  fill(0);
  ellipse(faceX+noseX-eyeSeparation, faceY+eyeY, faceWidth/20, faceWidth/20); // Left eye 
  ellipse(faceX+noseX+eyeSeparation, faceY+eyeY, faceWidth/20, faceWidth/20); // Right eye 
}

Comments

Nobody has said anything yet.