Tässä nyt yksinkertainen rekursiolla toimiva saman värisen alueen täyttö functio. Soveltuu hyvin joidenkin pienien alueiden uudelleen maalaamiseen...
Code: Select all
////////////////////////////////////////////////
// AreaFill 0.1 Made by Jonhu 23.12.09 //
////////////////////////////////////////////////
imgx = 0
imgy = 0
Const width = 200
Const height = 200
Dim ColorTable(width, height)
img = Makeimage2()
Repeat
If MouseHit(1) Then
If ( MouseX()<=imgx + ImageWidth(img) And MouseX() >= 0 And MouseY()<=imgy+ImageHeight(img) And MouseY()>=0 ) Then
FormatColorTable()
MarkArea( img, MouseX(), MouseY() )
img = FillArea( img, cbred )
EndIf
EndIf
DrawImage img,0,0
DrawScreen
Forever
Function FillArea( img, r=200,g=0,b=0)
Color r,g,b
DrawToImage img
For y=0 To ImageHeight(img)
For x=0 To ImageWidth(img)
If ColorTable(x,y)=1 Then Dot x,y
Next x
Next y
DrawToScreen
Return img
EndFunction
Function MarkArea( img, fillpointx, fillpointy, Distance_=0, r1=0,g1=0,b1=0) // by Jonhu
If colortable(fillpointx, fillpointy) = 1 Then Return False // väri jo merkattu --> palataan
If (fillpointx >= ImageWidth(img) Or fillpointx<=0 Or fillpointy <=0 Or fillpointy >= ImageHeight(img)) Then Return False // menossa kuvan ulkopuolelle --> palataan
PickImageColor img, fillpointx, fillpointy
If Distance_ = 0 Then r1 = getRGB(RED) : g1 = getRGB(GREEN) : b1 = getRGB(BLUE) // merkataan muutettavaväri jos mennään ekaa kierrosta
If ( getRGB(RED)<>r1 Or getRGB(GREEN)<>g1 Or getRGB(BLUE)<>b1 ) Then Return False // Jos erivärinen kuin alkuperäinen pikseli --> palataan takaisin
colortable(fillpointx, fillpointy) = 1
For a=-1 To 1 Step 2 // a saa arvot -1 ja +1
MarkArea( img, fillpointx, fillpointy+a, distance_ + 1, r1,g1,b1)
MarkArea( img, fillpointx+a, fillpointy, distance_ + 1, r1,g1,b1)
Next a
EndFunction
Function Makeimage2()
img = MakeImage(width,height)
DrawToImage img
Box 10,10,190,190,0
Line 10,30,200,160
Color cbgreen
Line 100,3,100,200
Circle 50,50,100,0
Color cbblue
Circle 30,120,14
Line 0,200,200,20
DrawToScreen
Return img
EndFunction
Function FormatColorTable( nro = 0 )
For x=0 To width
For y=0 To height
ColorTable( x, y ) = nro
Next y
Next x
EndFunction