Page 1 of 1

Transformation Language Design

Posted: Tue Jun 09, 2009 1:23 am
by PyTom
So, I'm working on the transformation language that will be part of Ren'Py, probably starting with the next release. The idea of the transformation language is to provide a convenient way to specify the placement, rotation, scaling, and opacity of images. It will also provide a way to define animations. The idea is that this will become the preferred way to specify aspects of display that vary with time.

Let's see the most trivial transform:

Code: Select all

transform right:
    xalign 1.0
This is the equivalent of the current "right" position, displaying an image on the right of the screen.

This is pretty boring, so let's take a look at a transform that starts the image on the left, moves it to the right, then back to the left:

Code: Select all

transform bounce_once:
    0: xalign 0.0
    2: xalign 1.0
    4: xalign 0.0
We now have multiple lines. Each gives a time, and a position. So at 0 seconds it's at the left, at 2 seconds it's at the right, and then at 4 seconds its at the left again. By default, the values are linearly interpolated, but that can be changed, using (for example):

Code: Select all

transform bounce_once_ease:
    0: xalign 0.0
    2: xalign ease(1.0)
    4: xalign ease(0.0)
Which would use the ease function to do the interpolation.

Giving the repeat statement causes the current block of code to repeat from 0.

Code: Select all

transform bounce:
    0: xalign 0.0
    2: xalign 1.0
    4: repeat
By nesting statements, the amount of time the repeat is for can be controlled:

Code: Select all

transform bounce_three_times:
    0: 
         0: xalign 0.0
         2: xalign 1.0
         4: repeat
    12: 
         xalign 0.0
By separating them with commas, one can include multiple properties on a single line. (Note: I need a better word than property here, as properties is used by the style system.)

Code: Select all

transform v_shape:
    0: xalign 0.0, yalign 0.0
    1: xalign 0.5, yalign 1.0
    2: xalign 1.0, yalign 0.0
Other properties include "rotate", "scale", and "alpha". The following spins its child forever:

Code: Select all

transform spin:
    0.0: rotate 0
    4.5: rotate 360, repeat
While this scales it to full size:

Code: Select all

transform scale:
    0.0: scale 0
    1.0: scale 1
The "parallel" statement lets you run both transforms at the same time. So the following will scale the child while spinning it, and then keep it spinning even after the scaling is done.

Code: Select all

transform scale_and_spin:
    parallel:
        0.0: rotate 0
        4.5: rotate 360, repeat
    parallel:
        0.0: scale 0
        1.0: scale 1

I'm not sure about the syntax, but I'd also like for it to be possible to define an animation using this mechanism. So one could probably do:

Code: Select all

image eileen anim: 
     0: "eileen_happy.png"
     1: "eileen_vhappy.png"
     2: repeat
Of course, this would compose with other transforms.

I have some other ideas (like the ability to respond to events such as idle and hover), but these are the basics, and I thought I'd run them by the community before I start the implementation work. Any comments? Suggestions?

Re: Transformation Language Design

Posted: Tue Jun 09, 2009 1:41 am
by KimiYoriBaka
I haven't done anything with transformations so I don't know if this would be obvious or not, but when would the repeat statement end if there's nothing in the transformation after it? Would it just wait until the image is told to hide?

Re: Transformation Language Design

Posted: Tue Jun 09, 2009 1:59 am
by PyTom
Yes, unless there's something to end it, it would go on forever. (Until hidden.)

Re: Transformation Language Design

Posted: Tue Jun 09, 2009 4:13 pm
by delta
I'm not sure whether I like a new kind of baseline block in addition to init and label blocks.

Re: Transformation Language Design

Posted: Fri Jun 12, 2009 5:25 am
by EvilDragon
This is a very good idea, opening up a LOT of possibilities. Syntax seems fairly easy to get a grasp on, too.

Will something similar be available for text? (Y'know, showing several lines at once in NVL mode for example, with various text effects here and there, etc.)

Re: Transformation Language Design

Posted: Fri Jun 12, 2009 12:33 pm
by delta
Well, Ren'Py does not offer a lot of text effects anyway, there isn't even a property for kerning bonuses. If there was, it would be a neat (but not crucial) effect to adjust it over time.

Re: Transformation Language Design

Posted: Mon Aug 17, 2009 9:04 pm
by PyTom
http://www.renpy.org/wiki/renpy/doc/ref ... m_Language

I've posted up a specification for how I plan to implement the new animation and transformation language. I think I've simplified it a bit compared to what I have above. Some examples.

An animation:

Code: Select all

image eileen anime:
    "eileen_happy.png", 1.0
    "eileen_vhappy.png", 1.0
    repeat
Move from the left side of the screen, to the right side of the screen, and then back to the left.

Code: Select all

transform left_right_left:
    xalign 0.0
    pause 2
    xalign linear 1.0
    pause 2
    xalign linear 0.0
Grow to 120% of the usual size when hovered, shrink back when unhovered.

Code: Select all

transform expando:
     event hover:
          pause .5
          zoom linear 1.2
     event idle:
          pause .5
          zoom linear 1.0
The idea is that the ATL will provide a high-level way of expressing things that are currently done by Animation, TransformAnimation, SMAnimation, Zoom, FactorZoom, RotoZoom, Move, Pan, Transform, and probably a bunch of other functions I can't remember offhand.

Re: Transformation Language Design

Posted: Tue Aug 18, 2009 5:18 am
by chronoluminaire
Cool. That does look... "Ren'Py-ish". As in, it's a very simple, punctuation-free way of expressing some very powerful and versatile concepts.

Re: Transformation Language Design

Posted: Sat Aug 22, 2009 7:49 pm
by Spiky Caterpillar
Ooh. I think that this will be quite cool.

Is 'pause' a pause between transformations, a pause during which transformations take place, or the duration of a transformation? If the lattermost it might be better to call it 'duration'.

In the definition for parallel:
The blocks within a set should be independent of each other, and manipulate different properties. When two blocks change the same property, the result is undefined.
In a likely-to-change-between versions sense, a likely-to-change-between-executions sense, or an exceptionthrowing sense?
(Eying the possibility of epicycle transforms. Even though I don't really need them.)

Re: Transformation Language Design

Posted: Sat Aug 22, 2009 10:48 pm
by PyTom
The pause is a pause during which transitions occur.

For now, if you were to do:

Code: Select all

parallel:
     xalign linear 0.0
     pause 2
     xalign linear 1.0
     pause 2
     repeat
parallel:
     xalign linear 0.0
     pause 1
     xalign linear 1.0
     pause 1
     repeat
The result would be that one of the two blocks (probably the second) would manipulate xalign, and the other one would not. I might eventually look into relaxing this (which would be a change between versions), but probably not in the first version. For many of these, composing two values is a meaningless operation... it's not clear to me that an xalign of 0.0 and an xalign of 1.0 should compose to 0.0, for example.

If someone wants to take it upon themselves to write sensible rules for composing property updates, by all means do so.

Re: Transformation Language Design

Posted: Sun Aug 23, 2009 12:39 am
by Counter Arts
Would it be too hard to have both just change the value whenever and the last written one wins? And if the pauses are equal in length and alter the same event just have it undefined or random?

Or are you compiling it so it can execute fast or doing something else to keep maintaining it easy?

But MAN this is going to really rock.

Re: Transformation Language Design

Posted: Sun Aug 23, 2009 12:59 am
by PyTom
That's how I plan to do it. But I want to reserve the right to alter this in the future, so for now it's undefined.

Re: Transformation Language Design

Posted: Sun Aug 23, 2009 3:17 am
by Counter Arts
Okay... I thought so.

If a position transformation is in progress with ease or linear and gets interrupted by an event, the "from" coordinates are going to be from where the displayable currently is right? And not the coordinates from the end of the first transformation?

Re: Transformation Language Design

Posted: Sun Aug 23, 2009 3:37 am
by luminarious
PyTom wrote:

Code: Select all

transform bounce_once:
    0: xalign 0.0
    2: xalign 1.0
    4: xalign 0.0
We now have multiple lines. Each gives a time, and a position. So at 0 seconds it's at the left, at 2 seconds it's at the right, and then at 4 seconds its at the left again. By default, the values are linearly interpolated, but that can be changed
This syntax is really easy on the eyes, being in turn quick to understand, especially if the sequence is longer. I'm all for it!

Re: Transformation Language Design

Posted: Sun Aug 23, 2009 12:43 pm
by PyTom
I've actually bounced off that syntax a bit. The new syntax for the same thing would be:

Code: Select all

transform bounce_once:
    time 0.0, xalign linear 0.0
    time 1.0, xalign 1.0
    time 2.0, xalign 0.0
You can also use pause, which can be written as:

Code: Select all

transform bounce_once:
    xalign linear 0.0
    pause 1.0, xalign 1.0
    pause 1.0, xalign 0.0
Since a number is a pause, this can also be:

Code: Select all

transform bounce_once:
    xalign linear 0.0, 1.0, xalign 1.0, 1.0, xalign 0.0