If the default palette does not satisfy the application's color requirements, the application can create its own indexed palette by using the colors: class method. In the following example, a palette with 5 different levels of gray, from black to white is created:
| colors palette | (colors := Array new: 5) at: 1 put: (CgRGBColor intensity: 16r0000); at: 2 put: (CgRGBColor intensity: 16r1FFF); at: 3 put: (CgRGBColor intensity: 16r7FFF); at: 4 put: (CgRGBColor intensity: 16rBFFF); at: 5 put: (CgRGBColor intensity: 16rFFFF). palette := CgIndexedPalette colors: colors
The following example creates a palette using named colors:
| names colors palette | names := #('black' 'white' 'red' 'green' 'blue' 'brown' 'aquamarine' 'pink'). colors := names collect: [:name | CgScreen default lookupColor: name]. palette := CgIndexedPalette colors: colors