Flood fill Algorithm คือ Algorithm การระบายสีโดยมีเงื่อนไขอยู่ว่ารูปทรงที่ต้องการระบายนั้นจะต้องเป็นรูปปิด ถ้าใครนึกภาพไม่ออกก็ลองนึกถึงโปรแกรม paint จะมีเครื่องมือเทสี(Fill) มีลักษณะเช่นเดียวกัน

scanline-floodfill-algorithm Flood fill Algorithm จะแบ่งออกเป็นหลายประเภทแต่ในบทความนี้ จะอธิบายถึง Scanline Flood fill Algorithm
หลักการทํางานของ Scanline Flood fill Algorithm คือ แสกนไปทีละ line ตามรูปตัวอย่าง

มาดูตัวอย่าง source code กันดีกว่าครับ
void floodFillScanlineStack(int x, int y, int newColor, int oldColor)
{
if(oldColor == newColor) return;
emptyStack();
int y1;
bool spanLeft, spanRight;
if(!push(x, y)) return;
while(pop(x, y))
{
y1 = y;
while(y1 >= 0 && screenBuffer[x][y1] == oldColor) y1--;
y1++;
spanLeft = spanRight = 0;
while(y1 < h && screenBuffer[x][y1] == oldColor )
{
screenBuffer[x][y1] = newColor;
if(!spanLeft && x > 0 && screenBuffer[x - 1][y1] == oldColor)
{
if(!push(x - 1, y1)) return;
spanLeft = 1;
}
else if(spanLeft && x > 0 && screenBuffer[x - 1][y1] != oldColor)
{
spanLeft = 0;
}
if(!spanRight && x < w - 1 && screenBuffer[x + 1][y1] == oldColor)
{
if(!push(x + 1, y1)) return;
spanRight = 1;
}
else if(spanRight && x < w - 1 && screenBuffer[x + 1][y1] != oldColor)
{
spanRight = 0;
}
y1++;
}
}
}
ตัวอย่างนี้จะเป็นการ scan ทางแนวตั้ง โดยจะใช้ Stack เข้ามาช่วย ลองทําความเข้าใจ source code ดูครับ
ข้อมูลจาก lodev.org
สวัสดีครับ ใน EP.4 เราได้เรียนรู้ Project structure file flutter กันไปแล้วนะครับ ในบทความนี้เราจะมาเรียนรู้การจัดการ State ใน Flutter ด้วย Provider กันครับ
สวัสดีครับ ในบทความนี้จะมีเนื้อหาเกี่ยวกับวิธีการใช้งาน DS18B20 (Digital Temperature Sensor) กับ Arduino กันนะครับ เพื่อเรียนรู้การใช้งาน Arduino กับ Digital Temperature Sensor ผ่าน 1-Wire Protocol
ก่อนอื่นมาดูกันว่า FTP คืออะไร FTP ย่อมาจาก File Transfer Protocol ซึ่งเป็น Protocol ที่ใช้ รับ-ส่ง ไฟล์ระหว่าง server และ client ส่วน SFTP ก็เหมือนกับ FTP แต่จะเพิ่มกระบวนการ SSL/TLS เพื่อให้มีความปลอดภัยมากยิ่งขึ้น