图形的填充
2018-01-01 23:03
197 查看
搜索可能是最笨的图形填充方法了,简单写了一遍。
DFS为了防止爆栈手动扩了一下栈应该够用了,或者改 BFS 弄,其实都一样。
使用了EasyX图形库,对 EasyX 团队表示感谢
#include <bits/stdc++.h>
#include <graphics.h>
#include <conio.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
int dirx[] = { 1,-1,0,0 }, diry[] = { 0,0,-1,1 };
void boundyary_fill_by_dfs(int n, int m, int x, int y, int fcolor, int bcolor) {
putpixel(x, y, fcolor);
for (int i = 0; i < 4; i++) {
int nowx = x + dirx[i], nowy = y + diry[i];
if (nowx<0 || nowx>n || nowy<0 || nowy>m) continue;
int color = getpixel(nowx, nowy);
if (color == fcolor || color == bcolor) continue;
boundyary_fill_by_dfs(n, m, nowx, nowy, fcolor, bcolor);
}
}
int main() {
initgraph(640, 640);
circle(150, 150, 100);
boundyary_fill_by_dfs(640, 640, 150, 150, RED, WHITE);
system("pause");
}
DFS为了防止爆栈手动扩了一下栈应该够用了,或者改 BFS 弄,其实都一样。
使用了EasyX图形库,对 EasyX 团队表示感谢
#include <bits/stdc++.h>
#include <graphics.h>
#include <conio.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
int dirx[] = { 1,-1,0,0 }, diry[] = { 0,0,-1,1 };
void boundyary_fill_by_dfs(int n, int m, int x, int y, int fcolor, int bcolor) {
putpixel(x, y, fcolor);
for (int i = 0; i < 4; i++) {
int nowx = x + dirx[i], nowy = y + diry[i];
if (nowx<0 || nowx>n || nowy<0 || nowy>m) continue;
int color = getpixel(nowx, nowy);
if (color == fcolor || color == bcolor) continue;
boundyary_fill_by_dfs(n, m, nowx, nowy, fcolor, bcolor);
}
}
int main() {
initgraph(640, 640);
circle(150, 150, 100);
boundyary_fill_by_dfs(640, 640, 150, 150, RED, WHITE);
system("pause");
}
相关文章推荐
- <canvas>学习笔记——如何给图形填充颜色
- 实用画刷填充图形
- 计算机图形学-基本图素的生成算法和图形填充
- 封闭图形的填充问题研究
- 扫描线填充面域图形
- Android贝塞尔曲线实现填充不规则图形并随手指运动
- 详述canvas(三)—绘制图形/填充和渐变
- 初学Android,图形图像之使用Shader填充图像(三十三)
- 实用画刷填充图形
- Open gl 的不规则图形的4联通种子递归填充和扫描线种子递归填充算法实现
- Graphic 矢量图形的区域填充与缠绕规则
- OpenCV - 图形图像处理 - 形态学处理 1931 1 Opencv图像识别从零到精通(17)----开运算、闭运算、顶帽、黑帽、形态学梯度、形态学角点、细化、填充 作者:qq_208236
- IOS学习 绘图 UIBezierPath 绘基本图形、样式设置、渲染填充
- Stroking or Filling a Shape:画图或填充图形
- 实用画刷填充图形
- Bitmap BitmapData 基于现有图形来填充组件
- 关于图形填充的讨论
- GDI+绘制图形和画刷填充图形
- flex填充图形,渐变
- D3 笔记二:SVG、Canvas、画布、矩形、填充图形