Drawing a head nose and mouth in one function. Confused !!!!!!1
in
Programming Questions
•
2 years ago
Hi like the title says i need to draw a head nose and mouth in one function. I am still new to processing and i get concfused very easily with all the vars and in doing so i get lost what i want to do. my head function is very basic but i wanna use better code for drawing my head a nose and a mouth. My head function only draws the head i dunno why it's not drawing the mouth and the nose when i call the head function in the void setup. here is my code.
Also i have to Rewrite drawHead() so that it will accept two arguments which specify the position at which the head is drawn then i have to draw the head in three places on the display. Please reply asap. I really need help with this.
void setup() {
smooth();
size(500,500);
drawHead(250,350);
drawHead(400,120); // draws head at specific pos
drawHead(120,120); // draws head at specific pos
drawEyes(380, 100);
drawEyes(100, 100); // draws eyes at specific X .Y pos
}
// Function that draws head with eyes, mouth and nose
void drawHead(int xPos, int yPos) {
int headSize = 100; // var for the headsize
int mouthX = 100; // var for the x pos of the mouth
int mouthY = 125; // var for the y pos of the mouth
int mouthWidth = 100; // var for the mouth width of the mouth
int mouthHeight = 40; // var for the mouth height of the mouth
// booleon mouthTrue = true;
fill(255,216,0); // applies colour to the head
ellipse(xPos,yPos,headSize,headSize); // position of the head
line(113,130,125,130); // position of the first coordinate for the nose
line(113,130,120,135); // position of the second coordinate for the nose
line(120,135,125,130); // position of the third coordinate for the nose
noFill(); // applies no fill to the mouth
arc(mouthX,mouthY,mouthWidth, mouthHeight, PI/6,PI/2 ); // position of the mouse
}
void drawEye(int xPos, int yPos, int eyeSize) {
// set the fill to white
fill(255);
// draw the white of the eye
ellipse(xPos, yPos, eyeSize, eyeSize);
// set the fill to black
fill(0);
// draw the black pupil
ellipse(xPos, yPos, eyeSize/2, eyeSize/2);
}
void drawEyes(int xPos, int yPos) {
// specify the size of the eye
int eyeSize = 20;
// specify the gap between eyes
// base it on the size to ensure enough space
int gap = eyeSize*2;
drawEye(xPos, yPos, eyeSize); // draw the left eye
drawEye(xPos+gap, yPos, eyeSize); // draw the right eye
}
Also i have to Rewrite drawHead() so that it will accept two arguments which specify the position at which the head is drawn then i have to draw the head in three places on the display. Please reply asap. I really need help with this.
void setup() {
smooth();
size(500,500);
drawHead(250,350);
drawHead(400,120); // draws head at specific pos
drawHead(120,120); // draws head at specific pos
drawEyes(380, 100);
drawEyes(100, 100); // draws eyes at specific X .Y pos
}
// Function that draws head with eyes, mouth and nose
void drawHead(int xPos, int yPos) {
int headSize = 100; // var for the headsize
int mouthX = 100; // var for the x pos of the mouth
int mouthY = 125; // var for the y pos of the mouth
int mouthWidth = 100; // var for the mouth width of the mouth
int mouthHeight = 40; // var for the mouth height of the mouth
// booleon mouthTrue = true;
fill(255,216,0); // applies colour to the head
ellipse(xPos,yPos,headSize,headSize); // position of the head
line(113,130,125,130); // position of the first coordinate for the nose
line(113,130,120,135); // position of the second coordinate for the nose
line(120,135,125,130); // position of the third coordinate for the nose
noFill(); // applies no fill to the mouth
arc(mouthX,mouthY,mouthWidth, mouthHeight, PI/6,PI/2 ); // position of the mouse
}
void drawEye(int xPos, int yPos, int eyeSize) {
// set the fill to white
fill(255);
// draw the white of the eye
ellipse(xPos, yPos, eyeSize, eyeSize);
// set the fill to black
fill(0);
// draw the black pupil
ellipse(xPos, yPos, eyeSize/2, eyeSize/2);
}
void drawEyes(int xPos, int yPos) {
// specify the size of the eye
int eyeSize = 20;
// specify the gap between eyes
// base it on the size to ensure enough space
int gap = eyeSize*2;
drawEye(xPos, yPos, eyeSize); // draw the left eye
drawEye(xPos+gap, yPos, eyeSize); // draw the right eye
}
1