[orx-shadestyles] n-point gradient shadeStyle and demos (#138)
This commit is contained in:
@@ -11,7 +11,7 @@ import org.openrndr.math.Vector2
|
||||
class LinearGradient(
|
||||
color0: ColorRGBa,
|
||||
color1: ColorRGBa,
|
||||
offset: Vector2,
|
||||
offset: Vector2 = Vector2.ZERO,
|
||||
rotation: Double = 0.0,
|
||||
exponent: Double = 1.0) : ShadeStyle() {
|
||||
|
||||
|
||||
35
orx-shade-styles/src/main/kotlin/NPointGradient.kt
Normal file
35
orx-shade-styles/src/main/kotlin/NPointGradient.kt
Normal file
@@ -0,0 +1,35 @@
|
||||
package org.openrndr.extra.shadestyles
|
||||
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.draw.ShadeStyle
|
||||
import org.openrndr.extra.parameters.Description
|
||||
import org.openrndr.math.Vector2
|
||||
import org.openrndr.math.Vector3
|
||||
|
||||
@Description("N-Point gradient")
|
||||
class NPointGradient(
|
||||
numPoints: Int,
|
||||
colors: Array<ColorRGBa>,
|
||||
points: Array<Vector2> = arrayOf(Vector2.ZERO)) : ShadeStyle() {
|
||||
|
||||
var numPoints: Int by Parameter()
|
||||
var colors: Array<ColorRGBa> by Parameter()
|
||||
var points: Array<Vector2> by Parameter()
|
||||
|
||||
init {
|
||||
this.numPoints = numPoints
|
||||
this.colors = colors
|
||||
this.points = points
|
||||
|
||||
fragmentTransform = """
|
||||
float sum = 0;
|
||||
vec4 rgba = vec4(0.0);
|
||||
for(int i=0; i<p_numPoints; i++) {
|
||||
float dist = 1.0 / (1.0 + distance(p_points[i], c_screenPosition));
|
||||
sum += dist;
|
||||
rgba += p_colors[i] * dist;
|
||||
}
|
||||
x_fill = rgba/sum;
|
||||
"""
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user