/* hedra3.c (isu.c) - Don Yang (uguu.org) Preprocess 3: replace constants 12/04/00 */ #include int *vertex, vertex_cube[] = { 0, 3, 6, 3, 12, 3, 18, 3, 0, 9, 6, 9, 12, 9, 18, 9, 0,0}, vertex_octa[] = { 0, 6, 6, 6, 12, 6, 18, 6, 0,12, 0,24, 0,0}, vertex_tetra[] = { 0,12, 0, 4, 8, 4, 16, 4, 0,0}, *edge, edge_cross[] = {0,4, 2,6, 8,10, 0,0}, edge_cube[] = {0,2, 2,4, 4,6, 6,0, 8,10, 10,12, 12,14, 14,8, 0,8, 2,10, 4,12, 6,14, 0,0}, edge_octa[] = {0,8, 2,8, 4,8, 6,8, 0,10, 2,10, 4,10, 6,10, 0,2, 2,4, 4,6, 6,0, 0,0}, edge_tetra[] = {0,2, 0,4, 0,6, 2,4, 4,6, 6,2, 0,0}, i, j, width, height, scale, rotatex, rotatey; double conv, t, p, r, xi, yi, zi, xf, yf, zf, x[16], y[16], z[16]; char screen[256][256]; main(int argc, char **argv) { width = argc > 1 ? atoi(argv[1]) : 79; height = argc > 2 ? atoi(argv[2]) : 23; if( !(width < 20 || width > 256 || height < 20 || height > 256) ) { scale = (width > height ? height : width) / 2; srand(time(0)); rotatex = rand() % 24; rotatey = rand() % 24; conv = atan2(0, -1) / 12; for(i = 0; i < height; i++) for(j = 0; j < width; screen[i][j++] = 32); i = rand(); vertex = (i & 1) ? (i & 2) ? vertex_cube : vertex_tetra : vertex_octa; edge = (i & 1) ? (i & 2) ? edge_cube : edge_tetra : (i & 2) ? edge_octa : edge_cross; for(i = 0; vertex[i] + vertex[i + 1] > 0; i += 2) { x[i] = (r = sin(p = vertex[i + 1] * conv)) * cos(t = (vertex[i] + rotatey) * conv) * 1.5; z[i] = cos(p); y[i] = r * sin(t); r = rotatex * conv; t = cos(r) * y[i] - sin(r) * z[i]; z[i] = sin(r) * z[i] + cos(r) * y[i]; y[i] = t; } for(i = 0; (rotatex = edge[i]) - (rotatey = edge[i + 1]); i += 2) { xi = x[rotatex]; xf = x[rotatey]; yi = y[rotatex]; yf = y[rotatey]; zi = z[rotatex]; zf = z[rotatey]; for(j = 0; j < 128; j++) screen [ (int)((yi + j * (yf - yi) / 128) * scale + height / 2) ] [ (int)((xi + j * (xf - xi) / 128) * scale + width / 2) ] = (zi + j * (zf - zi) / 128) > 0 ? 120 : 46; } for(i = 0; i < height; i++) { for(j = 0; j < width; putchar(screen[i][j++])); putchar(10); } } }