Easy GIF Recorder

  • FeynmanLogomaker
    15th Oct 2013 Member 0 Permalink

    The code and .DLLs are here, just copy-paste all the scripts and .DLLs into your Powder Toy folder.

     

    To use, press 'j' to start, and then enter the file name and the frame rate of the GIF.

     

    To end it, press control-j. Once you've made it, you have to restart TPT to make another.

     

    There's supposed to be a GIF above this text, but it's not showing up for me. I'll fix that soon. 

     

    Version:

     

         1.0:

         First created

     

         1.5:

         Allow for multiple gifs to be recorded in one session without restart

         Removed unneeded code

                

    Planned in next version:

     

         Better GUI, more customizable features

         Allow multiple recordings without having to restart

         Looping

     

    Current version of script:

     

    require 'gd'

    gif = gif or {}

    local im = gd.createTrueColor(610, 380)

    local scnum = 0

    local capt

    function gif.control(a, b, c, d)
        if a == 'j' and not(c == 64) then
            capt = true
            gif.current = tpt.input('GIF name', 'Enter the GIF filename here.') .. '.gif'
            gif.speed = 100 / tonumber(tpt.input('GIF Speed', 'In FPS', '30'))
            im:gifAnimBegin(gif.current, false, 10000)
            tpt.register_step(gif.capture)
        elseif a == 'j' and c == 64 then
            capt = nil
            im:gifAnimEnd(gif.current)
            tpt.unregister_step(gif.capture)
        end
    end

    tpt.register_keypress(gif.control)

    function gif.capture()
        if capt then
            tpt.screenshot()
            im, errstr = gd.createFromPng(("screenshot_%06d"):format(scnum) .. '.png')
            if im then im:gifAnimAdd(gif.current, true, 0, 0, gif.speed, gd.DISPOSAL_NONE) end
            os.remove(("screenshot_%06d"):format(scnum) .. '.png')
            scnum = scnum + 1
        end
    end

    Edited 8 times by FeynmanLogomaker. Last: 16th Oct 2013
  • mniip
    16th Oct 2013 Developer 0 Permalink
    im, errstr = gd.createFromPng('screenshot_' .. string.rep('0', 6 - #tostring(scnum)) .. tostring(scnum) .. '.png')
    1) "errstr" is global
    2) the thing you are looking for is called string.format, ("screenshot_%06d"):format(scnum)
  • FeynmanLogomaker
    16th Oct 2013 Member 0 Permalink

    I don't really care about errstr being global, although your second suggestion actually makes sense.

  • mniip
    16th Oct 2013 Developer 0 Permalink
    @FeynmanLogomaker (View Post)
    you could'be brought the ".png" under string.format
  • FeynmanLogomaker
    16th Oct 2013 Member 0 Permalink

    Meh. This works exactly the same.

     

    And why are you always hypercritical of my scripts? THere are much worse ones out there, and mine, while not written as well as they could be, actually work quite well.

    Edited once by FeynmanLogomaker. Last: 16th Oct 2013
  • mniip
    16th Oct 2013 Developer 1 Permalink
    This post has been removed by jacob1: well then stop, before I make a rule "people who's main account's name start with 'm' can only criticize one lua script per month" :)
  • FeynmanLogomaker
    16th Oct 2013 Member 1 Permalink
    This post has been removed by jacob1: argument
    Edited once by FeynmanLogomaker. Last: 16th Oct 2013
  • mniip
    16th Oct 2013 Developer 1 Permalink
    This post has been removed by jacob1: argument
    Edited once by mniip. Last: 16th Oct 2013
  • FeynmanLogomaker
    16th Oct 2013 Member 0 Permalink
    This post has been removed by jacob1: argument
    Edited once by FeynmanLogomaker. Last: 16th Oct 2013
  • mniip
    16th Oct 2013 Developer 0 Permalink
    This post has been removed by jacob1: WARNING: if you write neat, readable code your computer might explode