Page 1 of 3
Move() and cubic functions
Posted: Wed Aug 16, 2006 3:42 pm
by monele
I've just started looking into this. Here's what I want : instead of using a simple linear interpolation as Move does right now, I'd like either a Move with some "function" option, or simply other Moves using something else than a linear function.
What I have so far : in renpy.display.layout I found Motion, Move and Interpolate. I see where the interpolate function is and that's exactly what I'd like to change by offering others than this one.
What's said though, is that the functions need to be pickleable... Interpolate also being a Class, I wonder if there's a way to define these in the script รด_o... I'm a bit afraid I'd have to make the changes in the Ren'Py code itself ^^;... Wouldn't be too horrible in a way but uh... I'm afraid I'll break stuff XD.
So yea, I'll try things right now but in the meantime, I wouldn't mind precisions on how I could work this out.
Of course, the overarching goal of this is to allow movements to start out slow, then speed up, then slow down, and other things like that, allowing smoother animations in the end ^^
Posted: Wed Aug 16, 2006 4:09 pm
by PyTom
Well, you can just copy the definition of Interpolate into a python block inside an init block, and change it to your liking. Functions defined inside an python (but not python hide) block inside an init block should be pickleable. What happens is that python stores the name of the function or class, and then the system needs to look it up again after unserialization. Since this happens after the init phase, everything will be there and things should work.
Posted: Wed Aug 16, 2006 4:14 pm
by monele
I'll say yay then ^.^. Thanks.
Now to remember my maths and find how to have progressive deceleration @_@.... (and turn all this into a working interpolation function ? *explodes*)
EDIT : Acceleration works, booya X3... *easily made happy when it comes to maths...*
Posted: Thu Aug 17, 2006 6:21 am
by monele
Ok, made this work. Do you think anyone would be interested in this ? Could it even be added to Ren'Py ? So far I have "ease" using power functions (quadratic, cubic, etc...), circular functions and sinusoidal functions.
Not being good at maths, I only managed to have a variable value on power functions. I don't know if it's possible with the other ones.
Posted: Thu Aug 17, 2006 6:46 am
by Watercolorheart
^ :O
I have no idea what you just said. Well, I do actually because I went all the way up to Calculus, but what I mean is that I'm not sure how that relates to movement ...
I didn't know that functions were pickleable ....... don't they taste like brine then? D:
Posted: Thu Aug 17, 2006 8:07 am
by Alessio
monele wrote:Do you think anyone would be interested in this ?
Sure! Non-linear movements are definitely a good addition.
Posted: Thu Aug 17, 2006 8:10 am
by Jake
BCS wrote:I have no idea what you just said. Well, I do actually because I went all the way up to Calculus, but what I mean is that I'm not sure how that relates to movement ...
He's talking about varying the speed of the movement transition over time - currently, if you just use the Move on its own, it moves with a fixed speed - effectively the "speed over time" graph is a zeroth-power (flat) function. If one were to use instead (for instance) a y=-1*x*x function (which produces a pleasing hump) with a suitable offset, it would be possible to have movement which started off slow (the left of the hump) sped up in the middle (the peak of the hump) then slowed to a halt at the end rather than the sudden and abrupt halt you get with the fixed-speed function.
I must admit, I'm pretty curious to see your code, Monele, even leaving aside that it would be a useful feature - wouldn't you need to make sure that the function you were using had a fixed and known integral between the start and finish points to be able to use it for interpolation readily? Or am I over-thinking the problem?
[EDIT: Unless... is the interpolation more of a "find my position between these two points at time
t" thing, where you only need to know the maximum of the graph? I guess I should really look at the existing code first...]
BCS wrote:
I didn't know that functions were pickleable ....... don't they taste like brine then? D:
No!
Vinegar!
'Picklable' just means that Python can save them, and thus Ren'Py can save a game in which they're used (which is pretty important, for obvious reasons)...
Posted: Thu Aug 17, 2006 8:20 am
by monele
http://monele.clearlyseen.net/Divers/easeExample.html
#1 : linear motion
#2 : with acceleration and then deceleration.
Smoothes out movements and makes things less... "blocky" ? ^^;. Like comparing a sawtooth wave with a sinusoidal wave.
There should be ways to simulate bounces and even elasticity this way. I'll try to use elasticity for explosions so it shakes less and less through time.
EDIT : Jake > I'll admit I don't understand half of what I've coded XD... But I didn't have any problem with interpolation. I just used what was already in there for linear movements... and yes it's a function returning the position based on time, start pos and end pos. Nifty maths actually ^.^. I just changed the very boring "t" into "t**2" and other things

Posted: Thu Aug 17, 2006 8:32 am
by Jake
monele wrote:and yes it's a function returning the position based on time, start pos and end pos. Nifty maths actually ^.^. I just changed the very boring "t" into "t**2" and other things

Yeah, the more I thought about it the more I thought that I was taking a far too physics-based and far too not-really-easily-programmable approach to the question.

Posted: Thu Aug 17, 2006 10:41 am
by DaFool
monele...
1.) Get Macromedia Flash
2.) Import the graphic
3.) Tween the animation to your heart's content
4.) export the frames, and convert them to transparent png if necessary.
No physics necessary

Posted: Thu Aug 17, 2006 11:21 am
by Jake
DaFool wrote:1.) Get Macromedia Flash
2.) Import the graphic
3.) Tween the animation to your heart's content
4.) export the frames, and convert them to transparent png if necessary.
This does mean distributing more graphics than you'd otherwise need to, and getting an animation that doesn't get any smoother as the rendering framerate increases, though... if it's simple to do it in code, it's a far neater solution.

Posted: Thu Aug 17, 2006 11:37 am
by monele
DaFool wrote:monele...
1.) Get Macromedia Flash
2.) Import the graphic
3.) Tween the animation to your heart's content
4.) export the frames, and convert them to transparent png if necessary.
No physics necessary

Yes but that's not *FUN*

. Why would I spend hours in front of my keyboard at night, trying to figure out how to define the quadratic function for easing out otherwise ?
No really, it works, and I've actually needed this *exact* thing for work today which is like... a sign from heaven ? XD
I'll try to optimize the classes and stuff (would like to have *one* function with a "function" parameter) and post this later tonight.
Posted: Thu Aug 17, 2006 11:53 am
by PyTom
I'm thinking at some point I'll add a parameter to Motion, Move, and Pan that makes them distort time. (To be honest, I thought that parameter was already there.)
Posted: Thu Aug 17, 2006 11:56 am
by shaja
BTW, the tiny demo I came up with for Motion documentation brings a smile to my face.
All about the cheesy humor.
http://www.bishoujo.us/wiki/Functions/Motion
Posted: Thu Aug 17, 2006 1:10 pm
by monele
Lol ^.^. Didn't even realize you could make a custom function that easily

.
Btw, I also realize what I have with Ease functions can simulate simple curved movements too ^.^. We're far from the control of a custom bezier curve, but hey, it's something ^^;