Add parameter annotations to orx-shade-styles
This commit is contained in:
3
orx-shade-styles/build.gradle
Normal file
3
orx-shade-styles/build.gradle
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
dependencies {
|
||||||
|
api project(":orx-parameters")
|
||||||
|
}
|
||||||
52
orx-shade-styles/src/main/kotlin/AngularGradient.kt
Normal file
52
orx-shade-styles/src/main/kotlin/AngularGradient.kt
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
package org.openrndr.extra.shadestyles
|
||||||
|
|
||||||
|
import org.openrndr.color.ColorRGBa
|
||||||
|
import org.openrndr.draw.ShadeStyle
|
||||||
|
import org.openrndr.extra.parameters.ColorParameter
|
||||||
|
import org.openrndr.extra.parameters.Description
|
||||||
|
import org.openrndr.math.Vector2
|
||||||
|
|
||||||
|
@Description("Angular gradient")
|
||||||
|
class AngularGradient(color0: ColorRGBa, color1: ColorRGBa, offset: Vector2 = Vector2.ZERO, rotation: Double = 0.0) : ShadeStyle() {
|
||||||
|
@ColorParameter("start color", order = 0)
|
||||||
|
var color0 : ColorRGBa by Parameter()
|
||||||
|
@ColorParameter("end color", order = 1)
|
||||||
|
var color1 : ColorRGBa by Parameter()
|
||||||
|
@ColorParameter("offset", order = 2)
|
||||||
|
var offset : Vector2 by Parameter()
|
||||||
|
@ColorParameter("rotation", order = 3)
|
||||||
|
var rotation : Double by Parameter()
|
||||||
|
|
||||||
|
init {
|
||||||
|
this.color0 = color0
|
||||||
|
this.color1 = color1
|
||||||
|
this.offset = offset
|
||||||
|
this.rotation = rotation
|
||||||
|
|
||||||
|
fragmentTransform = """
|
||||||
|
vec2 coord = (c_boundsPosition.xy - vec2(0.5) + p_offset/2.0) * 2.0;
|
||||||
|
|
||||||
|
float cr = cos(radians(p_rotation));
|
||||||
|
float sr = sin(radians(p_rotation));
|
||||||
|
mat2 rm = mat2(cr, -sr, sr, cr);
|
||||||
|
vec2 rc = rm * coord;
|
||||||
|
float f = (atan(rc.y, rc.x) + 3.1415926536) / (2.0 * 3.1415926536);
|
||||||
|
|
||||||
|
vec4 color0 = p_color0 * vec4(p_color0.aaa, 1.0);
|
||||||
|
vec4 color1 = p_color1 * vec4(p_color1.aaa, 1.0);
|
||||||
|
|
||||||
|
vec4 gradient = color0 * (1.0-f) + color1 * f;
|
||||||
|
|
||||||
|
vec4 fn = vec4(x_fill.rgb, 1.0) * x_fill.a;
|
||||||
|
|
||||||
|
x_fill = fn * gradient;
|
||||||
|
if (x_fill.a !=0) {
|
||||||
|
x_fill.rgb /= x_fill.a;
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun angularGradient(color0: ColorRGBa, color1: ColorRGBa, offset: Vector2 = Vector2.ZERO, rotation: Double = 0.0): ShadeStyle {
|
||||||
|
return AngularGradient(color0, color1, offset, rotation)
|
||||||
|
}
|
||||||
55
orx-shade-styles/src/main/kotlin/HalfAngularGradient.kt
Normal file
55
orx-shade-styles/src/main/kotlin/HalfAngularGradient.kt
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
package org.openrndr.extra.shadestyles
|
||||||
|
|
||||||
|
import org.openrndr.color.ColorRGBa
|
||||||
|
import org.openrndr.draw.ShadeStyle
|
||||||
|
import org.openrndr.extra.parameters.ColorParameter
|
||||||
|
import org.openrndr.extra.parameters.DoubleParameter
|
||||||
|
import org.openrndr.math.Vector2
|
||||||
|
|
||||||
|
class HalfAngularGradient(color0: ColorRGBa, color1: ColorRGBa, offset: Vector2 = Vector2.ZERO, rotation: Double = 0.0) : ShadeStyle() {
|
||||||
|
@ColorParameter("start color", order = 0)
|
||||||
|
var color0: ColorRGBa by Parameter()
|
||||||
|
@ColorParameter("end color", order = 1)
|
||||||
|
var color1: ColorRGBa by Parameter()
|
||||||
|
var offset: Vector2 by Parameter()
|
||||||
|
@DoubleParameter("rotation", -180.0, 180.0, order = 2)
|
||||||
|
var rotation: Double by Parameter()
|
||||||
|
@DoubleParameter("length", 0.0, 10.0, order = 3)
|
||||||
|
var length: Double by Parameter()
|
||||||
|
|
||||||
|
init {
|
||||||
|
this.color0 = color0
|
||||||
|
this.color1 = color1
|
||||||
|
this.offset = offset
|
||||||
|
this.rotation = rotation
|
||||||
|
this.length = length
|
||||||
|
|
||||||
|
fragmentTransform = """
|
||||||
|
vec2 coord = (c_boundsPosition.xy - vec2(0.5) + p_offset/2.0) * 2.0;
|
||||||
|
|
||||||
|
float cr = cos(radians(p_rotation));
|
||||||
|
float sr = sin(radians(p_rotation));
|
||||||
|
mat2 rm = mat2(cr, -sr, sr, cr);
|
||||||
|
vec2 rc = rm * coord;
|
||||||
|
float f = abs(atan(rc.y, rc.x)) / (3.1415926536);
|
||||||
|
|
||||||
|
//float f = abs(atan(rc.y/rc.x)) / (3.1415926536/2.0);
|
||||||
|
//float f = (atan(rc.y/rc.x) + 3.1415926536/2.0) / (3.1415926536);
|
||||||
|
|
||||||
|
vec4 color0 = p_color0 * vec4(p_color0.aaa, 1.0);
|
||||||
|
vec4 color1 = p_color1 * vec4(p_color1.aaa, 1.0);
|
||||||
|
|
||||||
|
vec4 gradient = color0 * (1.0-f) + color1 * f;
|
||||||
|
vec4 fn = vec4(x_fill.rgb, 1.0) * x_fill.a;
|
||||||
|
x_fill = fn * gradient;
|
||||||
|
if (x_fill.a !=0) {
|
||||||
|
x_fill.rgb /= x_fill.a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun halfAngularGradient(color0: ColorRGBa, color1: ColorRGBa, offset: Vector2 = Vector2.ZERO, rotation: Double = 0.0): ShadeStyle {
|
||||||
|
return HalfAngularGradient(color0, color1, offset, rotation)
|
||||||
|
}
|
||||||
@@ -3,18 +3,43 @@ package org.openrndr.extra.shadestyles
|
|||||||
import org.openrndr.color.ColorRGBa
|
import org.openrndr.color.ColorRGBa
|
||||||
import org.openrndr.draw.ShadeStyle
|
import org.openrndr.draw.ShadeStyle
|
||||||
import org.openrndr.draw.shadeStyle
|
import org.openrndr.draw.shadeStyle
|
||||||
|
import org.openrndr.extra.parameters.ColorParameter
|
||||||
|
import org.openrndr.extra.parameters.Description
|
||||||
|
import org.openrndr.extra.parameters.DoubleParameter
|
||||||
import org.openrndr.math.Vector2
|
import org.openrndr.math.Vector2
|
||||||
|
|
||||||
fun linearGradient(color0: ColorRGBa, color1: ColorRGBa, offset : Vector2 = Vector2.ZERO, rotation:Double = 0.0) : ShadeStyle {
|
@Description("Linear gradient")
|
||||||
return shadeStyle {
|
class LinearGradient(
|
||||||
|
color0: ColorRGBa,
|
||||||
|
color1: ColorRGBa,
|
||||||
|
offset: Vector2,
|
||||||
|
rotation: Double) : ShadeStyle() {
|
||||||
|
|
||||||
|
@ColorParameter("start color", order = 0)
|
||||||
|
var color0: ColorRGBa by Parameter()
|
||||||
|
@ColorParameter("end color", order = 1)
|
||||||
|
var color1: ColorRGBa by Parameter()
|
||||||
|
var offset: Vector2 by Parameter()
|
||||||
|
@DoubleParameter("rotation", -180.0, 180.0, order = 2)
|
||||||
|
var rotation: Double by Parameter()
|
||||||
|
|
||||||
|
init {
|
||||||
|
this.color0 = color0
|
||||||
|
this.color1 = color1
|
||||||
|
this.offset = offset
|
||||||
|
this.rotation = rotation
|
||||||
|
|
||||||
fragmentTransform = """
|
fragmentTransform = """
|
||||||
vec2 coord = (c_boundsPosition.xy - vec2(0.5) + p_offset);
|
vec2 coord = (c_boundsPosition.xy - vec2(0.5) + p_offset);
|
||||||
float cr = cos(p_rotation);
|
float cr = cos(radians(p_rotation));
|
||||||
float sr = sin(p_rotation);
|
float sr = sin(radians(p_rotation));
|
||||||
mat2 rm = mat2(cr, -sr, sr, cr);
|
mat2 rm = mat2(cr, -sr, sr, cr);
|
||||||
float f = clamp((rm * coord).y + 0.5, 0.0, 1.0);
|
float f = clamp((rm * coord).y + 0.5, 0.0, 1.0);
|
||||||
|
|
||||||
vec4 gradient = p_color0 * (1.0-f) + p_color1 * f;
|
vec4 color0 = p_color0 * vec4(p_color0.aaa, 1.0);
|
||||||
|
vec4 color1 = p_color1 * vec4(p_color1.aaa, 1.0);
|
||||||
|
|
||||||
|
vec4 gradient = color0 * (1.0-f) + color1 * f;
|
||||||
|
|
||||||
vec4 fn = vec4(x_fill.rgb, 1.0) * x_fill.a;
|
vec4 fn = vec4(x_fill.rgb, 1.0) * x_fill.a;
|
||||||
|
|
||||||
@@ -23,91 +48,11 @@ fun linearGradient(color0: ColorRGBa, color1: ColorRGBa, offset : Vector2 = Vect
|
|||||||
x_fill.rgb /= x_fill.a;
|
x_fill.rgb /= x_fill.a;
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
parameter("offset", offset)
|
|
||||||
parameter("color0", color0.alphaMultiplied)
|
|
||||||
parameter("color1", color1.alphaMultiplied)
|
|
||||||
parameter("rotation", Math.toRadians(rotation) )
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun radialGradient(color0: ColorRGBa, color1: ColorRGBa, offset: Vector2 = Vector2.ZERO, rotation:Double = 0.0, length: Double = 1.0) : ShadeStyle {
|
fun linearGradient(color0: ColorRGBa, color1: ColorRGBa, offset: Vector2 = Vector2.ZERO, rotation: Double = 0.0) =
|
||||||
return shadeStyle {
|
LinearGradient(color0, color1, offset, rotation)
|
||||||
fragmentTransform = """
|
|
||||||
vec2 coord = (c_boundsPosition.xy - vec2(0.5) + p_offset/2.0) * 2.0;
|
|
||||||
|
|
||||||
float cr = cos(p_rotation);
|
|
||||||
float sr = sin(p_rotation);
|
|
||||||
mat2 rm = mat2(cr, -sr, sr, cr);
|
|
||||||
float f = clamp(p_length * length(rm * coord), 0.0, 1.0);
|
|
||||||
|
|
||||||
vec4 gradient = p_color0 * (1.0-f) + p_color1 * f;
|
|
||||||
|
|
||||||
vec4 fn = vec4(x_fill.rgb, 1.0) * x_fill.a;
|
|
||||||
|
|
||||||
x_fill = fn * gradient;
|
|
||||||
if (x_fill.a !=0) {
|
|
||||||
x_fill.rgb /= x_fill.a;
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
parameter("offset", offset)
|
|
||||||
parameter("color0", color0.alphaMultiplied)
|
|
||||||
parameter("color1", color1.alphaMultiplied)
|
|
||||||
parameter("rotation", Math.toRadians(rotation))
|
|
||||||
parameter("length", length)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun angularGradient(color0: ColorRGBa, color1: ColorRGBa, offset: Vector2 = Vector2.ZERO, rotation:Double = 0.0) : ShadeStyle {
|
|
||||||
return shadeStyle {
|
|
||||||
fragmentTransform = """
|
|
||||||
vec2 coord = (c_boundsPosition.xy - vec2(0.5) + p_offset/2.0) * 2.0;
|
|
||||||
|
|
||||||
float cr = cos(p_rotation);
|
|
||||||
float sr = sin(p_rotation);
|
|
||||||
mat2 rm = mat2(cr, -sr, sr, cr);
|
|
||||||
vec2 rc = rm * coord;
|
|
||||||
float f = (atan(rc.y, rc.x) + 3.1415926536) / (2.0 * 3.1415926536);
|
|
||||||
|
|
||||||
vec4 gradient = p_color0 * (1.0-f) + p_color1 * f;
|
|
||||||
|
|
||||||
vec4 fn = vec4(x_fill.rgb, 1.0) * x_fill.a;
|
|
||||||
|
|
||||||
x_fill = fn * gradient;
|
|
||||||
if (x_fill.a !=0) {
|
|
||||||
x_fill.rgb /= x_fill.a;
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
parameter("offset", offset)
|
|
||||||
parameter("color0", color0.alphaMultiplied)
|
|
||||||
parameter("color1", color1.alphaMultiplied)
|
|
||||||
parameter("rotation", Math.toRadians(rotation) )
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun halfAngularGradient(color0: ColorRGBa, color1: ColorRGBa, offset: Vector2 = Vector2.ZERO, rotation:Double = 0.0) : ShadeStyle {
|
|
||||||
return shadeStyle {
|
|
||||||
fragmentTransform = """
|
|
||||||
vec2 coord = (c_boundsPosition.xy - vec2(0.5) + p_offset/2.0) * 2.0;
|
|
||||||
|
|
||||||
float cr = cos(p_rotation);
|
|
||||||
float sr = sin(p_rotation);
|
|
||||||
mat2 rm = mat2(cr, -sr, sr, cr);
|
|
||||||
vec2 rc = rm * coord;
|
|
||||||
float f = abs(atan(rc.y, rc.x)) / (3.1415926536);
|
|
||||||
|
|
||||||
//float f = abs(atan(rc.y/rc.x)) / (3.1415926536/2.0);
|
|
||||||
//float f = (atan(rc.y/rc.x) + 3.1415926536/2.0) / (3.1415926536);
|
|
||||||
|
|
||||||
vec4 gradient = p_color0 * (1.0-f) + p_color1 * f;
|
|
||||||
vec4 fn = vec4(x_fill.rgb, 1.0) * x_fill.a;
|
|
||||||
x_fill = fn * gradient;
|
|
||||||
if (x_fill.a !=0) {
|
|
||||||
x_fill.rgb /= x_fill.a;
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
parameter("offset", offset)
|
|
||||||
parameter("color0", color0.alphaMultiplied)
|
|
||||||
parameter("color1", color1.alphaMultiplied)
|
|
||||||
parameter("rotation", Math.toRadians(rotation) )
|
|
||||||
}
|
|
||||||
}
|
|
||||||
61
orx-shade-styles/src/main/kotlin/RadialGradient.kt
Normal file
61
orx-shade-styles/src/main/kotlin/RadialGradient.kt
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
package org.openrndr.extra.shadestyles
|
||||||
|
|
||||||
|
import org.openrndr.color.ColorRGBa
|
||||||
|
import org.openrndr.draw.ShadeStyle
|
||||||
|
import org.openrndr.draw.shadeStyle
|
||||||
|
import org.openrndr.extra.parameters.ColorParameter
|
||||||
|
import org.openrndr.extra.parameters.Description
|
||||||
|
import org.openrndr.extra.parameters.DoubleParameter
|
||||||
|
import org.openrndr.math.Vector2
|
||||||
|
|
||||||
|
@Description("Radial gradient")
|
||||||
|
class RadialGradient(color0: ColorRGBa, color1: ColorRGBa, offset: Vector2 = Vector2.ZERO, rotation: Double = 0.0, length: Double = 1.0) : ShadeStyle() {
|
||||||
|
@ColorParameter("start color", order = 0)
|
||||||
|
var color0 : ColorRGBa by Parameter()
|
||||||
|
@ColorParameter("end color", order = 1)
|
||||||
|
var color1 : ColorRGBa by Parameter()
|
||||||
|
var offset : Vector2 by Parameter()
|
||||||
|
@DoubleParameter("rotation", -180.0, 180.0)
|
||||||
|
var rotation : Double by Parameter()
|
||||||
|
@DoubleParameter("length", 0.0, 10.0)
|
||||||
|
var length: Double by Parameter()
|
||||||
|
|
||||||
|
init {
|
||||||
|
this.color0 = color0
|
||||||
|
this.color1 = color1
|
||||||
|
this.offset = offset
|
||||||
|
this.rotation = rotation
|
||||||
|
this.length = length
|
||||||
|
|
||||||
|
fragmentTransform = """
|
||||||
|
vec2 coord = (c_boundsPosition.xy - vec2(0.5) + p_offset/2.0) * 2.0;
|
||||||
|
|
||||||
|
float cr = cos(radians(p_rotation));
|
||||||
|
float sr = sin(radians(p_rotation));
|
||||||
|
mat2 rm = mat2(cr, -sr, sr, cr);
|
||||||
|
float f = clamp(p_length * length(rm * coord), 0.0, 1.0);
|
||||||
|
|
||||||
|
vec4 color0 = p_color0 * vec4(p_color0.aaa, 1.0);
|
||||||
|
vec4 color1 = p_color1 * vec4(p_color1.aaa, 1.0);
|
||||||
|
|
||||||
|
vec4 gradient = color0 * (1.0-f) + color1 * f;
|
||||||
|
|
||||||
|
vec4 fn = vec4(x_fill.rgb, 1.0) * x_fill.a;
|
||||||
|
|
||||||
|
x_fill = fn * gradient;
|
||||||
|
if (x_fill.a !=0) {
|
||||||
|
x_fill.rgb /= x_fill.a;
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun radialGradient(
|
||||||
|
color0: ColorRGBa,
|
||||||
|
color1: ColorRGBa,
|
||||||
|
offset: Vector2 = Vector2.ZERO,
|
||||||
|
rotation: Double = 0.0,
|
||||||
|
length: Double = 1.0
|
||||||
|
): ShadeStyle {
|
||||||
|
return RadialGradient(color0, color1, offset, rotation, length)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user