fill tool

Blitz3D Forums/Blitz3D Programming/fill tool

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Hoi

AlteFarbe = Old color, NeueFarbe = New color.


Here is my best way :\
Graphics 800,600,16,2

Global x1,y1,NeueFarbe,AlteFarbe
Global xstart,xend,ystart,yend

BGimage = CreateImage(800, 600)


;double buffer setup
SetBuffer BackBuffer()

While Not KeyDown(1)
;the line drawing stuff
;uh, me being lazy
CursorX=MouseX()
CursorY=MouseY()
;end me being lazy and not bothering to fix my lame code
If MouseDown(1)
	If linebefore=0
		lastmouseX=CursorX
		lastmouseY=CursorY
		linebefore=1
	EndIf

    SetBuffer ImageBuffer(BGimage)
	Line lastmouseX,lastmouseY,CursorX,CursorY
	lastmouseX=CursorX
	lastmouseY=CursorY
EndIf



;flood fill function
If MouseDown(2)
	;lock buffer for speed up
	LockBuffer ImageBuffer(BGimage)
	colorfill(MouseX(),MouseY(),ImageBuffer(BGimage),GraphicsWidth(),GraphicsHeight(),$ff000000,$ff0000ff)
	;unlock buffer
	UnlockBuffer ImageBuffer(BGimage)
EndIf

SetBuffer BackBuffer()
Cls
DrawBlock BGimage, 0, 0


;double buffering
Flip
Wend

Function colorfill(x%, y%, buffer%, breite%, hoehe%, rgbalt%, rgbneu%)
   If (ReadPixelFast(x%, y%, buffer%) )=rgbalt% Then
      WritePixelFast(x%, y%, rgbneu%, buffer%)
      If (x% - 1)>=0 Then colorfill((x% - 1), y%, buffer%, breite%, hoehe%, rgbalt%, rgbneu%)
      If (x% + 1)<breite% Then colorfill((x% + 1), y%, buffer%, breite%, hoehe%, rgbalt%, rgbneu%)
      If (y% + 1)<hoehe% Then colorfill(x%, (y% + 1), buffer%, breite%, hoehe%, rgbalt%, rgbneu%)
      If (y% - 1)>=0 Then colorfill(x%, (y% - 1), buffer%, breite%, hoehe%, rgbalt%, rgbneu%)
   EndIf
End Function