2.5D打印机
2025-08-04 20:39:51
发布于:浙江
2.5D打印机
- 效果:将输入的3D模型打印在2D屏幕上
- 使用:先输入三个数表示长宽高,接着(从下层往上层)分别输入每层的俯视图,1表示有方块,0表示无方块(程序的最后有一组样例输入)
- 说明:自己花一天写的,仅供娱乐(doge
#include <bits/stdc++.h>
using namespace std;
int dir[3][5] = {1,0,0,0,5,0,1,0,2,-2,0,0,1,-3,0};
char block[6][8] = {'.','.','+','-','-','-','-','+',
'.','/',' ',' ',' ',' ','/','|',
'+','-','-','-','-','+',' ','|',
'|',' ',' ',' ',' ','|',' ','+',
'|',' ',' ',' ',' ','|','/','.',
'+','-','-','-','-','+','.','.'};
int A,B,C,n,m;
char graph[1005][1005];
bool mp[105][105][105],vis[105][105][105];
bool in(int a,int b,int c) {
return a <= A && b <= B && c <= C;
}
void draw(int sx,int sy) {
for(int x = sx;x <= sx + 5;x++) {
for(int y = sy;y <= sy + 7;y++) {
int bx = x - sx,by = y - sy;
if(block[bx][by] == '.') continue;
graph[x][y] = block[bx][by];
}
}
}
void create() {
int sx,sy;
n = 2 * B + 3 * C + 1,m = 5 * A + 2 * B + 1;
sx = 3 * C - 2,sy = 2 * B - 1;
queue<array<int,5>> q;
q.push({1,1,1,sx,sy});
vis[1][1][1] = 1;
while(!q.empty()) {
auto now = q.front();
q.pop();
if(mp[now[0]][now[1]][now[2]]) draw(now[3],now[4]);
for(int d = 0;d < 3;d++) {
int na = now[0] + dir[d][0];
int nb = now[1] + dir[d][1];
int nc = now[2] + dir[d][2];
if(in(na,nb,nc) && !vis[na][nb][nc]) {
vis[na][nb][nc] = 1;
q.push({na,nb,nc,now[3] + dir[d][3],now[4] + dir[d][4]});
}
}
}
}
int main() {
cin >> A >> B >> C;
for(int c = 1;c <= C;c++) {
for(int b = 1;b <= B;b++) {
for(int a = 1;a <= A;a++) {
cin >> mp[a][b][c];
}
}
}
create();
for(int x = 1;x <= n;x++) {
for(int y = 1;y <= m;y++) {
cout << graph[x][y];
}
cout << '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