Welcome Guest.   Make a donation to an author on the site December 19, 2014, 04:07:57 AM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
Read the Practical Guide to DonationCoder.com Forum Search Features
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: Challenge: algorithm for counting progressively/exponentially  (Read 1640 times)
housetier
Charter Honorary Member
***
Posts: 1,321


see users location on a map View Profile Give some DonationCredits to this forum member
« on: September 16, 2010, 01:56:52 PM »

I have tasked myself with writing a function that will count up to a number in a dynamic fashion, that means it'll start with large steps that become smaller and smaller as the counter reaches the target. So while at first it would start counting in the thousands, at the end it would only increment using 1.

However, it seems I have lost all mathematical ability since leaving school. I cannot for the time of my life come up with the algorithm! There is only half-ideas and flashes, but nothing like "start like so, then for every iteration check this and that, calculate the increment by whatever and increment"; I can design and implement complex applications, but I cannot see this one algorithm.

When plotting the counter value it should look similar to this image (taken from a wikipedia article about Sigmoid functionsw), more precisely like the upper right quadrant: it increases steeply at first and then flattens ever more.

So here goes the challenge:

Can anyone tell or show me the algorithm (easy, I think) and can anybody explain this algorithm to me, maybe step by step.
Logged
Codebyte
Supporting Member
**
Posts: 160



"Premature Optimization is the root of all evil."

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #1 on: September 16, 2010, 02:02:30 PM »

housetier, you should check out "easing". This will help you do alot of things with calculating progress. I use this in my animator library for js. Here is the link for the easing stuff:

http://robertpenner.com/easing/

and here is how I use it:

http://concepts.codebyter.com/js/cb_animator2/

calculating easing is a really cool concept and there are a ton of things you can do with it. You can specify your own effects etc.
« Last Edit: September 16, 2010, 02:26:35 PM by Codebyte » Logged

CodeByter.com - http://www.codebyter.com
housetier
Charter Honorary Member
***
Posts: 1,321


see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #2 on: September 16, 2010, 02:15:21 PM »

Excellent, that gives me an idea for the first of the challenge.

Thank you very much!  Kiss
Logged
Deozaan
Charter Member
***
Posts: 6,532



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #3 on: September 16, 2010, 03:21:47 PM »

This doesn't look like that graph, but basically you just add half the distance (rounded to an integer) between the current value and the target value until the distance is <=1 then you just add the remaining distance.

EDIT: I noticed this is called the Standard Exponential Slide in Robert Penner's chapter on Tweening in Flash.
« Last Edit: September 16, 2010, 05:35:38 PM by Deozaan » Logged

CWuestefeld
Supporting Member
**
Posts: 944



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #4 on: September 16, 2010, 04:31:05 PM »

Since I'm a sci-fi geek, I'm thinking of the velocity of a starship as it travels to its destination under constant (say, 1g) acceleration. The idea is that you reach your highest velocity at the halfway point, then turn around, and start decelerating.

So:


halfway = distance / 2
velocity = 0
counter = 0
accelerationfactor = 1
while (counter < distance)
    if (counter > halfway AND accelerationfactor > 1)
        accelerationfactor = accelerationfactor * -1 // turnaround
    velocity += accelerationfactor
    counter += velocity


You'll need to clean up for overshooting, but I think that should pretty much do what you want.

EDIT: re-reading your question, your linked image doesn't look like what you've described textually. The algorithm I've outlined will give you the linked image. But if you want to start from "high speed" and just decelerate, then either do the geometric algorithm that Deozaan gives, or


velocity = 100 // or whatever
acceleration = 1
counter = 0
while (counter < target)
    velocity -= acceleration
    counter += velocity

« Last Edit: September 16, 2010, 04:37:13 PM by CWuestefeld » Logged



Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.033s | Server load: 0.01 ]