-
Notifications
You must be signed in to change notification settings - Fork 0
/
RainbowGenerator.cs
129 lines (112 loc) · 3.87 KB
/
RainbowGenerator.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
using ColorChooserCSharp;
using System.IO;
using DoubleRainbow.Interfaces;
namespace DoubleRainbow
{
/*
* Requirements:
* Event-driven lighting. Run scripts for animations by accepting requests or events
* events can be raised externally with custom scripts
* Structure: source pixel, active width (left and right independent), animation mask
* */
public partial class RainbowGenerator : Form
{
const int KaiLength = Globals.KaiLength;
IHueGenerator _huey = null;
AnimationThread _at = null;
public RainbowGenerator(IHueGenerator huey)
{
InitializeComponent();
_huey = huey;
_at = new AnimationThread(Animate);
}
public void Animate()
{
// Color Generation
DRColor.HSV color_gen = _huey.getNextColor((float)Slider1Value, (float)Slider2Value, (float)Slider3Value);
DRColor.RGB new_color = new DRColor.RGB(color_gen);
// Position Generation
Rainbow.Kai[23] = new_color;
Rainbow.Kai[24] = new_color;
Push();
RainbowUtils.update();
Thread.Sleep(refreshRate);
}
// Pushes from the center like this --> <--
public void Push()
{
double mid = 23.5;
for (int i = 0; i < 23; i++)
{
int wave_up = 0+i;//(int)(Math.Ceiling(mid + i));
int wave_down = 47-i;//(int)(Math.Floor(mid - i));
Rainbow.Kai[wave_up] = Rainbow.Kai[wave_up + 1];
Rainbow.Kai[wave_down] = Rainbow.Kai[wave_down - 1];
}
}
// Starts/stops repeat thread
private void PlayPause(object sender, EventArgs e)
{
if (_at.isOn)
{
this.button2.Text = "Play";
_at.Stop();
}
else
{
this.button2.Text = "Pause";
_at.Start();
StoreState();
}
}
private void ClearButton(object sender, EventArgs e)
{
RainbowUtils.TurnOff();
}
public double Slider1Value = 61;
private void Slider1_Scroll(object sender, ScrollEventArgs e)
{
Slider1Value = Math.Pow(Math.E, (5.545d * Slider1.Value / 1000) );
Slider1ValueLbl.Text = "Val: " + String.Format("{0:N2}", Slider1Value);
}
public double Slider2Value = 45;
private void Slider2_Scroll(object sender, ScrollEventArgs e)
{
Slider2Value = Math.Pow(Math.E, (5.545d * Slider2.Value / 1000) );
Slider2ValueLbl.Text = "Val: " + String.Format("{0:N2}", Slider2Value);
}
public double Slider3Value = 34;
private void Slider3_Scroll(object sender, ScrollEventArgs e)
{
Slider3Value = Math.Pow(Math.E, (5.545d * Slider3.Value / 1000));
Slider3ValueLbl.Text = "Val: " + String.Format("{0:N2}", Slider3Value);
}
public int refreshRate = 0;
private void RefreshBar_Scroll(object sender, ScrollEventArgs e)
{
refreshRate = RefreshBar.Value;
refreshLbl.Text = refreshRate + " ms";
}
DRColor.RGB[] storedState = new DRColor.RGB[KaiLength];
private void StoreState()
{
Array.Copy(Rainbow.Kai, storedState, KaiLength);
}
private DRColor.RGB AdjustVal(DRColor.RGB rgb, double perc)
{
DRColor.HSV hsv = new DRColor.HSV(rgb);
hsv.Value = (int)(hsv.Value * perc);
return new DRColor.RGB(hsv);
}
}
}