I saw Intas' Typewriter Effect and it was really cool. But when I say the name, I don't know why, I expected another thing.
So I made something near to what I expected, and here's it: my version of the Typewriter Effect.
I, personally, like it.
- Save a 'typewriter.ms' file with the code below
- File.copy '/sys/sounds/cha-ching.wav' to the folder where the 'typewriter.ms' file is and rename it to "chaching.wav"
- Run the 'typewriter.ms'. It will print an example. Use 'typewriter.type (text)' to print text.
Here's the code:
display(5).mode = displayMode.pixel
gfx = display(5)
gfx.clear "#00000000"
gfx.scrollX = 0
gfx.scrollY = 0
Typewriter = {}
Typewriter.x = 0
Typewriter.y = 25
Typewriter.clear = 1
Typewriter.delay = 0
Typewriter.curX = 0
Typewriter.curY = 25
Typewriter.pageLenght = 55
Typewriter.typeSound = file.loadSound("chaching.wav")
Typewriter.pageEndSound = file.loadSound("chaching.wav")
Typewriter.type = function( text )
self.curX = self.x
self.curY = self.y
if self.clear then gfx.clear
for c in text
wait self.delay
self.curX = self.curX + 1
if self.curX == self.pageLenght + 1 then
self.curX = 0
self.curY = self.curY - 1
self.pageEndSound.play
end if
slightYchange = floor(rnd * 6) - 3
slightXchange = floor(rnd * 6) - 3
gfx.print c, self.curX * 17 + slightXchange, self.curY * 20 + slightYchange
self.typeSound.play 1, 0, 10 + round(rnd * 10 / 10, 1)
for i in range(self.curX * 17, self.curX * 17 + 17)
for n in range(self.curY * 20, self.curY * 20 + 18)
if gfx.pixel(i, n) == "#FFFFFFFF" then
if gfx.pixel(i + 1, n) == "#00000000" and floor(rnd * 10) == 0 then gfx.setPixel i + 1, n, "#FFFFAAFF"
if gfx.pixel(i - 1, n) == "#00000000" and floor(rnd * 10) == 0 then gfx.setPixel i - 1, n, "#FFFFAAFF"
if gfx.pixel(i, n + 1) == "#00000000" and floor(rnd * 10) == 0 then gfx.setPixel i, n + 1, "#FFFFAAFF"
if gfx.pixel(i, n - 1) == "#00000000" and floor(rnd * 10) == 0 then gfx.setPixel i, n - 1, "#FFFFAAFF"
end if
end for
end for
end for
self.y = self.curY
self.x = self.curX
key.clear
end function
Typewriter.setPos = function(x, y)
if y != self.y then self.pageEndSound.play
self.x = x
self.y = y
end function
typewriter = new Typewriter
typewriter.type "Hello. This is World Lover sending a message to you: Love the world."
typewriter.clear = 0
wait 1
typewriter.setPos 0,typewriter.y-1
typewriter.type ["And brush your teeth.","And love me.","And watch TV.","And use typewriters."][floor(rnd*4)]
wait 1
typewriter.setPos 0,typewriter.y-3
typewriter.type "- World Lover"```