top of page

Functions

So, functions are all those key words that we use in our code like rect, fill or draw. These are longer pieces of code that are called by this single word because they are used over and over again and programmers want to repeat them quickly. You can make your own functions by writing a variable with the word function in it and in braces, {}, putting the code you want repeated. Then you need to call the function each time you want to use it (see below.) If you add parameters to the function, inside the parentheses, each time you call the function you can change the parameters. Whenever you find yourself repeating bits of code you should think: Can I make this into a function? If you make a function that calculates something you need to return the function to make it appear on the canvas. Local variables are defined inside a function and can only be used and seen within a function. Global variables are are defined outside of functions and can be seen throughout the entire program. There are some functions in JavaScript that have already been defined like: draw(), mouseMoved() and keyPressed(). These are called ProcessingJS functions and they are for drawing and interaction. If you want to use that function you HAVE to use that word exactly, e.g. draw rather than drawCar, because otherwise it won't work. It also means that you can't give any other functions that name. See more of the processingJS functions here. See my project related to functions here: Project: Fish Tank

 
Some function-based coding.
Featured Posts
Recent Posts
Archive
Search By Tags
Follow Us
  • LinkedIn Social Icon
  • Pinterest Social Icon
  • Facebook Basic Square

© 2023 by Coming Soon

Proudly created with Wix.com

bottom of page