Bitmap/Flood fill: Difference between revisions

added FreeBASIC
(Lingo added)
(added FreeBASIC)
Line 1,115:
 
<lang fortran> call floodfill(animage, point(100,100), rgb(0,0,0), rgb(0,255,0))</lang>
=={{header|FreeBASIC}}==
{{trans|BBC BASIC}}
<lang freebasic>' version 01-11-2016
' compile with: fbc -s console
 
' ----==== Start FLOOD FILL ====----
Dim Shared As Long x_max, y_max
 
Sub f_fill(x As Integer, y As Integer, target As UInteger, fill_color As UInteger)
 
' 0, 0 is top left corner
If Point(x,y) <> target Then Exit Sub
 
Dim As Long l = x, r = x
While Point(l -1, y) = target AndAlso l -1 > -1
l = l -1
Wend
While Point(r +1, y) = target AndAlso r +1 < x_max
r = r +1
Wend
Line (l,y) - (r,y), fill_color
For x = l To r
If y +1 < y_max Then f_fill(x, y +1, target, fill_color)
If y -1 > -1 Then f_fill(x, y -1, target, fill_color)
Next
 
End Sub
 
' the flood_fill needs to know the boundries of the window/screen
' without them the routine start to check outside the window
' this leads to crashes (out of stack)
' the Line routine has clipping it will not draw outside the window
 
Sub flood_fill(x As Integer, y As Integer, target As UInteger, fill_color As UInteger)
 
ScreenInfo x_max, y_max
f_fill(x, y, target, fill_color)
 
End Sub
 
' ----==== End FLOOD FILL ====----
 
' ------=< MAIN >=------
 
Dim As ULong i, col, x, y
 
ScreenRes 400, 400, 32
Randomize Timer
 
For i As ULong = 1 To 5
Circle(Rnd * 400 ,Rnd * 400), i * 40, Rnd * &hFFFFFF
Next
 
' hit a key to end
Do
x = Rnd * 400
y = Rnd * 400
col = Point(x, y)
flood_fill(x, y, col, Rnd * &hFFFFFF)
Sleep 2000,1
If Inkey <> "" Then End
Loop</lang>
 
=={{header|Go}}==
An addition to code from the bitmap task:
457

edits