SHOP

PLAY

CREATE

4

Calling functions with parameters

Material required: Download material .pdf

Play

1

What is our goal?

A player draws a a drawing on the screen (whiteboard). The goal is for him/her to write a program that enables a second player to replicate the exact same drawing by reading the program.

2

How do we play?

1) One player draws a drawing using basic geometric shapes on a coordinate system. 2) Without showing the drawing to the other player, he/she writes a program that allows anyone to replicate the drawing. 3) Once the program is written, the second player interprets it to recreate the original drawing.

3

Parameters?

1

When you want to draw a circle you call the 'drawCircle' function

Program with blocks that draws a circle using a drawCircle function call

But where on the screen will the program draw the circle?

Programmer confused about where does he has to draw a circle on a screen "Will the circle be drawn on the left or the right side of the screen?"

What size will the program draw the circle?

Programmer confused about the size of a circle he has to draw on a screen "Will the circle be small or large?"

To solve this problem, the function requires parameters.

Parameters specify where the function should draw the circle and what its size should be.

To achieve this, drawCircle function has three parameters: x, y and radius.

drawCircle(x, y, radius)

Example of function call:

drawCircle(5,6,3);

Program with blocks that draws a circle using a drawCircle function call with parameters
Circle drawn on a screen over coordinate system
2

Let's practice!

  • drawRectangle(x,y,width,height);
    Rectangle drawn on a screen over coordinate system using a drawRectangle function with parameters
    drawRectangle(6,2,4,1);
  • drawLine(x1,y1,x2,y2);
    Line drawn on a screen over coordinate system using a drawLine function with parameters
    drawLine(10,3,15,5);
  • drawTriangle(x1,y1,x2,y2,x3,y3);
    Triangle drawn on a screen over coordinate system using a drawLine function with parameters
    drawTriangle(7,11,7,13,4,13);
  • drawCircle(x,y,radius);
    Circle drawn on a screen over coordinate system using a drawCircle function with parameters
    drawCircle(8,2,2);
  • drawSemicircle(x,y,radius,angle);
    Semicircle drawn on a screen over coordinate system using a drawSemicircle function with parameters
    drawSemicircle(8,2,2,0);
    angle = 0°
    Semicircle drawn on a screen over coordinate system using a drawSemicircle function with parameters
    drawSemicircle(8,2,2,90)
    angle = 90°
    Semicircle drawn on a screen over coordinate system using a drawSemicircle function with parameters
    drawSemicircle(8,2,2,180);
    angle = 180°
4

Draw secretly!

Do not show your drawing to the other player!

Player 1 draws a drawing using basic geometric shapes on the 'draw your own' card with a coordinate system. If you don't have one download the coordinate system here.

Drawing of a plane on a coordinate system using basic geometric figures. It is a plane
5

Writing the program

1

Using blank tiles, create the function calls with parameters needed to replicate the drawing.

Code block blank tiles

TIP: If tile is too small use big ones or use shorter names for function such as 'dTriangle' instead of 'drawTriangle'.

Function calls with arguments written on blank tiles.
2

Using BEGIN, END, code blocks and the the blank tiles with the function calls you created, create the program to draw the plane.

Program that draws a plane
5

Reading the program

The player that wrote the program shows it to the second player.

With the help of a pawn, starting at BEGIN, the second player interprets the code line by line and draws on the screen (whiteboard).

Player interpreting a program's code
6

When does the game end?

The game ends when the player that is interpreting the program finish calling all the functions and drawing the plane. Once finished, verify this drawing done from code with the original one..