-
Notifications
You must be signed in to change notification settings - Fork 0
/
printing.c
88 lines (79 loc) · 2.24 KB
/
printing.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* printing.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cgleason <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/08/03 13:58:24 by cgleason #+# #+# */
/* Updated: 2018/08/03 13:58:37 by cgleason ### ########.fr */
/* */
/* ************************************************************************** */
#include "swap_push.h"
void find_extrema(t_dblstck *stck, long *min, long *max)
{
t_dblstck *start;
start = stck;
*min = (long)stck->num;
*max = (long)stck->num;
stck = stck->next;
while (stck != start)
{
if ((long)stck->num < *min)
*min = (long)stck->num;
if ((long)stck->num > *max)
*max = (long)stck->num;
stck = stck->next;
}
}
int color_of(t_dblstck *stck)
{
static long min;
static long max;
static t_bool cached;
if (!cached)
{
find_extrema(stck, &min, &max);
cached = wahr;
}
return (20 + (32 * (stck->num - min)) / (max - min + 1));
}
void print_line(t_dblstck **stck)
{
int color;
int width;
if (*stck != NULL)
{
color = color_of(*stck);
width = 2 * ((color - 20) / 2) + 2;
ft_printf("%*.i%{b}%*.i\033[0m%*.i\t", (32 - width) / 2, 0, color,
width, 0, (32 - width) / 2, 0);
cleanup();
*stck = (*stck)->next;
}
else
ft_printf("%32.i\t", 0);
}
void clear_and_print(t_dblstck *astck, t_dblstck *bstck)
{
t_dblstck *atop;
t_dblstck *btop;
usleep(10000);
ft_printf("\033[2J\033[;H\033[?25l\n\n");
atop = astck;
btop = bstck;
if (astck != NULL)
astck->prev->next = NULL;
if (bstck != NULL)
bstck->prev->next = NULL;
while (astck != NULL || bstck != NULL)
{
print_line(&astck);
print_line(&bstck);
ft_printf("\n");
}
if (atop != NULL)
atop->prev->next = atop;
if (btop != NULL)
btop->prev->next = btop;
}