#ifndef __RESISTOR_COLOUR__ #define __RESISTOR_COLOUR__ #include "ResistorColour.h" enum Code { BOLD = 1, UNDERLINE = 4, NEGATIVE = 7, CONCEAL = 8, STRIKE = 28, FG_BLACK = 30, FG_RED = 31, FG_GREEN = 32, FG_YELLOW = 33, FG_BLUE = 34, FG_MAGENTA = 35, FG_CYAN = 36, FG_WHITE = 37, FG_DEFAULT = 39, BG_BLACK = 40, BG_RED = 41, BG_GREEN = 42, BG_YELLOW = 43, BG_BLUE = 44, BG_MAGENTA = 45, BG_CYAN = 46, BG_WHITE = 47, BG_DEFAULT = 49, FG_LIGHT_BLACK = 90, FG_LIGHT_RED = 91, FG_LIGHT_GREEN = 92, FG_LIGHT_YELLOW = 93, FG_LIGHT_BLUE = 94, FG_LIGHT_MAGENTA = 95, FG_LIGHT_CYAN = 96, FG_LIGHT_WHITE = 97, BG_LIGHT_BLACK = 100, BG_LIGHT_RED = 101, BG_LIGHT_GREEN = 102, BG_LIGHT_YELLOW = 103, BG_LIGHT_BLUE = 104, BG_LIGHT_MAGENTA = 105, BG_LIGHT_CYAN = 106, BG_LIGHT_WHITE = 107, }; enum resistor_colours{ black = FG_LIGHT_BLACK, brown = FG_YELLOW, red = FG_RED, orange = FG_LIGHT_RED + (BG_YELLOW<<8), yellow = FG_LIGHT_YELLOW, green = FG_GREEN, blue = FG_LIGHT_BLUE, violet = FG_MAGENTA + (BG_BLUE<<8), grey = FG_WHITE, white = FG_LIGHT_WHITE, gold = FG_LIGHT_YELLOW + (BG_LIGHT_WHITE<<8), silver = FG_WHITE + (BG_LIGHT_WHITE<<8) }; ResistorColour::ResistorColour(double r){ resistance = r; } std::string ResistorColour::GetColouredBlock(int c) { std::string ss; if( c < 128){ ss="\033["+std::to_string(c)+"m"+"█"+"\033["+std::to_string(FG_DEFAULT)+"m"; } else { int c1 = c % 128; int c2 = c>>8; ss="\033["+std::to_string(c1)+"m"+"\033["+std::to_string(c2)+"m"+"▒"+"\033["+std::to_string(BG_DEFAULT)+"m"+"\033["+std::to_string(FG_DEFAULT)+"m"; } return ss; } std::string ResistorColour::GetDigit(int digit) { if(digit < 0 || digit > 9) return "?"; int digits[] = {black, brown, red, orange, yellow, green, blue, violet, grey, white}; return GetColouredBlock(digits[digit]); } std::string ResistorColour::GetExponent(int exponent) { if(exponent < -2 || exponent > 7) return "?"; int exponents[] = {silver, gold, black, brown, red, orange, yellow, green, blue, violet, grey}; return GetColouredBlock(exponents[exponent+2]); } void ResistorColour::PaintCode(){ if(resistance<0){ std::cerr<<"There is no resistor of these resistance and tolerance."<=0 && res<10){ std::cout<=10 && res<100){ int second = res%10; int first = (res-second)/10; std::cout<=100 && res<1000){ double tmp = (double)res/10.0; res = round(tmp); int second = res%10; int first = (res-second)/10; std::cout<=1000 && res<10000){ double tmp = (double)res/100.0; res = round(tmp); int second = res%10; int first = (res-second)/10; std::cout<=10000 && res<100000){ double tmp = (double)res/1000.0; res = round(tmp); int second = res%10; int first = (res-second)/10; std::cout<=100000 && res<1000000){ double tmp = (double)res/10000.0; res = round(tmp); int second = res%10; int first = (res-second)/10; std::cout<=1000000 && res<10000000){ double tmp = (double)res/100000.0; res = round(tmp); int second = res%10; int first = (res-second)/10; std::cout<=10000000 && res<100000000){ double tmp = (double)res/1000000.0; res = round(tmp); int second = res%10; int first = (res-second)/10; std::cout<=100000000 && res<1000000000){ double tmp = (double)res/10000000.0; res = round(tmp); int second = res%10; int first = (res-second)/10; std::cout<