Help! need assistance on including a void in an if statement? is it possible?

Hi, this is something that I am working on for a college project, is it possible to put the void eyes() into the snowman head?

void setup() {
size(1280, 720);
background(55, 126, 231);
fill(255);
rect(0, 610, width, height/6);
fill(29, 157, 25);
triangle(0, 610, 170, 120, 610, 610);
fill(29, 107, 25);
triangle(0, 610, 250, 150, 610, 610);
fill(29, 157, 115);
triangle(0, 610, 70, 220, 610, 610);
fill(129, 127, 125);
triangle(50, 610, 370, 150, 610, 610);
frameRate(25);

//Littleforest using a for loop
for (int x = 1; x < 11; x++)
{
fill(33, 79, 24);
triangle(320 + 69 * x, 610, 330 + 69 * x, 500, 350 + 69 * x, 610);
fill(133, 209, 24);
triangle(370 + 75 * x, 610, 380 + 75 * x, 510, 400 + 75 * x, 610);
fill(29, 167, 25);
triangle(460 + 50 * x, 610, 470 + 50 * x, 520, 490 + 50 * x, 610);
fill(51, 105, 30);
triangle(420 + 60 * x, 610, 430 + 60 * x, 510, 450 + 60 * x, 610);
fill(34, 139, 34);
triangle(390 + 55 * x, 610, 400 + 55 * x, 490, 420 + 55 * x, 610);
}
}

void draw() {//sets up the event listener for all the events below
eye(150, 360);
eye(170, 350);

if (mousePressed) {
if (mouseButton ==LEFT) {
stroke(1);
fill(255, 255, 250);
ellipse(150, 580, 180, 180); //body
} else if (mouseButton==CENTER)
{
stroke(1);
fill(255, 255, 250);
ellipse(150, 480, 140, 140); //Middle
} else if (mouseButton==RIGHT) {// head

  stroke(1);
  fill(255, 255, 250);
  ellipse(150, 380, 110, 110); 
  fill(0);

  //ellipse(130, 360, 10, 10);//left eye
  // ellipse(170, 360, 10, 10); //right eye
  fill(255, 50, 0);
  triangle(160, 370, 160, 400, 140, 370);//nose
  ellipse(120, 400, 10, 10);//smileleft
  ellipse(130, 410, 10, 10);//smileleft
  ellipse(140, 415, 10, 10);//smileright
  ellipse(180, 400, 10, 10);//smileleft
  ellipse(150, 415, 10, 10);//smileright
  ellipse(160, 415, 10, 10);//smileright
  ellipse(170, 410, 10, 10);//smileright
}

}
}
void eye(int x,int y){
fill(255);
ellipse(x,y,12,12);
fill(0);
ellipse(x+2,y,6,6);
fill(255);
ellipse(x+3,y-1,1,1);
}

void mouseMoved()
{
fill(25, 25, 25);
textSize(50);
text(“Do you want to build a Snowman?”, width/3, height/4);
}
void mousePressed() {

fill(12, 45, 255);
textSize(30);
text(“Did you just Sing that??”, width/9, height/9);
}

void mouseDragged() {
noStroke();
fill(255);
ellipse(random(mouseX), random(mouseY), 5, 5);
textSize(100);
fill(60, 225, 225);
text(“Let it Snow”, width/2, height/2);
}

void mouseClicked () {
}

Yes you can call eye from snowman function

Looks very nice! Great Sketch!

Here is the Sketch with eyes in the if-clause. The function eye() gets called from inside the if-clause.

Hey, and welcome to the forum!

Great to have you here!

Chrisir




void setup() {
  size(1280, 720);

  background(55, 126, 231);
  fill(255);
  rect(0, 610, width, height/6);
  fill(29, 157, 25);
  triangle(0, 610, 170, 120, 610, 610);
  fill(29, 107, 25);
  triangle(0, 610, 250, 150, 610, 610);
  fill(29, 157, 115);
  triangle(0, 610, 70, 220, 610, 610);
  fill(129, 127, 125);
  triangle(50, 610, 370, 150, 610, 610);
  frameRate(25);

  //Little forest using a for loop
  for (int x = 1; x < 11; x++)
  {
    fill(33, 79, 24);
    triangle(320 + 69 * x, 610, 330 + 69 * x, 500, 350 + 69 * x, 610);
    fill(133, 209, 24);
    triangle(370 + 75 * x, 610, 380 + 75 * x, 510, 400 + 75 * x, 610);
    fill(29, 167, 25);
    triangle(460 + 50 * x, 610, 470 + 50 * x, 520, 490 + 50 * x, 610);
    fill(51, 105, 30);
    triangle(420 + 60 * x, 610, 430 + 60 * x, 510, 450 + 60 * x, 610);
    fill(34, 139, 34);
    triangle(390 + 55 * x, 610, 400 + 55 * x, 490, 420 + 55 * x, 610);
  }
}

void draw() {

  //sets up the event listener for all the events below

  if (mousePressed) {
    if (mouseButton == LEFT) {
      //body
      stroke(1);
      fill(255, 255, 250);
      ellipse(150, 580, 180, 180);
    } else if (mouseButton == CENTER) {
      // middle
      stroke(1);
      fill(255, 255, 250);
      ellipse(150, 480, 140, 140);
    } else if (mouseButton == RIGHT) {
      // head
      stroke(1);
      fill(255, 255, 250);
      ellipse(150, 380, 110, 110); 
      fill(0);

      //ellipse(130, 360, 10, 10);//left eye
      // ellipse(170, 360, 10, 10); //right eye
      fill(255, 50, 0);
      triangle(160, 370, 160, 400, 140, 370);//nose
      ellipse(120, 400, 10, 10);//smileleft
      ellipse(130, 410, 10, 10);//smileleft
      ellipse(140, 415, 10, 10);//smileright
      ellipse(180, 400, 10, 10);//smileleft
      ellipse(150, 415, 10, 10);//smileright
      ellipse(160, 415, 10, 10);//smileright
      ellipse(170, 410, 10, 10);//smileright

      eye(150, 360);
      eye(170, 350);
    }
  }
}

void eye(int x, int y) {
  fill(255);
  ellipse(x, y, 12, 12);
  fill(0);
  ellipse(x+2, y, 6, 6);
  fill(255);
  ellipse(x+3, y-1, 1, 1);
}

void mouseMoved() {
  fill(25, 25, 25);
  textSize(50);
  text("Do you want to build a Snowman?", width/3, height/4);
}

void mousePressed() {
  fill(12, 45, 255);
  textSize(30);
  text("Did you just Sing that??", width/9, height/9);
}

void mouseDragged() {
  noStroke();
  fill(255);
  ellipse(random(mouseX), random(mouseY), 5, 5);
  textSize(100);
  fill(60, 225, 225);
  text("Let it Snow", width/2, height/2);
}

void mouseClicked () {
}
//

1 Like

Thank you was pulling out my hair on that :smile:

1 Like

Of course you could display the sun and when you click on the sun, eyes appear… :wink: