Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <curses.h>
- typedef struct {
- int r;
- int g;
- int b;
- } RGB;
- RGB newRGB(int r, int g, int b)
- {
- RGB color;
- color.r = r;
- color.g = g;
- color.b = b;
- return color;
- }
- void calcColor(RGB* colors, int totalColors, int currentIndex, float saturation, float lightness);
- int main()
- {
- int totalColors = 60;
- RGB colors[totalColors];
- float saturation = 1.0;
- float lightness = 0.3;
- initscr(); // Initialize curses mode
- start_color(); // Initialize colors
- int end = totalColors - 18;
- int start = end - 42;
- for (int i = end; i >= start; i--) {
- calcColor(&colors[i], totalColors, i, saturation, lightness);
- // Convert RGB colors to curses default model
- int r = colors[i].r * 1000 / 255;
- int g = colors[i].g * 1000 / 255;
- int b = colors[i].b * 1000 / 255;
- // Set color in curses
- init_color(i, r, g, b);
- init_pair(i + 16, COLOR_BLACK, i + 16);
- // Print the color
- attron(COLOR_PAIR(i));
- printw(" ");
- attroff(COLOR_PAIR(i));
- }
- refresh(); // Update the screen
- getch(); // Wait for user input
- endwin(); // End curses mode
- return 0;
- }
- void calcColor(RGB* colors, int totalColors, int currentIndex, float saturation, float lightness)
- {
- float hue = currentIndex * (360.0 / totalColors);
- float chroma = (1 - fabs(2 * lightness - 1)) * saturation;
- float x = chroma * (1 - fabs(fmod(hue / 60, 2) - 1));
- float m = lightness - chroma / 2;
- float r, g, b;
- if (hue >= 0 && hue < 60) {
- r = chroma;
- g = x;
- b = 0;
- } else if (hue >= 60 && hue < 120) {
- r = x;
- g = chroma;
- b = 0;
- } else if (hue >= 120 && hue < 180) {
- r = 0;
- g = chroma;
- b = x;
- } else if (hue >= 180 && hue < 240) {
- r = 0;
- g = x;
- b = chroma;
- } else if (hue >= 240 && hue < 300) {
- r = x;
- g = 0;
- b = chroma;
- } else {
- r = chroma;
- g = 0;
- b = x;
- }
- colors->r = (r + m) * 255;
- colors->g = (g + m) * 255;
- colors->b = (b + m) * 255;
- }
Advertisement
Add Comment
Please, Sign In to add comment