Code

void setup(){
  size (300,300);
  background (255,0,0);
  smooth();

  drawRandomLine();

  float x = getTheLargerOfTwoRandomNumbers();
  println (x);

  boolean y= isTheMonthGreaterThanTheHour();
  println ("the month is greater than the hour:" + y);

  float z= averageOfThreeNumbers(10,57,60);
  println ("the average is:" + z);

color potato = color(180, 150, 90);
  drawMisterPotatoHead(3, potato, true);

}

void drawRandomLine(){
  float x= random(5,50);
  float y= random (5,50);
  line(x, y, 2*x, 2*y);
}

float getTheLargerOfTwoRandomNumbers(){
  float firstNum = random (0,50);
  float secondNum = random (0,50);
  float biggerNum = max(firstNum, secondNum);
  return biggerNum;
}

boolean isTheMonthGreaterThanTheHour(){
  int hr = hour();
  int mo = month();
  boolean problem= hr < mo;
  return problem;
}

float averageOfThreeNumbers(int one, int two, int three){
  float totalAve= (float)((one + two + three)/3);
  return totalAve;
}

void drawMisterPotatoHead(int e, color c, boolean m) {
  fill(c);
  ellipse(150, 150, 200, 250);
  if (m=true) {
    mustache(width/2, (height/2)+20);
  }
  for (int i=0; i<e; i++) {
    int x= (int) random (100, 200);
    int y= (int) random (100, 200);
    eye(x, y);
  }
  
  
  
}

void eye(int x, int y) {
  fill(255);
  strokeWeight(1);
  stroke(0);
  ellipse(x,y, 40,40);
  fill(0);
  ellipse(x,y, 10,10);
}

void mustache(int x, int y) {
  fill(67, 34, 9);
  strokeWeight (10);
  line (100,170,200,170);
}

0401 - Function review: All manner of functions

Statement:This assignment asks you to create and use several functions. In addition to defining the code for the functions themselves, please also prove that they work correctly by calling/invoking them from your setup function. If you test a function by printing a result, make sure that your print command is not in the code of the function itself, but in the code which calls/invokes your custom function.

  • Create a function drawRandomLine, which takes no arguments, and which returns no values, but which draws a small random line in the upper left corner of the canvas.
  • Create a function called getTheLargerOfTwoRandomNumbers, which takes no arguments, but which generates two random numbers, and then returns the larger of these.
  • Create a function called isTheMonthGreaterThanTheHour, which takes no arguments, but which returns a true-or-false value indicating whether or not the month (numbered 1-12) is larger than the hour (numbered 0-23). To do this properly, go look up the month() and hour() functions in the Processing reference.
  • Create a function called averageOfThreeNumbers, which takes three integer arguments, and which returns a number which is the exact mathematical average of the inputs. Keep in mind that the answer could have a fractional component.
  • Create a function called drawMisterPotatoHead which draws a face of sorts, and which returns no value, but which takes the following three arguments: a round (whole) number; a color; and a true-or-false value. Use the round number to govern the number of eyes which are rendered (minimally, it should draw something reasonable-looking with up to 5 eyes). Use the color to change the color of the potato skin. Use the true-false value to govern whether a mustache is present.

    Broadly speaking, your code will look approximately like the following:

    void setup(){
      doSomething();
      println( doThingThatReturnsTrue() );
    }
    
    void doSomething(){
      // what goes here?
    }
    
    boolean doThingThatReturnsTrue(){
      return true;
    }
    

    hide statement