[orx-shadestyles] n-point gradient shadeStyle and demos (#138)
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.color.ColorXSVa
|
||||
import org.openrndr.draw.isolated
|
||||
import org.openrndr.extensions.SingleScreenshot
|
||||
import org.openrndr.extra.shadestyles.*
|
||||
import org.openrndr.math.Polar
|
||||
import org.openrndr.shape.Rectangle
|
||||
import kotlin.random.Random
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 1000
|
||||
height = 500
|
||||
}
|
||||
program {
|
||||
if (System.getProperty("takeScreenshot") == "true") {
|
||||
@@ -19,33 +23,40 @@ fun main() {
|
||||
|
||||
// Create gradients with initial colors
|
||||
val gradients = listOf(
|
||||
radialGradient(ColorRGBa.PINK, ColorRGBa.WHITE),
|
||||
angularGradient(ColorRGBa.PINK, ColorRGBa.WHITE),
|
||||
linearGradient(ColorRGBa.PINK, ColorRGBa.WHITE),
|
||||
halfAngularGradient(ColorRGBa.PINK, ColorRGBa.WHITE)
|
||||
RadialGradient(ColorRGBa.PINK, ColorRGBa.WHITE),
|
||||
AngularGradient(ColorRGBa.PINK, ColorRGBa.WHITE),
|
||||
NPointGradient(4, Array(4) {
|
||||
ColorRGBa.PINK.shade(it / 3.0)
|
||||
}),
|
||||
LinearGradient(ColorRGBa.PINK, ColorRGBa.WHITE),
|
||||
HalfAngularGradient(ColorRGBa.PINK, ColorRGBa.WHITE)
|
||||
)
|
||||
|
||||
extend {
|
||||
gradients.forEachIndexed { i, gradient ->
|
||||
gradients.forEachIndexed { gradientId, gradient ->
|
||||
for (column in 0 until 10) {
|
||||
val color1 = ColorRGBa.PINK.toHSVa().shiftHue(column * 12.0)
|
||||
.scaleValue(0.5).toRGBa()
|
||||
|
||||
val w = width.toDouble() / 10.0
|
||||
val h = height.toDouble() / gradients.size
|
||||
val rect = Rectangle(column * w, gradientId * h, w, h)
|
||||
|
||||
val offset = Polar((seconds + column) * 15.0, 0.3).cartesian
|
||||
|
||||
drawer.isolated {
|
||||
when (gradient) {
|
||||
is RadialGradient -> {
|
||||
gradient.color1 = color1
|
||||
gradient.exponent = column / 3.0 + 0.3
|
||||
gradient.length = 0.6
|
||||
gradient.offset = Polar(
|
||||
(seconds + column) * 15.0, 0.3).cartesian
|
||||
gradient.offset = offset
|
||||
}
|
||||
is AngularGradient -> {
|
||||
gradient.color1 = color1
|
||||
gradient.exponent = column / 3.0 + 0.3
|
||||
gradient.rotation = (seconds - column) * 10.0
|
||||
gradient.offset = Polar(
|
||||
(seconds + column) * 30.0, 0.3).cartesian
|
||||
gradient.offset = offset
|
||||
}
|
||||
is LinearGradient -> {
|
||||
gradient.color1 = color1
|
||||
@@ -56,13 +67,20 @@ fun main() {
|
||||
gradient.color1 = color1
|
||||
gradient.exponent = column / 3.0 + 0.3
|
||||
gradient.rotation = (column - seconds) * 10.0
|
||||
gradient.offset = Polar(
|
||||
(seconds + column) * 8.0, 0.3).cartesian
|
||||
gradient.offset = offset
|
||||
}
|
||||
is NPointGradient -> {
|
||||
// Animate points.
|
||||
// We could also animate colors.
|
||||
gradient.points = Array(gradient.numPoints) {
|
||||
rect.center + Polar(it * 90.0 +
|
||||
column * 36 - seconds * 10,
|
||||
40.0).cartesian
|
||||
}
|
||||
}
|
||||
}
|
||||
shadeStyle = gradient
|
||||
rectangle(column * width / 10.0, i * height / 4.0,
|
||||
width / 10.0, height / 4.0)
|
||||
rectangle(rect)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user