This repository has been archived on 2023-12-10. You can view files and clone it, but cannot push or open issues or pull requests.
PainterlyUNO/Matrix App/PregeneratedMods/generators/SimpleRainbow.cs

50 lines
1.7 KiB
C#
Raw Normal View History

2021-06-09 16:43:27 +00:00
using System;
using System.Windows.Forms;
2021-06-11 11:36:55 +00:00
using Matrix_App.PregeneratedMods.reflection;
2021-06-09 16:43:27 +00:00
using static Matrix_App.GifGeneratorUtils;
2021-06-09 19:19:30 +00:00
namespace Matrix_App.PregeneratedMods
2021-06-09 16:43:27 +00:00
{
2021-06-11 11:36:55 +00:00
public sealed class SimpleRainbow : MatrixGifGenerator
2021-06-09 16:43:27 +00:00
{
2021-06-11 11:36:55 +00:00
[UiWidget]
2021-06-09 19:19:30 +00:00
[UiDescription(title: "Radial", description: "Uses the angle to alter hues")]
2021-06-11 11:36:55 +00:00
private bool radial = false;
2021-06-09 16:43:27 +00:00
2021-06-11 11:36:55 +00:00
[UiWidget]
2021-06-09 19:19:30 +00:00
[UiDescription(title: "Saturation", description: "Overall saturation")]
2021-06-11 11:36:55 +00:00
private float saturation = 1.0f;
[UiWidget]
2021-06-09 19:19:30 +00:00
[UiDescription(title: "Brightness", description: "Overall brightness")]
2021-06-11 11:36:55 +00:00
private float value = 1.0f;
[UiWidget]
2021-06-09 19:19:30 +00:00
[UiDescription(title: "Hue rotation", description: "Offset for hue calculation")]
2021-06-11 11:36:55 +00:00
private float rotation = 0.0f;
2021-06-09 16:43:27 +00:00
2021-06-11 11:36:55 +00:00
protected override void ColorFragment(in int x, in int y, in float u, in float v, in int frame, out float r, out float g, out float b)
2021-06-09 16:43:27 +00:00
{
if (radial)
{
CartesianToPolar(u - 0.5f, v - 0.5f, out float angle, out float _);
RgbFromHsv(AddHueOffset((angle + MathF.PI) / MathF.PI * 180.0f + frame / (float)totalFrames * 360.0f), saturation, value, out r, out g, out b);
} else
{
RgbFromHsv(AddHueOffset(u * 360.0f + frame / (float) (totalFrames + 0.001) * 360.0f), saturation, value, out r, out g, out b);
}
}
protected override void CreateUi(FlowLayoutPanel anchor, update invokeGenerator)
{
}
2021-06-09 16:43:27 +00:00
private float AddHueOffset(float hue)
{
return MathF.Abs(hue + rotation * 360) % 360.0f;
}
}
}