From b90d0a91117508314dcc19f227ffe731ebd0de75 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Fri, 4 Jan 2019 12:55:29 -0500 Subject: Clean up scheme --- bin/scheme.c | 62 ++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 29 deletions(-) (limited to 'bin') diff --git a/bin/scheme.c b/bin/scheme.c index 95123508..c766d94c 100644 --- a/bin/scheme.c +++ b/bin/scheme.c @@ -27,7 +27,11 @@ typedef unsigned uint; typedef unsigned char byte; -static const struct HSV { double h, s, v; } +struct HSV { + double h, s, v; +}; + +static const struct HSV R = { 0.0, 1.0, 1.0 }, Y = { 60.0, 1.0, 1.0 }, G = { 120.0, 1.0, 1.0 }, @@ -35,7 +39,11 @@ static const struct HSV { double h, s, v; } B = { 240.0, 1.0, 1.0 }, M = { 300.0, 1.0, 1.0 }; -static struct RGB { byte r, g, b; } toRGB(struct HSV hsv) { +struct RGB { + byte r, g, b; +}; + +static struct RGB rgb(struct HSV hsv) { double c = hsv.v * hsv.s; double h = hsv.h / 60.0; double x = c * (1.0 - fabs(fmod(h, 2.0) - 1.0)); @@ -59,21 +67,9 @@ static struct HSV x(struct HSV o, double hd, double sf, double vf) { } enum { - Black, - Red, - Green, - Yellow, - Blue, - Magenta, - Cyan, - White, - Dark = 0, - Light = 8, - Background = 16, - Foreground, - Bold, - Selection, - Cursor, + Black, Red, Green, Yellow, Blue, Magenta, Cyan, White, + Dark = 0, Light = 8, + Background = 16, Foreground, Bold, Selection, Cursor, SchemeLen, }; static struct HSV scheme[SchemeLen]; @@ -117,8 +113,10 @@ static void printHSV(uint n) { } static void printRGB(uint n) { - struct RGB rgb = toRGB(scheme[n]); - printf("%02hhX%02hhX%02hhX\n", rgb.r, rgb.g, rgb.b); + printf( + "%02hhX%02hhX%02hhX\n", + rgb(scheme[n]).r, rgb(scheme[n]).g, rgb(scheme[n]).b + ); } static const char *CNames[SchemeLen] = { @@ -148,16 +146,20 @@ static void printCHead(void) { printf("enum {\n"); } static void printC(uint n) { - struct RGB rgb = toRGB(scheme[n]); - printf("\t%s = 0x%02hhX%02hhX%02hhX,\n", CNames[n], rgb.r, rgb.g, rgb.b); + printf( + "\t%s = 0x%02hhX%02hhX%02hhX,\n", + CNames[n], rgb(scheme[n]).r, rgb(scheme[n]).g, rgb(scheme[n]).b + ); } static void printCTail(void) { printf("};\n"); } static void printLinux(uint n) { - struct RGB rgb = toRGB(scheme[n]); - printf("\x1B]P%X%02hhX%02hhX%02hhX", n, rgb.r, rgb.g, rgb.b); + printf( + "\x1B]P%X%02hhX%02hhX%02hhX", + n, rgb(scheme[n]).r, rgb(scheme[n]).g, rgb(scheme[n]).b + ); } static const char *MinttyNames[SchemeLen] = { @@ -183,8 +185,10 @@ static const char *MinttyNames[SchemeLen] = { }; static void printMintty(uint n) { if (!MinttyNames[n]) return; - struct RGB rgb = toRGB(scheme[n]); - printf("%s=%hhd,%hhd,%hhd\n", MinttyNames[n], rgb.r, rgb.g, rgb.b); + printf( + "%s=%hhu,%hhu,%hhu\n", + MinttyNames[n], rgb(scheme[n]).r, rgb(scheme[n]).g, rgb(scheme[n]).b + ); } static void png(uint at, uint to) { @@ -200,11 +204,11 @@ static void png(uint at, uint to) { pngHead(stdout, width, height, 8, PNGIndexed); - struct RGB rgb[len]; + struct RGB pal[len]; for (uint i = 0; i < len; ++i) { - rgb[i] = toRGB(scheme[at + i]); + pal[i] = rgb(scheme[at + i]); } - pngPalette(stdout, (byte *)rgb, sizeof(rgb)); + pngPalette(stdout, (byte *)pal, sizeof(pal)); uint8_t data[height][1 + width]; memset(data, 0, sizeof(data)); @@ -222,7 +226,7 @@ static void png(uint at, uint to) { pngTail(stdout); } -static void print(void (*fn)(uint), uint at, uint to) { +static void print(void fn(uint), uint at, uint to) { for (uint i = at; i < to; ++i) { fn(i); } -- cgit 1.4.1 06:09 -0400'>2019-07-01Use env.sh as 1sh todo listJune McEnroe 2019-06-29Clean up 1sh prompt settingJune McEnroe 2019-06-29Add Parable of the TalentsJune McEnroe 2019-06-28Rename catsh to 1shJune McEnroe Yes it's another rename because I felt like catsh was too long. 1sh is short and unique. 2019-06-28Set HISTSIZE in catshJune McEnroe 2019-06-28Unset iflag when exiting catshJune McEnroe It saves history! It's usable! 2019-06-24Consolidate catsh history documentationJune McEnroe 2019-06-19Set LESS=FRXJune McEnroe This is how git invokes less by default. I think I want this everywhere. This allows color, exits if the input fits on one screen, and doesn't clear the screen. 2019-06-16Alias date=ddateJune McEnroe Will I regret this? 2019-06-15Set sensitivity by slot in TF2June McEnroe 2019-06-15Add AcceptanceJune McEnroe 2019-06-07Add variables to bitJune McEnroe 2019-06-05Add A Closed and Common OrbitJune McEnroe 2019-06-02Add RebornJune McEnroe 2019-05-30Add bit to bin.7June McEnroe 2019-05-30Simplify and build bitJune McEnroe lex is a waste of time. 2019-05-29Add xx -p optionJune McEnroe 2019-05-27Add FrontierJune McEnroe 2019-05-27Break nicks with ZWNJJune McEnroe This should prevent bad wrapping. 2019-05-26Add DawnJune McEnroe 2019-05-20Declare vasprintf(3) for GNUJune McEnroe who the fuck is scraeming "#define _GNU_SOURCE" at my house. show yourself, coward. i will never #define _GNU_SOURCE 2019-05-20Fix comparison warning in ttpreJune McEnroe 2019-05-20Add AuthorityJune McEnroe 2019-05-19Specify precedence of unary versions of operatorsJune McEnroe 2019-05-18Add compound assignment operators to orderJune McEnroe 2019-05-15Support simple assignment in orderJune McEnroe 2019-05-15Implement sizeof in orderJune McEnroe 2019-05-15Add orderJune McEnroe 2019-05-12Add T suffix in bitJune McEnroe 2019-05-10Highlight yacc and lex files as CJune McEnroe Their %-prefixed directives should probably be highlighted Macro. 2019-05-10Use val instead of suboptargJune McEnroe suboptarg doesn't exist in GNU. Hopefully BSD getsubopt also sets val on failure? 2019-05-09Add Parable of the SowerJune McEnroe 2019-05-07Add bit without buildJune McEnroe Need to do some stuff in the Makefile for lex and yacc and generating HTML pages for it. 2019-05-04Fix MANDIR typoJune McEnroe 2019-05-04Move relay to binJune McEnroe