← Back to Learning Home

Turing Programming – Part 3

Graphics, Animation, and Your First Game

Why Graphics Matter

Graphics transform programming from text into something visual and interactive. Many real-world applications — games, simulations, engineering tools — depend on graphical programming.

⭐ Once you understand animation, you understand the foundation of game development.

1. Drawing Shapes

Turing includes powerful built-in drawing tools.

drawbox(100,100,300,300,blue)
drawoval(400,250,50,80,red)
drawfillbox(320,100,380,160,green)
✔ drawbox → rectangle ✔ drawoval → ellipse ✔ drawfillbox → solid rectangle

2. Graphing with Code

You can use loops to create graph-like visuals. Example: plotting a simple mathematical pattern.

for x : 0 .. 400
    var y := x div 2
    drawdot(x, y, brightblue)
end for

This produces a straight-line graph!

💡 Graphing is widely used in engineering, physics, and data science.

3. Creating a Moving Object

Animation works by repeatedly drawing an object in a new position.

var x := 0

loop
    cls
    drawfilloval(x,200,20,20,red)
    x += 2
    delay(10)
end loop

The circle moves across the screen!

⚠️ cls clears the screen each frame — essential for smooth animation.

4. Keyboard Control

Let the player control an object.

var x := 200
var chars : array char of boolean

loop
    Input.KeyDown(chars)

    if chars(KEY_LEFT_ARROW) then
        x -= 3
    end if

    if chars(KEY_RIGHT_ARROW) then
        x += 3
    end if

    cls
    drawfillbox(x,50,x+60,80,cyan)

    delay(10)
end loop

Now the object moves with arrow keys!

5. Simple Shooting Game 🔥

Let’s combine everything into a mini game. The player moves left/right and shoots upward.

var playerX := 200
var bulletX := -1
var bulletY := -1
var chars : array char of boolean

loop

    Input.KeyDown(chars)

    % Move player
    if chars(KEY_LEFT_ARROW) then
        playerX -= 4
    end if

    if chars(KEY_RIGHT_ARROW) then
        playerX += 4
    end if

    % Shoot bullet
    if chars(' ') and bulletY = -1 then
        bulletX := playerX + 20
        bulletY := 80
    end if

    % Move bullet
    if bulletY not= -1 then
        bulletY += 6

        if bulletY > maxy then
            bulletY := -1
        end if
    end if

    cls

    % Draw player
    drawfillbox(playerX,50,playerX+40,80,green)

    % Draw bullet
    if bulletY not= -1 then
        drawfilloval(bulletX, bulletY, 5, 5, yellow)
    end if

    delay(10)

end loop
🚀 Congratulations — you just built the foundation of a real video game!

Challenge Yourself

Try improving the game:
🔥 These are the same concepts used in professional games.

What You Should Learn Next