2006/01/10(Tue)閉領域塗りつぶしモジュール

はてブ数 2006/01/10 17:05 プログラミング::HSP3 つーさ

指定した座標と同じ色で繋がっている領域を塗りつぶすことができます。
ペイントにもついてるアレです。
べちゃっ

中身は単なるExtFloodFill APIのラッパです。

このモジュールはスクリプトに組み込んで自由に使用できます。

#module
#deffunc floodfill int startX, int startY, int noredraw
;// 開始座標と同じ色で繋がっている領域を選択色で塗りつぶす。
;// noredraw を 1 にしたときは画面には反映されないので、
;// 自分で redraw すること。

#uselib "gdi32.dll"
#cfunc CreateSolidBrush "CreateSolidBrush" int
#func SelectObject "SelectObject" int,int
#func ExtFloodFill "ExtFloodFill" int,int,int,int,int
#func DeleteObject "DeleteObject" int
#define ctype RGB(%1,%2,%3) ((%1)|(%2<<8)|(%3<<16))
nc = ginfo_r,ginfo_g,ginfo_b
pget startX,startY : tc = RGB(ginfo_r,ginfo_g,ginfo_b)
hBrush = CreateSolidBrush( RGB(nc.0,nc.1,nc.2 ) )
SelectObject hdc,hBrush : oldbrs = stat
ExtFloodFill hdc, startX, startY, tc, 1
SelectObject hdc,oldbrs : DeleteObject hBrsuh
color nc.0,nc.1,nc.2 : if (noredraw=0){redraw} : return
#global

;//////// ここからサンプル ////////
  randomize

  ;// 適当に塗り絵を作る
  repeat 12
    circle rnd(840)-100,rnd(680)-100,rnd(840)-100,rnd(680)-100,0
  loop

  onclick *clk : stop

*clk
  color rnd(4)*64+63,rnd(4)*64+63,rnd(4)*64+63 ;// 適当に色を作る
  floodfill mousex,mousey ;// マウス座標塗りつぶし
  stop