From 9f14581beacb1bd33cb5245ab91c33d33d24d7d5 Mon Sep 17 00:00:00 2001 From: Franciszek Malinka Date: Sun, 24 Apr 2022 02:59:19 +0200 Subject: Display cube colors --- cube.c | 62 +++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/cube.c b/cube.c index 1f57299..ef34359 100644 --- a/cube.c +++ b/cube.c @@ -32,7 +32,8 @@ typedef enum { GREEN = 2, RED = 3, BLUE = 4, - YELLOW = 5 + YELLOW = 5, + EMPTY_COLOR = 6 } colors; typedef struct { @@ -70,7 +71,7 @@ static inline face_t ror(face_t x, face_t y) { } #define DEFINE_ROTATION(rotation, face, len, f0, M0, f1, M1, f2, M2, f3, M3, C0, C1, C2, C3) \ -static inline void rotation_ ## rotation (cube_t *cube) { \ +static void rotation_ ## rotation (cube_t *cube) { \ ABSTRACT_ROTATION(*cube, face, len, f0, M0, f1, M1, f2, M2, f3, M3, C0, C1, C2, C3); \ } @@ -87,34 +88,43 @@ static void init_cube(cube_t *cube) { } static const char letters[] = { 'W', 'O', 'G', 'R', 'B', 'Y' }; - -static char get_tile(face_t face, int tile) { - uint8_t color = face >> (tile * sizeof(face_t)) & ((1<> (tile * sizeof(face_t)) & ((1<faces[face], buf); - buf[1][1] = letters[face]; + buf[1][1] = (colors)face; } static void dump_cube_grid(cube_t *cube) { int i, j, row, col; - char buf[3][4][3][3]; /* XD */ + colors buf[3][4][3][3]; /* XD */ - memset(buf, ' ', 3*4*3*3); + memset(buf, -1, 3*4*3*3*sizeof(colors)); fill_face(cube, UP, buf[0][1]); fill_face(cube, LEFT, buf[1][0]); fill_face(cube, FRONT, buf[1][1]); @@ -126,7 +136,8 @@ static void dump_cube_grid(cube_t *cube) { for (row = 0; row < 3; row++) { for (j = 0; j < 4; j++) { for (col = 0; col < 3; col++) { - printf("%c", buf[i][j][row][col]); + colors color = buf[i][j][row][col]; + printf("%s", (color == -1 ? " " : terminal_letters[color])); } } printf("\n"); @@ -136,11 +147,12 @@ static void dump_cube_grid(cube_t *cube) { int main() { cube_t cube; + int i; init_cube(&cube); - dump_cube_grid(&cube); - rotation_r(&cube); - rotation_u(&cube); - rotation_r(&cube); - rotation_u(&cube); + + for (i = 0; i < 3; i++) { + rotation_r(&cube); + rotation_u(&cube); + } dump_cube_grid(&cube); } -- cgit v1.2.3