´╗┐

1.1 - What is a program ?

This tutorial will show you how the Algoid Turtle travels through its environment.
It covers moving and rotation of the little turtle, which will then create fun geometric shapes.

synopsis

  1. prerequisite
  2. basics
  3. moving and environment
  4. rotation
  5. it is your turn to play
  6. summary

  7. << back to tu(r)torials

prerequisite

No prerequisite is needed to read this tutorial, except the Algois app on your device ;-)

basics

What is a program?
A computer program is a sequence of written instructions that tell a computer to do things for us.
When I was little, I thought it was sufficient to talk to the computer to ask it do things.
Many people would love this to happen so there is a lot of effort in this direction.
But for now we have to settle for using programming languages that a computer can interpret.
The sequence of instructions that you write is called source code.
Therefore the programmer must imagine the process involved and then write the source code of the program.
After writing, the program is executed by the machine and it does what the programmer wanted it to do (most of the time!).
In AL, lines of code are usually separated by a semi-colon symbol ";" but it is not mandatory.
It is good practice to separate your lines of code with a carriage return too.

 
This is an example of an AL programm: 
  • 1
  • 2
  • 3
algo.go (100);
algo.turnRight (90);
algo.go (100);

Note: To execute the program touch menu / run.
You can disable the step by step mode by touching the menu / execution / step by step.

Translation:
Move turtle forward 100 pixels
Rotate turtle to the right through a 90 degree angle
Move turtle forward 100 pixels

What does it do?

moving and environment

The Algoid turtle can move forwards in relative mode: it moves from the current position along its current orientation for the required distance.
In our previous example, the turtle was oriented to the top of the screen at position 0, 0 (at the center of the algoid screen).
We move the turtle foreward with the instruction algo.go (100), and when the turtle executes this it moves up to coordinates 0, 100.

rotation

The turtle can also rotate in relative mode. The new orientation is determined by adding the angle turned to the current orientation.
In our previous example, the turtle's initial orientation was 0┬░ and we told it to turn right through a 90┬░ angle.
All angles are between 0┬░ and 360┬░, where 360┬░ is a complete turn around and corresponds to 0┬░.
This image demonstrates the different orientations achieved using the instruction algo.turnRight ():
The algo.turnLeft () does the same thing but in reverse, so the angles are reversed on the wheel:
So the simplest approach is usually to use the both functions; algo.turnRight () and algo.turnLeft () between 0┬░ and 180┬░:

relativity

Eurêka! Everything is relative!
The relative way to determine the position of a point in space is called euclidean space.
Each time the turtle is moved and rotated, its reference changes and that will affect its future position.
For example, if the turtle has already been rotated to 45┬░ with algo.turnRight () function, its new orientation will be:

it is your turn to play

ex1: a square

Draw a small square. Write a script to draw the following square:

 
Solution: 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
// left
algo.go (100);
algo.turnRight (90);
// top
algo.go (100);
algo.turnRight (90);
// right
algo.go (100);
algo.turnRight (90);
// bottom
algo.go (100);
algo.turnRight (90);

ex2: a starecase

Draw a small staircase. Write a script to draw the following figure:

 
Solution: 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
// floor
algo.turnLeft (90);
algo.go (200);
// stare 1
algo.turnRight (90);
algo.go (50);
algo.turnRight (90);
algo.go (50);
// stare 2
algo.turnLeft (90);
algo.go (50);
algo.turnRight (90);
algo.go (50);
// stare 3
algo.turnLeft (90);
algo.go (50);
algo.turnRight (90);
algo.go (50);
// stare 4
algo.turnLeft (90);
algo.go (50);
algo.turnRight (90);
algo.go (50);
// closing
algo.turnRight (90);
algo.go (200);

ex3: a pyramid

Write a script to draw the following figure:

 
Solution: 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
// floor
algo.turnLeft (90);
algo.go (200);
// stare 1
algo.turnRight (90);
algo.go (50);
algo.turnRight (90);
algo.go (50);
// stare 2
algo.turnLeft (90);
algo.go (50);
algo.turnRight (90);
algo.go (50);
// stare 3
algo.turnLeft (90);
algo.go (50);
algo.turnRight (90);
algo.go (50);
// stare 4
algo.turnLeft (90);
algo.go (50);
algo.turnRight (90);
algo.go (50);
// stare 5
algo.go (50);
algo.turnRight (90);
algo.go (50);
algo.turnLeft (90);
// stare 6
algo.go (50);
algo.turnRight (90);
algo.go (50);
algo.turnLeft (90);
// stare 7
algo.go (50);
algo.turnRight (90);
algo.go (50);
algo.turnLeft (90);
// stare 8
algo.go (50);
algo.turnRight (90);
algo.go (50);
// floor
algo.turnRight (90);
algo.go (200);

ex4: another pyramid

Write a script to draw the following figure:
Tip : The angle at each corner of the triangle is 360┬░ / 3 sides = 120┬░

 
Solution: 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
// initialize the turtle position
algo.turnLeft (90);
// the begin of the bottom side
algo.go (100);
algo.turnRight (120); // 360 / 3
// side 2
algo.go (200);
algo.turnRight (120);
// side 3
algo.go (200);
algo.turnRight (120);
// finnish the bottom side
algo.go (100);

´╗┐

summary

Summary

In this tutorial, you have learned:

  • what is a program?
  • how to do some fun drawings with very simple instructions.

Functions used

FunctionDescription