-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanimation.lua
More file actions
84 lines (56 loc) · 1.41 KB
/
animation.lua
File metadata and controls
84 lines (56 loc) · 1.41 KB
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
--[[
functions related to simple text animations. These are declared as
comma-separated lists like so:
~a{1,2,3,4}
the above would cause the displayed value to march from 1 to 4 over and over
for as long as the animation is active. Other effects can be obtained with
clever use of characters, e.g.
~a{\,|,/,-,}
should create a classic 'spinner' and
~a{.,o,O}
should create a 'bubbling' effect
However, it's important to use monospaced fonts to get good results
Color tags like ~r, or ~g can be used in these animations:
~a{~r-~0--,-~r-~0,--~r-~0,-~r-~0-}
Gives a 'knight rider' effect with a single red '-' sliding back and forth
]]--
animations={
--animations.tick() returns the next string in the animation
tick=function(self, anim, pos)
local toks, str, i
local count=0
toks=strutil.TOKENIZER(anim, ",", "q")
str=toks:next()
while str
do
count = count + 1
str=toks:next()
end
if count > 0 then count = pos % count end
toks=strutil.TOKENIZER(anim, ",", "q")
for i=0,count,1
do
str=toks:next()
end
return str
end,
-- find ~a{...} stanzas in an input string and process them
process=function(self, input, pos)
local toks, str
local output=""
toks=strutil.TOKENIZER(input, "~a{|}", "ms")
str=toks:next()
while str
do
if str == "~a{"
then
str=toks:next()
output=output .. self:tick(str, pos)
toks:next() -- remove finishing '}'
else output=output .. str
end
str=toks:next()
end
return output
end
}