Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Dynamic movement code


Mouzi's Avatar
Member
0 0

Well I don't know if that's what it should be called. Anyways what I mean is that if there would be like one pixel in coordinates 10, 10 and you would randomly generate new coordinates for it. Like 205, 163. Now, how can you make that pixel move there so that it doesn't jump there immediately but kind of slides there. I tried to make this work in JavaScript but it went a bit too messy and it didn't even work. I know this must be some basic stuff because it is used quite a lot in all kind of programming. And I think you just have to first count how many pixels in x and how many in y the pixel has to move to be on the right track. But I just couldn't get it working and I was probably making it too complicated.

So could someone give me some advice on this or give something to google for? I'd really like to learn more about this.


ghost's Avatar
0 0

http://en.wikipedia.org/wiki/Linear_equation

You have two points, find the slope and create a point slope linear equation. Find an appropriate time limit for each distinct point and go through all x values starting at your first point while making sure when you graph your new point you clear the previous one before you blit it.

EDIT:

I think a general term is just animation or to animate.. when I read 'Dynamic movement code' I thought self modifying code.


spyware's Avatar
Banned
0 0

Yea, your best shot is math, since there is no "slide" function in javascript ;).


Mouzi's Avatar
Member
0 0

I think a general term is just animation or to animate.. when I read 'Dynamic movement code' I thought self modifying code.

Well I'm finnish so I'm not so good with the english terms :P

I was trying to do it with math but it went too complicated and didn't work so I just gave up :/

Thanks for the help anyways (even though I didn't understand much).

EDIT: Ok now I got what that wikipedia page was about. I've had that stuff in school and I knew that if you want to do it with math it has to be something like that. I just can't apply it to my problem.

It's rather difficult to get what you mean because we have different terms in math.

Would be cool to solve this one but I think I won't get it.


ghost's Avatar
0 0

In North America linear equations are covered early in high school/late middle school, for schools in Europe I think it's even earlier. They are one of the more simpler Cartesian constructs.


ghost's Avatar
0 0

Assuming primary school is middle school then yes.