Your programs should draw compositions of compound figures using the least possible code.
Using the necessary blocks and what you know so far, imagine the code that can create this image:
Does it seem laborious and repetitive to you? If you have reached this conclusion, you are on the right track! Can you think of a solution to avoid repeating the code several times when drawing the 2 girls and the 3 birds?
To solve this problem, functions were invented.
A function is a block of code that contains a series of instructions.
Each function performs a specific task such as "draw a bird" or "draw a girl". Every time you want to "draw a bird", instead of calling a bunch of functions to draw figures, simply call the "drawBird" function.
Declare and implement the 'drawBird' function as follows:
That's it! Now you can call the 'drawBird' function whenever you want to draw a bird.
The 'drawBird' function in written code (do not show to very young players):
Now you can reuse the function. Every time you call the 'drawBird' function, a bird is drawn.
Using blocks, declare and implement the 'drawGirl' and 'drawHouse' functions.
You can now complete the following program to draw a tree with 3 birds and 2 girls next to a house using the 'drawHouse', 'drawBird', and 'drawGirl' functions.
Of course! You already know how to create functions and how to reuse them in your programs! Create other programs that call your functions and draw other compositions. Run the programs and draw on the whiteboard.
You can use blank tiles to write new functions. Use the marker to write on them.
Use more tiles to draw other geometric shapes.