Skip to content

Commit c92dc86

Browse files
committed
[orx-palette] Add ColorBrewer2, demos, update README
1 parent 660cac3 commit c92dc86

14 files changed

Lines changed: 3061 additions & 73 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ To make use of these extensions clone the [OPENRNDR template](https://github.com
4242
| [`orx-no-clear`](orx-no-clear/) | Provides the classical "draw-without-clearing-the-screen" functionality. |
4343
| [`orx-noise`](orx-noise/) | Randomness for every type of person: Perlin, uniform, value, simplex, fractal and many other types of noise. |
4444
| [`orx-obj-loader`](orx-obj-loader/) | Simple loader and saver for Wavefront .obj 3D mesh files. |
45-
| [`orx-palette`](orx-palette/) | Provides hundreds of color palettes. |
45+
| [`orx-palette`](orx-palette/) | Collections of color palettes and tools for interacting with them. |
4646
| [`orx-parameters`](orx-parameters/) | Provides annotations and tools for turning Kotlin properties into introspectable parameters. Used by [`orx-gui`](../orx-jvm/orx-gui/README.md) to automatically generate user interfaces. |
4747
| [`orx-property-watchers`](orx-property-watchers/) | Tools for setting up property watcher based pipelines |
4848
| [`orx-quadtree`](orx-quadtree/) | A [Quadtree](https://en.wikipedia.org/wiki/Quadtree) is a spatial partioning tree structure meant to provide fast spatial queries such as nearest points within a range. |

orx-palette/README.md

Lines changed: 61 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,44 @@
11
# orx-palette
22

3-
Provides hundreds of color palettes.
3+
Collections of color palettes and tools for interacting with them.
44

5-
## Usage
5+
Find demos in the demo folder.
6+
7+
## ColorBrewer2
8+
9+
A collection of color palettes based on the research of Dr. Cynthia Brewer. Explore them live at [colorbrewer2.org](https://colorbrewer2.org/).
10+
11+
Each Palette has between 3 and 11 colors.
12+
13+
Use `colorBrewer2Palettes()` to query and obtain a list of `ColorBrewer2Palette` instances.
614

715
```kotlin
8-
import org.openrndr.extra.palette.PaletteStudio
16+
// all palettes
17+
val palettes = colorBrewer2Palettes()
18+
19+
// palettes with 5 colors
20+
val palettes = colorBrewer2Palettes(numberOfColors = 5)
21+
22+
// palettes of type Sequential
23+
val palettes = colorBrewer2Palettes(palettetype = ColorBrewer2Type.Sequential)
24+
```
25+
26+
Once we have some palettes, we can pick one and use its colors:
27+
28+
```kotlin
29+
palettes.first().colors.forEachIndexed { i, color ->
30+
drawer.fill = color
31+
drawer.circle(drawer.bounds.center, 300.0 - i * 40.0)
32+
}
33+
```
34+
35+
## Palette Studio
936

37+
A class to load palette collections from JSON files, load random palettes and sort colors. JVM only.
38+
39+
### Usage
40+
41+
```kotlin
1042
val paletteStudio = PaletteStudio(
1143
loadDefault = true, // Loads the first collection of palettes. [default -> true]
1244
sortBy = PaletteStudio.SortBy.DARKEST, // Sorts the colors by luminance. [default -> PaletteStudio.SortBy.NO_SORTING]
@@ -28,79 +60,43 @@ paletteStudio.randomPalette()
2860
paletteStudio.randomize()
2961

3062
// changes the collection of palettes
31-
paletteStudio.changeCollection(PaletteStudio.Collections.TWO)
63+
paletteStudio.loadCollection(PaletteStudio.Collections.TWO)
3264

3365
// load your own from a JSON file with a structure of Array<Array<String>>
3466
paletteStudio.loadExternal("data/palette-autumn.json")
3567
```
3668

37-
### Keybindings
69+
#### Keybindings
3870

3971
Keybindings for getting a random palette (`l`) and randomizing (`k`) one can be set easily by declaring inside the `program`:
4072
```kotlin
4173
val paletteStudio = PaletteStudio()
4274

4375
extend(paletteStudio)
4476
```
77+
<!-- __demos__ -->
78+
## Demos
79+
### DemoColorBrewer2_01
80+
[source code](src/jvmDemo/kotlin/DemoColorBrewer2_01.kt)
4581

46-
## Example
82+
![DemoColorBrewer2_01Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-palette/images/DemoColorBrewer2_01Kt.png)
4783

48-
```kotlin
49-
fun main() = application {
50-
configure {
51-
title = "Palette"
52-
width = 720
53-
height = 720
54-
}
55-
program {
56-
val colors = mutableListOf<ColorRGBa>()
57-
58-
fun fillColors() {
59-
for (n in 0..36) {
60-
when(n) {
61-
12 -> paletteStudio.changeCollection(PaletteStudio.Collections.TWO)
62-
24 -> paletteStudio.changeCollection(PaletteStudio.Collections.THREE)
63-
}
64-
65-
val color = Random.pick(paletteStudio.colors!!)
66-
67-
colors.add(color)
68-
}
69-
}
70-
71-
keyboard.keyDown.listen {
72-
if (it.name == "c") {
73-
colors.clear()
74-
fillColors()
75-
}
76-
}
77-
78-
fillColors()
79-
80-
extend() {
81-
drawer.background(paletteStudio.background)
82-
83-
val size = 120.0
84-
val radius = size / 2.0
85-
86-
for (x in 0 until 6) {
87-
for (y in 0 until 6) {
88-
val index = x + y * 6
89-
val color = colors[index]
90-
val x = size * x
91-
val y = size * y
92-
93-
drawer.fill = color
94-
drawer.stroke = color
95-
96-
if (index <= 11 || index > 23) {
97-
drawer.circle(x + radius, y + radius, radius)
98-
} else {
99-
drawer.rectangle(x, y, size, size)
100-
}
101-
}
102-
}
103-
}
104-
}
105-
}
106-
```
84+
### DemoColorBrewer2_02
85+
[source code](src/jvmDemo/kotlin/DemoColorBrewer2_02.kt)
86+
87+
![DemoColorBrewer2_02Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-palette/images/DemoColorBrewer2_02Kt.png)
88+
89+
### DemoColorBrewer2_03
90+
[source code](src/jvmDemo/kotlin/DemoColorBrewer2_03.kt)
91+
92+
![DemoColorBrewer2_03Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-palette/images/DemoColorBrewer2_03Kt.png)
93+
94+
### DemoPaletteStudio01
95+
[source code](src/jvmDemo/kotlin/DemoPaletteStudio01.kt)
96+
97+
![DemoPaletteStudio01Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-palette/images/DemoPaletteStudio01Kt.png)
98+
99+
### DemoPaletteStudio02
100+
[source code](src/jvmDemo/kotlin/DemoPaletteStudio02.kt)
101+
102+
![DemoPaletteStudio02Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-palette/images/DemoPaletteStudio02Kt.png)

orx-palette/build.gradle.kts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
plugins {
2-
org.openrndr.extra.convention.`kotlin-jvm`
2+
org.openrndr.extra.convention.`kotlin-multiplatform`
33
}
44

5-
dependencies {
6-
implementation(libs.gson)
7-
implementation(project(":orx-noise"))
8-
implementation(libs.openrndr.application)
9-
implementation(libs.openrndr.math)
10-
}
5+
kotlin {
6+
sourceSets {
7+
@Suppress("UNUSED_VARIABLE")
8+
val jvmMain by getting {
9+
dependencies {
10+
implementation(libs.gson)
11+
implementation(project(":orx-noise"))
12+
implementation(libs.openrndr.application)
13+
implementation(libs.openrndr.math)
14+
}
15+
}
16+
17+
val jvmDemo by getting {
18+
dependencies {
19+
implementation(project(":orx-palette"))
20+
implementation(project(":orx-palette"))
21+
implementation(project(":orx-shapes"))
22+
}
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)