Code: Select all
#SquaredShape=0
#RhombShape=1
EnableExplicit
Define i,wi,he, ev,Fon,Img,ImGad
DisableDebugger ; with debugger on, slow drawing
Procedure CAux(Array Arr.Point(1),X,Y,A,B,Rgb,N)
If Point(X,Y)=RGB And Point(A,B)<>Rgb
Arr(N)\X=x : Arr(N)\Y=y
N+1
EndIf
ProcedureReturn N
EndProcedure
Procedure Outline(Array Arr.Point(1),Img,Rgb=0,Rhomb=0)
;ret Arr con outline de rgb
Protected I,X,Y,N
Protected Iwi=ImageWidth(Img)-2
Protected Ihe=ImageHeight(Img)-2
Dim arr(iwi*ihe)
For X=1 To Iwi
For y=1 To Ihe
If Rhomb=1 Or (Rhomb=2 And 1&Y) ; if Odd(y)
N=CAux(Arr(),X,Y,X-1,Y ,Rgb,N) ; left
N=CAux(Arr(),X,Y,X ,Y-1,Rgb,N) ; top
N=CAux(Arr(),X,Y,X+1,Y ,Rgb,N) ; right
N=CAux(Arr(),X,Y,X ,Y+1,Rgb,N) ; bottom
EndIf
If Rhomb=0 Or (Rhomb=2 And Not(1&Y)) ; if Even(Y)
N=CAux(Arr(),X,Y,X-1,Y-1,Rgb,N) ; left top
N=CAux(Arr(),X,Y,X-1,Y+1,Rgb,N) ; left bottom
N=CAux(Arr(),X,Y,X+1,Y-1,Rgb,N) ; top right
N=CAux(Arr(),X,Y,X+1,Y+1,Rgb,N) ; bottom right
EndIf
Next
Next
ReDim arr(n-1)
EndProcedure
;Test it <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;StartDrawing is inside loop to see the growing outline effect
Procedure TestDraw(img,imgad)
Protected RGB,j
Dim arr.point(0)
StartDrawing(ImageOutput(Img))
Outline(arr(),Img,0,#RhombShape) ; try #SquaredShape <<<<<<<<<<
RGB=Random(#White)
For j=0 To ArraySize(arr())
Plot(arr(j)\x,arr(j)\y,RGB)
Next
StopDrawing()
SetGadgetState(Imgad,ImageID(Img))
EndProcedure
OpenWindow(0, 100, 100,900,320 ,"Get Outline", #PB_Window_SystemMenu |1)
Wi=WindowWidth(0):He=WindowHeight(0)
Fon=LoadFont(-1,"arial",80)
Img=CreateImage(-1,Wi,He)
Imgad=ImageGadget(-1,0,0,0,0,ImageID(Img))
StartDrawing(ImageOutput(Img))
DrawingFont(FontID(Fon))
DrawingMode(#PB_2DDrawing_Outlined)
DrawText(130,90,"Pure Basic",Random(#White),0)
StopDrawing()
SetGadgetState(Imgad,ImageID(Img))
Repeat
ev= WaitWindowEvent(1)
If i<90
testdraw(img,imgad)
i+1
EndIf
Until ev=#PB_Event_CloseWindow