Very simple snake game for beginners

I made this snake game (its free roaming so you can turn in all directions not cell based) for a codea user and I thought it the ideas behind it were so simple it would be good for beginners.
Start moving your finger over the screen in different directions and you’ll soon know how to make it turn. Feel free to use this however you please.

-- snake by Luatee

-- Use this function to perform your initial setup
function setup()
    -- We set up a table of the snake parts (1. Head, 2+. Body) 3 to begin with the first being the head
    snaketbl = {vec2(WIDTH/2,100),vec2(WIDTH/2,80),vec2(WIDTH/2,60)}
    snakespeed = 3
    -- Give the snake some food as a position
    snakefood = vec2(100,HEIGHT-200)
    -- Direction the snake travels
    snakedir = vec2(0,1)
    score = 0
    started = false

function touched(t)
    -- Start the program when first tapped
    if started == false and t.state == BEGAN then
        started = true
    -- Move snake according to touch direction
    snakedir = snakedir + vec2(t.deltaX/75,t.deltaY/75)
    snakedir = snakedir:normalize() 
-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(71, 71, 90, 255)

    -- This sets the line thickness
    -- This creates a scope in which different styles can be set (i.e. fill,stroke,blendMode)
    for i=1,#snaketbl do
        if i>1 then
            -- This makes the previous part of the snakes body link to the one in front
            snaketbl[i] = snaketbl[i-1]+(snaketbl[i]-snaketbl[i-1]):normalize()*20
        -- Draw snake body using ellipse
    if started then
    fill(40, 110, 130, 255)
    -- Move the snakes head (snaketbl[1]) using the snakespeed and direction of travel
    snaketbl[1] = snaketbl[1] + snakedir*snakespeed
    -- Slowly increase the snakespeed to add difficulty
    snakespeed = snakespeed + 0.0005
        Tap the screen to begin!
        Drag your finger in the direction you want
        the snake to turn to. If you leave the screen
        you will die. Eat the food to become bigger!
        Warning the snake speeds up over time!]],WIDTH/2,HEIGHT/2)
    -- Kill the snake if it hits the wall and restart program
    if snaketbl[1].x<10 or snaketbl[1].x>WIDTH-10 or snaketbl[1].y<10 or snaketbl[1].y>HEIGHT-10 then
    -- Check if the snake head can reach its food
    if snaketbl[1]:dist(snakefood)<20 then
        -- Move snakefood once eaten
        snakefood = vec2(math.random(50,WIDTH-50),math.random(50,HEIGHT-50))
        score = score + 1
        -- Add new part to snake body
    text("Score: "..score,50,50)

Enjoy, hope you guys can use this.

@luatee very cool! I’d like the snake to die if it touches itself too!

@luatee very nice. Here’s my take on snake aimed at beginners -

@Jmv38 sure I will probably have to slow down direction change to avoid the head hitting the third or fourth if the turn is too quick, thanks! Is it simple enough do you think?

@West that’s very in depth I think that will help a lot of people, with a different approach too.