float angle = 0;
void setup() {
size(600, 600);
background(255);
//translate coordinates
pushMatrix();
float centreX = width/2;
float centreY = height/2;
translate(centreX, centreY);
head(400);
}
void head(float a) {
//unit a
float headlength = a;
float headheight = 0.85*a;
//ears
//reference point
float earpoint_1X = 0.1*a;
float earpoint_1Y = 0.3*a;
float eartipX = 0.5*a;
float eartipY = 0.7*a;
float earpoint_2X = 0.25*a;
float earpoint_2Y = 0.3*a;
//reference point for outer ear
float earouter_X = 0.4*a;
float earouter_Y = 0.1*a;
stroke(0);
strokeWeight(2);
fill(180,153,154);
//ear_triangle
beginShape();
vertex(-earpoint_1X, -earpoint_1Y);
vertex(-eartipX, -eartipY);
vertex(-earpoint_2X, -earpoint_2Y);
endShape(CLOSE);
beginShape();
vertex(earpoint_1X, -earpoint_1Y);
vertex(eartipX, -eartipY);
vertex(earpoint_2X, -earpoint_2Y);
endShape(CLOSE);
//ear_outer
stroke(0);
strokeWeight(2);
noFill();
line(-eartipX, -eartipY, -earouter_X, -earouter_Y);
line(eartipX, -eartipY, earouter_X, -earouter_Y);
//outer contour
stroke(0);
strokeWeight(2);
fill(180,153,154);
ellipse(0, 0, headlength, headheight);
//lower face
stroke(255);
strokeWeight(0);
fill(255);
arc(0,0,headlength, headheight, 0,PI);
//Contour of upper face
strokeWeight(0);
beginShape();
vertex(-0.5*headlength, 0);
bezierVertex(-0.25*headlength, 0, -0.25*headlength, -0.2*headheight, 0, -0.4*headheight);
bezierVertex(0.25*headlength, -0.2*headheight, 0.25*headlength, 0, 0.5*headlength, 0);
endShape(CLOSE);
//eyes
stroke(0);
strokeWeight(2);
fill(255);
ellipse(-0.25*a,-0.05*a,0.35*a,0.35*a); //left eye
ellipse(0.25*a,-0.05*a,0.35*a,0.35*a); //right eye
fill(0);
ellipse(-0.23*a,-0.04*a,0.2*a,0.2*a); //left eyeball
ellipse(0.23*a,-0.04*a,0.2*a,0.2*a); //right eyeball
//nose
stroke(0);
strokeWeight(2);
fill(0);
arc(0, 0.11*a, 0.08*a, 0.08*a, radians(225), radians(315));
//mouth
stroke(0);
strokeWeight(3);
noFill();
beginShape();
curveVertex(-0.25*a, 0.2*a);
curveVertex(-0.12*a, 0.28*a);
curveVertex(0, 0.2*a);
curveVertex(0.12*a, 0.28*a);
curveVertex(0.25*a, 0.2*a);
endShape();
// Whiskers
stroke(180,153,154);
strokeWeight(3);
float x = 0.23*a;
float y = 0.18*a;
float whiskerlength = 0.35*a;
line(-x,y,-x-whiskerlength,y-0.1*a);
line(x,y,x+whiskerlength,y-0.1*a);
line(-x,y+0.02*a,-x-whiskerlength,y+0.02*a);
line(x,y+0.02*a,x+whiskerlength,y+0.02*a);
line(-x,y+0.04*a,-x-whiskerlength,y+0.14*a);
line(x,y+0.04*a,x+whiskerlength,y+0.14*a);
}
/*
void draw() {
background(255);
translate(width/2, height/2);
rotate(angle);
head(400);
angle += 0.01;
}
*/
Processing(一) 简单的猫
最新推荐文章于 2024-08-30 20:56:13 发布