Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: [MATH] D:  (Read 2620 times)

0 Members and 1 Guest are viewing this topic.

Xiphirx

wat
[MATH] D:
« on: March 09, 2010, 11:36:48 pm »
  • Xiphirx
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3007
Hey there,

I am trying to figure out how to make a box expand height wise (easing) using a function for y...

right now I have y=400-x where x is the counting variable in a for loop, but its not very "easing"-like  D: ...

lets define some things:
x = counter variable, increasing by one every frame
z = the desired height
c = starting height

I hope this is possible...
Logged
  • For The Swarm
Re: [MATH] D:
« Reply #1 on: March 09, 2010, 11:42:35 pm »
  • Doesn't afraid of anything
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 7002
while ( y < z )
{
    y = 400 - x++;
}

Seems simple enough i think?
Logged



i love big weenies and i cannot lie

Xiphirx

wat
Re: [MATH] D:
« Reply #2 on: March 09, 2010, 11:48:50 pm »
  • Xiphirx
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3007
uhm, that is what I basically have, just in another form...

That doesn't have easing though... how would I add that?
Logged
  • For The Swarm

DJvenom

super-sage
Re: [MATH] D:
« Reply #3 on: March 09, 2010, 11:51:01 pm »
  • Colbydude was here.
  • *
  • Reputation: +7/-0
  • Offline Offline
  • Gender: Female
  • Posts: 2898
easing as in starts out fast, then gets slower?

if so, have it take the difference between y and z, divided by some number (say like 4) then have x subtract that, and recalc the difference, so it'll start out 4x as fast then ease into nothing.
« Last Edit: March 09, 2010, 11:52:46 pm by DJvenom »
Logged
I do art
I ermmm... DID do art
I do art

Xiphirx

wat
Re: [MATH] D:
« Reply #4 on: March 09, 2010, 11:51:24 pm »
  • Xiphirx
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3007
easing as in starts out fast, then gets slower?

yes exactly :D
Logged
  • For The Swarm

DJvenom

super-sage
Re: [MATH] D:
« Reply #5 on: March 09, 2010, 11:53:36 pm »
  • Colbydude was here.
  • *
  • Reputation: +7/-0
  • Offline Offline
  • Gender: Female
  • Posts: 2898
I could make a demo of what I said in GM, if you want, although I'm sure that's not what you're using.
Logged
I do art
I ermmm... DID do art
I do art

Xiphirx

wat
Re: [MATH] D:
« Reply #6 on: March 09, 2010, 11:57:19 pm »
  • Xiphirx
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3007

if so, have it take the difference between y and z, divided by some number (say like 4) then have x subtract that, and recalc the difference, so it'll start out 4x as fast then ease into nothing.
so..
y = x-((y-z)/4)


I think I did it wrong D:

could you post the equation you had in mind?

and yeah, this is for a C++ project.
Logged
  • For The Swarm
Re: [MATH] D:
« Reply #7 on: March 09, 2010, 11:59:58 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1141
You should use a non-linear equation like:
y(t) = min_y + (max_y - min_y) * [ (t / t_max) ^ alpha]
alpha should be so that 0<alpha<1.
(Try 0.5 at first)
Logged

DJvenom

super-sage
Re: [MATH] D:
« Reply #8 on: March 10, 2010, 12:00:25 am »
  • Colbydude was here.
  • *
  • Reputation: +7/-0
  • Offline Offline
  • Gender: Female
  • Posts: 2898
well in create I have:
current=0
max_size=600
difference=0

in step I have:
if current<max_size
{
difference=(max_size-current)/4
if difference<1 { difference=1 }
current+=difference
}

then in draw:
draw_rectangle(0,0,30,current,0)


Don't know how that translates to an equation, as I failed math horribly all 4 years of high school.

Also, try /8 as it gives more of a popup windowy vibe than the /4 ;)
« Last Edit: March 10, 2010, 12:08:09 am by DJvenom »
Logged
I do art
I ermmm... DID do art
I do art

Xiphirx

wat
Re: [MATH] D:
« Reply #9 on: March 10, 2010, 12:37:36 am »
  • Xiphirx
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3007
Thank you sjegtp and everyone, I have gotten it :D
Logged
  • For The Swarm
Re: [MATH] D:
« Reply #10 on: March 10, 2010, 09:00:11 am »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3725
in step I have:
if current<max_size
{
difference=(max_size-current)/4
if difference<1 { difference=1 }
current+=difference
}

First of all I would make the step code different:
Using target size as the size you want
Code: [Select]
if current != target_size
difference = (target_size - current)/4
if difference < 1 && difference > -1 { current = target_size }
else current+= difference

But frankly, for an easy-in, ease-out feature I would use a sigmoid function => http://en.wikipedia.org/wiki/Sigmoid_function It's S shape give a smooth ease in and ease out.
Logged
Re: [MATH] D:
« Reply #11 on: March 10, 2010, 03:14:57 pm »
  • Doesn't afraid of anything
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 7002
Not good, Niek, that can potentially go over the target_size.
Logged



i love big weenies and i cannot lie
Re: [MATH] D:
« Reply #12 on: March 10, 2010, 04:35:04 pm »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3725
It depends on how you use it.

I made a GameMaker example (GM8 attached):
Create event:
Code: [Select]
size1 = 5;      //rectangles original size
size2 = 100;    //rectangles target size
timer = 0;      //time passed since increasing
s = 0;          //rectangles size to be drawn

half_point = 15; //halfway point where speed is max, best to take half the fps
delay = 5;      //to slow down the increase of the rectangle the higher the longer the it takes.

Draw Event:
Code: [Select]
//just some color settings unimportant
draw_set_color(c_blue);
draw_set_alpha(1);

//calculate the size that needs to be drawn of the rectangle
s = size1 + (size2-size1) / (1 + exp( -(timer / delay - half_point) ));

//draw rectangle
draw_rectangle(view_wview[0]/2-s,
                view_hview[0]/2-s,
                view_wview[0]/2+s,
                view_hview[0]/2+s,
                false);
//increase the time passed Game Maker necessity
timer += 1;

//reset when done increasing not really important
if(timer == 2*half_point*delay){
    timer = 0;
    //In order to also decrease just swap the sizes
    var p;
    p = size1;
    size1 = size2;
    size2 = p;
}
« Last Edit: March 10, 2010, 10:10:04 pm by Niek »
Logged
Re: [MATH] D:
« Reply #13 on: March 11, 2010, 04:39:18 am »
  • Doesn't afraid of anything
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 7002
Actually..this could be done really easily with some calculus..

Code: [Select]
//y = 10/x  adjust the numerator to make it more or less sensitive
//y' = -10/x² derivative

int desired = 100;
int x = 1;
rectangle rect;
rect.height = 0;

while (rect.height < desired)
{
      rect.height = (-1)*(-10/(x*x))
      x++;
}


And just gonna throw out there, the calculus is just to be fancy.  You could do it with just the hyperbola for f(y) and just remove the (-1) from the while loop.  Neither way is more or less efficient really.  And you'll probably have to write your own rectangle class, unless you have one from somewhere already.

..Can you guys tell I'm bored? rofl

EDIT: Ahh...actually, this won't work as well as I thought.  The algorithm works in theory, but it doesn't apply well.  I declare this algorithm Communist.


« Last Edit: March 11, 2010, 04:50:11 am by MG-Zero »
Logged



i love big weenies and i cannot lie

Xiphirx

wat
Re: [MATH] D:
« Reply #14 on: March 11, 2010, 06:50:23 am »
  • Xiphirx
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3007
Thank you sjegtp and everyone, I have gotten it :D

D:
Logged
  • For The Swarm
Re: [MATH] D:
« Reply #15 on: March 11, 2010, 08:18:57 am »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3374
Thank you sjegtp and everyone, I have gotten it :D

D:
peeps are allowed to discuss.
Logged
Quote from: Jason
Your community is a bunch of stuck up turds.

Xiphirx

wat
Re: [MATH] D:
« Reply #16 on: March 11, 2010, 03:27:41 pm »
  • Xiphirx
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3007
Thank you sjegtp and everyone, I have gotten it :D

D:
peeps are allowed to discuss.

NEVER IN A MILLION YEARS D8
Logged
  • For The Swarm
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.044 seconds with 72 queries.

anything