~npisanti/rsk_tools

f10aefe3aafdf6093723f344b9964af047858e38 — Nicola Pisanti 3 months ago 27cef66
shader_gif
2 files changed, 63 insertions(+), 1 deletions(-)

M README.md
A shader_gif/main.lua
M README.md => README.md +2 -1
@@ 6,8 6,9 @@ Collection of scripted tools made with [raylyeh](https://git.sr.ht/~npisanti/ray
* `eye`: monochrome webcam viewer
* `framescan` : tools to acquire stop motion drawing using the webcam
* `shader` : minimum lua script to livecode a shader passed as cli argument
* `shader_gif` : as `shader`, but renders to a gif with some given arguments
* `shadercam` : as `shader`, but with webcam input 
* `shaderdrop` : as `shader`, but with test png frames drawn upon the layer 

 
## license 
Nicola Pisanti MIT License 2020

A shader_gif/main.lua => shader_gif/main.lua +61 -0
@@ 0,0 1,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