Skip to content
Michael Musick edited this page Apr 30, 2017 · 23 revisions

HW 7 - Refactor a Sketch with Functions

This is due by class on Monday (March 13th)

For your homework this week, you are to take an old sketch and "refactor" it to leverage functions.

This means you are to take an old sketch, and use functions to simplify the code, or to make it more "readable". Ideally, each function, would encapsulate the most simple thing to do possible. To do this, you will take parts of your code that exist in the setup() or draw() loops, and move them into their own function definitions.

/* EXAMPLE OF CALLING FUNCTIONS */
draw(){
    var der = myFunc(34, myVar1);
    myFunc2();
}

/* EXAMPLE OF DEFINING FUNCTIONS */
// Global Function Declaration
function myFunc(arg1, arg2){
    doSomethingWith(arg1);
    doSomethingWith(arg2);
    // or
    return arg1 + arg2;
}
// Static Function Declaration
var myFunc2 = function(){
    doSomething();
}

Feel free to extend your creative work as well, but know that the main goal of this weeks assignment is to practice defining, and calling functions.

READ AND WATCH (Optional)

SUBMISSIONS

Clone this wiki locally