|
-
Jul 21st, 2001, 02:20 AM
#1
Lively Member
u can try this code, if u really just want to plot (x1,y1) to (x2,y2), i used the Line Method to connect the dots...
1. add a command button and name it cmdPlot
2. add two labels namely lblPoint1 and lblPoint2
3. and paste this code in the general declaration
'---------------------------------------------------------------------------------
Option Explicit
Dim CX1 As Integer, CY1 As Integer 'point 1 of the line
Dim CX2 As Integer, CY2 As Integer 'point 2 of the line
Dim curX As Integer, curY As Integer 'current Xpos and Ypos
Dim maxDot As Integer
Private Sub cmdPlot_Click()
If cmdPlot.Caption = "&Plot" Then
'draw a line
Line (CX1, CY1)-(CX2, CY2)
cmdPlot.Caption = "&Another Try"
ElseIf cmdPlot.Caption = "&Another Try" Then
lblPoint1.Caption = ""
lblPoint2.Caption = ""
maxDot = 0
cmdPlot.Caption = "&Plot"
cmdPlot.Enabled = False
End If
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
maxDot = maxDot + 1
If maxDot <= 2 Then 'limit the user to plot 2 points only
Select Case maxDot
Case 1
CX1 = curX
CY1 = curY
lblPoint1.Caption = curX & ", " & curY
Case 2
CX2 = curX
CY2 = curY
lblPoint2.Caption = curX & ", " & curY
cmdPlot.Enabled = True
End Select
'draw a dot
PSet (curX, curY), vbRed
Else
Exit Sub
End If
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
curX = X
curY = Y
Form1.Caption = curX & ", " & curY
End Sub
'-----------------------------------------------------------------------------------
i'll try to code same program but this time i'll be using the bresenham's line algorithm. i think there are many things to consider in ploting a point using the said algorithm...
You never become a failure, unless you quit on trying!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|