-
Notifications
You must be signed in to change notification settings - Fork 0
/
yellowave.lua
365 lines (304 loc) · 8.27 KB
/
yellowave.lua
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
-- Yellowave
-- viluon's visual signature, improved approach
-- Uses the BLittle API by Bomb Bloke
local root = "/" .. fs.getDir( shell.getRunningProgram() ) .. "/"
if not fs.exists( root .. "blittle" ) then
shell.run( "pastebin get ujchRSnU " .. root .. "blittle" )
end
os.loadAPI( root .. "blittle" )
local blittle = blittle
local rnd = math.random
local term = term
local colours = colours
local w, h = term.getSize()
local oldTerm = term.current()
local mainWindow = window.create( oldTerm, 1, 1, w, h, false )
term.setBackgroundColour( colours.black )
term.clear()
local renderBuffer = blittle.createWindow( mainWindow )
term.redirect( renderBuffer )
local biggestX, biggestY = -1, -1
local animWidth = -1
local xOffset, yOffset = 0, 0
local xOffsetImage, yOffsetImage = 0, 0
local yellowavePos
-- Approx. total time of the animation, used for scaling the stationary time of particles
-- The higher this is, the greater the difference between arrival time of particles at the left vs particles at the right will be
local totalTime = 3
local particles = {}
local frames = {}
local flypaths = {
{
fn = function( dt, particle )
if particle.stationaryTime < 0 then
particle.x = particle.x + particle.xSpeed * dt
particle.y = particle.y + particle.ySpeed * dt
else
particle.stationaryTime = particle.stationaryTime - dt
end
end;
new = function( x, y )
local stationaryTime = ( animWidth - x ) / animWidth * totalTime
return {
x = x;
y = y;
stationaryTime = stationaryTime;
xSpeed = rnd( -10, 10 ) * ( stationaryTime + x / animWidth );
ySpeed = rnd( -10, 10 ) * ( stationaryTime + x / animWidth );
colour = colours.white;
}
end;
};
{
fn = function( dt, particle )
if particle.stationaryTime < 0 then
particle.life = particle.life + dt
particle.x = particle.x + particle.xSpeed * dt
particle.y = particle.y + particle.ySpeed * dt
else
particle.stationaryTime = particle.stationaryTime - dt
end
if particle.life < 0.5 then
particle.ySpeed = math.abs( particle.ySpeed )
--particle.colour = colours.green
else
particle.ySpeed = -math.abs( particle.ySpeed )
--particle.colour = colours.white
end
end;
new = function( x, y )
local stationaryTime = ( animWidth - x ) / animWidth * totalTime
return {
x = x;
y = y;
stationaryTime = stationaryTime;
xSpeed = rnd( -1, 10 ) * ( stationaryTime + x / animWidth );
ySpeed = rnd( 4, 10 ) * ( stationaryTime + x / animWidth );
life = 0;
colour = colours.white;
}
end;
};
{
fn = function( dt, particle )
if particle.stationaryTime < 0 then
particle.x = particle.x + particle.xSpeed * dt
particle.y = particle.y + particle.ySpeed * dt
else
particle.stationaryTime = particle.stationaryTime - dt
end
end;
new = function( x, y )
local stationaryTime = ( animWidth - x ) / animWidth * totalTime + y / 15
return {
x = x;
y = y;
stationaryTime = stationaryTime;
xSpeed = rnd( 15, 20 ) * ( stationaryTime + x / animWidth );
ySpeed = rnd( -1, 1 ) * ( stationaryTime + x / animWidth );
colour = colours.white;
}
end;
};
{
fn = function( dt, particle )
if particle.stationaryTime < 0 then
particle.life = particle.life + dt
particle.x = particle.x + particle.xSpeed * dt
particle.y = particle.y + particle.ySpeed * dt
else
particle.stationaryTime = particle.stationaryTime - dt
end
if particle.life < 0.5 then
particle.ySpeed = math.abs( particle.ySpeed )
--particle.colour = colours.green
else
particle.ySpeed = -math.abs( particle.ySpeed )
--particle.colour = colours.white
end
end;
new = function( x, y )
local stationaryTime = ( animWidth - x ) / animWidth * totalTime
return {
x = x;
y = y;
stationaryTime = stationaryTime;
xSpeed = rnd( -10, 1 ) * ( stationaryTime + x / animWidth );
ySpeed = rnd( 10, 12 ) * ( stationaryTime + x / animWidth );
life = 0;
colour = colours.white;
}
end;
};
{
fn = function( dt, particle )
particle.x = particle.x + particle.xSpeed * dt
particle.y = particle.y + particle.ySpeed * dt
end;
new = function( x, y )
return {
x = x;
y = y;
stationaryTime = stationaryTime;
xSpeed = ( ( animWidth - x ) / animWidth > 0.4 and 1 or -1 ) * rnd( 12, 15 );
ySpeed = -0.5 + rnd();
colour = colours.white;
}
end;
};
{
fn = function( dt, particle )
particle.x = particle.x + particle.xSpeed * dt
particle.y = particle.y + particle.ySpeed * dt
end;
new = function( x, y )
return {
x = x;
y = y;
xSpeed = rnd( -5, 5 );
ySpeed = rnd( 8, 10 ) + x / animWidth * 15 - 10;
colour = colours.white;
}
end;
};
{
fn = function( dt, particle )
if particle.stationaryTime < 0 then
particle.life = particle.life + dt
particle.x = particle.x + particle.xSpeed * dt
particle.y = particle.y + particle.ySpeed * dt
else
particle.stationaryTime = particle.stationaryTime - dt
end
if particle.life < 0.5 then
particle.xSpeed = particle.xSpeed + 5 * dt
particle.ySpeed = particle.ySpeed - 1 * dt
elseif particle.life < 1.5 then
particle.xSpeed = particle.xSpeed - 10 * dt
particle.ySpeed = particle.ySpeed - 30 * dt
elseif particle.life < 2 then
particle.xSpeed = particle.xSpeed - 40 * dt
particle.ySpeed = particle.ySpeed + 20 * dt
end
end;
new = function( x, y )
local stationaryTime = ( animWidth - x ) / animWidth * totalTime
return {
x = x;
y = y;
stationaryTime = stationaryTime;
xSpeed = rnd( 2, 5 ) * ( stationaryTime + x / animWidth );
ySpeed = rnd( 6, 8 ) * ( stationaryTime + x / animWidth );
life = 0;
colour = colours.white;
}
end;
};
}
local args = { ... }
local flypath = flypaths[ tonumber( args[ 1 ] ) or rnd( 1, #flypaths ) ] -- flypaths[ rnd( 1, #flypaths ) ]
local function newParticle( x, y )
particles[ #particles + 1 ] = flypath.new( x, y )
end
local function loadInitialFrame( path )
local frame = {}
local f = io.open( path, "r" )
if not f then
error( "File not found", 2 )
end
local y = 1
for line in f:lines() do
animWidth = math.max( animWidth, #line )
for x = 1, #line do
if line:sub( x, x ) ~= " " then
biggestX = math.max( biggestX, x )
biggestY = math.max( biggestY, y )
newParticle( x, y )
end
end
y = y + 1
end
return frame
end
local function updateParticles( dt )
for i, particle in ipairs( particles ) do
flypath.fn( dt, particle )
end
end
local function drawParticles()
mainWindow.setVisible( false )
term.setBackgroundColour( colours.black )
term.clear()
term.redirect( mainWindow )
term.setCursorPos( xOffsetImage, yOffsetImage + 3 )
term.write( "made by" )
term.redirect( renderBuffer )
for i, particle in ipairs( particles ) do
if yellowavePos and yellowavePos >= particle.x then
term.setBackgroundColour( colours.yellow )
else
term.setBackgroundColour( particle.colour )
end
term.setCursorPos( particle.x + xOffset, particle.y + yOffset )
term.write( " " )
end
mainWindow.setVisible( true )
end
local function copy( tbl )
if type( tbl ) ~= "table" then
return tbl
end
local result = {}
for k, v in pairs( tbl ) do
result[ copy( k ) ] = copy( v )
end
return result
end
local function saveFrame()
frames[ #frames + 1 ] = copy( particles )
end
local function loadFrames()
local i = #frames
return function()
particles = frames[ i ]
i = i - 1
if not particles then return nil end
return true
end
end
-- Compute
loadInitialFrame( root .. "assets/frames/viluon.frm" )
xOffsetImage = w / 2 - ( biggestX / 2 ) / 2
yOffsetImage = h / 2 - ( biggestY / 3 ) / 2
xOffset = w * 2 / 2 - biggestX / 2 -- w / 2 - biggestX / 2
yOffset = h * 3 / 2 - biggestY / 2 -- h / 2 - biggestY / 2
saveFrame()
for i = 1, 3 do
updateParticles( 0.1 )
saveFrame()
end
for i = 1, 20 do
updateParticles( 0.2 )
saveFrame()
end
for i = 1, 10 do
updateParticles( 0.5 )
saveFrame()
end
-- Render
for _ in loadFrames() do
drawParticles()
sleep( 0.01 )
end
particles = frames[ 1 ]
yellowavePos = 1
local totalWaveAnimTime = 0.4
local startTime = os.clock()
while yellowavePos < animWidth do
local now = os.clock()
yellowavePos = ( now - startTime ) / totalWaveAnimTime * animWidth
drawParticles()
sleep( 0 )
end
term.redirect( oldTerm )
term.setCursorPos( 1, 1 )