|
-
Oct 2nd, 2002, 11:37 PM
#1
Thread Starter
New Member
drawing dashed line using PSet
Hi i was wondering how i would be able to draw a line that is dashed, or dotted using Pset. I was able to draw a line that has only one pixel break, but i need more than that. How can i implement that?
Code:
Dim d As Single
Dim incrE As Integer
Dim incrNE As Integer
'Bresenham algorithm
dx = x1 - x0
dy = y1 - y0
d = dy * 2 - dx
incrE = dy * 2
incrNE = (dy - dx) * 2
x = x0
y = y0
PSet (x, y)
Do While x < x1 Or y < y1
If (d <= 0) Then
d = d + incrE
x = x + 1
Else
d = d + incrNE
x = x + 1
y = y + 1
End If
PSet (x, y)
Loop
Any suggestions?
thanks
-
Oct 3rd, 2002, 11:46 AM
#2
Addicted Member
Hi,
I hope this helps. I haven't named the algorithm...yet! ;-)
Create a VB app, copy the Private Sub DrawLine code into your form...add 8 command buttons...and voila! Run program and click on each button...you will see line change from solid to invisible. The key is using a filter value I call 'nFilter'.
Before I draw each pixel, I check the next bit in this 8 bit binary value. If it is a 0, I draw the pixel. If the bit is 1, I don't draw anything. You can change this to 16 bit number I think...like &HF731 and change the '7' to '15' in nFilterCount>...
Code:
Private Sub DrawLine(s As Integer, t As Integer, nLength As Integer, nFilter As Integer)
If s < 1 Then s = 100 'out of boundary stuff...limited
If t < 1 Then t = 100
If nLength < 1 Then nLength = 100
If nFilter < 1 Then nFilter = &HF
Dim nFilterCount As Integer 'create couple of variables
Dim x As Integer
Form1.ScaleMode = vbPixels 'set draw mode
Form1.DrawWidth = 2
For x = 0 To nLength
a = (2 ^ nFilterCount And nFilter)
If a = False Then
PSet (s + x, t)
End If
nFilterCount = nFilterCount + 1
If nFilterCount > 7 Then nFilterCount = 0
Next x
End Sub
Private Sub Command1_Click()
DrawLine 100, 20, 100, &H1
End Sub
Private Sub Command2_Click()
DrawLine 100, 30, 100, &H3
End Sub
Private Sub Command3_Click()
DrawLine 100, 40, 100, &H7
End Sub
Private Sub Command4_Click()
DrawLine 100, 50, 100, &HF
End Sub
Private Sub Command5_Click()
DrawLine 100, 60, 100, &H1F
End Sub
Private Sub Command6_Click()
DrawLine 100, 70, 100, &H3F
End Sub
Private Sub Command7_Click()
DrawLine 100, 80, 100, &H7F
End Sub
Private Sub Command8_Click()
DrawLine 100, 90, 100, &HFF
End Sub
Regards,
ChuckB
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
|