[orx-shadestyles] n-point gradient shadeStyle and demos (#138)

This commit is contained in:
Abe Pazos
2020-07-18 17:15:54 +02:00
committed by GitHub
parent 1683154676
commit 508e5d3a37
4 changed files with 120 additions and 14 deletions

View File

@@ -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() {

View 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;
"""
}
}