Repository navigation
Expand file tree
/
Copy pathmoat_TextEffects.lua
More file actions
376 lines (185 loc) · 7.95 KB
/
Copy pathmoat_TextEffects.lua
File metadata and controls
376 lines (185 loc) · 7.95 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
--[[
Moat's text effects for garry's mod :D
https://steamcommunity.com/id/moat_
]]--
local function m_AlignText( text, font, x, y, xalign, yalign )
surface.SetFont( font )
local textw, texth = surface.GetTextSize( text )
if ( xalign == TEXT_ALIGN_CENTER ) then
x = x - ( textw / 2 )
elseif ( xalign == TEXT_ALIGN_RIGHT ) then
x = x - textw
end
if ( yalign == TEXT_ALIGN_BOTTOM ) then
y = y - texth
end
return x, y
end
function DrawShadowedText( shadow, text, font, x, y, color, xalign, yalign )
local xalign = xalign or TEXT_ALIGN_LEFT
local yalign = yalign or TEXT_ALIGN_TOP
draw.SimpleText( text, font, x + shadow, y + shadow, Color( 0, 0, 0, color.a or 255 ), xalign, yalign )
draw.SimpleText( text, font, x, y, color, xalign, yalign )
end
function GlowColor( col1, col2, mod )
local newr = col1.r + ( ( col2.r - col1.r ) * ( mod ) )
local newg = col1.g + ( ( col2.g - col1.g ) * ( mod ) )
local newb = col1.b + ( ( col2.b - col1.b ) * ( mod ) )
return Color( newr, newg, newb )
end
function DrawEnchantedText( speed, text, font, x, y, color, glow_color, xalign, yalign )
local xalign = xalign or TEXT_ALIGN_LEFT
local yalign = yalign or TEXT_ALIGN_TOP
local glow_color = glow_color or Color( 127, 0, 255 )
local texte = string.Explode( "", text )
local x, y = m_AlignText( text, font, x, y, xalign, yalign )
surface.SetFont( font )
local chars_x = 0
for i = 1, #texte do
local char = texte[i]
local charw, charh = surface.GetTextSize( char )
local color_glowing = GlowColor( glow_color, color, math.abs( math.sin( ( RealTime() - ( i * 0.08 ) ) * speed ) ) )
draw.SimpleText( char, font, x + chars_x, y, color_glowing, xalign, yalign )
chars_x = chars_x + charw
end
end
function DrawFadingText( speed, text, font, x, y, color, fading_color, xalign, yalign )
local xalign = xalign or TEXT_ALIGN_LEFT
local yalign = yalign or TEXT_ALIGN_TOP
local color_fade = GlowColor( color, fading_color, math.abs( math.sin( ( RealTime() - 0.08 ) * speed ) ) )
draw.SimpleText( text, font, x, y, color_fade, xalign, yalign )
end
local col1 = Color( 0, 0, 0 )
local col2 = Color( 255, 255, 255 )
local next_col = 0
function DrawRainbowText( speed, text, font, x, y, xalign, yalign )
local xalign = xalign or TEXT_ALIGN_LEFT
local yalign = yalign or TEXT_ALIGN_TOP
next_col = next_col + 1 / ( 100 / speed )
if ( next_col >= 1 ) then
next_col = 0
col1 = col2
col2 = ColorRand()
end
draw.SimpleText( text, font, x, y, GlowColor( col1, col2, next_col ), xalign, yalign )
end
function DrawGlowingText( static, text, font, x, y, color, xalign, yalign )
local xalign = xalign or TEXT_ALIGN_LEFT
local yalign = yalign or TEXT_ALIGN_TOP
local initial_a = 20
local a_by_i = 5
local alpha_glow = math.abs( math.sin( ( RealTime() - 0.1 ) * 2 ) )
if ( static ) then alpha_glow = 1 end
for i = 1, 2 do
draw.SimpleTextOutlined( text, font, x, y, color, xalign, yalign, i, Color( color.r, color.g, color.b, ( initial_a - ( i * a_by_i ) ) * alpha_glow ) )
end
draw.SimpleText( text, font, x, y, color, xalign, yalign )
end
function DrawBouncingText( style, intesity, text, font, x, y, color, xalign, yalign )
local xalign = xalign or TEXT_ALIGN_LEFT
local yalign = yalign or TEXT_ALIGN_TOP
local texte = string.Explode( "", text )
surface.SetFont( font )
local chars_x = 0
local x, y = m_AlignText( text, font, x, y, xalign, yalign )
for i = 1, #texte do
local char = texte[i]
local charw, charh = surface.GetTextSize( char )
local y_pos = 1
local mod = math.sin( ( RealTime() - ( i * 0.1 ) ) * ( 2 * intesity ) )
if ( style == 1 ) then
y_pos = y_pos - math.abs( mod )
elseif ( style == 2 ) then
y_pos = y_pos + math.abs( mod )
else
y_pos = y_pos - mod
end
draw.SimpleText( char, font, x + chars_x, y - ( 5 * y_pos ), color, xalign, yalign )
chars_x = chars_x + charw
end
end
local next_electic_effect = CurTime() + 0
local electric_effect_a = 0
function DrawElecticText( intensity, text, font, x, y, color, xalign, yalign )
local xalign = xalign or TEXT_ALIGN_LEFT
local yalign = yalign or TEXT_ALIGN_TOP
local charw, charh = surface.GetTextSize( text )
draw.SimpleText( text, font, x, y, color, xalign, yalign )
if ( electric_effect_a > 0 ) then
electric_effect_a = electric_effect_a - ( 1000 * FrameTime() )
end
surface.SetDrawColor( 102, 255, 255, electric_effect_a )
for i = 1, math.random( 5 ) do
line_x = math.random( charw )
line_y = math.random( charh )
line_x2 = math.random( charw )
line_y2 = math.random( charh )
surface.DrawLine( x + line_x, y + line_y, x + line_x2, y + line_y2 )
end
local effect_min = 0.5 + ( 1 - intensity )
local effect_max = 1.5 + ( 1 - intensity )
if ( next_electic_effect <= CurTime() ) then
next_electic_effect = CurTime() + math.Rand( effect_min, effect_max )
electric_effect_a = 255
end
end
function DrawFireText( intensity, text, font, x, y, color, xalign, yalign, glow, shadow )
local xalign = xalign or TEXT_ALIGN_LEFT
local yalign = yalign or TEXT_ALIGN_TOP
surface.SetFont( font )
local charw, charh = surface.GetTextSize( text )
local fire_height = charh * intensity
for i = 1, charw do
local line_y = math.random( fire_height, charh )
local line_x = math.random( -4, 4 )
local line_col = math.random( 255 )
surface.SetDrawColor( 255, line_col, 0, 150 )
surface.DrawLine( x - 1 + i, y + charh, x - 1 + i + line_x, y + line_y )
end
if ( glow ) then
DrawGlowingText( true, text, font, x, y, color, xalign, yalign )
end
if ( shadow ) then
draw.SimpleText( text, font, x + 1, y + 1, Color( 0, 0, 0 ), xalign, yalign )
end
draw.SimpleText( text, font, x, y, color, xalign, yalign )
end
function DrawSnowingText( intensity, text, font, x, y, color, color2, xalign, yalign )
local xalign = xalign or TEXT_ALIGN_LEFT
local yalign = yalign or TEXT_ALIGN_TOP
local color2 = color2 or Color( 255, 255, 255 )
draw.SimpleText( text, font, x, y, color, xalign, yalign )
surface.SetFont( font )
local textw, texth = surface.GetTextSize( text )
surface.SetDrawColor( color2.r, color2.g, color2.b, 255 )
for i = 1, intensity do
local line_y = math.random( 0, texth )
local line_x = math.random( 0, textw )
surface.DrawLine( x + line_x, y + line_y, x + line_x, y + line_y + 1 )
end
end
local MOAT_SHOW_EFFECT_EXAMPLES = false
function moat_DrawEffectExamples()
if ( not MOAT_SHOW_EFFECT_EXAMPLES ) then return end
local font = "DermaLarge"
draw.RoundedBox( 0, 50, 50, 700, 500, Color( 0, 0, 0, 200 ) )
local x = 100
local y = 100
DrawGlowingText( false, "GLOWING TEXT", font, x, y, Color( 255, 0, 0, 255 ) )
y = y + 50
DrawFadingText( 1, "FADING COLORS TEXT", font, x, y, Color( 255, 0, 0 ), Color( 0, 0, 255 ) )
y = y + 50
DrawRainbowText( 1, "RAINBOW TEXT", font, x, y )
y = y + 50
DrawEnchantedText( 2, "ENCHANTED TEXT", font, x, y, Color( 255, 0, 0 ), Color( 0, 0, 255 ) )
y = y + 50
DrawFireText( 0.5, "INFERNO TEXT", font, x, y, Color( 255, 0, 0 ), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP, true, true )
y = y + 50
DrawElecticText( 1, "ELECTRIC TEXT", font, x, y, Color( 255, 0, 0 ), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP )
y = y + 50
DrawBouncingText( 3, 3, "BOUNCING AND WAVING TEXT", font, x, y, Color( 255, 0, 0 ), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP )
y = y + 50
DrawSnowingText( 10, "SPARKLING/SNOWING TEXT", font, x, y, Color( 255, 0, 0 ), Color( 255, 255, 255 ) )
end
hook.Add( "HUDPaint", "moat_TextEffectsExample", moat_DrawEffectExamples )
concommand.Add( "moat_TextExamples", function() MOAT_SHOW_EFFECT_EXAMPLES = not MOAT_SHOW_EFFECT_EXAMPLES end )