Alphabet: 26 Languages

A few months ago, I started a project called Alphabet. 26 letters in my alphabet, 26 languages to discover.

What

I intend to write a small (tiny) program in 26 different languages, one for each letter of the latin alphabet.

I’m not sure yet what the program has to do but each implementation will probably have to do something with the first letter of its language.

Why

  • I will discover crazy languages
  • I will learn a lot about programming languages in general
  • It’s fun!

Letters already done

So far, only letters B and L are completed : Brainfuck and Lua.

Brainfuck

If you’ve read my brainfuck series, you’ve already seen the B entry.

1
2
+++++++++++[->+++>++++++>+<<<]>->>->>>++>+>+>++>+>+>++<<<<<<
[-[<+<+>>-]<<[>>+<<-]+>[[-]<[<]>>....>.[>]<->]<[[<]>>.<...>.>.[>]<-]+>>[-]>]

It prints a big B letter made of little B characters:

BBBB
B   B
B   B
BBBB
B   B
B   B
BBBB

Here is the commented code:

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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
***************
* Description *
***************

This program outputs:
BBBB
B B
B B
BBBB
B B
B B
BBBB

*************
* Algorithm *
*************

It defines two kinds of lines:
BBBB type 2
and
B B type 1

It also defines a sequence of lines:
2112112
corresponding to the final drawing

********
* Code *
********
prepare the letters
space = 32
B = 66
\n = 10
+++++ +++++ +
[-
>+++
>++++++
>+
<<<
]
>->>-



leave some space for temporary variables T1 and T2
>>
define the drawing pattern
>++>+>+>++>+>+>++
<<<<<<


main loop
[-
[<+<+>>-]<<[>>+<<-]+ if/else preparation

>[ if x

[-] T2 = 0
<[<]> rewind to letters
>....>. print line of type 2
[>] back to T2
<- T1 = 0 marks the if block as done
>] end if

<[ else
[<]> rewind to letters

>.<...>.>. print line of type 1
[>]< back to T1
-] end else
+>>[-]> T1 = 1 (for correct rewinds) / T2 is new T1 / reset x (new T2) / then go to next line in the sequence

]

Lua

The Lua code is a lot easier to read!

I used a framework but it starts with a L (Löve2D) so I decided it was fine :-). It’s a 2D game framework which I intend to write about later.

This code just draws a spinning colored L. Rotation speed and color oscillate.

You can change the letter by pressing another one.

Löve2D calls love.load() once, then calls love.update() and love.draw() repeatedly until you exit the program. love.keypressed/keyreleased() are called when such an event occurs.

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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
-- Lua starts with a L
-- Löve (2D framework) starts with an L
--> double fun

local angle = 0
local omega = 0
local mainFont
local infoFont
local hue
local letter = 'L' -- default letter
local infoText = 'If you don\'t like the L letter, press another one.'
local sadDeveloper = false
local sadText = 'I said a letter...'

function love.load()
mainFont = love.graphics.newFont(250)
infoFont = love.graphics.newFont(12)
end

function love.update(dt)
local t = love.timer.getTime()
omega = math.sin(t) * math.pi * 3 -- speed oscillates between ± 3 pi rad/s
angle = angle + omega * dt
angle = angle % (2 * math.pi)
hue = 128 + 127*math.cos(t)
end

function love.draw()
local w = love.graphics.getWidth()
local h = love.graphics.getHeight()

love.graphics.setFont(infoFont)
love.graphics.setColor(255, 255, 255)
local infoWidth = infoFont:getWidth(infoText)
love.graphics.print(infoText, (w - infoWidth)/2, 10)

if sadDeveloper then
local sadWidth = infoFont:getWidth(sadText)
love.graphics.print(sadText, (w - sadWidth)/2, h - 20)
end
-- rotation
love.graphics.translate(w/2, h/2)
love.graphics.rotate(angle)
love.graphics.translate(-w/2, -h/2)

love.graphics.setFont(mainFont)
love.graphics.setColor(HSL( hue , 255, 128))
local letterWidth = mainFont:getWidth(letter)
love.graphics.print(letter, (w - letterWidth)/2, (h - 250)/2)
end

function love.keypressed(k)
if k == 'escape' then
love.event.push('q') -- quit the game
end

-- change the printed letter
k = k:upper()
if k:len() == 1 and k:byte() >= string.byte('A') and k:byte() <= string.byte('Z') then -- if it's a letter
letter = k
else
letter = ':-('
sadDeveloper = true
end
end

function love.keyreleased(k)
letter = 'L'
sadDeveloper = false
end

-- from Love's wiki
function HSL(h, s, l, a)
if s<=0 then return l,l,l,a end
h, s, l = h/256*6, s/255, l/255
local c = (1-math.abs(2*l-1))*s
local x = (1-math.abs(h%2-1))*c
local m,r,g,b = (l-.5*c), 0,0,0
if h < 1 then r,g,b = c,x,0
elseif h < 2 then r,g,b = x,c,0
elseif h < 3 then r,g,b = 0,c,x
elseif h < 4 then r,g,b = 0,x,c
elseif h < 5 then r,g,b = x,0,c
else r,g,b = c,0,x
end return (r+m)*255,(g+m)*255,(b+m)*255,a
end

Next

My goal is to write one program per letter. It’s likely to take years.

I have selected several candidates for the other letters. Some are well-known languages, some are esoteric.

2 down, 24 to go!