Tracing shapes

Maartuh03
03-23-2004, 12:50 PM
Hi,

Im looking for a way to Make Shape1 (a square) trace Shape2 (a line) I want to do this in a timer so that I can see the square tracing the line...
plz help

Thanks in advance,

Maartuh03

GavinO
03-23-2004, 01:10 PM
If you mean to have a square move along a line, you just have to position it at points generated by a line drawing algorithm:

Function GetLinePoint(P1 As POINT,P2 As POINT,Step As Integer,NumSteps As Integer) As POINT
GetLinePoint.X=P1.X+(P2.X-P1.X)/NumSteps*Step
GetLinePoint.Y=P1.Y+(P2.Y-P1.Y)/NumSteps*Step
End Function

Maartuh03
03-23-2004, 01:33 PM
im getting an error,

Compile error:

User-defined type not defined

GavinO
03-23-2004, 03:32 PM
Sorry, I forgot to mention that you would need to define the POINT structure:

Private Type POINT
X As Integer
Y As Integer
End Type

You'll probably also want to write a function to position the box that takes a POINT as an argument.

Maartuh03
03-24-2004, 04:03 AM
well the compile error has changed to one I've never seen before.

Compile error:

Private Enum and user defined types cannot be used as parameters or return types for public procedures, public data members, or fields of public user defined types.

do I get this error couse i should place the codes in a Module? if so how do I "Connect" the timer to that code?

Regards,
Maartuh

passel
03-24-2004, 07:04 AM
Seems to work for me. I'm using VB6. I would expect the function to return 10,10 since I'm specifying the 5th step on a 100 pixels line that is at 45 degrees starting at 0,0 and I'm specifying it be divided into 50 steps.


'In the General Declarations area
Private Type Point
X As Integer
Y As Integer
End Type

Dim b1 As Point
Dim b2 As Point

Private Function GetLinePoint(P1 As Point, P2 As Point, Step As Integer, NumSteps As Integer) As Point
GetLinePoint.X = P1.X + (P2.X - P1.X) / NumSteps * Step
GetLinePoint.Y = P1.Y + (P2.Y - P1.Y) / NumSteps * Step
End Function

Private Sub Command1_Click()
Dim c As Point
b1.X = 0: b1.Y = 0
b2.X = 99: b2.Y = 99
c = GetLinePoint(b1, b2, 5, 50)
Debug.Print c.X; c.Y
End Sub

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum