68 lines
1.7 KiB
C#
68 lines
1.7 KiB
C#
|
|
using Godot;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
|
||
|
|
namespace Rokojori
|
||
|
|
{
|
||
|
|
[Tool]
|
||
|
|
[GlobalClass, Icon("res://addons/rokojori_action_library/Icons/Flash.svg") ]
|
||
|
|
public partial class RainbowGradient:GradientGenerator
|
||
|
|
{
|
||
|
|
[Export( PropertyHint.Range, "0,360" )]
|
||
|
|
public float hueStart = 0;
|
||
|
|
|
||
|
|
[Export( PropertyHint.Range, "0,100" )]
|
||
|
|
public float saturation = 100f;
|
||
|
|
|
||
|
|
[Export( PropertyHint.Range, "0,100" )]
|
||
|
|
public float lightness = 50f;
|
||
|
|
|
||
|
|
[Export( PropertyHint.Range, "0,10" )]
|
||
|
|
public float intensity = 0f;
|
||
|
|
|
||
|
|
[Export( PropertyHint.Range, "6,36" )]
|
||
|
|
public int resolution = 6;
|
||
|
|
[Export]
|
||
|
|
public Gradient gradient;
|
||
|
|
|
||
|
|
[ExportGroup("Output")]
|
||
|
|
[ExportToolButton( "Show Output")]
|
||
|
|
public Callable showOutputButton => Callable.From( ()=> outputGradient = GetGradient() );
|
||
|
|
[Export]
|
||
|
|
public Gradient outputGradient;
|
||
|
|
|
||
|
|
public override Gradient GetGradient()
|
||
|
|
{
|
||
|
|
var colors = new List<Color>();
|
||
|
|
|
||
|
|
for ( int i = 0; i < resolution; i++ )
|
||
|
|
{
|
||
|
|
var hue = i / (float)( resolution - 1 ) * 360f + hueStart;
|
||
|
|
hue = MathX.Repeat( hue, 360f );
|
||
|
|
|
||
|
|
var color = new HSLColor( hue, saturation / 100f, lightness / 100f );
|
||
|
|
var rgb = color.ToRGBA();
|
||
|
|
colors.Add( rgb.WithIntensity( intensity ) );
|
||
|
|
}
|
||
|
|
|
||
|
|
return GradientExtensions.Create( colors );
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
[ExportGroup("Repeat")]
|
||
|
|
[Export]
|
||
|
|
public float repeat = 1f;
|
||
|
|
public override float GetRepeat()
|
||
|
|
{
|
||
|
|
return repeat;
|
||
|
|
}
|
||
|
|
|
||
|
|
[Export]
|
||
|
|
public GradientExtensions.GradientRepeatMode repeatMode = GradientExtensions.GradientRepeatMode.Clamp;
|
||
|
|
public override GradientExtensions.GradientRepeatMode GetRepeatMode()
|
||
|
|
{
|
||
|
|
return repeatMode;
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|