aucun rapport avec l'algo de Bresenham
la même peut être dessinée avec une seule boucle puisque c'est une diagonale... ou x=y
Code : Tout sélectionner
If OpenWindow(0, 0, 0, 200, 200, "Line in pixels", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If CreateImage(0, 200, 200) And StartDrawing(ImageOutput(0))
For n=0 To 100
Plot(n,n,RGB(255,0,0))
Next
StopDrawing()
ImageGadget(0, 0, 0, 200, 200, ImageID(0))
EndIf
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
ou avec une simple instruction linexy()
Code : Tout sélectionner
If OpenWindow(0, 0, 0, 200, 200, "Line in pixels", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If CreateImage(0, 200, 200) And StartDrawing(ImageOutput(0))
LineXY(0,0,100,100,$0000ff)
StopDrawing()
ImageGadget(0, 0, 0, 200, 200, ImageID(0))
EndIf
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
il existe des implémentations de l’algorithme de Bresenham en pure basic.
ci dessous trouvé sur le forum, par comtois.
Code : Tout sélectionner
; code par comtois.
Declare DoLine(XStart,YStart,xend,YEnd,CoulR,CoulG,CoulB)
InitSprite()
InitKeyboard()
OpenScreen(640, 480, 32, "DoLine")
;- Boucle
rayon=200
Repeat
ClearScreen(0)
For i.w = 0 To 359 Step 6
DoLine(320,240, 320 + rayon * Cos(i * 0.0174533), 240 + rayon * Sin(i* 0.0174533),Random(255),Random(255),Random(255))
Next i
FlipBuffers()
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
End
Procedure PlotN(x,y)
Plot(x,y)
Plot(x-1,y-1)
Plot(x+1,y+1)
Plot(x-1,y+1)
Plot(x+1,y-1)
EndProcedure
Procedure DoLine(xi,yi,xf,yf,CoulR,CoulG,CoulB)
StartDrawing(ScreenOutput())
FrontColor(rgb(CoulR,CoulG,CoulB))
x = xi
y = yi
dx = xf - xi
dy = yf - yi
If dx > 0
xinc = 1
Else
xinc = -1
EndIf
If dy > 0
yinc = 1
Else
yinc = -1
EndIf
dx = Abs(dx)
dy = Abs(dy)
PlotN(x,y)
If dx > dy
cumul = dx / 2
For i = 1 To dx
x + xinc
cumul + dy
If (cumul >= dx)
cumul - dx
y + yinc
EndIf
PlotN(x,y)
Next
Else
cumul = dy / 2
For i = 1 To dy
y + yinc
cumul + dx
If cumul >= dy
cumul - dy
x + xinc
EndIf
PlotN(x,y)
Next
EndIf
StopDrawing()
EndProcedure