|
-
Aug 13th, 2002, 12:28 PM
#1
Thread Starter
Member
Line algorithm
Hi,
This is the best place where I can post this, I think
Say, I have a subroutine called drawline, which accepts as parameters:
x1, y1, x2, y2
We have a screen, and on point (x1,y1) we start drawing our line to (x2,y2). Each pixel on the line should be determined by an algorithm, and than colored, say gree. Does anybody know an algorithm?
-
Aug 13th, 2002, 02:01 PM
#2
Frenzied Member
Most graphics systems have support the LineTo verb since PostScript came out with it in 1984. Windows version of drawing a line with LineTo:
Code:
'This project needs:
'- picture box
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, lpPoint As POINTAPI) As Long
Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Const Yellow = &HFFFF&
Private Sub Form_Load()
Dim Cnt1 As Byte, Cnt2 As Byte, Point As POINTAPI
Me.AutoRedraw = True
Me.ScaleMode = vbPixels
Picture1.ForeColor = Yellow
Picture1.ScaleMode = vbPixels
Picture1.AutoRedraw = True
Cnt1=100
Cnt2=100
'Set the start-point's coördinates
Point.X = Cnt1: Point.Y = Cnt2
'Move the active point
MoveToEx Picture1.hDC.hdc, Cnt1, Cnt2, Point
'Draw a line from the active point to the given point
LineTo Picture1.hdc, 200, 200
Picture1.Refresh
End Sub
-
Aug 13th, 2002, 07:59 PM
#3
Hyperactive Member
I think he wanted to know how LineTo drew the line, and how it knows which pixels to change.
-
Aug 14th, 2002, 02:45 AM
#4
Thread Starter
Member
Yes, that was the point.
It is, however, for a C project, but VB code is nice too, I know both.
-
Aug 14th, 2002, 09:36 PM
#5
Frenzied Member
Ok. My bad.
You asked. So- It's called Bresnham's Algorithm. It's all over the net.
Here is a pretty good explanation, if you can do basic algebra:
http://www.cs.helsinki.fi/group/goa/...s/bresenh.html
-
Aug 15th, 2002, 02:41 AM
#6
Thread Starter
Member
Kinda nice stuff for the math lessons
-
Aug 15th, 2002, 01:35 PM
#7
Hyperactive Member
Yer, thanx for that link Jim.
There are 10 types of people in the world - those that understand binary, and those that don't.
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
|