# Week 5 - tut­o­r­i­a­l 7/8

• Show Code
• Show Sketch
``````//Star with 15 points, change the int points value in order to manage the number of points the star has.

/** @peep sketchcode */
/** @peep sketch */

size(200, 200);
background(204);
strokeWeight(4);

star(100, 100, 20, 40);
star(30, 80, 20, 30);
star(150, 50, 15, 40);

void star(float x, float y, float inner, float outer) {
// Define some variables to use to draw a star
int points = 15;
// Draw the star shape...
beginShape();
for (int i = 0; i < points; i++) {
// Draw the outer point
float ox = x + outer * cos(i*delta);
float oy = y + outer * sin(i*delta);
vertex(ox, oy);
// Draw the inner point
float ix = x + inner * cos(i*delta + delta/2);
float iy = y + inner * sin(i*delta + delta/2);
vertex(ix, iy);
}
endShape(CLOSE);
}``````
• Show Code
``````//Many faces in a crowd, edit the f int to edit how many faces there are in the crowd.

/** @peep sketch */
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 = -100; 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) {
fill(255);
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
}``````
• Show Code
``````//TUT 8 Tranformations in multiple calls. Notice as it gets smaller towards the bottom and the points get closer together.

/** @peep sketch */
void setup() {
size(200, 200);
background(204);
translate(width/3, height/3);
grid();
translate(width/6, height/6);
grid();
translate(width/9, height/6);
grid();
translate(width/12, height/12);
grid();
translate(width/15, height/15);
grid();
translate(width/18, height/18);
grid();
}

void grid() {
stroke(0, 32);
fill(255, 64);
rect(0, 0, width, height);
for (int x = 0; x <= width; x += 10) { line(x, 0, x, height); }
for (int y = 0; y <= height; y += 10) { line(0, y, width, y); }
stroke(255, 0, 0, 128);
line(10, 10, 30, 10);
line(25, 15, 30, 10);
line(25, 5, 30, 10);
stroke(0, 0, 255, 128);
line(10, 10, 10, 30);
line(15, 25, 10, 30);
line( 5, 25, 10, 30);
}``````