Using Functions
As you probably know, functions help make your code reusable. They also ensure your code isn’t duplicated unnecessarily throughout your app. You place the code you want to re-use inside a function, and that function is what you tell the rest of your app to call. That is pretty straighforward.
When it comes to drawing stuff on the canvas
, the biggest advantage of functions is that you can pass arguments that your drawing code then uses to customize what gets drawn. Before I bore you any further, here is the full code for the circles example:
Get hands-on with 1400+ tech skills courses.