xxxxxxxxxx
410
let eye;
let mouth;
let nose;
let face
function setup() {
createCanvas(400, 400);
eye = new Eye();
mouth = new Mouth();
nose = new Nose();
face = new Face(width/2,height/2);
}
function draw() {
background(220);
stroke(0, 255);
// eye.render();
// mouth.render();
// nose.render();
face.render();
stroke(0, 50);
line(width / 2, 0, width / 2, height);
line(0, height / 2, width, height / 2);
}
class Eye {
constructor() {
this.pos = createVector(0, 0);
this.eyeheight = 2 * random(0.6, 1.4);
this.eyewidth = 10 * random(0.6, 1.2);
this.r = this.eyeheight;
this.eyetilt = createVector(random(-0.3, 0.4), random(-0.3, 0.4));
this.eyeslope = random(1, 1.5);
}
render() {
let multiplier = 10;
push();
translate(this.pos.x, this.pos.y);
fill(255);
beginShape();
for (let i = 0; i <= 10; i++) {
let w = map(i, 0, 10, PI, 0);
let x = map(i, 0, 10, this.eyewidth / 2, -this.eyewidth / 2);
let y = this.eyeheight * -sin(w);
y -= this.eyeheight * sin(w * this.eyeslope) * this.eyetilt.x;
vertex(x * multiplier, y * multiplier);
}
for (let i = 0; i <= 10; i++) {
let w = map(i, 0, 10, 0, PI);
let x = map(i, 0, 10, -this.eyewidth / 2, this.eyewidth / 2);
let y = this.eyeheight * sin(w);
y -= this.eyeheight * sin(w * this.eyeslope) * this.eyetilt.y;
vertex(x * multiplier, y * multiplier);
}
for (let i = 0; i <= 1; i++) {
let w = map(i, 0, 10, PI, 0);
let x = map(i, 0, 10, this.eyewidth / 2, -this.eyewidth / 2);
let y = this.eyeheight * -sin(w);
y -= this.eyeheight * sin(w * this.eyeslope) * this.eyetilt.x;
vertex(x * multiplier, y * multiplier);
}
endShape();
fill(0);
ellipse(0, 0, this.eyeheight * 15);
pop();
}
}
class Mouth {
constructor() {
this.pos = createVector(0, 0);
this.r = 20;
// this.mouthHeight = random(1,3);
// this.mouthWidth = random(2,10);
this.mouthHeight = random(1, 2);
this.mouthWidth = random(5, 14);
this.cupids = random(0.9, -0.5);
this.lipsRatio = createVector(random(0.4, 2), random(0.8, 2.8));
this.lipPart = createVector(random(-1, 1), random(0, 1), random(-0.3, 0.3));
}
render() {
let multiplier = 10;
push();
translate(this.pos.x, this.pos.y);
fill(255);
//Draws Lip outline
beginShape();
let maxRes = 1000;
//Draws a sem-circle (PI) from "-(half width of the mouth)" to "0"
// i is the resolution of your shape, how many points are on the graph
for (let i = 0; i <= maxRes; i++) {
// w Maps the resolution/num of points to a a range - controls how much of one period to display
let w = map(i, 0, maxRes, 0, PI);
// x Maps the resolution/num of points across a certain distance along the x axis - controls where I want my wave to be long the x axis
let x = map(i, 0, maxRes, -this.mouthWidth / 2, 0);
// The sign (+/-) of sin basically flips the sin wave vertically
// Adding values inside the sine function changes the phase/slides wave across the x axis
// Multiplying values inside the sine function stretches/contracts the graph along the x axis
let y = this.mouthHeight * -sin(w * this.cupids);
//
// let y = this.mouthHeight * -sin(w *5);
// Multiplies the top lip & bottom lip with different values to acheieve a certain lip size ratio & draws the points
y *= this.lipsRatio.x;
vertex(x * multiplier, y * multiplier);
}
for (let i = 0; i <= 10; i++) {
let w = map(i, 0, 10, PI, 0);
let x = map(i, 0, 10, 0, this.mouthWidth / 2);
let y = this.mouthHeight * -sin(w * this.cupids);
y *= this.lipsRatio.x;
vertex(x * multiplier, y * multiplier);
}
for (let i = 0; i <= 10; i++) {
let w = map(i, 0, 10, PI, 0);
let x = map(i, 0, 10, this.mouthWidth / 2, -this.mouthWidth / 2);
let y = this.mouthHeight * sin(w);
y *= this.lipsRatio.y;
vertex(x * multiplier, y * multiplier);
}
endShape();
noFill();
beginShape();
for (let i = 0; i <= 10; i++) {
let w = map(i, 0, 10, 0, PI);
let x = map(i, 0, 10, -this.mouthWidth / 2, 0);
let y = this.mouthHeight * sin(w + this.lipPart.x * 0.7);
y *= this.lipPart.z;
vertex(x * multiplier, y * multiplier);
}
for (let i = 0; i <= 10; i++) {
let w = map(i, 0, 10, PI, 0);
let x = map(i, 0, 10, 0, this.mouthWidth / 2);
let y = this.mouthHeight * sin(w + this.lipPart.x * 0.7);
y *= this.lipPart.z;
vertex(x * multiplier, y * multiplier);
}
endShape();
pop();
}
}
class Nose2 {
constructor() {
this.pos = createVector(width / 2, height / 2);
this.noseWidth = random(2, 4);
this.noseHeight = random(4, 13);
this.nostrilHide = random(-1, 0);
this.nostrilWidth = random(3, 9);
this.nostrilHeight = random(7, 14);
this.nostrilHeight2 = random(0.05, 0.2);
this.bulbShape = random(0.4, 1);
this.bulbShape2 = random(0.4, 1);
this.nostrolTilt = random(-0.5,0.5);
this.nostrilTilt = random(1);
this.nostrolPart = random(-0.7 ,0.7);
this.nostrolHeight = random(0.1,1);
this.nostrolWidth = random(0.1,1);
}
render() {
let multiplier = 10;
push();
translate(this.pos.x, this.pos.y);
fill(255);
//nostril
beginShape();
for (let i = 0; i <= 10; i++) {
let w = map(i, 0, 10, 0, PI);
let x = map(i, 0, 10, -this.nostrilWidth / 2, 0);
let y = this.nostrilHeight * -sin(w);
y *= this.nostrilHeight2;
x -= this.noseWidth + this.nostrilHide - 2*this.bulbShape2;
vertex(x * multiplier, y * multiplier);
}
for (let i = 0; i <= 10; i++) {
let w = map(i, 0, 10, PI, 0);
let x = map(i, 0, 10, 0, -this.nostrilWidth / 2);
let y = this.nostrilHeight * sin(w);
y *= this.nostrilHeight2;
x -= this.noseWidth + this.nostrilHide - 2*this.bulbShape2;
vertex(x * multiplier, y * multiplier);
}
endShape();
beginShape();
for (let i = 0; i <= 10; i++) {
let w = map(i, 0, 10, 0, PI);
let x = map(i, 0, 10, 0, this.nostrilWidth / 2);
let y = this.nostrilHeight * -sin(w);
y *= this.nostrilHeight2;
x += this.noseWidth + this.nostrilHide - 2*this.bulbShape2;
vertex(x * multiplier, y * multiplier);
}
for (let i = 0; i <= 10; i++) {
let w = map(i, 0, 10, PI, 0);
let x = map(i, 0, 10, this.nostrilWidth / 2, 0);
let y = this.nostrilHeight * sin(w);
y *= this.nostrilHeight2;
x += this.noseWidth + this.nostrilHide - 2*this.bulbShape2;
vertex(x * multiplier, y * multiplier);
}
endShape();
//nose bulb
beginShape();
for (let i = 0; i <= 10; i++) {
let w = map(i, 0, 10, 0, PI);
let z = map(i, 0, 10, -this.noseWidth / 2, this.noseWidth / 2);
let x = this.noseWidth * -sin(z * this.bulbShape);
let y = this.noseHeight * -sin(w);
vertex(x * multiplier, y * multiplier);
}
for (let i = 0; i <= 10; i++) {
let w = map(i, 0, 10, 0, PI);
let z = map(i, 0, 10, this.noseWidth / 2, -this.noseWidth / 2);
let x = this.noseWidth * -sin(z * this.bulbShape2);
let y = this.noseHeight * sin(w);
y *= 0.3;
y -= 0;
vertex(x * multiplier, y * multiplier);
}
endShape();
fill(0);
beginShape();
for (let i = 0; i <= 10; i++) {
let w = map(i, 0, 10, 0, PI);
let x = map(i, 0, 10, -this.noseWidth / 2, 0);
let y = this.noseHeight * -sin(w+this.nostrolTilt);
y *= 0.15*this.nostrolHeight;
x*=1.6 *this.nostrolWidth;
x -= this.noseWidth * 0.7 + this.nostrilHide - 2*this.bulbShape2 + this.nostrolPart;
y+=2;
vertex(x * multiplier, y * multiplier);
}
endShape();
beginShape();
for (let i = 0; i <= 10; i++) {
let w = map(i, 0, 10, 0, PI);
let x = map(i, 0, 10, this.noseWidth / 2, 0);
let y = this.noseHeight * -sin(w+this.nostrolTilt);
y *= 0.15 * this.nostrolHeight;
x*=1.6 *this.nostrolWidth;
x += this.noseWidth *0.7 + this.nostrilHide - 2*this.bulbShape2 + this.nostrolPart;
y+= 2;
vertex(x * multiplier, y * multiplier);
}
endShape();
pop();
}
}
class Nose {
constructor() {
this.pos = createVector(0, 0);
this.noseWidth = random(2, 8);
this.noseHeight = random(2, 11);
this.nostrilHide = random(-1, 0);
this.nostrilWidth = random(3, 9);
this.nostrilHeight = random(2, 7);
this.nostrilHeight2 = random(0.05, 0.2);
this.bulbShape = random(0.4, 1);
this.bulbShape2 = random(0.4, 1);
this.nostrolTilt = random(-0.5,0.5);
this.nostrilTilt = random(1);
this.nostrolPart = random(-0.7 ,0.7);
this.nostrolHeight = random(0.1,1);
this.nostrolWidth = random(0.1,1);
this.nostrilShape = random(0.5,1.7);
this.septum = random(2,7);
}
render() {
let multiplier = 10;
push();
translate(this.pos.x, this.pos.y);
fill(255);
//nostril
beginShape();
for (let i = 0; i <= 10; i++) {
let w = map(i, 0, 10, 0, PI);
let x = map(i, 0, 10, -this.noseWidth / 2, this.noseWidth/2);
let y = this.noseHeight * -sin(w) ;
vertex(x * multiplier, y * multiplier);
}
for (let i = 0; i <= 10; i++) {
let w = map(i, 0, 10, 0, PI);
// let x = map(i, 0, 10, this.noseWidth/2,0);
let x = this.noseWidth/5 * cos(w*this.nostrilShape);
let y = this.nostrilHeight/3 * sin(w);
x+= this.noseWidth/3;
vertex(x * multiplier, y * multiplier);
}
for (let i = 0; i <= 10; i++) {
let w = map(i, 0, 10, 0, PI);
// let x = map(i, 0, 10, this.noseWidth/2,0);
let x = this.noseWidth/4 * cos(w);
let y = this.septum/3 * sin(w);
// x+=2;
vertex(x * multiplier, y * multiplier);
}
for (let i = 0; i <= 10; i++) {
let w = map(i, 0, 10, PI, 0);
// let x = map(i, 0, 10, this.noseWidth/2,0);
let x = -(this.noseWidth/5 * cos(w*this.nostrilShape));
let y = this.nostrilHeight/3 * sin(w);
x-= this.noseWidth/3;
vertex(x * multiplier, y * multiplier);
}
endShape();
pop();
}
}
class Face{
constructor(x,y){
this.pos = createVector(x,y)
this.eyedist = random(50,95);
this.eyerise = random(-30,-70);
this.eyes = new Eye();
this.mouth = new Mouth();
this.nose = new Nose();
this.noseLoc = createVector(0,0);
this.mouthLoc = createVector (0,random(50,80));
this.eyeLoc = createVector (-this.eyedist,this.eyerise);
this.eyeLoc2 = createVector (this.eyedist,this.eyerise);
this.eyetilt= random(-0.1*PI,0.1*PI);;
this.noseLoc = random(-20,20)
}
render(){
push();
push();
translate(this.pos.x,this.pos.y);
translate(0,this.noseLoc);
this.nose.render();
pop();
push();
translate(this.pos.x,this.pos.y);
translate(this.mouthLoc);
this.mouth.render();
pop();
push();
// scale(0.8);
translate(this.pos.x,this.pos.y);
translate(this.eyeLoc);
rotate(this.eyetilt);
this.eyes.render();
pop();
push();
translate(this.pos.x,this.pos.y);
translate(this.eyeLoc2);
scale(-1,1);
rotate(this.eyetilt);
// translate(-width,0);
this.eyes.render();
pop();
pop();
}
}