EFileTahi-A Posted May 12, 2005 Posted May 12, 2005 (edited) How can I draw a line from one point to another? Imagine that the starting point will be 100,100(x,y(pixels)) to the mouse click coordenates, let's say 345,201 and a line will be drawn from these two points. I can do this all right, but the problem is to make it animated, like seeing the line being drawn from x,y to xx,yy using a timer, so that a every tick will increase the lines size from the starting point to the target point... //each line represents a tick... (frame per second) //x,y means the starting point //xx,yy means the ending point // "----" means the line to be drawn x,y - xx,yy x,y -- xx,yy x,y --- xx,yy x,y ---- xx,yy x,y ---- xx,yy x,y ---- xx,yy x,y ---- xx,yy x,y ---- xx,yy x,y ---- xx,yy x,y ---- xx,yy x,y ---- xx,yy x,y ---- xx,yy x,y ---- xx,yy x,y ---- xx,yy x,y ---- xx,yy x,y ---- xx,yy x,y ---- xx,yy x,y ---- xx,yy x,y ---- xx,yy x,y ---- xx,yy x,y --- xx,yy x,y -- xx,yy x,y - xx,yy x,y xx,yy If using a line seems to be too tricky, at least I would like to know how to animate a "dot" from the too points... I guess this will involve Math.Cos / Match.P / Match.Atan / Math.Sin... Unfortunately my math skills stink... If there is someone kind enough to teach me this, please... :) Edited May 12, 2005 by EFileTahi-A Quote
EFileTahi-A Posted May 14, 2005 Author Posted May 14, 2005 If I was not explicit enought let me know about it... Quote
thenerd Posted May 14, 2005 Posted May 14, 2005 Well, you can use gdi+ and use .drawline(pen,x,y,xx,yy) And then just do it over and over again, each time changing x and y and xx and yy.. Quote
Leaders snarfblam Posted May 14, 2005 Leaders Posted May 14, 2005 You are... looking for an algorithm to acheive the effect of the line slowly being drawn from point a to point b? If so, why not make a function to give you intermediate points within the line so that you may draw the line one portion at a time using a timer. Use a simple weighted average function to get the intermediate points, and draw the segments on a timer. Function IntermediatePoints(ByVal Point1 As Point, ByVal Point2 As Point, ByVal Segments As Integer) As Point() Dim Result As Point() = New Point(Segments) {} Dim StepSize As Double = 1 / Segments Dim StepVal As Double Result(0) = Point1 Result(Segments) = Point2 For i As Integer = 1 To Segments - 1 StepVal += StepSize Result(i) = PointAverage(Point1, Point2, StepVal) Next Return Result End Function Function PointAverage(ByVal Point1 As Point, ByVal Point2 As Point, ByVal Weight As Double) As Point Dim Result As Point Result.X = CInt(Point1.X * Weight + Point2.X * (1 - Weight)) Result.Y = CInt(Point1.Y * Weight + Point2.Y * (1 - Weight)) Return Result End Function Those might help. Quote [sIGPIC]e[/sIGPIC]
EFileTahi-A Posted May 16, 2005 Author Posted May 16, 2005 (edited) Ok, thanks for the posts. Currently am busy learning DirectX. When things will get going I will try this out... Edited May 16, 2005 by EFileTahi-A Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.