Archived

This topic is now archived and is closed to further replies.

piknic

Quadratic Path

Recommended Posts

I was wondering if someone could give me code ( actual or just explanation ) on how to, after user puts in three values ( a,b and c..for the euqation ax^2+bx+c) , to make a picturebox follow this line.. For example say my equation is y=x^2.. How would i make a picture box follow this curve (preferably using a timer since i want it to go relatively slow). I need some explantion on how to do this.. Like i need the pic1.Left = whatever and pic2.Top = w/e... ( im new at this and im sure that is very dumb and wont work and must be much more complex).. Either way some example code with good explantion would help..Or if it is that simple please tell em Thanks

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
y = a*x*x + b*x + c.

Just increment x by a little bit each time, and calculate the y value through the equation. Then draw your picture at (x,y).

Share this post


Link to post
Share on other sites
ok..thanks..oh and btw...How do u do (x,y)..rly i have no idea how to make a picture box have a point on the form without doing .top and .left lol...whats an example of code saying X = 2 and Y = 4.. What would i use to draw the picture box on the form.??

Share this post


Link to post
Share on other sites
quote:
Original post by vanillacoke
I think your best bet would be using C++.


Hmm, why?

Piknik: what language are you using? You mention forms, so I assume you are using some sort of RAD language, like VB, Delphi or C++Builder, correct?
Here's some Delphi code that will do your job:


    
Function Quadratic (Parameter : Integer) : Integer;
Var
Temp : Integer;
Begin
{ Form AX^2 + BX + C }
Temp := (Parameter * Parameter) + (5 * Parameter) + 2;
Result := Temp;
End;

Procedure MovePicture (Var Image : TImage);
Var
Loop, QuadraticResult : Integer;
Begin
While True Do Begin
If Loop = 100 Then Begin
Loop := 0;
End;
QuadraticResult := Quadratic (Loop);
Inc (Loop);
Image.Left := Image.Left + QuadraticResult;
Image.Right := Image.Right + QuadraticResult;
Image.Bottom := Image.Bottom + QuadraticResult;
Image.Top := Image.Top + QuadraticResult;
End;
End;


I haven't tested that, mind.
Edit: fixed type inconsistencies.

[edited by - MDI on May 5, 2003 4:29:12 PM]

Share this post


Link to post
Share on other sites
Unless of course you want it to move at a uniform speed along your function, in which case the math (and programming) gets much more interesting I won''t go into it unless that''s what you want though...

Share this post


Link to post
Share on other sites