created draw function to reduce string section size

This commit is contained in:
Valerie Wolfe 2024-03-22 23:52:46 -04:00
parent 7157c681ea
commit 5e69b344f8
9 changed files with 171 additions and 133 deletions

119
basic.c
View file

@ -2,79 +2,94 @@
#include <stdio.h>
#include "draw.h"
void rainbow_8() {
printf(
RED STRIPE
L_RED STRIPE
L_YELLOW STRIPE
GREEN STRIPE
BLUE STRIPE
MAGENTA STRIPE
);
color colors [] = {
RED,
L_RED,
L_YELLOW,
GREEN,
BLUE,
MAGENTA
};
draw(6, colors);
}
void aroace_8() {
printf(
YELLOW STRIPE
L_YELLOW STRIPE
WHITE STRIPE
L_CYAN STRIPE
BLUE STRIPE
);
color colors [] = {
YELLOW,
L_YELLOW,
WHITE,
L_CYAN,
BLUE
};
draw(5, colors);
}
void bisexual_8() {
printf(
RED STRIPE STRIPE
MAGENTA STRIPE
BLUE STRIPE STRIPE
);
color colors [] = {
RED,
RED,
MAGENTA,
BLUE,
BLUE
};
draw(5, colors);
}
void gay_8() {
printf(
CYAN STRIPE
L_CYAN STRIPE
WHITE STRIPE
L_BLUE STRIPE
BLUE STRIPE
);
color colors [] = {
CYAN,
L_CYAN,
WHITE,
L_BLUE,
BLUE
};
draw(5, colors);
}
void lesbian_8() {
printf(
RED STRIPE
L_RED STRIPE
WHITE STRIPE
L_MAGENTA STRIPE
MAGENTA STRIPE
);
color colors [] = {
RED,
L_RED,
WHITE,
L_MAGENTA,
MAGENTA
};
draw(5, colors);
}
void nonbinary_8() {
printf(
L_YELLOW STRIPE
WHITE STRIPE
MAGENTA STRIPE
BLACK STRIPE
);
color colors [] = {
L_YELLOW,
WHITE,
MAGENTA,
BLACK
};
draw(4, colors);
}
void pansexual_8() {
printf(
MAGENTA STRIPE STRIPE
L_YELLOW STRIPE STRIPE
CYAN STRIPE STRIPE
);
color colors [] = {
MAGENTA,
MAGENTA,
L_YELLOW,
L_YELLOW,
CYAN,
CYAN
};
draw(6, colors);
}
void transgender_8() {
printf(
L_CYAN STRIPE
L_MAGENTA STRIPE
WHITE STRIPE
L_MAGENTA STRIPE
L_CYAN STRIPE
);
color colors [] = {
L_CYAN,
L_MAGENTA,
WHITE,
L_MAGENTA,
L_CYAN
};
draw(5, colors);
}

34
basic.h
View file

@ -1,23 +1,21 @@
#pragma once
#include "color.h"
#define BLACK COLOR(0)
#define RED COLOR(1)
#define GREEN COLOR(2)
#define YELLOW COLOR(3)
#define BLUE COLOR(4)
#define MAGENTA COLOR(5)
#define CYAN COLOR(6)
#define GRAY COLOR(7)
#define L_BLACK COLOR(8)
#define L_RED COLOR(9)
#define L_GREEN COLOR(10)
#define L_YELLOW COLOR(11)
#define L_BLUE COLOR(12)
#define L_MAGENTA COLOR(13)
#define L_CYAN COLOR(14)
#define WHITE COLOR(15)
#define BLACK 0
#define RED 1
#define GREEN 2
#define YELLOW 3
#define BLUE 4
#define MAGENTA 5
#define CYAN 6
#define GRAY 7
#define L_BLACK 8
#define L_RED 9
#define L_GREEN 10
#define L_YELLOW 11
#define L_BLUE 12
#define L_MAGENTA 13
#define L_CYAN 14
#define WHITE 15
void rainbow_8();
void aroace_8();

View file

@ -1,5 +0,0 @@
#pragma once
#define COLOR(n) "\x1b[38;5;" #n "m"
#define STRIPE "██████████████████\n"

10
draw.c Normal file
View file

@ -0,0 +1,10 @@
#include "draw.h"
#include <stdio.h>
void draw(unsigned short int len, color colors []) {
for(int i = 0; i < len; i++) {
printf(ANSI "%dm" STRIPE, colors[i]);
}
}

10
draw.h Normal file
View file

@ -0,0 +1,10 @@
#pragma once
#define ANSI "\x1b[38;5;"
#define COLOR(n) ANSI #n "m"
#define STRIPE "██████████████████\n"
typedef unsigned short int color;
void draw(unsigned short int len, color colors[]);

120
full.c
View file

@ -2,83 +2,93 @@
#include <stdio.h>
#include "color.h"
#include "draw.h"
void rainbow_256() {
printf(
COLOR(196) STRIPE // red
COLOR(208) STRIPE // orange
COLOR(220) STRIPE // yellow
COLOR(28) STRIPE // green
COLOR(21) STRIPE // blue
COLOR(90) STRIPE // purple
);
color colors [] = {
196, // red
208, // orange
220, // yellow
28, // green
21, // blue
90 // purple
};
draw(6, colors);
}
void aroace_256() {
printf(
COLOR(172) STRIPE
COLOR(184) STRIPE
COLOR(255) STRIPE
COLOR(38) STRIPE
COLOR(17) STRIPE
);
color colors [] = {
172, // orange
184, // yellow
255, // white
38, // blue
17 // navy
};
draw(5, colors);
}
void bisexual_256() {
printf(
COLOR(161) STRIPE STRIPE
COLOR(91) STRIPE
COLOR(21) STRIPE STRIPE
);
color colors [] = {
161, // magenta
161,
91, // purple
21,
21 // blue
};
draw(5, colors);
}
void gay_256() {
printf(
COLOR(29) STRIPE
COLOR(49) STRIPE
COLOR(123) STRIPE
COLOR(255) STRIPE
COLOR(75) STRIPE
COLOR(63) STRIPE
COLOR(56) STRIPE
);
color colors [] = {
29,
49, // greens
123,
255, // white
75,
63, // blues
56
};
draw(7, colors);
}
void lesbian_256() {
printf(
COLOR(202) STRIPE
COLOR(209) STRIPE
COLOR(255) STRIPE
COLOR(134) STRIPE
COLOR(161) STRIPE
);
color colors [] = {
202, // orange
209, // tangerine
255, // white
134, // pink
161 // magenta
};
draw(5, colors);
}
void nonbinary_256() {
printf(
COLOR(226) STRIPE
COLOR(255) STRIPE
COLOR(134) STRIPE
COLOR(16) STRIPE
);
color colors [] = {
226, // yellow
255, // white
134, // purple
16 // black
};
draw(4, colors);
}
void pansexual_256() {
printf(
COLOR(161) STRIPE STRIPE
COLOR(220) STRIPE STRIPE
COLOR(45) STRIPE STRIPE
);
color colors [] = {
161, 161, // magenta
220, 220, // yellow
45, 45 // cyan
};
draw(6, colors);
}
void transgender_256() {
printf(
COLOR(45) STRIPE
COLOR(117) STRIPE
COLOR(255) STRIPE
COLOR(117) STRIPE
COLOR(45) STRIPE
);
color colors [] = {
45, // blue
117, // pink
255, // white
117, // pink
45 // blue
};
draw(5, colors);
}

2
full.h
View file

@ -1,6 +1,6 @@
#pragma once
#include "color.h"
#include "draw.h"
void rainbow_256();
void aroace_256();

View file

@ -1,4 +1,4 @@
build:
gcc main.c basic.c full.c -o pride-c
gcc main.c draw.c basic.c full.c -o pride-c

2
main.c
View file

@ -1,7 +1,7 @@
#include <stdio.h>
#include <string.h>
#include "color.h"
#include "draw.h"
#include "basic.h"
#include "full.h"