~npisanti/rl_tools

ref: 42fc19701d10897ec966f18c35ad1ed3ce2ccc44 rl_tools/shader_gif/main.lua -rw-r--r-- 1.2 KiB
42fc1970Nicola Pisanti defaults to nearest pixel for textures 3 months ago
                                                                                
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
require "strict"

----------------------------------------------------
window.title( " " )

if args.count() > 0 then 
    frag.load( args.get(0), "glsl" ) 
end    

local w = 480 
local h = 480
local sec = 0
local fps = 0 


if args.count() > 4 then
	w = tonumber( args.get(1) )
	h = tonumber( args.get(2) )
	fps = tonumber( args.get(3) )
	sec = tonumber( args.get(4) )
end

window.size( w, h )
layer.create( "def" )

local count = 0
local step = 1.0 / fps
local frames =  sec * fps;

----------------------------------------------------
function loop()
	local t = count * step 
	clock.set( t ) 	

    layer.open()
        rl.clear(0,0,0,0)
    layer.close() 

    frag.apply( "glsl" )

	if count < frames then	
		local filename = "out "
		if count < 10 then 
			filename = "output/frame_0"..tostring(count)..".png"
		else 
			filename = "output/frame_"..tostring(count)..".png"
		end
		 
		layer.save( filename )

	elseif count == frames then
		local delay = 100 / fps 
		io.popen( "mogrify -background black -alpha off output/* && convert -delay "..delay.." -loop 0 -dispose 2 output/*.png output/output.gif && rm output/*.png" )		
		print("generated gif in shader_gif/output" )
		
		os.exit()
	end

	count = count + 1
end