|
| 1 | +import java.util.Arrays; |
| 2 | +import java.util.ArrayList; |
| 3 | +import java.util.List; |
| 4 | + |
| 5 | +import heronarts.lx.LX; |
| 6 | +import heronarts.lx.LXChannel; |
| 7 | +import heronarts.lx.LXUtils; |
| 8 | +import heronarts.lx.color.LXColor; |
| 9 | +import heronarts.lx.modulator.Accelerator; |
| 10 | +import heronarts.lx.modulator.Click; |
| 11 | +import heronarts.lx.modulator.LinearEnvelope; |
| 12 | +import heronarts.lx.modulator.SawLFO; |
| 13 | +import heronarts.lx.modulator.SinLFO; |
| 14 | +import heronarts.lx.parameter.BasicParameter; |
| 15 | +import heronarts.lx.parameter.BooleanParameter; |
| 16 | +import heronarts.lx.parameter.DiscreteParameter; |
| 17 | +import heronarts.lx.parameter.LXParameter; |
| 18 | + |
| 19 | +import toxi.geom.Vec2D; |
| 20 | +import org.apache.commons.lang3.ArrayUtils; |
| 21 | +import toxi.math.noise.PerlinNoise; |
| 22 | +import toxi.math.noise.SimplexNoise; |
| 23 | + |
| 24 | +class Circles extends TSPattern { |
| 25 | + |
| 26 | + // Variable Declarations go here |
| 27 | + private float minz = Float.MAX_VALUE; |
| 28 | + private float maxz = -Float.MAX_VALUE; |
| 29 | + private float waveWidth = 1; |
| 30 | + private float speedMult = 1000; |
| 31 | + |
| 32 | + final BasicParameter speedParam = new BasicParameter("Speed", 5, 20, .01); |
| 33 | + final BasicParameter waveSlope = new BasicParameter("waveSlope", 360, 1, 720); |
| 34 | + final SawLFO wave360 = new SawLFO(0, 360, speedParam.getValuef() * speedMult); |
| 35 | + final SawLFO wave100 = new SawLFO(0, 100, speedParam.getValuef() * speedMult); |
| 36 | + |
| 37 | + // add speed, wave width |
| 38 | + |
| 39 | + // Constructor and inital setup |
| 40 | + // Remember to use addParameter and addModulator if you're using Parameters or sin waves |
| 41 | + Circles(LX lx) { |
| 42 | + super(lx); |
| 43 | + addModulator(wave360).start(); |
| 44 | + addModulator(wave100).start(); |
| 45 | + addParameter(waveSlope); |
| 46 | + addParameter(speedParam); |
| 47 | + |
| 48 | + for (BaseCube cube : model.baseCubes) { |
| 49 | + if (cube.z < minz) {minz = cube.z;} |
| 50 | + if (cube.z > maxz) {maxz = cube.z;} |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + |
| 55 | + // This is the pattern loop, which will run continuously via LX |
| 56 | + public void run(double deltaMs) { |
| 57 | + wave360.setPeriod(speedParam.getValuef() * speedMult); |
| 58 | + wave100.setPeriod(speedParam.getValuef() * speedMult); |
| 59 | + |
| 60 | + // Use a for loop here to set the cube colors |
| 61 | + for (BaseCube cube : model.baseCubes) { |
| 62 | + float v = (float)( (-wave360.getValuef() + waveSlope.getValuef()) + Math.sqrt(Math.pow(cube.sx,2)+Math.pow(cube.sz,2))*5 ); |
| 63 | + colors[cube.index] = lx.hsb( v % 360, 100, 100); |
| 64 | + //colors[cube.index] = lx.hsb( (float)( Math.sqrt(Math.pow(cube.sx,2)+Math.pow(cube.sz,2)) % 360), 100, 100); |
| 65 | + } |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +class LineScan extends TSPattern { |
| 70 | + // Variable Declarations go here |
| 71 | + private float waveWidth = 1; |
| 72 | + private float speedMult = 1000; |
| 73 | + |
| 74 | + private float nx = 0; |
| 75 | + private float nz = 0; |
| 76 | + private float n = 0; |
| 77 | + private double total_ms =0.0; |
| 78 | + final BasicParameter speedParam = new BasicParameter("Speed", 5, 20, .01); |
| 79 | + final BasicParameter waveSlope = new BasicParameter("waveSlope", 360, 1, 720); |
| 80 | + final BasicParameter theta = new BasicParameter("theta", 45, 0, 360); |
| 81 | + final BasicParameter hue = new BasicParameter("hue", 45, 0, 360); |
| 82 | + final BasicParameter wave_width = new BasicParameter("waveWidth", 500, 10, 1500); |
| 83 | + final SawLFO wave360 = new SawLFO(0, 360, speedParam.getValuef() * speedMult); |
| 84 | + final SinLFO wave100 = new SinLFO(0, 100, speedParam.getValuef() * speedMult); |
| 85 | + |
| 86 | + LineScan(LX lx) { |
| 87 | + super(lx); |
| 88 | + addModulator(wave360).start(); |
| 89 | + addModulator(wave100).start(); |
| 90 | + addParameter(waveSlope); |
| 91 | + addParameter(speedParam); |
| 92 | + addParameter(theta); |
| 93 | + addParameter(hue); |
| 94 | + addParameter(wave_width); |
| 95 | + |
| 96 | + |
| 97 | + } |
| 98 | + private float dist(float x, float z) { |
| 99 | + return (nx*x+nz*z)/n; |
| 100 | + } |
| 101 | + // This is the pattern loop, which will run continuously via LX |
| 102 | + public void run(double deltaMs) { |
| 103 | + float theta_rad = (float)Math.toRadians((int)theta.getValuef()); |
| 104 | + nx = (float)Math.sin(theta_rad); |
| 105 | + nz = (float)Math.cos(theta_rad); |
| 106 | + n = (float)Math.sqrt(Math.pow(nx,2)+Math.pow(nz,2)); |
| 107 | + wave360.setPeriod(speedParam.getValuef() * speedMult); |
| 108 | + wave100.setPeriod(speedParam.getValuef() * speedMult); |
| 109 | + |
| 110 | + float field_len=7000; |
| 111 | + total_ms+=deltaMs; |
| 112 | + // Use a for loop here to set the ube colors |
| 113 | + for (BaseCube cube : model.baseCubes) { |
| 114 | + double d = Math.abs(dist(cube.x,cube.z)-speedParam.getValuef()*(total_ms%field_len-field_len/2)/10); |
| 115 | + if (d<wave_width.getValuef()) { |
| 116 | + //float d = (float)(50.0*(Math.sin(dist(cube.x,cube.z)/(wave_width.getValuef()) + speedParam.getValuef()*total_ms/1000.0)+1.0)); |
| 117 | + colors[cube.index] = lx.hsb( hue.getValuef() , 100, (float)((1.0-d/wave_width.getValuef())*100.0 )); |
| 118 | + } else { |
| 119 | + colors[cube.index] = lx.hsb( hue.getValuef() , 100, 0); |
| 120 | + } |
| 121 | + } |
| 122 | + } |
| 123 | +} |
| 124 | + |
| 125 | +class WaveScan extends TSPattern { |
| 126 | + // Variable Declarations go here |
| 127 | + private float waveWidth = 1; |
| 128 | + private float speedMult = 1000; |
| 129 | + |
| 130 | + private float nx = 0; |
| 131 | + private float nz = 0; |
| 132 | + private float n = 0; |
| 133 | + private double total_ms =0.0; |
| 134 | + final BasicParameter speedParam = new BasicParameter("Speed", 5, 20, .01); |
| 135 | + final BasicParameter waveSlope = new BasicParameter("waveSlope", 360, 1, 720); |
| 136 | + final BasicParameter theta = new BasicParameter("theta", 45, 0, 360); |
| 137 | + final BasicParameter hue = new BasicParameter("hue", 45, 0, 360); |
| 138 | + final BasicParameter wave_width = new BasicParameter("waveWidth", 20, 1, 50); |
| 139 | + final SawLFO wave360 = new SawLFO(0, 360, speedParam.getValuef() * speedMult); |
| 140 | + final SinLFO wave100 = new SinLFO(0, 100, speedParam.getValuef() * speedMult); |
| 141 | + |
| 142 | + WaveScan(LX lx) { |
| 143 | + super(lx); |
| 144 | + addModulator(wave360).start(); |
| 145 | + addModulator(wave100).start(); |
| 146 | + addParameter(waveSlope); |
| 147 | + addParameter(speedParam); |
| 148 | + addParameter(theta); |
| 149 | + addParameter(hue); |
| 150 | + addParameter(wave_width); |
| 151 | + |
| 152 | + |
| 153 | + } |
| 154 | + private float dist(float x, float z) { |
| 155 | + return (nx*x+nz*z)/n; |
| 156 | + } |
| 157 | + // This is the pattern loop, which will run continuously via LX |
| 158 | + public void run(double deltaMs) { |
| 159 | + float theta_rad = (float)Math.toRadians((int)theta.getValuef()); |
| 160 | + nx = (float)Math.sin(theta_rad); |
| 161 | + nz = (float)Math.cos(theta_rad); |
| 162 | + n = (float)Math.sqrt(Math.pow(nx,2)+Math.pow(nz,2)); |
| 163 | + wave360.setPeriod(speedParam.getValuef() * speedMult); |
| 164 | + wave100.setPeriod(speedParam.getValuef() * speedMult); |
| 165 | + total_ms+=deltaMs; |
| 166 | + // Use a for loop here to set the ube colors |
| 167 | + for (BaseCube cube : model.baseCubes) { |
| 168 | + float d = (float)(50.0*(Math.sin(dist(cube.x,cube.z)/(wave_width.getValuef()) + speedParam.getValuef()*total_ms/1000.0)+1.0)); |
| 169 | + colors[cube.index] = lx.hsb( hue.getValuef() , 100, d); |
| 170 | + } |
| 171 | + } |
| 172 | +} |
| 173 | + |
| 174 | +class RainbowWaveScan extends TSPattern { |
| 175 | + // Variable Declarations go here |
| 176 | + private float waveWidth = 1; |
| 177 | + private float speedMult = 1000; |
| 178 | + |
| 179 | + private float nx = 0; |
| 180 | + private float nz = 0; |
| 181 | + private float n = 0; |
| 182 | + private double total_ms =0.0; |
| 183 | + final BasicParameter speedParam = new BasicParameter("Speed", 5, 20, .01); |
| 184 | + final BasicParameter waveSlope = new BasicParameter("waveSlope", 360, 1, 720); |
| 185 | + final BasicParameter theta = new BasicParameter("theta", 45, 0, 360); |
| 186 | + final BasicParameter hue = new BasicParameter("hue", 45, 0, 360); |
| 187 | + final BasicParameter wave_width = new BasicParameter("waveWidth", 20, 1, 50); |
| 188 | + final SawLFO wave360 = new SawLFO(0, 360, speedParam.getValuef() * speedMult); |
| 189 | + final SinLFO wave100 = new SinLFO(0, 100, speedParam.getValuef() * speedMult); |
| 190 | + |
| 191 | + RainbowWaveScan(LX lx) { |
| 192 | + super(lx); |
| 193 | + addModulator(wave360).start(); |
| 194 | + addModulator(wave100).start(); |
| 195 | + addParameter(waveSlope); |
| 196 | + addParameter(speedParam); |
| 197 | + addParameter(theta); |
| 198 | + addParameter(hue); |
| 199 | + addParameter(wave_width); |
| 200 | + |
| 201 | + |
| 202 | + } |
| 203 | + private float dist(float x, float z) { |
| 204 | + return (nx*x+nz*z)/n; |
| 205 | + } |
| 206 | + // This is the pattern loop, which will run continuously via LX |
| 207 | + public void run(double deltaMs) { |
| 208 | + float theta_rad = (float)Math.toRadians((int)theta.getValuef()); |
| 209 | + nx = (float)Math.sin(theta_rad); |
| 210 | + nz = (float)Math.cos(theta_rad); |
| 211 | + n = (float)Math.sqrt(Math.pow(nx,2)+Math.pow(nz,2)); |
| 212 | + wave360.setPeriod(speedParam.getValuef() * speedMult); |
| 213 | + wave100.setPeriod(speedParam.getValuef() * speedMult); |
| 214 | + total_ms+=deltaMs; |
| 215 | + // Use a for loop here to set the ube colors |
| 216 | + for (BaseCube cube : model.baseCubes) { |
| 217 | + float d = (float)(50.0*(Math.sin(dist(cube.x,cube.z)/(wave_width.getValuef()) + speedParam.getValuef()*total_ms/1000.0)+1.0)); |
| 218 | + colors[cube.index] = lx.hsb( wave360.getValuef() , 100, d); |
| 219 | + } |
| 220 | + } |
| 221 | +} |
| 222 | + |
| 223 | + |
| 224 | + |
| 225 | + |
| 226 | +/** |
| 227 | +* A template pattern to get ya started. |
| 228 | +*/ |
| 229 | +/* |
| 230 | +class PatternTemplate extends TSPattern { |
| 231 | +
|
| 232 | + // Variable declarations, parameters, and modulators go here |
| 233 | + float minValue; |
| 234 | + float maxValue; |
| 235 | + float startValue; |
| 236 | + float period; |
| 237 | + final BasicParameter parameterName = new BasicParameter("parameterName", startValue, minValue, maxValue); |
| 238 | + final SawLFO modulatorName = new SawLFO(minValue, maxValue, period); |
| 239 | +
|
| 240 | + // Constructor |
| 241 | + PatternTemplate(LX lx) { |
| 242 | + super(lx); |
| 243 | +
|
| 244 | + // Add any needed modulators or parameters here |
| 245 | + addModulator(modulatorName).start(); |
| 246 | + addParameter(parameterName); |
| 247 | +
|
| 248 | + } |
| 249 | +
|
| 250 | +
|
| 251 | + // This is the pattern loop, which will run continuously via LX |
| 252 | + public void run(double deltaMs) { |
| 253 | +
|
| 254 | + // Use a for loop here to set the cube colors |
| 255 | + for (BaseCube cube : model.baseCubes) { |
| 256 | + colors[cube.index] = lx.hsb( , , ); |
| 257 | + } |
| 258 | + } |
| 259 | +} |
| 260 | +*/ |
0 commit comments