Page 1 of 1

New ATL warpers

Posted: Fri Nov 13, 2015 8:55 am
by nyaatrap
(This code requires Ren'py 6.99.8 or later)
Currently, ATL has only linear and sin/cos warpers. But when you look around other game engines, you'll notice they have many - actually 30+ - warpers by default. They are all based on Robert Penner Easing Equations (http://robertpenner.com/easing/). I ported all of them into ATL, by modifying the code simpler and understandable. Here is the script file.
000warpers.rpy
(4.55 KiB) Downloaded 178 times
If you drop this file into your game folder, you can use the following warpers:
easein_quad, easeout_quad, ease_quad
easein_cubic, easeout_cubic, ease_cubic
easein_quart, easeout_quart, ease_quart
easein_quint, easeout_quint, ease_quint
easein_expo, easeout_expo, ease_expo
easein_circ, easeout_circ, ease_circ
easein_back, easeout_back, ease_back
easein_elastic, easeout_elastic, ease_elastic
easein_bounce, easeout_bounce, ease_bounce

Full code is here:

Code: Select all

python early:
    
    # Modified easing equations based on Robert Penner (http://robertpenner.com/easing/)
    # License: http://robertpenner.com/easing_terms_of_use.html
    
    # -in / -out surfix are inverted to much default warpers in ATL.
        
    # quad
    @renpy.atl_warper
    def easeout_quad(t):
        return pow(t, 2)
        
    @renpy.atl_warper
    def easein_quad(t):
        return 1 - easeout_quad(1 - t)
        
    @renpy.atl_warper
    def ease_quad(t):
        if t < .5:
            return easeout_quad(t * 2.0) / 2.0    
        else:            
            return 1 - easeout_quad((1 - t)* 2.0) / 2.0
            
    
    # cubic
    @renpy.atl_warper
    def easeout_cubic(t):
        return pow(t, 3)
        
    @renpy.atl_warper
    def easein_cubic(t):
        return 1 - easeout_cubic(1 - t)
        
    @renpy.atl_warper
    def ease_cubic(t):
        if t < .5:
            return easeout_cubic(t * 2.0) / 2.0    
        else:            
            return 1 - easeout_cubic((1 - t)* 2.0) / 2.0
            
            
    # quart
    @renpy.atl_warper
    def easeout_quart(t):
        return pow(t, 4)
        
    @renpy.atl_warper
    def easein_quart(t):
        return 1 - easeout_quart(1 - t)
        
    @renpy.atl_warper
    def ease_quart(t):
        if t < .5:
            return easeout_quart(t * 2.0) / 2.0    
        else:            
            return 1 - easeout_quart((1 - t)* 2.0) / 2.0
            
            
    # quint
    @renpy.atl_warper
    def easeout_quint(t):
        return pow(t, 5)
        
    @renpy.atl_warper
    def easein_quint(t):
        return 1 - easeout_quint(1 - t)
        
    @renpy.atl_warper
    def ease_quint(t):
        if t < .5:
            return easeout_quint(t * 2.0) / 2.0    
        else:            
            return 1 - easeout_quint((1 - t)* 2.0) / 2.0
            
            
    # exponential
    @renpy.atl_warper
    def easeout_expo(t):
        return pow(2, 10 * (t - 1))
                
    @renpy.atl_warper
    def easein_expo(t):
        return 1 - easeout_expo(1 - t)
        
    @renpy.atl_warper
    def ease_expo(t):
        if t < .5:
            return easeout_expo(t * 2.0) / 2.0    
        else:            
            return 1 - easeout_expo((1 - t)* 2.0) / 2.0
            
        
    # circular
    @renpy.atl_warper
    def easeout_circ(t):
        import math
        return 1 - math.sqrt(1 - t * t)
                
    @renpy.atl_warper
    def easein_circ(t):
        return 1 - easeout_circ(1- t)
        
    @renpy.atl_warper
    def ease_circ(t):
        if t < .5:
            return  easeout_circ(t * 2.0) / 2.0
        else:
            return 1 - easeout_circ((1- t) * 2.0) / 2.0
            
        
    # back
    @renpy.atl_warper
    def easeout_back(t):
        s = 1.7015 # Overshoot. It ranges .0 (swing 0%) ~ 8.4435 (swing 100%).  
        return t * t * ((s + 1) * t - s)
        
    @renpy.atl_warper
    def easein_back(t):
        return  1 - easeout_back(1- t)
        
    @renpy.atl_warper
    def ease_back(t):
        if t < .5:
            return  easeout_back(t * 2.0) / 2.0
        else:
            return 1 - easeout_back((1- t) * 2.0) / 2.0
            
            
    # elastic
    @renpy.atl_warper
    def easein_elastic(t):
        import math
        p = .3 # Period. It ranges 0.1 (spring many) ~ 1.0 (spring once). 
        return 1 + pow(2, - 10 * t) * math.sin((t - p / 4.0) * (2.0 * math.pi) / p)
        
    @renpy.atl_warper
    def easeout_elastic(t):
        return 1 - easein_elastic(1 - t)
        
    @renpy.atl_warper
    def ease_elastic(t):
        if t < .5:
            return  easeout_elastic(t * 2.0) / 2.0
        else:
            return 1 - easeout_elastic((1- t) * 2.0) / 2.0
            
          
    # bounce
    @renpy.atl_warper
    def easein_bounce(t):
        p = 2.75 # Period. It's a fixed value. Don't change this.
        s = pow(p, 2)
        if t < (1.0 / p):
            return s * t * t
        elif t < (2.0 / p):
            return 1 + s * (pow(t - 1.5 / p, 2) - pow(- .5 / p, 2))
        elif t < (2.5 / p):
            return 1 + s * (pow(t - 2.25 / p, 2) - pow(- .25 / p, 2))
        else:
            return 1 + s * (pow(t - 2.625 / p, 2) - pow(- .125 / p, 2))
                        
    @renpy.atl_warper
    def easeout_bounce(t):
        return 1 - easein_bounce(1 - t)
        
    @renpy.atl_warper
    def ease_bounce(t):
        if t < .5:
            return  easeout_bounce(t * 2.0) / 2.0
        else:
            return 1 - easeout_bounce((1- t) * 2.0) / 2.0

Re: New ATL warpers

Posted: Fri Nov 13, 2015 2:14 pm
by Donmai
Wow! Thank you.

Re: New ATL warpers

Posted: Fri Nov 13, 2015 3:15 pm
by xela
:!: :idea: :!:

Moar funcs = More fun!

Re: New ATL warpers

Posted: Sat Nov 14, 2015 1:37 am
by PyTom
These are nice. Can I merge them into 6.99.8?

Re: New ATL warpers

Posted: Sat Nov 14, 2015 2:30 am
by nyaatrap
Of course :D

Re: New ATL warpers

Posted: Sat Nov 14, 2015 10:56 am
by nyaatrap
BTW, overshoot parameter on ease_back was 1.70158 in the original code. But someone calculated the exact number then it turned out 1.701540198866824... so I dropped 8. Other parameters should much exactly to the original code (unless I did something miscalculated).

Re: New ATL warpers

Posted: Fri Jun 25, 2021 4:06 pm
by crowl
I hate to rez an old thread like this, but it was the only thread I could find about Penner's easeing equations. Since they were still mentioned on the wiki (here: ) I assumed they were still valid. However! I've imported the warpers file, and when I try to call any of the functions, this happens:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/battle1.rpy", line 501, in script
    show turn enemystart at ease_elastic
  File "game/warpers.rpy", line 145, in ease_elastic
    return 1 - easeout_elastic((1 - t) * 2.0) / 2.0
TypeError: unsupported operand type(s) for -: 'int' and 'ImageReference'

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/battle1.rpy", line 501, in script
    show turn enemystart at ease_elastic
  File "renpy/ast.py", line 1191, in execute
    show_imspec(self.imspec, atl=getattr(self, "atl", None))
  File "renpy/ast.py", line 1161, in show_imspec
    atl=atl)
  File "renpy/exports.py", line 756, in show
    img = i(img)
  File "game/warpers.rpy", line 145, in ease_elastic
    return 1 - easeout_elastic((1 - t) * 2.0) / 2.0
TypeError: unsupported operand type(s) for -: 'int' and 'ImageReference'

Windows-10-10.0.19041
Ren'Py 7.4.5.1648
Ghost Economy (DEMO) 1.0
Fri Jun 25 15:02:10 2021

and just for clarities sake, this is how i'm calling the code:

Code: Select all

show turn enemystart at ease_elastic
i'm hoping i just did something wrong that's simple to point out, but the warpers file is exactly the same as the code in the OP so I'm genuinely at a loss for what to do.