Demos: ensure all use fun main() = application {
- Adjust some demo window sizes. - Replace Random.double by Double.uniform - Tweak some demos so screenshots look more interesting
This commit is contained in:
@@ -9,77 +9,81 @@ import org.openrndr.shape.Rectangle
|
||||
* Example of 5 gradient styles.
|
||||
* NPointLinear and NPoingGradient have separate demos.
|
||||
*/
|
||||
fun main() {
|
||||
application {
|
||||
configure {
|
||||
width = 1000
|
||||
height = 500
|
||||
}
|
||||
program {
|
||||
// Create gradients with initial colors
|
||||
val gradients = listOf(
|
||||
RadialGradient(ColorRGBa.PINK, ColorRGBa.WHITE),
|
||||
AngularGradient(ColorRGBa.PINK, ColorRGBa.WHITE),
|
||||
NPointGradient(Array(4) {
|
||||
ColorRGBa.PINK.shade(it / 3.0)
|
||||
}),
|
||||
LinearGradient(ColorRGBa.PINK, ColorRGBa.WHITE),
|
||||
HalfAngularGradient(ColorRGBa.PINK, ColorRGBa.WHITE)
|
||||
)
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 1000
|
||||
height = 500
|
||||
}
|
||||
program {
|
||||
// Create gradients with initial colors
|
||||
val gradients = listOf(
|
||||
RadialGradient(ColorRGBa.PINK, ColorRGBa.WHITE),
|
||||
AngularGradient(ColorRGBa.PINK, ColorRGBa.WHITE),
|
||||
NPointGradient(Array(4) {
|
||||
ColorRGBa.PINK.shade(it / 3.0)
|
||||
}),
|
||||
LinearGradient(ColorRGBa.PINK, ColorRGBa.WHITE),
|
||||
HalfAngularGradient(ColorRGBa.PINK, ColorRGBa.WHITE)
|
||||
)
|
||||
|
||||
extend {
|
||||
gradients.forEachIndexed { gradientId, gradient ->
|
||||
for (column in 0 until 10) {
|
||||
val color1 = ColorRGBa.PINK.toHSVa().shiftHue(column * 12.0)
|
||||
.shade(0.5).toRGBa()
|
||||
extend {
|
||||
gradients.forEachIndexed { gradientId, gradient ->
|
||||
for (column in 0 until 10) {
|
||||
val color1 = ColorRGBa.PINK.toHSVa().shiftHue(column * 12.0)
|
||||
.shade(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 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
|
||||
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 = offset
|
||||
}
|
||||
is AngularGradient -> {
|
||||
gradient.color1 = color1
|
||||
gradient.exponent = column / 3.0 + 0.3
|
||||
gradient.rotation = (seconds - column) * 10.0
|
||||
gradient.offset = offset
|
||||
}
|
||||
is LinearGradient -> {
|
||||
gradient.color1 = color1
|
||||
gradient.exponent = column / 3.0 + 0.3
|
||||
gradient.rotation = seconds * 10.0
|
||||
}
|
||||
is HalfAngularGradient -> {
|
||||
gradient.color1 = color1
|
||||
gradient.exponent = column / 3.0 + 0.3
|
||||
gradient.rotation = (column - seconds) * 10.0
|
||||
gradient.offset = offset
|
||||
}
|
||||
is NPointGradient -> {
|
||||
// Animate points.
|
||||
// We could also animate colors.
|
||||
gradient.points = Array(gradient.colors.size) {
|
||||
rect.center + Polar(it * 90.0 +
|
||||
drawer.isolated {
|
||||
when (gradient) {
|
||||
is RadialGradient -> {
|
||||
gradient.color1 = color1
|
||||
gradient.exponent = column / 3.0 + 0.3
|
||||
gradient.length = 0.6
|
||||
gradient.offset = offset
|
||||
}
|
||||
|
||||
is AngularGradient -> {
|
||||
gradient.color1 = color1
|
||||
gradient.exponent = column / 3.0 + 0.3
|
||||
gradient.rotation = (seconds - column) * 10.0
|
||||
gradient.offset = offset
|
||||
}
|
||||
|
||||
is LinearGradient -> {
|
||||
gradient.color1 = color1
|
||||
gradient.exponent = column / 3.0 + 0.3
|
||||
gradient.rotation = seconds * 10.0
|
||||
}
|
||||
|
||||
is HalfAngularGradient -> {
|
||||
gradient.color1 = color1
|
||||
gradient.exponent = column / 3.0 + 0.3
|
||||
gradient.rotation = (column - seconds) * 10.0
|
||||
gradient.offset = offset
|
||||
}
|
||||
|
||||
is NPointGradient -> {
|
||||
// Animate points.
|
||||
// We could also animate colors.
|
||||
gradient.points = Array(gradient.colors.size) {
|
||||
rect.center + Polar(
|
||||
it * 90.0 +
|
||||
column * 36 - seconds * 10,
|
||||
40.0).cartesian
|
||||
}
|
||||
40.0
|
||||
).cartesian
|
||||
}
|
||||
}
|
||||
shadeStyle = gradient
|
||||
rectangle(rect)
|
||||
}
|
||||
shadeStyle = gradient
|
||||
rectangle(rect)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,23 +3,21 @@ import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.color.spaces.toOKLABa
|
||||
import org.openrndr.extra.shadestyles.linearGradient
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
program {
|
||||
extend {
|
||||
drawer.shadeStyle = linearGradient(
|
||||
ColorRGBa.RED.toOKLABa(),
|
||||
ColorRGBa.BLUE.toOKLABa(),
|
||||
)
|
||||
drawer.rectangle(120.0, 40.0, 200.0, 400.0)
|
||||
fun main() = application {
|
||||
program {
|
||||
extend {
|
||||
drawer.shadeStyle = linearGradient(
|
||||
ColorRGBa.RED.toOKLABa(),
|
||||
ColorRGBa.BLUE.toOKLABa(),
|
||||
)
|
||||
drawer.rectangle(120.0, 40.0, 200.0, 400.0)
|
||||
|
||||
drawer.shadeStyle = linearGradient(
|
||||
ColorRGBa.RED,
|
||||
ColorRGBa.BLUE
|
||||
)
|
||||
drawer.shadeStyle = linearGradient(
|
||||
ColorRGBa.RED,
|
||||
ColorRGBa.BLUE
|
||||
)
|
||||
|
||||
drawer.rectangle(120.0+200.0, 40.0, 200.0, 400.0)
|
||||
}
|
||||
drawer.rectangle(120.0 + 200.0, 40.0, 200.0, 400.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,31 +16,29 @@ import kotlin.math.cos
|
||||
* on a static shape (a circle for example) or you can animate a shape
|
||||
* with a static gradient.
|
||||
*/
|
||||
fun main() {
|
||||
application {
|
||||
program {
|
||||
val numPoints = 8
|
||||
val gradient = NPointGradient(Array(numPoints) {
|
||||
ColorXSVa(it * 360.0 / numPoints, 1.0, 1.0).toRGBa()
|
||||
})
|
||||
fun main() = application {
|
||||
program {
|
||||
val numPoints = 8
|
||||
val gradient = NPointGradient(Array(numPoints) {
|
||||
ColorXSVa(it * 360.0 / numPoints, 1.0, 1.0).toRGBa()
|
||||
})
|
||||
|
||||
extend {
|
||||
drawer.run {
|
||||
clear(ColorRGBa.WHITE.shade(0.9))
|
||||
val t = PI * 2 * (frameCount % 300) / 300.0
|
||||
val points = Array(numPoints) {
|
||||
val lfo = cos(it * PI / 2 - t)
|
||||
val theta = it * 360.0 / numPoints - 22.5 * lfo
|
||||
val radius = 200 + 170 * lfo
|
||||
bounds.center + Polar(theta, radius).cartesian
|
||||
}
|
||||
gradient.points = points
|
||||
shadeStyle = gradient
|
||||
stroke = ColorRGBa.WHITE
|
||||
strokeWeight = 4.0
|
||||
contour(ShapeContour.fromPoints(points.asList(), true))
|
||||
extend {
|
||||
drawer.run {
|
||||
clear(ColorRGBa.WHITE.shade(0.9))
|
||||
val t = PI * 2 * (frameCount % 300) / 300.0
|
||||
val points = Array(numPoints) {
|
||||
val lfo = cos(it * PI / 2 - t)
|
||||
val theta = it * 360.0 / numPoints - 22.5 * lfo
|
||||
val radius = 200 + 170 * lfo
|
||||
bounds.center + Polar(theta, radius).cartesian
|
||||
}
|
||||
gradient.points = points
|
||||
shadeStyle = gradient
|
||||
stroke = ColorRGBa.WHITE
|
||||
strokeWeight = 4.0
|
||||
contour(ShapeContour.fromPoints(points.asList(), true))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,52 +15,50 @@ import kotlin.math.sin
|
||||
* uniformly between 0.0 and 1.0 and then animated towards one of
|
||||
* the ends over time using pow() and sin(seconds).
|
||||
*/
|
||||
fun main() {
|
||||
application {
|
||||
program {
|
||||
val numPoints = 8
|
||||
// Create gradients using two different color spaces
|
||||
val gradients = listOf(
|
||||
NPointLinearGradient(Array(numPoints) {
|
||||
ColorXSVa(it * 360.0 / numPoints, 1.0, 1.0).toRGBa()
|
||||
}),
|
||||
// OKLab is better at maintaining luminosity across the gradient
|
||||
NPointLinearGradientOKLab(Array(numPoints) {
|
||||
ColorXSVa(it * 360.0 / numPoints, 1.0, 1.0).toRGBa()
|
||||
.toOKLABa()
|
||||
})
|
||||
)
|
||||
fun main() = application {
|
||||
program {
|
||||
val numPoints = 8
|
||||
// Create gradients using two different color spaces
|
||||
val gradients = listOf(
|
||||
NPointLinearGradient(Array(numPoints) {
|
||||
ColorXSVa(it * 360.0 / numPoints, 1.0, 1.0).toRGBa()
|
||||
}),
|
||||
// OKLab is better at maintaining luminosity across the gradient
|
||||
NPointLinearGradientOKLab(Array(numPoints) {
|
||||
ColorXSVa(it * 360.0 / numPoints, 1.0, 1.0).toRGBa()
|
||||
.toOKLABa()
|
||||
})
|
||||
)
|
||||
|
||||
extend {
|
||||
// The points should be sorted values between 0.0 and 1.0
|
||||
val distribution = Array(numPoints) {
|
||||
// uniform distribution
|
||||
// (it / (numPoints - 1.0))
|
||||
extend {
|
||||
// The points should be sorted values between 0.0 and 1.0
|
||||
val distribution = Array(numPoints) {
|
||||
// uniform distribution
|
||||
// (it / (numPoints - 1.0))
|
||||
|
||||
// skewed and animated distribution
|
||||
(it / (numPoints - 1.0)).pow(1.0 + 0.5 * sin(seconds))
|
||||
}
|
||||
drawer.run {
|
||||
clear(rgb(0.2))
|
||||
stroke = rgb(0.35)
|
||||
strokeWeight = 8.0
|
||||
// skewed and animated distribution
|
||||
(it / (numPoints - 1.0)).pow(1.0 + 0.5 * sin(seconds))
|
||||
}
|
||||
drawer.run {
|
||||
clear(rgb(0.2))
|
||||
stroke = rgb(0.35)
|
||||
strokeWeight = 8.0
|
||||
|
||||
gradients.forEachIndexed { i, gradient ->
|
||||
shadeStyle = gradient
|
||||
gradient.points = distribution
|
||||
gradients.forEachIndexed { i, gradient ->
|
||||
shadeStyle = gradient
|
||||
gradient.points = distribution
|
||||
|
||||
gradient.rotation = seconds * 10
|
||||
circle(bounds.position(0.34, 0.29 + 0.44 * i), 110.0)
|
||||
gradient.rotation = seconds * 10
|
||||
circle(bounds.position(0.34, 0.29 + 0.44 * i), 110.0)
|
||||
|
||||
gradient.rotation += 90
|
||||
rectangle(
|
||||
Rectangle.fromCenter(
|
||||
bounds.position(0.655, 0.29 + 0.44 * i), 200.0
|
||||
)
|
||||
gradient.rotation += 90
|
||||
rectangle(
|
||||
Rectangle.fromCenter(
|
||||
bounds.position(0.655, 0.29 + 0.44 * i), 200.0
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,35 +6,37 @@ import org.openrndr.shape.Circle
|
||||
import kotlin.random.Random
|
||||
|
||||
/**
|
||||
* Demonstrate using a multi color radial gradient.
|
||||
* Demonstrate using a multicolor radial gradient.
|
||||
* The gradient has 5 colors (first and last ones are transparent).
|
||||
* Any of the properties can be animated, including colors and points.
|
||||
* See DemoNPointLinearGradient01.kt for an example of animated properties.
|
||||
*/
|
||||
fun main() {
|
||||
application {
|
||||
program {
|
||||
val gradient = NPointRadialGradient(arrayOf(
|
||||
ColorRGBa.PINK.opacify(0.0),
|
||||
ColorRGBa.PINK, ColorRGBa.WHITE, ColorRGBa.PINK,
|
||||
ColorRGBa.PINK.opacify(0.0)
|
||||
), arrayOf(0.0, 0.4, 0.5, 0.6, 1.0))
|
||||
fun main() = application {
|
||||
program {
|
||||
val gradient = NPointRadialGradient(
|
||||
arrayOf(
|
||||
ColorRGBa.PINK.opacify(0.0),
|
||||
ColorRGBa.PINK, ColorRGBa.WHITE, ColorRGBa.PINK,
|
||||
ColorRGBa.PINK.opacify(0.0)
|
||||
), arrayOf(0.0, 0.4, 0.5, 0.6, 1.0)
|
||||
)
|
||||
|
||||
val circles = List(25) {
|
||||
Circle(Random.nextDouble() * drawer.width,
|
||||
Random.nextDouble() * drawer.height,
|
||||
Random.nextDouble() * 150.0)
|
||||
}
|
||||
val circles = List(25) {
|
||||
Circle(
|
||||
Random.nextDouble() * drawer.width,
|
||||
Random.nextDouble() * drawer.height,
|
||||
Random.nextDouble() * 150.0
|
||||
)
|
||||
}
|
||||
|
||||
extend {
|
||||
drawer.run {
|
||||
clear(rgb(0.2))
|
||||
shadeStyle = gradient
|
||||
fill = ColorRGBa.WHITE
|
||||
stroke = null
|
||||
circles(circles)
|
||||
}
|
||||
extend {
|
||||
drawer.run {
|
||||
clear(rgb(0.2))
|
||||
shadeStyle = gradient
|
||||
fill = ColorRGBa.WHITE
|
||||
stroke = null
|
||||
circles(circles)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,17 +3,15 @@ import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.shadestyles.radialGradient
|
||||
import kotlin.math.cos
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
program {
|
||||
extend {
|
||||
drawer.shadeStyle = radialGradient(
|
||||
ColorRGBa.PINK,
|
||||
ColorRGBa.PINK.toHSVa().shiftHue(180.0).shade(0.5).toRGBa(),
|
||||
exponent = cos(seconds)*0.5+0.5
|
||||
)
|
||||
drawer.rectangle(120.0, 40.0, 400.0, 400.0)
|
||||
}
|
||||
fun main() = application {
|
||||
program {
|
||||
extend {
|
||||
drawer.shadeStyle = radialGradient(
|
||||
ColorRGBa.PINK,
|
||||
ColorRGBa.PINK.toHSVa().shiftHue(180.0).shade(0.5).toRGBa(),
|
||||
exponent = cos(seconds) * 0.5 + 0.5
|
||||
)
|
||||
drawer.rectangle(120.0, 40.0, 400.0, 400.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user