-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMixer.cs
60 lines (47 loc) · 1.62 KB
/
Mixer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using UnityEngine;
namespace Ix
{
namespace Spectra
{
[ExecuteAlways]
public class Mixer : MonoBehaviour
{
public Palette p;
public float hMin = 0;
public float hMax = 1;
public float sMin = 0;
public float sMax = 1;
public float vMin = 0;
public float vMax = 1;
public int nKeys = 5;
public int nColors = 3;
public void RandomizeGradient()
{
p.gradient = new Gradient();
GradientColorKey[] c = new GradientColorKey[nKeys];
GradientAlphaKey[] a = new GradientAlphaKey[nKeys];
var rand = new System.Random();
for (int i = 0; i < nKeys; i++)
{
float h = (float)rand.NextDouble() * (hMax - hMin) + hMin;
float s = (float)rand.NextDouble() * (sMax - sMin) + sMin;
float v = (float)rand.NextDouble() * (vMax - vMin) + vMin;
Color nc = Color.HSVToRGB(h, s, v);
c[i].color = nc;
a[i].time = c[i].time = (i * (1.0f / nKeys));
a[i].alpha = 1.0f;
}
p.gradient.SetKeys(c, a);
}
public void SetColors()
{
p.colors = new Color[nColors];
for (int i = 0; i < nColors; i++)
{
float t = (i * (1.0f / nColors));
p.colors[i] = p.gradient.Evaluate(t);
}
}
}
}
}