Nodes - Added color nodes

This commit is contained in:
Robert committed 2021-08-22 22:31:47 +02:00
1 parent 0bb93f2ebd
commit 9d6a61f1e5
20 files changed
+420 -34

No files matched your search

@@ -0,0 +1,27 @@
using Artemis.Core;
using SkiaSharp;
namespace Artemis.VisualScripting.Nodes.Color
{
[Node("Brighten Color", "Brightens a color by a specified amount in percent")]
public class BrightenSKColorNode : Node
{
public BrightenSKColorNode() : base("Brighten Color", "Brightens a color by a specified amount in percent")
{
Input = CreateInputPin<SKColor>("Color");
Percentage = CreateInputPin<float>("%");
Output = CreateOutputPin<SKColor>();
}
public InputPin<SKColor> Input { get; }
public InputPin<float> Percentage { get; }
public OutputPin<SKColor> Output { get; set; }
public override void Evaluate()
{
Input.Value.ToHsl(out float h, out float s, out float l);
l *= (Percentage.Value + 100f) / 100f;
Output.Value = SKColor.FromHsl(h, s, l);
}
}
}
@@ -0,0 +1,38 @@
using System.ComponentModel;
using Artemis.VisualScripting.Nodes.CustomViewModels;
using SkiaSharp;
namespace Artemis.VisualScripting.Nodes.Color.CustomViewModels
{
public class StaticSKColorValueNodeCustomViewModel : CustomNodeViewModel
{
private readonly StaticSKColorValueNode _node;
public StaticSKColorValueNodeCustomViewModel(StaticSKColorValueNode node) : base(node)
{
_node = node;
}
public SKColor Input
{
get => (SKColor) (_node.Storage ?? SKColor.Empty);
set => _node.Storage = value;
}
public override void OnActivate()
{
_node.PropertyChanged += NodeOnPropertyChanged;
}
public override void OnDeactivate()
{
_node.PropertyChanged -= NodeOnPropertyChanged;
}
private void NodeOnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Node.Storage))
OnPropertyChanged(nameof(Input));
}
}
}
@@ -0,0 +1,16 @@
<UserControl x:Class="Artemis.VisualScripting.Nodes.Color.CustomViews.StaticSKColorValueNodeCustomView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Artemis.VisualScripting.Nodes.Color.CustomViews"
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<shared:SKColorToColorConverter x:Key="SKColorToColorConverter" />
</UserControl.Resources>
<shared:ColorPicker VerticalAlignment="Center"
HorizontalAlignment="Stretch"
Color="{Binding Input, Converter={StaticResource SKColorToColorConverter}}" />
</UserControl>
@@ -0,0 +1,27 @@
using Artemis.Core;
using SkiaSharp;
namespace Artemis.VisualScripting.Nodes.Color
{
[Node("Darken Color", "Darkens a color by a specified amount in percent")]
public class DarkenSKColorNode : Node
{
public DarkenSKColorNode() : base("Darken Color", "Darkens a color by a specified amount in percent")
{
Input = CreateInputPin<SKColor>("Color");
Percentage = CreateInputPin<float>("%");
Output = CreateOutputPin<SKColor>();
}
public InputPin<SKColor> Input { get; }
public InputPin<float> Percentage { get; }
public OutputPin<SKColor> Output { get; set; }
public override void Evaluate()
{
Input.Value.ToHsl(out float h, out float s, out float l);
l *= (Percentage.Value * -1 + 100f) / 100f;
Output.Value = SKColor.FromHsl(h, s, l);
}
}
}
@@ -0,0 +1,29 @@
using System;
using Artemis.Core;
using SkiaSharp;
namespace Artemis.VisualScripting.Nodes.Color
{
[Node("Desaturate Color", "Desaturates a color by a specified amount in percent")]
public class DesaturateSKColorNode : Node
{
public DesaturateSKColorNode() : base("Desaturate Color", "Desaturates a color by a specified amount in percent")
{
Input = CreateInputPin<SKColor>("Color");
Percentage = CreateInputPin<float>("%");
Output = CreateOutputPin<SKColor>();
}
public InputPin<SKColor> Input { get; }
public InputPin<float> Percentage { get; }
public OutputPin<SKColor> Output { get; set; }
public override void Evaluate()
{
Input.Value.ToHsl(out float h, out float s, out float l);
s -= Percentage.Value;
s = Math.Clamp(s, 0, 100);
Output.Value = SKColor.FromHsl(h, s, l);
}
}
}
@@ -0,0 +1,32 @@
using Artemis.Core;
using SkiaSharp;
namespace Artemis.VisualScripting.Nodes.Color
{
[Node("HSL Color", "Creates a color from hue, saturation and lightness values")]
public class HslSKColorNode : Node
{
public HslSKColorNode() : base("HSL Color", "Creates a color from hue, saturation and lightness values")
{
H = CreateInputPin<float>("H");
S = CreateInputPin<float>("S");
L = CreateInputPin<float>("L");
Output = CreateOutputPin<SKColor>();
}
public InputPin<float> H { get; set; }
public InputPin<float> S { get; set; }
public InputPin<float> L { get; set; }
public OutputPin<SKColor> Output { get; }
#region Overrides of Node
/// <inheritdoc />
public override void Evaluate()
{
Output.Value = SKColor.FromHsl(H.Value, S.Value, L.Value);
}
#endregion
}
}
@@ -0,0 +1,25 @@
using Artemis.Core;
using SkiaSharp;
namespace Artemis.VisualScripting.Nodes.Color
{
[Node("Invert Color", "Inverts a color by a specified amount in percent")]
public class InvertSKColorNode : Node
{
public InvertSKColorNode() : base("Invert Color", "Inverts a color")
{
Input = CreateInputPin<SKColor>();
Output = CreateOutputPin<SKColor>();
}
public InputPin<SKColor> Input { get; }
public OutputPin<SKColor> Output { get; set; }
public override void Evaluate()
{
Input.Value.ToHsl(out float h, out float s, out float l);
h += 180;
Output.Value = SKColor.FromHsl(h % 360, s, l);
}
}
}
@@ -0,0 +1,27 @@
using Artemis.Core;
using SkiaSharp;
namespace Artemis.VisualScripting.Nodes.Color
{
[Node("Rotate Color Hue", "Rotates the hue of a color by a specified amount in degrees")]
public class RotateHueSKColorNode : Node
{
public RotateHueSKColorNode() : base("Rotate Color Hue", "Rotates the hue of a color by a specified amount in degrees")
{
Input = CreateInputPin<SKColor>("Color");
Amount = CreateInputPin<float>("Amount");
Output = CreateOutputPin<SKColor>();
}
public InputPin<SKColor> Input { get; }
public InputPin<float> Amount { get; }
public OutputPin<SKColor> Output { get; set; }
public override void Evaluate()
{
Input.Value.ToHsl(out float h, out float s, out float l);
h += Amount.Value;
Output.Value = SKColor.FromHsl(h % 360, s, l);
}
}
}
@@ -0,0 +1,29 @@
using System;
using Artemis.Core;
using SkiaSharp;
namespace Artemis.VisualScripting.Nodes.Color
{
[Node("Saturate Color", "Saturates a color by a specified amount in percent")]
public class SaturateSKColorNode : Node
{
public SaturateSKColorNode() : base("Saturate Color", "Saturates a color by a specified amount in percent")
{
Input = CreateInputPin<SKColor>("Color");
Percentage = CreateInputPin<float>("%");
Output = CreateOutputPin<SKColor>();
}
public InputPin<SKColor> Input { get; }
public InputPin<float> Percentage { get; }
public OutputPin<SKColor> Output { get; set; }
public override void Evaluate()
{
Input.Value.ToHsl(out float h, out float s, out float l);
s += Percentage.Value;
s = Math.Clamp(s, 0, 100);
Output.Value = SKColor.FromHsl(h, s, l);
}
}
}
@@ -0,0 +1,43 @@
using Artemis.Core;
using Artemis.VisualScripting.Nodes.Color.CustomViewModels;
using SkiaSharp;
namespace Artemis.VisualScripting.Nodes.Color
{
[Node("Color-Value", "Outputs a configurable color value.")]
public class StaticSKColorValueNode : Node<StaticSKColorValueNodeCustomViewModel>
{
#region Constructors
public StaticSKColorValueNode()
: base("Color", "Outputs a configurable color value.")
{
Output = CreateOutputPin<SKColor>();
}
#endregion
#region Properties & Fields
public OutputPin<SKColor> Output { get; }
#endregion
#region Methods
public override void Evaluate()
{
Output.Value = Storage as SKColor? ?? SKColor.Empty;
}
public override void Initialize(INodeScript script)
{
if (Storage is string && SKColor.TryParse(Storage.ToString(), out SKColor parsed))
Storage = parsed;
else
Storage = SKColor.Empty;
}
#endregion
}
}
@@ -0,0 +1,46 @@
using Artemis.Core;
using SkiaSharp;
namespace Artemis.VisualScripting.Nodes.Color
{
[Node("Sum (Color)", "Sums the connected color values.")]
public class SumSKColorsNode : Node
{
#region Properties & Fields
public InputPinCollection<SKColor> Values { get; }
public OutputPin<SKColor> Sum { get; }
#endregion
#region Constructors
public SumSKColorsNode()
: base("Sum", "Sums the connected color values.")
{
Values = CreateInputPinCollection<SKColor>("Values", 2);
Sum = CreateOutputPin<SKColor>("Sum");
}
#endregion
#region Methods
public override void Evaluate()
{
SKColor result = SKColor.Empty;
bool first = true;
foreach (SKColor current in Values.Values)
{
result = first ? current : result.Sum(current);
first = false;
}
Sum.Value = result;
}
#endregion
}
}