[orx-palette] Add ColorBrewer2, demos, update README (#363)
This commit is contained in:
22
orx-palette/src/jvmDemo/kotlin/DemoColorBrewer2_01.kt
Normal file
22
orx-palette/src/jvmDemo/kotlin/DemoColorBrewer2_01.kt
Normal file
@@ -0,0 +1,22 @@
|
||||
import org.openrndr.application
|
||||
|
||||
/**
|
||||
* Demonstrates how to use a ColorBrewer2 palette.
|
||||
* Finds the first available palette with 5 colors,
|
||||
* then draws concentric circles filled with those colors.
|
||||
*/
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
}
|
||||
program {
|
||||
val palette = colorBrewer2Palettes(numberOfColors = 5).first().colors
|
||||
extend {
|
||||
palette.forEachIndexed { i, color ->
|
||||
drawer.fill = color
|
||||
drawer.circle(drawer.bounds.center, 300.0 - i * 40.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
41
orx-palette/src/jvmDemo/kotlin/DemoColorBrewer2_02.kt
Normal file
41
orx-palette/src/jvmDemo/kotlin/DemoColorBrewer2_02.kt
Normal file
@@ -0,0 +1,41 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.shapes.primitives.Arc
|
||||
import org.openrndr.extra.shapes.primitives.grid
|
||||
|
||||
/**
|
||||
* Visualizes the ColorBrewer2 color palettes with 8 colors as circles
|
||||
* made of colored arcs.
|
||||
*/
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
}
|
||||
program {
|
||||
val palettes = colorBrewer2Palettes(numberOfColors = 8)
|
||||
// Make a grid and discard some cells if there are more cells than palettes
|
||||
val grid = drawer.bounds.grid(6, 6).flatten().take(palettes.size)
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.WHITE)
|
||||
// For each grid cell
|
||||
grid.forEachIndexed { i, rect ->
|
||||
// Find the corresponding palette
|
||||
val palette = palettes[i].colors
|
||||
// And display its colors on thick arcs
|
||||
palette.forEachIndexed { ci, color ->
|
||||
drawer.strokeWeight = 15.0
|
||||
drawer.stroke = color
|
||||
drawer.fill = null
|
||||
drawer.contour(
|
||||
Arc(
|
||||
rect.center, rect.width * 0.35,
|
||||
360.0 * (ci + 0.0) / palette.size,
|
||||
360.0 * (ci + 1.0) / palette.size
|
||||
).contour
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
38
orx-palette/src/jvmDemo/kotlin/DemoColorBrewer2_03.kt
Normal file
38
orx-palette/src/jvmDemo/kotlin/DemoColorBrewer2_03.kt
Normal file
@@ -0,0 +1,38 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.shapes.primitives.Arc
|
||||
import org.openrndr.extra.shapes.primitives.grid
|
||||
|
||||
/**
|
||||
* Visualizes 49 ColorBrewer2 color palettes of type "Diverging" as circles
|
||||
* made of colored arcs. Since there are more palettes than grid cells,
|
||||
* not all palettes are visualized.
|
||||
*/
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
}
|
||||
program {
|
||||
val palettes = colorBrewer2Palettes(paletteType = ColorBrewer2Type.Diverging)
|
||||
val grid = drawer.bounds.grid(7, 7).flatten().take(palettes.size)
|
||||
extend {
|
||||
drawer.clear(ColorRGBa.WHITE)
|
||||
grid.forEachIndexed { i, rect ->
|
||||
val palette = palettes[i].colors
|
||||
palette.forEachIndexed { ci, color ->
|
||||
drawer.strokeWeight = 15.0
|
||||
drawer.stroke = color
|
||||
drawer.fill = null
|
||||
drawer.contour(
|
||||
Arc(
|
||||
rect.center, rect.width * 0.4,
|
||||
360.0 * (ci + 0.0) / palette.size,
|
||||
360.0 * (ci + 1.0) / palette.size
|
||||
).contour
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
31
orx-palette/src/jvmDemo/kotlin/DemoPaletteStudio01.kt
Normal file
31
orx-palette/src/jvmDemo/kotlin/DemoPaletteStudio01.kt
Normal file
@@ -0,0 +1,31 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.extra.palette.PaletteStudio
|
||||
|
||||
/**
|
||||
* Demonstrates how to access palette colors using PaletteStudio.
|
||||
* A new random palette is loaded every 60 animation frames.
|
||||
*/
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 720
|
||||
height = 720
|
||||
}
|
||||
program {
|
||||
val paletteStudio = PaletteStudio()
|
||||
|
||||
// Choose a specific initial palette
|
||||
paletteStudio.select(11)
|
||||
|
||||
extend {
|
||||
if(frameCount % 60 == 50) {
|
||||
paletteStudio.randomPalette()
|
||||
}
|
||||
drawer.clear(paletteStudio.background)
|
||||
|
||||
paletteStudio.colors2.forEachIndexed { i, color ->
|
||||
drawer.fill = color
|
||||
drawer.circle(drawer.bounds.center, 300.0 - i * 40.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
68
orx-palette/src/jvmDemo/kotlin/DemoPaletteStudio02.kt
Normal file
68
orx-palette/src/jvmDemo/kotlin/DemoPaletteStudio02.kt
Normal file
@@ -0,0 +1,68 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.palette.PaletteStudio
|
||||
|
||||
/**
|
||||
* Demonstrates how to create a design using PaletteStudio.
|
||||
* Press the `c` key to load a random palette.
|
||||
*
|
||||
*/
|
||||
fun main() = application {
|
||||
configure {
|
||||
title = "Palette"
|
||||
width = 720
|
||||
height = 720
|
||||
}
|
||||
program {
|
||||
val paletteStudio = PaletteStudio()
|
||||
|
||||
val colors = mutableListOf<ColorRGBa>()
|
||||
|
||||
fun fillColors() {
|
||||
for (n in 0..36) {
|
||||
when (n) {
|
||||
12 -> paletteStudio.loadCollection(PaletteStudio.Collections.TWO)
|
||||
24 -> paletteStudio.loadCollection(PaletteStudio.Collections.THREE)
|
||||
}
|
||||
|
||||
val color = paletteStudio.colors.random()
|
||||
|
||||
colors.add(color)
|
||||
}
|
||||
}
|
||||
|
||||
keyboard.keyDown.listen {
|
||||
if (it.name == "c") {
|
||||
colors.clear()
|
||||
fillColors()
|
||||
}
|
||||
}
|
||||
|
||||
fillColors()
|
||||
|
||||
extend {
|
||||
drawer.clear(paletteStudio.background)
|
||||
|
||||
val size = 120.0
|
||||
val radius = size / 2.0
|
||||
|
||||
for (x in 0 until 6) {
|
||||
for (y in 0 until 6) {
|
||||
val index = x + y * 6
|
||||
val color = colors[index]
|
||||
val x = size * x
|
||||
val y = size * y
|
||||
|
||||
drawer.fill = color
|
||||
drawer.stroke = color
|
||||
|
||||
if (index <= 11 || index > 23) {
|
||||
drawer.circle(x + radius, y + radius, radius)
|
||||
} else {
|
||||
drawer.rectangle(x, y, size, size)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user