/* * [Palette.java] * * Summary: prepares HTML table of Netscape, X11 etc. palettes of Colors for display. * * Copyright: (c) 1998-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.4 2008-02-12 excess white space removed. * 1.5 2011-11-24 tidy up for release. Load palettes from CSV files, Configurable targetDir * 1.6 2014-07-01 add list of just 8 new HTML5 colours. */ package com.mindprod.palette; import com.mindprod.common18.BigDate; import com.mindprod.common18.EIO; import com.mindprod.common18.ST; import com.mindprod.csv.CSVReader; import com.mindprod.wavelength.Wavelength; import java.io.BufferedReader; import java.io.EOFException; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; import java.util.Map; import static java.lang.System.*; /** * prepares HTML table of Netscape, X11 etc. palettes of Colors for display. *

* Currently it exports 20 different html palettes/colour charts * 2 java snippets., an ASCII table. You can mix and match sets of colours, sorts * and degree of detail in the table. * * @author Roedy Green, Canadian Mind Products * @version 1.6 2014-07-01 add list of just 8 new HTML5 colours. * @see com.mindprod.entities.Entities * @see com.mindprod.repair.AnnotateColours * @see com.mindprod.repair.ExtractColours * @since 1998 */ public final class Palette { private static final int FIRST_COPYRIGHT_YEAR = 1998; @SuppressWarnings( { "UnusedDeclaration" } ) private static final String EMBEDDED_COPYRIGHT = "Copyright: (c) 1998-2017 Roedy Green, Canadian Mind Products, http://mindprod.com"; /** * when package was released. * * @noinspection UnusedDeclaration */ private static final String RELEASE_DATE = "2014-07-01"; /** * name of package. * * @noinspection UnusedDeclaration */ private static final String TITLE_STRING = "Palette"; /** * version of package. * * @noinspection UnusedDeclaration */ private static final String VERSION_STRING = "1.6"; /** * format as 099 */ private static final DecimalFormat THREE_DECIMAL_DIGITS = new DecimalFormat( "000" ); /** * format as 8.234 */ private static final DecimalFormat THREE_DECIMAL_PLACES = new DecimalFormat( "#0.000" ); /** * palette of dark colours. */ private static final NamedColor[] darks2022 = calculateDarks(); /** * palette of 256 greys256. */ private static final NamedColor[] greys256 = calculateGreys(); /** * mindprod.com colours, not supported by any browser */ private static final NamedColor[] mindprodPalette = loadPalette( "mindprodpalette.csv" ); /** * colours supported in HTML5new */ private static final NamedColor[] html5NewPalette8 = loadPalette( "html5newpalette.csv" ); /** * colours supported in HTML5 */ private static final NamedColor[] html5Palette140 = loadPalette( "html5palette.csv" ); /** * palette of offwhites. */ private static final NamedColor[] offWhites4096 = calculateOffWhites(); /** * palette of pales256. */ private static final NamedColor[] pales256 = calculatePales(); /** * palette of 4096 unnamed rainbow colours */ private static final NamedColor[] rainbows4096 = calculateRainbows(); /** * palette of simple colours. */ private static final NamedColor[] simples105 = calculateSimples(); /** * palette of 4096 unnamed spectrum colours */ private static final NamedColor[] spectrums4096 = calculateSpectrum(); /** * tiny palette of HTML 3.2 colours */ private static final NamedColor[] stdPalette16 = loadPalette( "stdpalette.csv" ); /** * palette of 125 websafe colours. */ private static final NamedColor[] webSafes216 = calculateWebSafes(); /** * colours supported in X11 */ private static final NamedColor[] x11Palette657 = loadPalette( "x11palette.csv" ); private static final String DO_NOT_EDIT = "\n"; /** * dir where we place generated html */ private static File dir; /** * Generate an array of dark colours. * * @return array of darks2022. */ private static NamedColor[] calculateDarks() { ArrayList darks = new ArrayList<>( 2022 ); // find dar colours for ( int r = 0; r <= 0xff; r += 0x11 ) { for ( int g = 0; g <= 0xff; g += 0x11 ) { for ( int b = 0; b <= 0xff; b += 0x11 ) { NamedColor n = new NamedColor( r, g, b, "" ); if ( n.getSaturation() > .29f && n.getBrightness() < .85f ) { darks.add( n ); } } } } // end for outer for return darks.toArray( new NamedColor[ darks.size() ] ); } /** * Generate an array of greys256 mathematically * * @return array of grays. */ private static NamedColor[] calculateGreys() { ArrayList greys = new ArrayList<>( 256 ); for ( int i = 0x0; i <= 0xffffff; i += 0x010101 ) { greys.add( new NamedColor( i, "" ) ); } return greys.toArray( new NamedColor[ greys.size() ] ); } /** * Generate an array of offwhite colours mathematically * * @return array of offwhites */ private static NamedColor[] calculateOffWhites() { ArrayList offWhites = new ArrayList<>( 4096 ); // find off white colours. Will be sorted later. // finer resolution closer we get to white. int[] select = { 0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, 0xf6, 0xf4, 0xf2, 0xf0, 0xec, 0xe8, 0xe4, 0xe0 }; for ( int rSelect : select ) { for ( int gSelect : select ) { for ( int bSelect : select ) { offWhites.add( new NamedColor( rSelect, gSelect, bSelect, "" ) ); } } } return offWhites.toArray( new NamedColor[ offWhites.size() ] ); } /** * Generate an array of pale colours mathematically * * @return array of pales256. */ private static NamedColor[] calculatePales() { ArrayList pales = new ArrayList<>( 256 ); // find pale colours for ( int r = 0; r <= 0xff; r += 0x11 ) { for ( int g = 0; g <= 0xff; g += 0x11 ) { for ( int b = 0; b <= 0xff; b += 0x11 ) { int points = 0; if ( r >= 0x80 ) { points++; } if ( g >= 0x80 ) { points++; } if ( b >= 0x80 ) { points++; } if ( r >= 0xcc ) { points += 2; } if ( g >= 0xcc ) { points += 2; } if ( b >= 0xcc ) { points += 2; } if ( points >= 7 ) { pales.add( new NamedColor( r, g, b, "" ) ); } } } } // end for outer for return pales.toArray( new NamedColor[ pales.size() ] ); } /** * Generate an array of unnamed rainbow colours. mathematically * * @return array of rainbow. */ private static NamedColor[] calculateRainbows() { ArrayList rainbows = new ArrayList<>( 4096 ); for ( int r = 0; r <= 0xff; r += 0x11 ) { for ( int g = 0; g <= 0xff; g += 0x11 ) { for ( int b = 0; b <= 0xff; b += 0x11 ) { int colour = r * 0x10000 + g * 0x100 + b; rainbows.add( new NamedColor( colour, "" ) ); } } } return rainbows.toArray( new NamedColor[ rainbows.size() ] ); } /** * Generate an array of simple colours mathematically * * @return array of simples. */ private static NamedColor[] calculateSimples() { ArrayList simples = new ArrayList<>( 105 ); for ( int row = 1; row < 8; row++ ) { int firstColourInRow = 0; if ( ( row & 0x4 ) != 0 ) { firstColourInRow += 0x110000; } if ( ( row & 0x2 ) != 0 ) { firstColourInRow += 0x001100; } if ( ( row & 0x1 ) != 0 ) { firstColourInRow += 0x000011; } for ( int col = 1; col <= 15; col++ ) { final int colour = col * firstColourInRow; simples.add( new NamedColor( colour, "" ) ); } } return simples.toArray( new NamedColor[ simples.size() ] ); } /** * Generate an array of spectrum colours mathematically * * @return array of rainbow. */ private static NamedColor[] calculateSpectrum() { ArrayList spectrums = new ArrayList<>( 4096 ); for ( float wavelength = 380.f; wavelength <= 780f; wavelength += 1.0f ) { spectrums.add( new NamedColor( Wavelength.wvColor( wavelength, 1.0f ), wavelength + " nm" ) ); } return spectrums.toArray( new NamedColor[ spectrums.size() ] ); } /** * Generate an array of 216 WebSafe colours. * * @return array of webdsafe soclours. */ private static NamedColor[] calculateWebSafes() { final ArrayList webSafes = new ArrayList<>( 6 * 6 * 6 ); final int inc = 0x33;// 0x33 for 6x6x6 samples 00 33 66 88 cc ff for ( int r = 0; r <= 0xff; r += inc ) { for ( int g = 0; g <= 0xff; g += inc ) { for ( int b = 0; b <= 0xff; b += inc ) { webSafes.add( new NamedColor( r, g, b, "" ) ); } } } return webSafes.toArray( new NamedColor[ webSafes.size() ] ); } /** * Generate grid of 256 greys mathematically * * @param filename where to generate the HTML. */ @SuppressWarnings( { "SameParameterValue" } ) private static void generateBackgroundGreys( String filename ) { try { out.println( greys256.length + " background greys" ); Arrays.sort( greys256, new NamedColor.ByRGB() ); FileWriter p = new FileWriter( new File( dir, filename ) ); p.write( DO_NOT_EDIT + "\n\n" + "\n" + "" + "\n" + "\n" + "\n" + "\n" ); int item = 0; for ( NamedColor n : greys256 ) { if ( item % 16 == 0 ) { p.write( "" ); } final String contrast; if ( item >= 128 ) { contrast = "black"; } else { contrast = "white"; } p.write( "\n" ); if ( item % 16 == 15 ) { p.write( "\n" ); } item++; } // end for p.write( "
A palette of 256 greys suitable for backgrounds
Background Grey Palette of 256 Numbered Colours
" + n.getRGBHexString() + "
\n" ); p.close(); } catch ( IOException e ) { err.println( e.getMessage() ); } } // end generateBackgroundGreys /** * Generate grid of dark colours * * @param filename where to put the generated HTML. */ @SuppressWarnings( { "SameParameterValue" } ) private static void generateDarks( String filename ) { try { out.println( darks2022.length + " darks2022" ); Arrays.sort( darks2022, new NamedColor.ByRGB() ); FileWriter p = new FileWriter( new File( dir, filename ) ); p.write( DO_NOT_EDIT + "\n" + "\n" + "" + "\n" + "\n" ); int item = 0; for ( NamedColor n : darks2022 ) { if ( item % 16 == 0 ) { p.write( "" ); } /* background-color defaults to white */ p.write( "\n" ); if ( item % 16 == 15 || item == darks2022.length - 1 ) { p.write( "\n" ); } item++; } p.write( "
List of " + "2022 dark foreground colours
Dark Foreground Colours Palette of 2022 Numbered Colours
" + n.getRGBHexString() + "
\n" ); p.close(); } catch ( IOException e ) { err.println( e.getMessage() ); } } // end generateDarks /** * Generate grid of 256 grey Foreground colours * * @param filename where to generate the HTML. */ @SuppressWarnings( { "SameParameterValue" } ) private static void generateForegroundGreys( String filename ) { try { out.println( greys256.length + " foreground greys" ); Arrays.sort( greys256, new NamedColor.ByRGB() ); FileWriter p = new FileWriter( new File( dir, filename ) ); p.write( DO_NOT_EDIT + "\n" + "\n" + "" + "\n" + "\n" + "\n" + "\n" ); int item = 0; for ( NamedColor n : greys256 ) { if ( item % 16 == 0 ) { p.write( "" ); } /* background-color:white by default */ p.write( "\n" ); if ( item % 16 == 15 ) { p.write( "\n" ); } item++; } // end for p.write( "
a palette" + " of greys suitable for foreground text colours
Foreground Grey Palette of 256 Numbered Colours
" + n.getRGBHexString() + "
\n" ); p.close(); } catch ( IOException e ) { err.println( e.getMessage() ); } } /** * Generate table of Colors * * @param palette palette of colours to display. * @param howToSort order to sort colours. * @param summary description of the table generated. * @param filename where to generate the HTML. */ private static void generateHTML( NamedColor[] palette, Comparator howToSort, String summary, String filename ) { try { Arrays.sort( palette, howToSort ); final FileWriter p = new FileWriter( new File( dir, filename ) ); p.write( DO_NOT_EDIT + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "" + "\n" + "\n" + "" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" ); int item = 0; for ( NamedColor aPalette : palette ) { p.write( "" ); p.write( "\n" ); /* background-color:white by default */ p.write( "\n" ); p.write( "\n" ); p.write( "\n" ); p.write( "\n" ); p.write( "\n" ); /* background-color:white by default */ p.write( "\n" ); p.write( "\n" ); p.write( "\n" ); p.write( "\n" ); p.write( "\n" ); p.write( "\n" ); p.write( "\n" ); p.write( "\n" ); p.write( "\n" ); p.write( "\n" ); p.write( "\n" ); } // end for p.write( "
" + summary + "
" + summary + "
Color NameUsing namehexUsing hexRedGreenBlueHueSatBright
" + aPalette.getColorName() + "testtesttesttest" + aPalette.getRGBHexString() + "testtesttesttest" + aPalette.getRed() + "" + aPalette.getGreen() + "" + aPalette.getBlue() + "" + threePlaces( aPalette.getHue() ) + "" + threePlaces( aPalette.getSaturation() ) + "" + threePlaces( aPalette.getBrightness() ) + "
\n" ); p.close(); } catch ( IOException e ) { err.println( e.getMessage() ); } } // end generateHTML /** * Generate List of all Colors that can be included in a Java source program to give access to named colours.. * * @param palette which colours to include, in desired order. * @param howToSort order to sort colours. * @param description a description of what this generated Java code is. * @param filename where to put the generated file. */ private static void generateJava( NamedColor[] palette, Comparator howToSort, String description, String filename ) { final String className = ST.chopTrailingString( filename, ".java" ); try { Arrays.sort( palette, howToSort ); FileWriter p = new FileWriter( new File( dir, filename ) ); p.write( "package com.mindprod.palette;import static java.lang.System.out;import static java.lang.System.err;\n" ); p.write( "import java.awt.Color;" ); p.write( "\n" ); p.write( "/**\n" ); p.write( " * List of " + palette .length + " " + description + "\n" ); p.write( " */\n" ); p.write( "public interface " + className + "\n" ); p.write( "{\n" ); p.write( "\n" ); p.write( "/* everything is implicitly public static final */\n" ); p.write( "\n" ); p.write( "/* R G B Hue Sat Bri */\n" ); for ( NamedColor aPalette : palette ) { p.write( "Color " ); String colourName = aPalette.getColorName().toUpperCase(); p.write( colourName ); int extraSpaces = 20 - colourName.length(); p.write( " ".substring( 0, extraSpaces ) ); p.write( " = new Color(0x" ); p.write( aPalette.getRawRGBHexString() ); p.write( ") /* " ); p.write( threePlaces( aPalette.getHue() ) ); p.write( " " ); p.write( threePlaces( aPalette.getSaturation() ) ); p.write( " " ); p.write( threePlaces( aPalette.getBrightness() ) ); p.write( " */;\n" ); } // end for p.write( "}\n" ); p.close(); } catch ( IOException e ) { err.println( e.getMessage() ); } } // end generateJava /** * Generate table of Colors, without trying to get browser to understand colour names. * * @param palette palette of colours to display. * @param howToSort order to sort colours. * @param summary description of the table generated. * @param filename where to generate the HTML. */ private static void generateMiniHTML( NamedColor[] palette, Comparator howToSort, String summary, String filename ) { try { Arrays.sort( palette, howToSort ); final FileWriter p = new FileWriter( new File( dir, filename ) ); p.write( DO_NOT_EDIT + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "" + "\n" + "\n" + "" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" ); int item = 0; for ( NamedColor aPalette : palette ) { p.write( "" ); p.write( "\n" ); /* background-color:white by default */ p.write( "\n" ); /* background-color:white by default */ p.write( "\n" ); p.write( "\n" ); p.write( "\n" ); p.write( "\n" ); p.write( "\n" ); p.write( "\n" ); p.write( "\n" ); p.write( "\n" ); p.write( "\n" ); p.write( "\n" ); p.write( "\n" ); } // end for p.write( "
" + summary + "
" + summary + "
Color NamehexUsing hexRedGreenBlueHueSatBright
" + aPalette.getColorName() + "" + aPalette.getRGBHexString() + "testtesttesttest" + aPalette.getRed() + "" + aPalette.getGreen() + "" + aPalette.getBlue() + "" + threePlaces( aPalette.getHue() ) + "" + threePlaces( aPalette.getSaturation() ) + "" + threePlaces( aPalette.getBrightness() ) + "
\n" ); p.close(); } catch ( IOException e ) { err.println( e.getMessage() ); } } // end generateHTML /** * Generate grid of offwhite colours. * * @param filename where to put the generated HTML. */ @SuppressWarnings( { "SameParameterValue" } ) private static void generateOffWhites( String filename ) { try { out.println( offWhites4096.length + " off whites" ); // sort by hue, brightness, saturation Arrays.sort( offWhites4096, new NamedColor.ByHSB() ); FileWriter p = new FileWriter( new File( dir, filename ) ); p.write( DO_NOT_EDIT + "\n" + "\n" + "" + "\n" + "\n" ); int item = 0; for ( NamedColor n : offWhites4096 ) { if ( item % 16 == 0 ) { p.write( "" ); } p.write( "\n" ); if ( item % 16 == 15 ) { p.write( "\n" ); } item++; } p.write( "
List of " + "4096 off white background colours
Off white Background Colours Palette of 4096 Numbered " + "Colours
" + n.getRGBHexString() + "
\n" ); p.close(); } catch ( IOException e ) { err.println( e.getMessage() ); } } /** * Generate grid of pale colours. * * @param filename where to put the generated HTML. */ @SuppressWarnings( { "SameParameterValue" } ) private static void generatePales( String filename ) { try { out.println( pales256.length + " pales256" ); // sort by hue, brightness, saturation Arrays.sort( pales256, new NamedColor.ByHSB() ); FileWriter p = new FileWriter( new File( dir, filename ) ); p.write( DO_NOT_EDIT + "\n" + "\n" + "" + "\n" + "\n" ); int item = 0; for ( NamedColor n : pales256 ) { if ( item % 16 == 0 ) { p.write( "" ); } final int r = n.getRed(); final int g = n.getGreen(); final int b = n.getBlue(); final String contrast; if ( r + g + b > 0x80 * 3 ) { contrast = "black"; } else { contrast = "white"; } p.write( "\n" ); if ( item % 16 == 15 ) { p.write( "\n" ); } item++; } p.write( "
List of " + "256 pale background colours
Pale Background Colours Palette of 256 Numbered Colours
" + n.getRGBHexString() + "
\n" ); p.close(); } catch ( IOException e ) { err.println( e.getMessage() ); } } // end generatePales /** * Generate Rainbow grid of unnamed colors at 00 11 22 33 ... ffffff. * * @param filename where to put the generated HTML. */ @SuppressWarnings( { "SameParameterValue" } ) private static void generateRainbow( String filename ) { try { out.println( rainbows4096.length + " rainbows" ); Arrays.sort( rainbows4096, new NamedColor.ByRGB() ); FileWriter p = new FileWriter( new File( dir, filename ) ); p.write( DO_NOT_EDIT + "\n" + "\n" + "" + "" + "\n" ); int item = 0; for ( NamedColor n : rainbows4096 ) { if ( item % 16 == 0 ) { p.write( "" ); } int r = n.getRed(); int g = n.getGreen(); int b = n.getBlue(); String contrast; if ( r + g + b > 0x80 * 3 ) { contrast = "black"; } else { contrast = "white"; } p.write( "\n" ); if ( item % 16 == 15 ) { p.write( "\n" ); } item++; } // end for p.write( "
4096 " + "colours of the rainbow
Rainbow Palette of 4096 Numbered Colours
" + n.getRGBHexString() + "
\n" ); p.close(); } catch ( IOException e ) { err.println( e.getMessage() ); } } /** * Generate Simple grid of unnamed colors, must have one primary or equal parts of two primaries. * * @param filename where to put the generated HTML. */ @SuppressWarnings( { "SameParameterValue" } ) private static void generateSimple( String filename ) { try { out.println( simples105.length + " simples" ); // don't sort. Leave in order generated. FileWriter p = new FileWriter( new File( dir, filename ) ); p.write( DO_NOT_EDIT + "\n" + "\n" + "" + "\n" + "\n" ); int item = 0; for ( NamedColor n : simples105 ) { if ( item % 15 == 0 ) { p.write( "" ); } final int r = n.getRed(); final int g = n.getGreen(); final int b = n.getBlue(); final String contrast; if ( r + g + b > 0x80 * 3 ) { contrast = "black"; } else { contrast = "white"; } p.write( "\n" ); if ( item % 15 == 14 ) { p.write( "\n" ); } item++; } p.write( "
palette " + "of simple colours
Simple Pure Colours Palette of 105 Numbered Colours
" + n.getRGBHexString() + "
\n" ); p.close(); } catch ( IOException e ) { err.println( e.getMessage() ); } } /** * Generate Spectrum grid of unnamed colors at 00 11 22 33 ... ffffff. * * @param filename where to put the generated HTML. */ @SuppressWarnings( { "SameParameterValue" } ) private static void generateSpectrum( String filename ) { try { out.println( spectrums4096.length + " spectrum" ); // don't sort by RRB, leave in order by nm FileWriter p = new FileWriter( new File( dir, filename ) ); p.write( DO_NOT_EDIT + "\n" + "\n" + "\n" + "" + "\n" + "\n" + "" + "\n" ); int item = 0; for ( NamedColor n : spectrums4096 ) { p.write( "" ); int r = n.getRed(); int g = n.getGreen(); int b = n.getBlue(); String contrast; if ( r + g + b > 0x80 * 3 ) { contrast = "black"; } else { contrast = "white"; } p.write( "\n" ); } // end for p.write( "
401 " + "colours of the spectrum
Spectrum Palette of 401 Colours
WavelengthHex
" ); p.write( n.getColorName() ); p.write( "" + n.getRGBHexString() + "
\n" ); p.close(); } catch ( IOException e ) { err.println( e.getMessage() ); } } /** * Generate List of all Netscape named Colors. * * @param palette which colours to include, in desired order. * @param howToSort order to sort colours. * @param summary description of the table generated. * @param filename where to put the generated file. */ private static void generateTxt( NamedColor[] palette, Comparator howToSort, String summary, String filename ) { try { Arrays.sort( palette, howToSort ); FileWriter p = new FileWriter( new File( dir, filename ) ); p.write( summary + "\n" + "Red " + "Grn " + "Blue " + "Hue " + "Sat " + "Brt " + "Hex " + "Name\n" ); for ( NamedColor aPalette : palette ) { p.write( threeDigits( aPalette.getRed() ) + " " ); p.write( threeDigits( aPalette.getGreen() ) + " " ); p.write( threeDigits( aPalette.getBlue() ) + " " ); p.write( threePlaces( aPalette.getHue() ) + " " ); p.write( threePlaces( aPalette.getSaturation() ) + " " ); p.write( threePlaces( aPalette.getBrightness() ) + " " ); p.write( aPalette.getRGBHexString() + " " ); p.write( aPalette.getColorName() ); p.write( "\n" ); } // end for p.close(); } catch ( IOException e ) { err.println( e.getMessage() ); } } // end generateTxt /** * Generate Websafe grid of unnamed colors,at 00 33 66 99 cc ff. * * @param filename where to put the generated HTML. */ @SuppressWarnings( { "SameParameterValue" } ) private static void generateWebSafe( String filename ) { try { FileWriter p = new FileWriter( new File( dir, filename ) ); p.write( DO_NOT_EDIT + "\n" + "\n" + "" + "\n" + "\n" ); int item = 0; for ( NamedColor n : webSafes216 ) { if ( item % 6 == 0 ) { p.write( "" ); } int r = n.getRed(); int g = n.getGreen(); int b = n.getBlue(); String contrast = ( r + g + b > 0x80 * 3 ) ? "black" : "white"; p.write( "\n" ); if ( item % 6 == 5 ) { p.write( "\n" ); } item++; } // end for p.write( "
The 216 " + "WebSafe colours that are very likely to be supported on any platform.
WebSafe Colours : a Basic Palette of 216 Numbered Colours
" + n.getRGBHexString() + "
\n" ); p.close(); } catch ( IOException e ) { err.println( e.getMessage() ); } } /** * load up a set of named colours from a CSV file * * @param filename CSV file containing the named colours. * * @return array of NamedColors comprising the palette. */ private static NamedColor[] loadPalette( String filename ) { try { final File file = new File( filename ); out.println( "Loading palette " + EIO.getCanOrAbsPath( file ) ); // O P E N BufferedReader br = EIO.getBufferedReader( file, 24 * 1024, EIO.UTF8 ); final CSVReader r = new CSVReader( br, ',', '\"', "#", true, true /* trimQuoted */, true /* trimUnquoted */, false ); final HashMap dupDescDetector = new HashMap<>( 1000 ); final HashMap knownColours = new HashMap<>( 1000 ); try { //noinspection InfiniteLoopStatement while ( true ) { String colour = r.get(); if ( colour == null ) { // bypass blank line. continue; } // get rid of lead x, if any colour = ST.trimLeading( colour, "x" ); final String desc = r.get(); // lookup by colour final String prevDesc = knownColours.put( colour, desc ); if ( prevDesc != null ) { err.println( "Error: Duplicate entry for colour " + colour + " : " + desc + " : " + prevDesc ); } // lookup by desc final String prevColour = dupDescDetector.put( desc, colour ); if ( prevColour != null ) { err.println( "Warning: Duplicate entry for description " + desc + " : " + colour + " : " + prevColour ); } r.skipToNextLine(); } } catch ( EOFException e ) { r.close(); } /* convert to an array of NamedColors */ final NamedColor[] result = new NamedColor[ knownColours.size() ]; int j = 0; for ( Map.Entry entry : knownColours.entrySet() ) { result[ j++ ] = new NamedColor( Integer.parseInt( entry.getKey(), 16 ), entry.getValue() ); } Arrays.sort( result, new NamedColor.ByRGB() ); return result; } catch ( IOException e ) { err.println( e.getMessage() ); System.exit( 2 ); return null; } } /** * display a number with three digits LZ * * @param i int number to display * * @return string with three decimal places. */ private static String threeDigits( int i ) { return THREE_DECIMAL_DIGITS.format( i ); } /** * display a number to three decimal places. * * @param f floating point number to display * * @return string with three decimal places. */ private static String threePlaces( float f ) { return THREE_DECIMAL_PLACES.format( f ); } /** * Generate HTML guts to various tables of colours sorted in various orders. * put directory where you want these to go on the command line. Default is current * directory . * e.g. Palette E:/mindprod/jgloss/include * * @param args not used */ public static void main( String[] args ) { if ( args.length == 0 ) { dir = new File( "." ); } else { dir = new File( args[ 0 ] ); } // palettes are created with loadPalette in static definitions. generateBackgroundGreys( "palette256backgroundgreys.htmlfrag" ); generateForegroundGreys( "palette256foregroundgreys.htmlfrag" ); generateDarks( "palette2022dark.htmlfrag" ); generatePales( "palette256pale.htmlfrag" ); generateOffWhites( "palette256offwhite.htmlfrag" ); generateRainbow( "palette4096rainbow.htmlfrag" ); generateSpectrum( "palette401spectrum.htmlfrag" ); generateSimple( "palette105simple.htmlfrag" ); generateWebSafe( "palette216websafe.htmlfrag" ); generateHTML( html5NewPalette8, new NamedColor.Alphabetically(), "All 8 New HTML5 colours sorted alphabetically.", "palette8byalpha.htmlfrag" ); generateHTML( html5Palette140, new NamedColor.Alphabetically(), "All 140 HTML5 colours sorted alphabetically.", "palette140byalpha.htmlfrag" ); generateTxt( html5Palette140, new NamedColor.Alphabetically(), "All 140 HTML5 colours sorted alphabetically.", "palette140byalpha.txt" ); generateJava( html5Palette140, new NamedColor.Alphabetically(), "All 140 HTML5 colours sorted alphabetically.", "Palette140ByAlpha.java" ); generateHTML( html5Palette140, new NamedColor.ByRGB(), "All 140 HTML5 colours sorted numerically by RGB.", "palette140byrgb.htmlfrag" ); generateHTML( html5Palette140, new NamedColor.ByBHS(), "All 140 HTML5 colours sorted by brightness, hue and saturation.", "palette140bybhs.htmlfrag" ); generateHTML( html5Palette140, new NamedColor.ByBSH(), "All 140 HTML5 colours sorted by brightness, saturation and hue.", "palette140bybsh.htmlfrag" ); generateHTML( html5Palette140, new NamedColor.ByHBS(), "All 140 HTML5 colours sorted by hue, brightness and saturation.", "palette140byhbs.htmlfrag" ); generateHTML( html5Palette140, new NamedColor.ByHSB(), "All 140 HTML5 colours sorted by hue, saturation and brightness.", "palette140byhsb.htmlfrag" ); generateHTML( html5Palette140, new NamedColor.BySBH(), "All 140 HTML colours sorted by saturation, brightness, and hue.", "palette140bysbh.htmlfrag" ); generateHTML( html5Palette140, new NamedColor.BySHB(), "All 140 HTML5 colours sorted by saturation, hue and brightness.", "palette140byshb.htmlfrag" ); out.println( stdPalette16.length + " HTML 3.2 colours" ); generateHTML( stdPalette16, new NamedColor.Alphabetically(), "HTML 3.2 Standard 16 named Colours Sorted Alphabetically.", "palette16html3byalpha.htmlfrag" ); out.println( mindprodPalette.length + " mindprod.com colours" ); // mini means without browser understanding colour names. generateMiniHTML( mindprodPalette, new NamedColor.ByHSB(), "All " + mindprodPalette.length + " Colours Used on the Mindprod.com website sorted by hue, " + "saturation and brightness", "mindprodcolours.htmlfrag" ); out.println( x11Palette657.length + " x11 colours" ); generateMiniHTML( x11Palette657, new NamedColor.ByHSB(), "All " + x11Palette657.length + " X11 Colours by hue, saturation and brightness", "palette657x11byhsb.htmlfrag" ); out.println( "generating ASCII table" ); out.println( "128 ASCII characters" ); Asciitab.generateAsciitab( dir, "asciitab.htmlfrag" ); // generate Java files generateJava( x11Palette657, new NamedColor.Alphabetically(), "\"All 657 X11 Colours", "Palette657X11ByAlpha.java" ); // generate txt files. out.println( "generating *.txt files" ); generateTxt( x11Palette657, new NamedColor.Alphabetically(), "All 657 X11 named colours, sorted alphabetically", "palette657x11byalpha.txt" ); generateTxt( stdPalette16, new NamedColor.Alphabetically(), "HTML 3.2 Standard 16 named Colours Sorted Alphabetically.", "palette16html3byalpha.txt" ); generateTxt( html5Palette140, new NamedColor.Alphabetically(), "All 140 HTML5 colours sorted alphabetically.", "palette140byalpha.txt" ); } // end main }