Browse Source

[lua] Added pulsecircle script

lua
Thomas Kolb 7 years ago
parent
commit
751ef5f24d
1 changed files with 99 additions and 0 deletions
  1. 99
    0
      pulsecircle.lua

+ 99
- 0
pulsecircle.lua View File

@@ -0,0 +1,99 @@
1
+COOLDOWN_FACTOR = 0.9998
2
+FADE_FACTOR = 0.985
3
+
4
+num_modules = 20
5
+center_module = 10
6
+
7
+-- maximum energy values for each band
8
+maxRedEnergy = 1
9
+maxGreenEnergy = 1
10
+maxBlueEnergy = 1
11
+
12
+-- output color buffers
13
+red = {}
14
+green = {}
15
+blue = {}
16
+
17
+tmpRed = {}
18
+tmpGreen = {}
19
+tmpBlue = {}
20
+
21
+function periodic()
22
+  local redEnergy = get_energy_in_band(0, 400);
23
+  local greenEnergy = get_energy_in_band(400, 4000);
24
+  local blueEnergy = get_energy_in_band(4000, 22000);
25
+  local centerIndex = 2 * center_module + 1;
26
+
27
+  maxRedEnergy = maxRedEnergy * COOLDOWN_FACTOR
28
+  if redEnergy > maxRedEnergy then
29
+    maxRedEnergy = redEnergy
30
+  end
31
+
32
+  maxGreenEnergy = maxGreenEnergy * COOLDOWN_FACTOR
33
+  if greenEnergy > maxGreenEnergy then
34
+    maxGreenEnergy = greenEnergy
35
+  end
36
+
37
+  maxBlueEnergy = maxBlueEnergy * COOLDOWN_FACTOR
38
+  if blueEnergy > maxBlueEnergy then
39
+    maxBlueEnergy = blueEnergy
40
+  end
41
+
42
+  -- move the color buffers on by one
43
+  for i = num_modules-1,1,-1 do
44
+    tmpRed[i+1]   = FADE_FACTOR * tmpRed[i]
45
+    tmpGreen[i+1] = FADE_FACTOR * tmpGreen[i]
46
+    tmpBlue[i+1]  = FADE_FACTOR * tmpBlue[i]
47
+  end
48
+
49
+  -- set the new value for the center module
50
+  newRed = redEnergy / maxRedEnergy
51
+  if newRed > tmpRed[num_modules] then
52
+    tmpRed[1] = newRed
53
+  else
54
+    tmpRed[1] = tmpRed[num_modules]
55
+  end
56
+
57
+  newGreen = greenEnergy / maxGreenEnergy
58
+  if newGreen > tmpGreen[num_modules] then
59
+    tmpGreen[1] = newGreen
60
+  else
61
+    tmpGreen[1] = tmpGreen[num_modules]
62
+  end
63
+
64
+  newBlue = blueEnergy / maxBlueEnergy
65
+  if newBlue > tmpBlue[num_modules] then
66
+    tmpBlue[1] = newBlue
67
+  else
68
+    tmpBlue[1] = tmpBlue[num_modules]
69
+  end
70
+
71
+  for i = 1,num_modules do
72
+    red[i] = tmpRed[i]
73
+    green[i] = tmpGreen[i]
74
+    blue[i] = tmpBlue[i]
75
+  end
76
+
77
+  -- return the 3 color arrays
78
+  return red, green, blue
79
+end
80
+
81
+function init(nmod, cmod)
82
+  num_modules = nmod
83
+  center_module = cmod
84
+
85
+  for i = 1,nmod do
86
+    red[i] = 0
87
+    green[i] = 0
88
+    blue[i] = 0
89
+  end
90
+
91
+  for i = 1,nmod do
92
+    tmpRed[i] = 0
93
+    tmpGreen[i] = 0
94
+    tmpBlue[i] = 0
95
+  end
96
+
97
+  -- don't use fading
98
+  return 0
99
+end

Loading…
Cancel
Save