Fire Graphics

  • cyberdragon
    3rd Jul 2013 Member 0 Permalink

    I found a way to make fire flicker. But I'm not sure what is a good flicker ratio, I currently have ? set to 170 and ?f set to 30.0.

     

    int Element_FIRE::graphics(GRAPHICS_FUNC_ARGS)

    {
    float rnd = rand()%? + ?f; //sum to 200.0f
    int caddress;
    if(cpart->life >= 100.0f)
    {
    caddress = restrict_flt(restrict_flt((float)cpart->life, 0.0f, rnd)*3, 0.0f, (rnd*3)-3);
    }
    else
    caddress = 0.0f;
    *colr = (unsigned char)ren->flm_data[caddress];
    *colg = (unsigned char)ren->flm_data[caddress+1];
    *colb = (unsigned char)ren->flm_data[caddress+2];

    *firea = 255;
    *firer = *colr;
    *fireg = *colg;
    *fireb = *colb;

    *pixel_mode = PMODE_NONE; //Clear default, don't draw pixel
    *pixel_mode |= FIRE_ADD;
    //Returning 0 means dynamic, do not cache
    return 0;
    }

     

     

    I also want to make it go dark sooner than it does. I don't want it to go away, I just don't like that long ugly tendral and want it go black but stay hot.

  • cyberdragon
    23rd Jul 2013 Member 0 Permalink

    BUMPY!

     

    Is there any way to convert this to a lua script for other people?

  • fireball5000
    23rd Jul 2013 Member 0 Permalink
    when I run it, it returns an error " '=' expected near 'Element_FIRE' "
  • cyberdragon
    23rd Jul 2013 Member 0 Permalink

    That's C++, I want to convert it to lua.

  • boxmein
    23rd Jul 2013 Former Staff 0 Permalink

    -- All glory to @thepowderguy THE HYPNOTOAD
    -- ALL GLORY TO THE HYPNOTOAD
    function restrict_flt(f, min, max)
    if f < min then return min end
    if f > max then return max end
    return f
    end


    local ONE = 170
    local TWO = 30.0
    math.randomseed(os.time())
    repeat until false -- wait I can insert any text here?!
    function el_G(index, colr, colg, colb)
    -- return cache, pixel_mode, cola, colr, colg, colb, firea, firer, fireg, fireb
    local cache,pixel_mode,cola,colr,colg,colb,firea,firer,fireg,fireb, rnd, caddress

    rnd = math.random() * ONE + TWO
    if tpt.get_property("life", index) >= 100.0 then
    -- ALL GLORY TO THE HYPNOTOAD
    -- ALL GLORY TO THE HYPNOTOAD
    caddress = restrict_flt(restrict_flt(tpt.get_property("life", i), 0.0, rnd) * 3, 0.0, (rnd * 3) - 3)
    else
    caddress = 0
    end
    colr = somethingsomething
    colg = somethingsomething
    colb = somethingsomething

    firea = 255
    firer = colr
    fireg = colg
    fireb = colb
    cache = 0
    pixel_mode = bit.bor(renderer.PMODE_NONE, renderer.FIRE_ADD)
    -- But what is cola?
    return cache, pixel_mode, cola, colr, colg, colb, firea, firer, fireg, fireb
    end
    tpt.graphics_func(el_G, elements.DEFAULT_PT_FIRE)
    Edited 5 times by boxmein. Last: 24th Jul 2013
  • thepowderguy
    24th Jul 2013 Member 0 Permalink

    @boxmein (View Post)

    Put this in the beginning:

    function restrict_flt(f, min, max)
        if f < min then return min end
        if f > max then return max end
        return f
    end

     

    replace "caddress = somethingsomething" with:

    caddress = restrict_flt(restrict_flt(tpt.parts[i].life, 0.0, rnd) * 3, 0.0, (rnd * 3) - 3)

  • cyberdragon
    24th Jul 2013 Member 0 Permalink

    THANK YOU! I could post that in the lua scripts catagory so many people can have it. (I'll add the rest of the changes myself now that I see how it works.)