Code

//yeah i can't get this to work at all...

void setup() {
  size(300,300);
  smooth();
  background(255);
  drawRandomLine();
  color cpotato = color (200,200,100);
  drawpotato(averageofthreenumbers, cpotato, isthemonthgreaterthanthehour);
  
}

void drawRandomLine() {
  float x1 = random (0,10);
  float x2 = random (0,50);
  float y1 = random (0,80); 
  float y2 = random (0,30);
  line(x1, y1, x2, y2);
}

float getthelargeroftworandomnumbers(){
  float number1 = random (0,50);
  float number2 = random (0,50);
  float larger = max (number1, number2);
  return larger;
}

boolean isthemonthgreaterthanthehour(){
  int imonth = month();
  int ihour = hour();
  boolean greater = imonth > ihour;
  return greater;
}

float averageofthreenumbers(float number1, float number2, float number3){
  float avg = ((number1 + number2 + number3)/3);
  return avg;
}

void eye(int x, int y){
  fill(255);
  strokeWeight(2);
  ellipse(x,y,20,30);
}

void mustache(int x, int y){
  fill (40,46,50);
  noStroke();
  rect((width/2)-10, (height/2)-10, 20,10);
}

void drawpotato(int averageofthreenumbers, color cpotato, boolean isthemonthgreaterthanthehour){
  noStroke();
  smooth();
  fill(cpotato);
  ellipse(width/2, height/2, 125,175);
  if (isthemonthgreaterthanthehour=true){
    mustache (width/2, height/1.75);
  }
  for (int i=0; i<n; i=i+1){
    eye(random(width/2)-20, random(width/2)+20);
    eye(random(width/2)-20, random(width/2)+20);
  }
  }
}

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