Core - Moved color sorter and quantizer to static classes

Nodes - Added colorgradient sort node
Nodes - Added GradientBuilder node
This commit is contained in:
Diogo Trindade authored and GitHub committed 2022-11-18 23:54:02 +01:00
1 parent 761447b3d2
commit d0f665aa10
16 files changed
+905 -342

No files matched your search

@@ -0,0 +1,55 @@
using Artemis.Core;
using SkiaSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Artemis.VisualScripting.Nodes.Color
{
[Node("Gradient Builder", "Generates a gradient based on some values", "Color", OutputType = typeof(ColorGradient), HelpUrl = "https://krazydad.com/tutorials/makecolors.php")]
public class GradientBuilderNode : Node
{
public OutputPin<ColorGradient> Output { get; }
public InputPin<Numeric> Frequency1 { get; }
public InputPin<Numeric> Frequency2 { get; }
public InputPin<Numeric> Frequency3 { get; }
public InputPin<Numeric> Phase1 { get; }
public InputPin<Numeric> Phase2 { get; }
public InputPin<Numeric> Phase3 { get; }
public InputPin<Numeric> Center { get; }
public InputPin<Numeric> Width { get; }
public InputPin<Numeric> Length { get; }
public GradientBuilderNode()
{
Output = CreateOutputPin<ColorGradient>();
Frequency1 = CreateInputPin<Numeric>("Frequency 1");
Frequency2 = CreateInputPin<Numeric>("Frequency 2");
Frequency3 = CreateInputPin<Numeric>("Frequency 3");
Phase1 = CreateInputPin<Numeric>("Phase 1");
Phase2 = CreateInputPin<Numeric>("Phase 2");
Phase3 = CreateInputPin<Numeric>("Phase 3");
Center = CreateInputPin<Numeric>("Center");
Width = CreateInputPin<Numeric>("Width");
Length = CreateInputPin<Numeric>("Length");
}
public override void Evaluate()
{
ColorGradient gradient = new ColorGradient();
for (int i = 0; i < Length.Value; i++)
{
Numeric r = Math.Sin(Frequency1.Value * i + Phase1.Value) * Width.Value + Center.Value;
Numeric g = Math.Sin(Frequency2.Value * i + Phase2.Value) * Width.Value + Center.Value;
Numeric b = Math.Sin(Frequency3.Value * i + Phase3.Value) * Width.Value + Center.Value;
gradient.Add(new ColorGradientStop(new SKColor((byte)r, (byte)g, (byte)b), i / Length.Value));
}
Output.Value = gradient;
}
}
}
@@ -0,0 +1,45 @@
using Artemis.Core;
using Artemis.Core.ColorScience;
using SkiaSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Artemis.VisualScripting.Nodes.Color
{
[Node("Sorted Gradient", "Generates a sorted gradient from the given colors", "Color", InputType = typeof(SKColor), OutputType = typeof(ColorGradient))]
public class SortedGradientNode : Node
{
public InputPinCollection<SKColor> Inputs { get; }
public OutputPin<ColorGradient> Output { get; }
public SortedGradientNode()
{
Inputs = CreateInputPinCollection<SKColor>();
Output = CreateOutputPin<ColorGradient>();
}
public override void Evaluate()
{
var colors = Inputs.Values.ToArray();
if (colors.Length == 0)
{
Output.Value = null;
return;
}
ColorSorter.Sort(colors, SKColors.Black);
var gradient = new ColorGradient();
for (int i = 0; i < colors.Length; i++)
{
gradient.Add(new(colors[i], (float)i / (colors.Length - 1)));
}
Output.Value = gradient;
}
}
}