forum.boolean.name

forum.boolean.name (http://forum.boolean.name/index.php)
-   2D-программирование (http://forum.boolean.name/forumdisplay.php?f=13)
-   -   Заливка (http://forum.boolean.name/showthread.php?t=8307)

rr333 17.05.2009 21:14

Заливка
 
Как реализовать в blitz заливку, как в paint'е? Т.е. закрасить произвольную область, ограниченную пикселями, или хотяб фигуру из произвольных линий.

Baisangur 17.05.2009 21:33

Ответ: Заливка
 
Ты имеешь ввиду 2D объект?
Код:

; Flip/Backbuffer()/Rect Example

; Set Graphics Mode
Graphics 640,480

; Go double buffering
SetBuffer BackBuffer()

; Setup initial locations for the box
box_x = -20 ; negative so it will start OFF screen
box_y = 100

While Not KeyHit(1)
Cls ; Always clear screen first
Rect box_x,box_y,20,20,1 ; Draw the box in the current x,y location
Flip ; Flip it into view
box_x = box_x + 1 ; Move the box over one pixel
If box_x = 640 Then box_x=-20 ; If it leaves the Right edge, reset its x location
Wend

Выдрал из хелпа по блицу(ваще очень хорошая вешь этот хелп).
Так вот примерно так оно и выглядит.

impersonalis 18.05.2009 00:40

Ответ: Заливка
 
рекурсия

rr333 18.05.2009 06:25

Ответ: Заливка
 
Рисовать закрашенные прямоугольники я умею, ето не то. Есть область, ограниченная пикселями, теперь как её закрасить?

rr333 19.05.2009 16:24

Ответ: Заливка
 
Неужели никто не делал заливку на blitz? Сам пробовал делать, но оставался след до края на одну из сторон, смотря откуда начинал заливать.

impersonalis 19.05.2009 21:23

Ответ: Заливка
 
Цитата:

Сообщение от impersonalis (Сообщение 105163)
рекурсия

сам правь мой говнокод (как минимум надо ввести коррецию границы буффера)
Код:

Function ZapiliBufferCvetom(buffer%,px%,py%,r%,g%,b%)
        Local pixcolor%=ReadPixel(px,py,buffer)
        Local npixcolor%=256^3+(256^2)*r+256*g+b
        LockBuffer(buffer)
        RecZap(buffer,px,py,pixcolor,npixcolor)
        UnlockBuffer(buffer)
End Function

Function RecZap(buffer,px,py,col,newcol%)
        If ReadPixelFast(px,py,buffer)<>col Return
        WritePixelFast(px,py,newcol,buffer)
        RecZap(buffer,px-1,py,col,newcol)
        RecZap(buffer,px+1,py,col,newcol)
        RecZap(buffer,px,py-1,col,newcol)
        RecZap(buffer,px,py+1,col,newcol)
End Function


Graphics 800,600,32,2
SetBuffer BackBuffer()

Color 255,255,0
Local GeomObjType%
Local XO%,YO%,WO%,HO%
For i=1 To 10
        GeomObjType=Rand(1,2)
        XO=Rand(0,300)
        XO=Rand(0,300)
        WO=Rand(0,300)
        HO=Rand(0,300)
        Select GeomObjType
                Case 1
                        Rect XO,YO,WO,HO,0
                Case 2
                        Oval XO,YO,WO,HO,0
        End Select
Next

Color 255,0,0
While Not KeyHit(1)
        If MouseHit(1)
                AppTitle "wait.."
                ZapiliBufferCvetom(BackBuffer(),MouseX(),MouseY(),ColorRed(),ColorGreen(),ColorBlue())
                Color Rand(0,255),Rand(0,255),Rand(0,255)
        EndIf
        AppTitle ""
        Flip
Wend
End


rr333 19.05.2009 21:54

Ответ: Заливка
 
Спасиб, то что нужно. Да и алгоритм побыстрее моего будет (я все пиксели обходил 2 циклами).

impersonalis 20.05.2009 02:08

Ответ: Заливка
 
Цитата:

XO=Rand(0,300)
XO=Rand(0,300)
Код:

XO=Rand(0,300)
YO=Rand(0,300)



Часовой пояс GMT +4, время: 15:02.

vBulletin® Version 3.6.5.
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Перевод: zCarot