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 » Fri Nov 13, 2015 8:55 am

(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 99 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: 1835
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
Projects: Slumberland
Location: Brazil
Contact:

Re: New ATL warpers

#2 Post by Donmai » Fri Nov 13, 2015 2:14 pm

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 » Fri Nov 13, 2015 3:15 pm

:!: :idea: :!:

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

User avatar
PyTom
Ren'Py Creator
Posts: 15407
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 » Sat Nov 14, 2015 1:37 am

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
"Silly and fun things are important." - Elon Musk
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 » Sat Nov 14, 2015 2:30 am

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 » Sat Nov 14, 2015 10:56 am

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).

Post Reply

Who is online

Users browsing this forum: No registered users