Creating functions()
Functions are used to make your code easier to write. Here’s a program I wrote:
float x_val; // the x value of each point
float y_val; // the y value of each point
void setup()
{
size(400,400);
strokeWeight(6);
frameRate(4);
colorMode(HSB);
}
void draw()
{
background(0);
stroke(random(255),255,255); // get a random color
x_val = (random(400));
y_val = (random(400));
point(x_val,y_val);
point(x_val,y_val+10);
point(x_val,y_val-10);
point(x_val+10,y_val);
point(x_val-10,y_val);
}
Watch Fun Programming Video [19]
Change the program to use a function like this:
void drawCross()
{
point(x_val,y_val);
point(x_val,y_val+10);
point(x_val,y_val-10);
point(x_val+10,y_val);
point(x_val-10,y_val);
}
Learning functions is really important. On this challenge, please show a mentor so we can check your code before marking the board and getting a prize.