Code
void setup(){
smooth();
size (300, 300);
drawRandomLine ();
float num = getTheLargerofTwoRandomNumbers ();
println ("number = " + num);
boolean isit = isTheMonthGreaterThanTheHour ();
println ("Is it true or false? " + isit);
float avgof3 = averageOfThreeNumbers (1, 2, 3);
println (avgof3);
drawMisterPotatoHead (5, color(30,200,200), true);
}
void drawRandomLine(){
line (random(20), random(20), random (20), random(20));
}
float getTheLargerofTwoRandomNumbers (){
float a = random(201923912);
float b = random(209192130);
float big;
if (a > b){
big = a;
}
else if (b > a){
big = b;
}
else { //if a and b are equal, big is set to 0
big = 0;
}
return big;
}
boolean isTheMonthGreaterThanTheHour(){
int h = hour();
int m = month();
boolean which;
if (m > h) {
which = true;
}
else {
which = false;
}
return which;
}
float averageOfThreeNumbers (int j, int k, int l){
float avg = (j + k + l)/3;
return avg;
}
void drawMisterPotatoHead (int number, color col, boolean TorF){
fill (col);
ellipse (width/2, height/2, 200, 275);
for (int i = 0; i < number; i++){
fill (255);
float ex = (width/2) + random (-50, 50);
float ey = 100 + random (-30, 30);
ellipse (ex, ey, 25, 50);
fill (0);
ellipse (ex, ey, 10, 20);
}
if (TorF == true){
triangle (100, 220, width/2, 190, 200, 220);
}
fill (255, 0, 0);
ellipse (width/2, height/2, 50, 50);
}
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