3.4 KiB
3.4 KiB
orx-palette
Collections of color palettes and tools for interacting with them.
Find demos in the demo folder.
ColorBrewer2
A collection of color palettes based on the research of Dr. Cynthia Brewer. Explore them live at colorbrewer2.org.
Each Palette has between 3 and 11 colors.
Use colorBrewer2Palettes() to query and obtain a list of ColorBrewer2Palette instances.
// all palettes
val palettes = colorBrewer2Palettes()
// palettes with 5 colors
val palettes = colorBrewer2Palettes(numberOfColors = 5)
// palettes of type Sequential
val palettes = colorBrewer2Palettes(palettetype = ColorBrewer2Type.Sequential)
Once we have some palettes, we can pick one and use its colors:
palettes.first().colors.forEachIndexed { i, color ->
drawer.fill = color
drawer.circle(drawer.bounds.center, 300.0 - i * 40.0)
}
Palette Studio
A class to load palette collections from JSON files, load random palettes and sort colors. JVM only.
Usage
val paletteStudio = PaletteStudio(
loadDefault = true, // Loads the first collection of palettes. [default -> true]
sortBy = PaletteStudio.SortBy.DARKEST, // Sorts the colors by luminance. [default -> PaletteStudio.SortBy.NO_SORTING]
collection = PaletteStudio.Collections.TWO, // Chooses which collection to load [default -> Collections.ONE]
colorCountConstraint = 3 // Constraints the number of colors in the palette [default -> 0]
)
// The choice of the background and foreground colors is based on contrast ratios
drawer.background(paletteStudio.background)
drawer.stroke = paletteStudio.foreground
val randomPaletteColor = Random.pick(paletteStudio.colors!!)
val randomColorExcludingBackground = Random.pick(paletteStudio.colors2!!)
// grabs a random palette from the collection
paletteStudio.randomPalette()
// randomizes the order of the colors in the palette
paletteStudio.randomize()
// changes the collection of palettes
paletteStudio.loadCollection(PaletteStudio.Collections.TWO)
// load your own from a JSON file with a structure of Array<Array<String>>
paletteStudio.loadExternal("data/palette-autumn.json")
Keybindings
Keybindings for getting a random palette (l) and randomizing (k) one can be set easily by declaring inside the program:
val paletteStudio = PaletteStudio()
extend(paletteStudio)




