2 using System.Collections.Generic;
5 using System.Xml.Serialization;
12 private int _PlasmaSpeed = 100;
21 public int PlasmaSpeed
23 get {
return _PlasmaSpeed; }
24 set { _PlasmaSpeed = value.Limit(1,
int.MaxValue); }
28 private int _PlasmaScale = 100;
37 public int PlasmaScale
39 get {
return _PlasmaScale; }
40 set { _PlasmaScale = value; }
44 private int _PlasmaDensity = 100;
53 public int PlasmaDensity
55 get {
return _PlasmaDensity; }
56 set { _PlasmaDensity = value; }
62 private const int RefreshIntervalMs = 30;
65 int CurrentTrigerrValue = 0;
68 DateTime PlasmaStartDateTime = DateTime.Now;
71 public bool Active {
get;
private set; }
73 private void DoPlasma()
75 int V = CurrentTrigerrValue.Limit(0, 255);
81 PlasmaStartDateTime = DateTime.Now;
82 Table.Pinball.Alarms.RegisterIntervalAlarm(RefreshIntervalMs, DoPlasma);
89 Table.Pinball.Alarms.UnregisterIntervalAlarm(DoPlasma);
99 private void DrawFrame()
101 int F = (FadeMode ==
FadeModeEnum.OnOff ? (CurrentTrigerrValue > 0 ? 255 : 0) : CurrentTrigerrValue.Limit(0, 255));
103 Time += ((double)PlasmaSpeed / 2000);
114 SX = (double)PlasmaScale / 100 / W;
119 SY = (double)PlasmaScale / 100 / H;
123 PrecalcTimeValues(Time);
125 for (
int X = 0; X < W; X++)
128 PrecalcXValues(XX, Time);
130 for (
int Y = 0; Y < H; Y++)
132 double YY = (double)SY * Y;
134 double V = CalcPositionValue(XX, YY, Time).Limit(0, 1);
136 MatrixLayer[AreaLeft + X, AreaTop + Y] = GetEffectValue(F, Time, V, XX, YY);
145 private void ClearFrame()
150 double KX = (double)W / H;
151 for (
int Y = 0; Y < H; Y++)
153 for (
int X = 0; X < W; X++)
155 MatrixLayer[AreaLeft + X, AreaTop + Y] = GetEffectValue(0, 0, 0, 0, 0);
163 double SinTimeDiv11767Mult05 = 0;
164 double CosTimeDiv1833371Mult05=0;
165 private void PrecalcTimeValues(
double Time)
167 CosTime = Math.Cos(Time);
168 SinTimeDiv11767Mult05 = .5 * Math.Sin(Time / 1.1767);
169 CosTimeDiv1833371Mult05 = .5 * Math.Cos(Time / 1.833371);
172 double XWaveValue1 = 0;
173 double XWaveValue2 = 0;
174 private void PrecalcXValues(
double X,
double Time)
176 XWaveValue1 = Math.Sin(X * Math.PI * (PlasmaDensity / 28) + Time);
177 XWaveValue2 = X * Math.Sin(Time / 2.567);
181 private double CalcPositionValue(
double X,
double Y,
double Time)
183 double V = XWaveValue1;
185 V += Math.Sin(Math.PI * (PlasmaDensity / 28) * (XWaveValue2 + Y * CosTime) + Time);
187 double cx = X + SinTimeDiv11767Mult05;
188 double cy = Y + CosTimeDiv1833371Mult05;
189 V += Math.Sin(Math.Sqrt((Math.PI * (PlasmaDensity / 56)) * (Math.PI * (PlasmaDensity / 56)) * (cx * cx + cy * cy) + 1) + Time);
195 protected abstract MatrixElementType GetEffectValue(
int TriggerValue,
double Time,
double Value,
double X,
double Y);
197 public override void Trigger(Table.TableElementData TableElementData)
200 if (MatrixLayer != null)
202 CurrentTrigerrValue = TableElementData.Value;
203 if (CurrentTrigerrValue > 0 && !Active)
Base class for effects targeting a matrix of toys (e.g. addressable ledstrip)
FadeModeEnum
Defines the fading behaviour.
override void Trigger(Table.TableElementData TableElementData)