Can somebody give me the equation that gives me the points to plot between the two end points.. in PureBasic?
I'll wait.. and take a pain reliever...
Code: Select all
Procedure draw(x1, y1, x2, y2)
Protected dy = Abs(y2 - y1), yInc = Sign(y2 - y1)
Protected dx = Abs(x2 - x1), xInc = Sign(x2 - x1)
Protected rowAc, ColAc
Protected y = y1, x = x1
err = dx
If dy > dx
err = dy
EndIf
endPt = err
If err = dx
rowAc = endPt / 2
Else
ColAc = endPt / 2
EndIf
While err > 0
rowAc + dy
If rowAc >= endPt
rowAc - endPt
y + yInc
EndIf
ColAc + dx
If ColAc >= endPt
ColAc - endPt
x + xInc
EndIf
Plot(x, y)
err - 1
Wend
EndProcedure
OpenWindow(0, 0, 0, 500, 500, "Bresenhem line drawing method", #PB_Window_SystemMenu)
Define event, quit
Repeat
StartDrawing(WindowOutput(0))
FrontColor(Random($FFFFFF))
draw(Random(500 - 1), Random(500 - 1), Random(500 - 1), Random(500 - 1)) ;stay in screen boundaries
StopDrawing()
Repeat
event = WindowEvent()
If event = #PB_Event_CloseWindow
quit = 1
EndIf
Until event = 0 Or quit = 1
Delay(10)
Until quit = 1Don't do that! Just wanted to say that you find more interesting stuff when searching for 'Bresenham'. That's all.WilliamL wrote:ok, now I DO feel that dumb!
Code: Select all
LineXY(x1, y1, x2, y2 [, Color])