Skip to content

Instantly share code, notes, and snippets.

@DoctorGester
Created June 23, 2018 00:30
Show Gist options
  • Select an option

  • Save DoctorGester/533ebe6096beee1431ae5c572953c4d0 to your computer and use it in GitHub Desktop.

Select an option

Save DoctorGester/533ebe6096beee1431ae5c572953c4d0 to your computer and use it in GitHub Desktop.
static u32 color_name_to_color_argb(String &color_name) {
char c = *color_name.start;
switch (color_name.length) {
// Red
case 3: return 0xFFE91E63;
case 4: {
if (c == 'B'/*lue*/) return 0xFF2196F3; else
if (c == 'G'/*ray*/) return 0xFF9E9E9E;
break;
}
case 5: {
if (c == 'B'/*rown*/) return 0xFF795548; else
if (c == 'G'/*reen*/) return 0xFF8BC34A;
break;
}
case 6: {
if (c == 'Y'/*ellow*/) return 0xFFFFEB3B; else
if (c == 'P'/*urple*/) return 0xFF9C27B0; else
if (c == 'O'/*range*/) return 0xFFFF9800; else
if (c == 'I'/*ndigo*/) return 0xFF673AB7;
break;
}
case 8: {
c = *(color_name.start + 4);
if (c == /*Dark*/'B'/*lue*/) return 0xFF3F51B5; else
if (c == /*Dark*/'C'/*yan*/) return 0xFF009688;
break;
}
// Turquoise
case 9: return 0xFF00BCD4;
// YellowGreen
case 11: return 0xFFCDDC39;
}
printf("Got unknown color: %.*s\n", color_name.length, color_name.start);
return 0xFF000000;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment