Cグラフィックを使用したフラッドフィルアルゴリズム
特定の長方形に関して、私たちのタスクは、フラッドフィルアルゴリズムを適用してこの長方形を塗りつぶすことです。
入力
rectangle(left = 50, top = 50, right= 100, bottom = 100) floodFill( a = 55, b = 55, NewColor = 12, OldColor = 0)
出力
メソッド
//'(a、b)'の前の色'OldColor'と(a、b)の周囲のすべてのピクセルを新しい色' NewColor'とfloodFill(a、b、NewColor、OldColor)に置き換える再帰関数
>-
aまたはbが画面の外にある場合は、戻ります。
-
getpixel(a、b)の色がOldColorと同じ場合、
-
上、下、右、左に繰り返します。
FloodFill(a + 1、b、NewColor、OldColor); <
FloodFill(a-1、b、NewColor、OldColor);
FloodFill(a、b + 1、NewColor、OldColor);
FloodFill(a、b-1、NewColor、OldColor);
// Shows program to fill polygon using floodfill
// algorithm
#include <graphics.h>
#include <stdio.h>
// Describes flood fill algorithm
void flood(int x1, int y1, int new_col, int old_col){
// Checking current pixel is old_color or not
if (getpixel(x1, y1) == old_col) {
// Putting new pixel with new color
putpixel(x1, y1, new_col);
// Shows recursive call for bottom pixel fill
flood(x1 + 1, y1, new_col, old_col);
//Shows recursive call for top pixel fill
flood(x1 - 1, y1, new_col, old_col);
// Shows recursive call for right pixel fill
flood(x1, y1 + 1, new_col, old_col);
// Shows recursive call for left pixel fill
flood(x1, y1 - 1, new_col, old_col);
}
}
int main(){
int gd1, gm1 = DETECT;
// Initializing graph
initgraph(&gd1, &gm1, "");
//Shows rectangle coordinate
int top1, left1, bottom1, right1;
top1 = left1 = 50;
bottom1 = right1 = 300;
// Shows rectangle for print rectangle
rectangle(left1, top1, right1, bottom1);
// Fills start cordinate
int x1 = 51;
int y1 = 51;
// Shows new color to fill
int newcolor = 12;
// Shows old color which you want to replace
int oldcolor = 0;
// Calling for fill rectangle
flood(x1, y1, newcolor, oldcolor);
getch();
return 0;
} 出力
-
C++のコンピュータグラフィックスにおけるポイントクリッピングアルゴリズム
コンピュータグラフィックスは、コンピュータ画面に画像やグラフィックスを描画することを扱います。ここでは、画面を2次元座標系として扱います。この座標系は左上(0,0)から始まり、右下で終わります。 表示平面 コンピュータグラフィックスでグラフィックスを描画するために定義された領域です。または画面の表示領域。 クリッピングとは、表示面の外側にあるポイントまたはグラフィックを削除することです。 クリッピングを理解するために例を見てみましょう。 ここで、ポイントCとDは、青色でマークされた表示平面の外側にあるため、クリップされます。 コンピュータグラフィックスのポイントをクリップするた
-
imagefilltoborder()(GD)関数を使用して、PHPで特定の色に塗りつぶします。
imagefilltoborder() はPHPに組み込まれている関数で、特定の色で塗りつぶしを実行するために使用されます。この色の境界線の色は境界線によって定義されます。塗りつぶしの開始点は(x、y)または左上は(0、0)で、領域は色で塗りつぶされます。 構文 bool imagefilltoborder(resource $image, int $x, int $y, int $border, int $color) パラメータ imagefilltoborder() $ image、$ x、$ y、$ border、$colorの5つの異なるパラメータを取ります。 $ ima