Code
boolean bMustache = true;
boolean bMonthGreaterThanTheHour = false;
int numberOfEyes = (int)random (6,10);
color potatoSkinColor = color (255, random (140,200), random (100,200));
float firstNumber = random (0,400);
float secondNumber = random (0,400);
void setup () {
size (300,300);
background (255);
drawRandomLine ();
float larger = getTheLargerOfTwoRandomNumbers ();
println ("The larger of " + firstNumber + " and " + secondNumber + " is " + larger);
bMonthGreaterThanTheHour = isTheMonthGreaterThanTheHour ();
if (bMonthGreaterThanTheHour == true) {
println ("The current Month is greater than the current hour!");
}
else {
println ("The current hour is greater than or equal to the current month!");
}
float average = averageOfThreeNumbers (60.0,85.0,42.0);
println ("The average of 60, 85, and 42 equals " + average);
drawMisterPotatoHead (numberOfEyes, potatoSkinColor, bMustache);
}
void drawRandomLine () {
float x1 = random (0,150);
float y1 = random (0,150);
float x2 = random (0,150);
float y2 = random (0,150);
line (x1,y1, x2,y2);
}
float getTheLargerOfTwoRandomNumbers () {
float larger = max (firstNumber, secondNumber);
return larger;
}
boolean isTheMonthGreaterThanTheHour () {
int currentMonth = month ();
int currentHour = hour ();
boolean result = currentMonth>currentHour;
return result;
}
float averageOfThreeNumbers (float a, float b, float c){
float average = (a+b+c)/3 ;
return average;
}
void drawMisterPotatoHead (int eyes, color skin, boolean mustache) {
noStroke();
fill (skin);
ellipse (225,225, 80,150);
float r = red(skin);
float g = green(skin);
float b = blue(skin);
color eyeColor = color (r-random(100,150),g-random(100,150),b-random(100,150));
fill (eyeColor);
for (int i=0; i<eyes; i++){
ellipse (random (225-20,225+20),random (225-55,225+55),random (5,25),random (5,25));
}
if (mustache == true){
fill (50,25,10);
bezier (225-30,225+20, 225-15,225, 225+15,225, 225+30,225+20);
}
fill (255);
ellipse (225+15,225-20, 15,15);
ellipse (225-15,225-20, 15,15);
fill (0);
ellipse (225+15,225-15, 5,5);
ellipse (225-15,225-15, 5,5);
}
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.
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