New ATL warpers

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

New ATL warpers

#1 Post 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 211 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

User avatar
Donmai
Eileen-Class Veteran
Posts: 1960
Joined: Sun Jun 10, 2012 1:45 am
Completed: Toire No Hanako, Li'l Red [NaNoRenO 2013], The One in LOVE [NaNoRenO 2014], Running Blade [NaNoRenO 2016], The Other Question, To The Girl With Sunflowers
Projects: Slumberland
Location: Brazil
Contact:

Re: New ATL warpers

#2 Post by Donmai »

Wow! Thank you.
Image
No, sorry! You must be mistaking me for someone else.
TOIRE NO HANAKO (A Story About Fear)

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: New ATL warpers

#3 Post by xela »

:!: :idea: :!:

Moar funcs = More fun!
Like what we're doing? Support us at:
Image

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: New ATL warpers

#4 Post by PyTom »

These are nice. Can I merge them into 6.99.8?
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: New ATL warpers

#5 Post by nyaatrap »

Of course :D

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: New ATL warpers

#6 Post 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).

User avatar
crowl
Newbie
Posts: 1
Joined: Fri Jun 25, 2021 3:41 pm
Contact:

Re: New ATL warpers

#7 Post 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.

Post Reply

Who is online

Users browsing this forum: No registered users