created animated cow

This commit is contained in:
2026-04-22 13:57:49 +02:00
parent ae219bbff4
commit 6620de21ad
3 changed files with 105 additions and 4 deletions

View File

@@ -36,11 +36,11 @@
## 4. C Programming ## 4. C Programming
- [ ] **`newcow.c`** - [x] **`newcow.c`**
- [ ] Create `affiche_vache` function: displays a cow without a speech bubble. - [x] Create `affiche_vache` function: displays a cow without a speech bubble.
- [ ] Compile and run. - [x] Compile and run.
- [ ] **Add Features** - [ ] **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. - [ ] Implement other options from `cowsay` manpage.
- [ ] **New Feature** - [ ] **New Feature**
- [ ] Implement a new feature (e.g., `--tail L` to adjust tail length, or display a herd). - [ ] Implement a new feature (e.g., `--tail L` to adjust tail length, or display a herd).

BIN
aaa Executable file

Binary file not shown.

101
src/C/newcow2.c Normal file
View File

@@ -0,0 +1,101 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
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;
}