Programming in Javascript - Functions
Complete the Khan Lessons. This assignment assumes you have completed the lesson that takes you through the Khan Academy tutorials assigned to you. Your teacher will track that you did all of tutorials by looking for the green circles for each tutorial that you will see linked vertically on the right of the Khan tutorial pages. There are points for this assignment for doing the tutorials assigned to you.
- Modify these previous assignment programs to use functions:
- Dancing Animals (from Khan Assignment 2); save this program at Khan with the name lastname_dancingAnimalsFun.
- Racing Animals (from Khan Assignment 2); save this program at Khan with the name lastname_racingAnimalsFun.
by identifing parts of the code that can be given a name (e.g. drawHead), and make those parts into functions. You must define and call at least two functions in each of the two programs, more are fine if good code design indicates more. The grading will be partially based on good choices for what parts of the code you made into functions. At least one function of all 4+ functions that you write should accept parameters (most of them probably should).
This results in two programs, A and B, for the modifications of the two past programs.
- Re-do your drawing of the animal from Khan Assignment 1 so that it two uses at least two functions.
Then, make drawing the whole animal into a function that takes parameters:
- the height of the animal,
- the animal's X coordinate center
- the animal's Y coordinate center
When called, your function should draw the whole animal proportionately with the height passed in the parameter. That is, a small height parameter should draw a smaller animal with all the animal parts proportionately smaller.
The function should draw the animal centered on the point indicatd by the X, and Y parameters.
Call your function 4 times to create instances of your animal with different heights at different places. Add a mousePressed function that draws a small height version of your animal at the position of the mouse when it was clicked. That is, your program should draw your animal four times before the mouse is clicked, then draw a small version of it every time the mouse is clicked (you can fill your screen with your animal by clicking). Save this program at Khan with the name lastname_resizeAnimal.