void TankGame::clear_picture() { int cirX = wide / 2; int cirY = high / 2; int depth = cirY > cirX ? cirY + 2 : cirX + 2; int lx, rx, uy, by; int l, r, u, b; for (int i = 0; i != depth; i++) { lx = cirX - i; rx = cirX + i; uy = cirY - i; by = cirY + i; uy <= 0 ? u = 1 : u = uy; by >= high - 1 ? b = high - 2 : b = by; lx <= 0 ? l = 1 : l = lx; rx >= wide -1 ? r = wide - 2 : r = rx; if (rx < wide - 1) { for (int k = u; k <= b; k++) grid(rx, k, " "); } if (lx > 0) { for (int k = u; k <= b; k++) grid(lx, k, " "); } if (by < high - 1) { for (int k = l; k <= r; k++) grid(k, by, " "); } if (uy > 0) { for (int k = l; k <= r; k++) grid(k, uy, " "); } } }
时间: 2024-04-02 19:37:00 浏览: 100
Android中使用Canvas绘制南丁格尔玫瑰图(Nightingale rose diagram)
这段代码是 C++ 语言编写的,实现了一个清空屏幕的函数。函数内部的代码逻辑包括:
1. 根据屏幕的宽度和高度计算出一个圆心坐标,以及圆的半径 depth;
2. 遍历从 0 到 depth 的整数 i,计算出每个圆环的左右上下边界;
3. 对于每个圆环,分别判断其四个边界是否在屏幕内,如果在,就在该边界上输出两个空格字符;
4. 最终会清空整个屏幕。
阅读全文