对象头实例数据对齐填充_实例说明边界填充算法和像素填充平方

对象头实例数据对齐填充

什么是边界填充算法? (What are Boundary Fill Algorithms?)

Boundary fill is the algorithm used frequently in computer graphics to fill a desired color inside a closed polygon having the same boundary color for all of its sides.

边界填充是在计算机图形学中经常使用的算法,用于在其所有边都具有相同边界颜色的封闭多边形内填充所需颜色。

The most approached implementation of the algorithm is a stack-based recursive function.

该算法最接近的实现是基于堆栈的递归函数。

工作示例: (Working Example:)

The problem is pretty simple and usually follows these steps:

该问题非常简单,通常按照以下步骤操作:

  1. Take the position of the starting point and the boundary color.

    取起点的位置和边界颜色。
  2. Decide whether you want to go in 4 directions (N, S, W, E) or 8 directions (N, S, W, E, NW, NE, SW, SE).

    决定要沿4个方向(N,S,W,E)还是沿8个方向(N,S,W,E,NW,NE,SW,SE)走。
  3. Choose a fill color.

    选择一种填充颜色。
  4. Travel in those directions.

    朝那些方向旅行。
  5. If the pixel you land on is not the fill color or the boundary color, replace it with the fill color.

    如果您着陆的像素不是填充颜色或边界颜色,则将其替换为填充颜色。
  6. Repeat 4 and 5 until you've been everywhere within the boundaries.

    重复4和5,直到到达边界内的任何地方。

某些限制: (Certain Restrictions:)

  1. The boundary color should be the same for all the edges of the polygon.

    多边形的所有边缘的边界颜色应相同。
  2. The starting point should be within the polygon.

    起点应在多边形内。

代码段: (Code Snippet:)

void boundary_fill(int pos_x, int pos_y, int boundary_color, int fill_color)
{  
current_color= getpixel(pos_x,pos_y);  //get the color of the current pixel position
if( current_color!= boundary_color || currrent_color != fill_color) // if pixel not already filled or part of the boundary then
{    
 putpixel(pos_x,pos_y,fill_color);  //change the color for this pixel to the desired fill_color
 boundary_fill(pos_x + 1, pos_y,boundary_color,fill_color);  // perform same function for the east pixel
 boundary_fill(pos_x - 1, pos_y,boundary_color,fill_color);  // perform same function for the west pixel
 boundary_fill(pos_x, pos_y + 1,boundary_color,fill_color);  // perform same function for the north pixel
 boundary_fill(pos_x, pos_y - 1,boundary_color,fill_color);  // perform same function for the south pixel
}
}

From the given code you can see that for any pixel that you land on, you first check whether it can be changed to the fill_color and then you do so for its neighbors till all the pixels within the boundary have been checked.

从给定的代码中可以看到,对于您着陆的任何像素,首先要检查是否可以将其更改为fill_color,然后对其相邻像素进行更改,直到检查了边界内的所有像素为止。

Here's a video tutorial that will walk you through these in detail in about 10 minutes:

这是一个视频教程,将在大约10分钟的时间内详细指导您:

翻译自: https://www.freecodecamp.org/news/boundary-fill-algorithm-pixel-filling-squares/

对象头实例数据对齐填充

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值