MiniDevil As beautiful as a shell
welcome_demon.c
Go to the documentation of this file.
1 /* ************************************************************************** */
2 /* */
3 /* ::: :::::::: */
4 /* welcome_demon.c :+: :+: :+: */
5 /* +:+ +:+ +:+ */
6 /* By: baelgadi <baelgadi@student.42.fr> +#+ +:+ +#+ */
7 /* +#+#+#+#+#+ +#+ */
8 /* Created: 2026/02/18 17:04:37 by zotaj-di #+# #+# */
9 /* Updated: 2026/03/04 03:56:35 by baelgadi ### ########.fr */
10 /* */
11 /* ************************************************************************** */
12 
13 #include "welcome_ui.h"
14 
21 const char *get_demon_art_line(int line)
22 {
23  static const char *demon_art[] = {
24  " ,-.",
25  " ___,---.__ /'|`\\ __,---,___",
26  " ,-' \\` `-.____,-' | `-.____,-' // `-.",
27  " ,' | ~'\\ /`~ | `.",
28  " / ___// `. ,' , , \\___ \\",
29  "| ,-' `-.__ _ | , __,-' `-. |",
30  "| / /\\_ ` . | , _/\\ \\ |",
31  "\\ | \\ \\`-.___ \\ | / ___,-'/ / | /",
32  " \\ \\ | `._ `\\\\ | //' _,' | / /",
33  " `-.\\ /' _ `---'' , . ``---' _ `\\ /,-'",
34  " `` / \\ ,='/ \\`=. / \\ ''",
35  " |__ /|\\_,--.,-.--,--._/|\\ __|",
36  " / `./ \\\\`\\ | | | /,//' \\,' \\",
37  " / / ||--+--|--+-/-| \\ \\",
38  " | | /'\\_\\_\\ | /_/_/`\\ | |",
39  " `-._,-' `-._______,-' `-._,-'"
40  };
41 
42  if (line < 0 || line >= DEMON_LINES)
43  return (NULL);
44  return (demon_art[line]);
45 }
46 
55 static const char *get_demon_color(int line)
56 {
57  if (line < 3)
58  return (C_AURA5);
59  if (line < 6)
60  return (C_AURA4);
61  if (line < 9)
62  return (C_AURA3);
63  if (line < 12)
64  return (C_AURA2);
65  return (C_AURA1);
66 }
67 
77 static void print_demon_line(t_welcome_term *t, int line, int row)
78 {
79  int col;
80  const char *color;
81  const char *art_line;
82 
83  art_line = get_demon_art_line(line);
84  if (!art_line)
85  return ;
86  color = get_demon_color(line);
87  col = (t->width - DEMON_WIDTH) / 2;
88  if (col < 1)
89  col = 1;
90  print_at_pos(row, col, color);
91  ft_printf("%s%s", art_line, RESET);
92 }
93 
100 {
101  int start_row;
102  int i;
103 
104  start_row = t->center_y - 4;
105  i = -1;
106  while (++i < DEMON_LINES)
107  {
108  print_demon_line(t, i, start_row + i);
109  ft_msleep(100);
110  }
111 }
112 
119 {
120  int row;
121  int col;
122 
123  row = t->center_y - 4 + 8;
124  col = (t->width - DEMON_WIDTH) / 2 + 22;
125  print_at_pos(row, col, C_M1 BOLD "_" RESET);
126  print_at_pos(row, col + 13, C_M1 BOLD "_" RESET);
127  ft_msleep(100);
128  print_at_pos(row, col, C_M5 BOLD "*" RESET);
129  print_at_pos(row, col + 13, C_M5 BOLD "*" RESET);
130  ft_msleep(150);
131  print_at_pos(row, col, C_M1 BOLD "_" RESET);
132  print_at_pos(row, col + 13, C_M1 BOLD "_" RESET);
133 }
#define BOLD
Definition: minishell_ui.h:38
#define RESET
Definition: minishell_ui.h:37
Extended terminal info (for welcome screen pos)
Definition: welcome_ui.h:49
int width
Terminal width.
Definition: welcome_ui.h:50
int center_y
Vertical center row.
Definition: welcome_ui.h:53
void flash_demon_eyes(t_welcome_term *t)
Animate the demon's eyes blinking.
static const char * get_demon_color(int line)
Map a Demon art row to its gradient color string.
Definition: welcome_demon.c:55
static void print_demon_line(t_welcome_term *t, int line, int row)
Print 1 demon art line at the correct terminal position, with color.
Definition: welcome_demon.c:77
const char * get_demon_art_line(int line)
Return 1 line of the ASCII Demon art by index.
Definition: welcome_demon.c:21
void animate_demon(t_welcome_term *t)
Animate the Demon art with 100ms delay.
Definition: welcome_demon.c:99
Welcome screen structures & prototypes.
#define C_AURA5
Definition: welcome_ui.h:32
#define C_AURA4
Definition: welcome_ui.h:31
#define DEMON_WIDTH
Definition: welcome_ui.h:60
#define C_AURA1
Definition: welcome_ui.h:28
#define DEMON_LINES
Definition: welcome_ui.h:62
#define C_M5
Definition: welcome_ui.h:39
#define C_AURA3
Definition: welcome_ui.h:30
#define C_AURA2
Definition: welcome_ui.h:29
#define C_M1
Definition: welcome_ui.h:35
void ft_msleep(int ms)
Sleep for approximately ms millisecondes using a little trick.
Definition: welcome_utils.c:28
void print_at_pos(int row, int col, const char *str)
Move the terminal cursor to [row, col] and print str.
Definition: welcome_utils.c:77