diff --git a/TODO.md b/TODO.md index 96306fd..d56ac10 100644 --- a/TODO.md +++ b/TODO.md @@ -36,11 +36,11 @@ ## 4. C Programming -- [ ] **`newcow.c`** - - [ ] Create `affiche_vache` function: displays a cow without a speech bubble. - - [ ] Compile and run. +- [x] **`newcow.c`** + - [x] Create `affiche_vache` function: displays a cow without a speech bubble. + - [x] Compile and run. - [ ] **Add Features** - - [ ] Support `-e`/ `--eyes` option to change cow's eyes. + - [x] Support `-e`/ `--eyes` option to change cow's eyes. - [ ] Implement other options from `cowsay` manpage. - [ ] **New Feature** - [ ] Implement a new feature (e.g., `--tail L` to adjust tail length, or display a herd). diff --git a/aaa b/aaa new file mode 100755 index 0000000..6997b44 Binary files /dev/null and b/aaa differ diff --git a/src/C/newcow2.c b/src/C/newcow2.c new file mode 100644 index 0000000..63c8d93 --- /dev/null +++ b/src/C/newcow2.c @@ -0,0 +1,101 @@ +#include +#include +#include +#include + +void update() { printf("\033[H\033[J"); } + +void gotoxy(int x, int y) { printf("\033[%d;%dH", y, x); } + +void affiche_vache(int x, int y, const char *yeux, const char *langue) { + gotoxy(x, y); + printf(" \\ ^__^\n"); + + gotoxy(x, y + 1); + printf(" \\ (%s)\\_______\n", yeux); + + gotoxy(x, y + 2); + printf(" (__)\\ )\\/\\\\\n"); + + gotoxy(x, y + 3); + printf(" %s ||----w |\n", langue); + + gotoxy(x, y + 4); + printf(" || ||\n"); + + fflush(stdout); +} + +void animation_blink() { + for (int i = 0; i < 12; i++) { + update(); + if (i % 4 == 0) + affiche_vache(5, 3, "--", " "); + else + affiche_vache(5, 3, "oo", " "); + usleep(250000); + } +} + +void animation_tongue() { + for (int i = 0; i < 12; i++) { + update(); + if (i % 2 == 0) + affiche_vache(5, 3, "oo", "U "); + else + affiche_vache(5, 3, "oo", " "); + usleep(250000); + } +} + +void animation_walk() { + for (int x = 1; x <= 40; x += 2) { + update(); + if ((x / 2) % 2 == 0) + affiche_vache(x, 3, "oo", " "); + else + affiche_vache(x, 3, "OO", " "); + usleep(120000); + } +} + +void animation_bounce() { + int x = 20; + for (int i = 0; i < 18; i++) { + update(); + int y; + if (i % 4 == 0 || i % 4 == 2) + y = 3; + else + y = 2; + affiche_vache(x, y, "oo", " "); + usleep(180000); + } +} + +void usage(char *prog) { + printf("Usage : %s [blink|tongue|walk|bounce]\n", prog); +} + +int main(int argc, char *argv[]) { + if (argc != 2) { + usage(argv[0]); + return 1; + } + + if (strcmp(argv[1], "blink") == 0) { + animation_blink(); + } else if (strcmp(argv[1], "tongue") == 0) { + animation_tongue(); + } else if (strcmp(argv[1], "walk") == 0) { + animation_walk(); + } else if (strcmp(argv[1], "bounce") == 0) { + animation_bounce(); + } else { + usage(argv[0]); + return 1; + } + + gotoxy(1, 10); + return 0; +}