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.
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