This theme is based on the fact that every calculator’s number could be drawn with the above schema:
If we want to draw a filled rectangle with dimensions 100 by 200, a first idea could be to draw a rectangle 100 by 200
then to draw a rectangle 99 by 199, then a rectangle 98 by 198 ... until the rectangle is fully filled.
Let’s begin by defining a rectangle with two variables corresponding to width and height
To fill our rectangle, we have to run:
rec 100 200 rec 99 199 rec 98 198 ..... rec 1 101
Let’s define a procedure for this filled rectangle.
We test rectangular 100 200 and we can see there is a problem: The procedure doesn’t stop when the rectangle has been filled, it continues infinitely! We must add a breakout test that will detect if width or height is equal to 0. When this condition is realized, we’ll ask the program to stop with the primitive stop.
Note: Instead of using the primitive or, it’s possible to use the symbol |, the line becomes:
if :h=0 | :w=0 [stop]
We must reuse the precedent filled rectangle:
We suppose that the turtle starts from the bottom left corner. We’re going to define a procedure called number
depending on 7 arguments :a, :b, :c, :d, :e, :f, :g. When :a is equal to 1, we draw the rectangle 1. If :a is equal
to 0, we don’t draw this rectangle. Here is the main idea.
The code:
In this part, we’ll define a countdown from 9 to 0.
Little problem: There is a flickering effect during each number drawing. To make the animation fluid, we’re going to
use the three primitives animation, stopanimation and repaint.
Here is the new code for this procedure: