Commit | Line | Data |
---|---|---|
7d60f6f6 | 1 | |
610db5fe | 2 | class SineSphere extends APat { |
251dcf21 | 3 | float modelrad = sqrt((model.xMax)*(model.xMax) + (model.yMax)*(model.yMax) + (model.zMax)*(model.zMax)); |
e88f9c30 | 4 | private BasicParameter yrotspeed = new BasicParameter("yspeed", 3000, 1, 10000); |
251dcf21 | 5 | private BasicParameter yrot2speed = new BasicParameter("y2speed", 4000, 1, 15000); |
e88f9c30 | 6 | private BasicParameter yrot3speed = new BasicParameter("y3speed", 1400, 1, 15000); |
251dcf21 | 7 | private BasicParameter vibrationrate = new BasicParameter("vib", 3000, 1, 10000); |
e88f9c30 AG |
8 | private SawLFO yrot = new SawLFO(0, TWO_PI, yrotspeed); |
9 | private SawLFO yrot2 = new SawLFO(0, -TWO_PI, yrot2speed); | |
10 | private SawLFO yrot3 = new SawLFO(0, -TWO_PI, yrot3speed); | |
610db5fe | 11 | public BasicParameter huespread = new BasicParameter("Hue", 0, 180); |
251dcf21 AG |
12 | public BasicParameter widthparameter= new BasicParameter("Width", 20, 1, 60); |
13 | public BasicParameter vibration_magnitude = new BasicParameter("Vmag", 20, 2, modelrad/2); | |
14 | public BasicParameter scale = new BasicParameter("Scale", 1, .1, 5); | |
45717f71 | 15 | private int pitch = 0; |
16 | private int channel = 0; | |
17 | private int velocity = 0; | |
18 | private int cur = 0; | |
19 | public final LXProjection sinespin; | |
09437b3e | 20 | public final LXProjection sinespin2; |
1a92d73a | 21 | public final LXProjection sinespin3; |
251dcf21 | 22 | |
45717f71 | 23 | Pick Galaxy, STime; |
09437b3e | 24 | |
09437b3e AG |
25 | public BasicParameter rotationx = new BasicParameter("rotx", 0, 0, 1 ); |
26 | public BasicParameter rotationy = new BasicParameter("roty", 1, 0, 1); | |
27 | public BasicParameter rotationz = new BasicParameter("rotz", 0, 0, 1); | |
28 | ||
7974acd6 | 29 | public final PVector P = new PVector(); |
a9aad043 | 30 | |
0b1785e3 | 31 | class Sphery { |
a9aad043 | 32 | float f1xcenter, f1ycenter, f1zcenter, f2xcenter , f2ycenter, f2zcenter; //second three are for an ellipse with two foci |
45717f71 | 33 | private SinLFO vibration; |
34 | private SinLFO surfacewave; | |
251dcf21 | 35 | |
a9aad043 AG |
36 | private SinLFO xbounce; |
37 | public SinLFO ybounce; | |
38 | private SinLFO zbounce; | |
610db5fe | 39 | float vibration_magnitude, vperiod, radius, vibration_min, vibration_max; |
1c44211b AG |
40 | |
41 | //public BasicParameter huespread; | |
a9aad043 AG |
42 | public BasicParameter bouncerate; |
43 | public BasicParameter bounceamp; | |
a62bf8ad | 44 | public BasicParameter vibrationrate; |
8f4e6c99 | 45 | public final PVector circlecenter; |
a9aad043 | 46 | |
45717f71 | 47 | public Sphery(float f1xcenter, float f1ycenter, float f1zcenter, float radius, float vibration_magnitude , float vperiod) |
a9aad043 | 48 | { |
0b1785e3 AG |
49 | this.f1xcenter = f1xcenter; |
50 | this.f1ycenter = f1ycenter; | |
51 | this.f1zcenter = f1zcenter; | |
45717f71 | 52 | this.radius = radius; |
8f4e6c99 | 53 | this.circlecenter= new PVector(f1xcenter,f1ycenter,f1zcenter); |
251dcf21 AG |
54 | |
55 | this.vibration_magnitude = vibration_magnitude; | |
56 | ||
0b1785e3 | 57 | this.vperiod = vperiod; |
1d414e45 | 58 | //addParameter(bounceamp = new BasicParameter("Amp", .5)); |
45717f71 | 59 | //addParameter(bouncerate = new BasicParameter("Rate", .5)); //ybounce.modulateDurationBy(bouncerate); |
e3da2932 | 60 | //addParameter(vibrationrate = new BasicParameter("vibration", 1000, 10000)); |
1c44211b | 61 | //addParameter(widthparameter = new BasicParameter("Width", .2)); |
45717f71 | 62 | //addModulator(xbounce = new SinLFO(model.xMax/3, 2*model.yMax/3, 2000)).trigger(); |
df18145f | 63 | addModulator(ybounce= new SinLFO(model.yMax/3, 2*model.yMax/3, 240000)).trigger(); //bounce.modulateDurationBy |
a9aad043 AG |
64 | |
65 | //addModulator(bounceamp); //ybounce.setMagnitude(bouncerate); | |
610db5fe | 66 | addModulator( vibration = new SinLFO( this.radius - vibration_magnitude , this.radius + vibration_magnitude, vperiod)).trigger(); //vibration.setPeriod(240000/lx.tempo.bpm()); |
251dcf21 | 67 | |
7974acd6 | 68 | |
a9aad043 | 69 | } |
a62bf8ad | 70 | |
45717f71 | 71 | // public Sphery(float f1xcenter, float f1ycenter, float f1zcenter, float vibration_magnitude, float vperiod) |
251dcf21 | 72 | // { |
45717f71 | 73 | // this.f1xcenter = f1xcenter; |
74 | // this.f1ycenter = f1ycenter; | |
75 | // this.f1zcenter = f1zcenter; | |
76 | // this.vibration_magnitude = vibration_magnitude; | |
251dcf21 | 77 | // this.vperiod = vperiod; |
45717f71 | 78 | // addModulator(ybounce= new SinLFO(model.yMax/3, 2*model.yMax/3, 240000)).trigger(); //bounce.modulateDurationBy |
79 | // addModulator( vibration = new SinLFO( modelrad/10 - vibration_magnitude , modelrad/10 + vibration_magnitude, vperiod)).trigger(); //vibration.setPeriod(240000/lx.tempo.bpm()); | |
251dcf21 AG |
80 | |
81 | // } | |
82 | ||
a62bf8ad | 83 | //for an ellipse |
45717f71 | 84 | // public Sphery(float f1xcenter, float f1ycenter, float f1zcenter, float f2xcenter, float f2ycenter, float f2zcenter, |
85 | // float vibration_min, float vibration_max, float vperiod) | |
38712136 | 86 | |
45717f71 | 87 | // { |
88 | // this.f1xcenter = f1xcenter; | |
89 | // this.f1ycenter = f1ycenter; | |
90 | // this.f1zcenter = f1zcenter; | |
91 | // this.f2xcenter = f2xcenter; | |
92 | // this.f2ycenter = f2ycenter; | |
93 | // this.f2zcenter = f2zcenter; | |
94 | // this.vibration_min = vibration_min; | |
95 | // this.vibration_max = vibration_max; | |
96 | // this.vperiod = vperiod; | |
97 | // //addModulator(xbounce = new SinLFO(model.xMax/3, 2*model.yMax/3, 2000)).trigger(); | |
98 | // addModulator(ybounce).trigger(); | |
99 | // addModulator( vibration = new SinLFO(vibration_min , vibration_max, lx.tempo.rampf())).trigger(); //vibration.modulateDurationBy(vx); | |
100 | // addParameter(widthparameter = new BasicParameter("Width", .1)); | |
101 | // //addParameter(huespread = new BasicParameter("bonk", .2)); | |
a9aad043 | 102 | |
1c44211b AG |
103 | // } |
104 | ||
45717f71 | 105 | public int c1c (float a) { return round(100*constrain(a,0,1)); } |
a9aad043 | 106 | |
e3da2932 | 107 | void setVibrationPeriod(double period){ |
45717f71 | 108 | // to-do: make this conditional upon time signature |
a9aad043 | 109 | |
1a92d73a | 110 | this.vibration.setPeriod(period); |
e3da2932 | 111 | } |
a9aad043 | 112 | |
251dcf21 AG |
113 | void setVibrationMagnitude(double mag){ |
114 | //to-do: make this optionally conditional upon decibel volume, frequency spectrum) | |
115 | this.vibration.setRange(-mag,mag); | |
116 | ||
117 | } | |
118 | ||
a9aad043 | 119 | |
45717f71 | 120 | float distfromcirclecenter(float px, float py, float pz, float f1x, float f1y, float f1z) |
a9aad043 | 121 | { |
0b1785e3 AG |
122 | return dist(px, py, pz, f1x, f1y, f1z); |
123 | } | |
c2f643bd | 124 | //void updatespherey(deltaMs, ) |
55a56424 | 125 | |
e0cfbe20 | 126 | float quadrant(PVector q) { |
45717f71 | 127 | float qtheta = atan2( (q.x-f1xcenter) , (q.z - f1zcenter) ); |
128 | float qphi = acos( (q.z-f1zcenter)/(PVector.dist(q,circlecenter)) ); | |
7b2faded | 129 | |
a62bf8ad | 130 | |
610db5fe | 131 | return map(qtheta, -PI/2, PI/2, 200-huespread.getValuef(), 240+huespread.getValuef()); |
e0cfbe20 | 132 | //if (q.x > f1xcenter ) {return 140 ;} |
45717f71 | 133 | //else {return 250;} |
55a56424 | 134 | } |
570ba27d AG |
135 | |
136 | // float noisesat(PVector q) { | |
137 | ||
138 | ||
45717f71 | 139 | // return noise() |
570ba27d AG |
140 | |
141 | // } | |
1a92d73a | 142 | color spheryvalue (PVector p) { |
45717f71 | 143 | circlecenter.set(this.f1xcenter, this.f1ycenter, this.f1zcenter); |
7974acd6 | 144 | |
a62bf8ad | 145 | |
45717f71 | 146 | //switch(sShpape.cur() ) {} |
7974acd6 | 147 | |
251dcf21 AG |
148 | float b = max(0, 100 - widthparameter.getValuef()*abs(p.dist(circlecenter) |
149 | - vibration.getValuef()) ); | |
7974acd6 MS |
150 | |
151 | if (b <= 0) { | |
152 | return 0; | |
153 | } | |
154 | ||
155 | return lx.hsb( | |
a62bf8ad | 156 | constrain(quadrant(p), 0, 360), |
251dcf21 AG |
157 | // constrain(100*noise(quadrant(p)), 0, 100), |
158 | 100, | |
159 | b | |
45717f71 | 160 | ); |
0b1785e3 | 161 | } |
a9aad043 AG |
162 | color ellipsevalue(float px, float py, float pz , float f1xc, float f1yc, float f1zc, float f2xc, float f2yc, float f2zc) |
163 | { | |
45717f71 | 164 | //switch(sShpape.cur() ) {} |
165 | return lx.hsb(huespread.getValuef()*5*px, dist(model.xMax-px, model.yMax-py, model.zMax-pz, f1xc, f1yc, f1zc) , | |
a9aad043 | 166 | max(0, 100 - 100*widthparameter.getValuef() * |
45717f71 | 167 | abs( (dist(px, py, pz, f1xc, ybounce.getValuef(), f1zc) + |
168 | (dist(px, py , pz, f2xc, ybounce.getValuef(), f2zc) ) )/2 | |
169 | - 1.2*vibration.getValuef() ) ) ) ; | |
0b1785e3 | 170 | } |
a9aad043 | 171 | |
0b1785e3 | 172 | |
45717f71 | 173 | } |
a9aad043 | 174 | |
8f4e6c99 AG |
175 | boolean noteOn(Note note) { |
176 | int row = note.getPitch(), col = note.getChannel(); | |
45717f71 | 177 | // if (row == 57) {KeyPressed = col; return true; } |
8f4e6c99 AG |
178 | return super.noteOn(note); |
179 | } | |
1c44211b | 180 | |
a9aad043 | 181 | |
45717f71 | 182 | // public boolean noteOn(Note note) { |
183 | // pitch= note.getPitch(); | |
8f4e6c99 AG |
184 | // velocity=note.getVelocity(); |
185 | // channel=note.getChannel(); | |
186 | // return true; | |
187 | // } | |
188 | ||
189 | // public boolean gridPressed(int row, int col) { | |
45717f71 | 190 | // pitch = row; channel = col; |
191 | // cur = NumApcCols*(pitch-53)+col; | |
192 | // //setState(row, col, 0 ? 1 : 0); | |
8f4e6c99 AG |
193 | // return true; |
194 | // } | |
df18145f AG |
195 | |
196 | //public grid | |
0b1785e3 | 197 | final Sphery[] spherys; |
1d414e45 | 198 | |
45717f71 | 199 | SineSphere(LX lx) |
a9aad043 | 200 | { |
dde75983 | 201 | super(lx); |
45717f71 | 202 | println("modelrad " + modelrad); |
9fa29818 | 203 | sinespin = new LXProjection(model); |
09437b3e | 204 | sinespin2 = new LXProjection(model); |
1a92d73a | 205 | sinespin3= new LXProjection(model); |
1c44211b | 206 | addParameter(huespread); |
1a92d73a | 207 | addParameter(vibrationrate); |
251dcf21 | 208 | addParameter(widthparameter); |
e3da2932 AG |
209 | addParameter(rotationx); |
210 | addParameter(rotationy); | |
211 | addParameter(rotationz); | |
1a92d73a AG |
212 | addParameter(yrotspeed); |
213 | addParameter(yrot2speed); | |
214 | addParameter(yrot3speed); | |
251dcf21 AG |
215 | addParameter(vibration_magnitude); |
216 | addParameter(scale); | |
d8239019 | 217 | addModulator(yrot).trigger(); |
45717f71 | 218 | addModulator(yrot2).trigger(); |
1a92d73a | 219 | addModulator(yrot3).trigger(); |
8f4e6c99 AG |
220 | //Galaxy = addPick("Galaxy", 1, 3, new String[] {"home", "vertical","single","aquarium"}); |
221 | STime =addPick("Time", 1, 4, new String[]{"half", "triplet", "beat", "2x", "3x" }); | |
e3da2932 | 222 | |
a9aad043 | 223 | spherys = new Sphery[] { |
610db5fe AG |
224 | new Sphery(model.xMax/4, model.yMax/2, model.zMax/2, modelrad/12, modelrad/25, 3000), |
225 | new Sphery(.75*model.xMax, model.yMax/2, model.zMax/2, modelrad/14, modelrad/28, 2000), | |
45717f71 | 226 | new Sphery(model.cx, model.cy, model.cz, modelrad/5, modelrad/15, 2300), |
610db5fe AG |
227 | new Sphery(.7*model.xMax, .65*model.yMax, .5*model.zMax, modelrad/11, modelrad/25, 3500), |
228 | new Sphery(.75*model.xMax, .8*model.yMax, .7*model.zMax, modelrad/12, modelrad/30, 2000) | |
229 | ||
45717f71 | 230 | |
231 | }; | |
0b1785e3 AG |
232 | } |
233 | ||
a9aad043 AG |
234 | // public void onParameterChanged(LXParameter parameter) |
235 | // { | |
e28f168c | 236 | |
e28f168c | 237 | |
45717f71 | 238 | // for (Sphery s : spherys) { |
239 | // if (s == null) continue; | |
240 | // double bampv = s.bounceamp.getValue(); | |
241 | // double brv = s.bouncerate.getValue(); | |
242 | // double tempobounce = lx.tempo.bpm(); | |
243 | // if (parameter == s.bounceamp) | |
244 | // { | |
245 | // s.ybounce.setRange(bampv*model.yMax/3 , bampv*2*model.yMax/3, brv); | |
246 | // } | |
247 | // else if ( parameter == s.bouncerate ) | |
248 | // { | |
249 | // s.ybounce.setDuration(120000./tempobounce); | |
250 | // } | |
251 | // } | |
252 | // } | |
e28f168c | 253 | |
1d414e45 | 254 | public void run( double deltaMs) { |
45717f71 | 255 | float t = lx.tempo.rampf(); |
1a92d73a | 256 | float bpm = lx.tempo.bpmf(); |
251dcf21 | 257 | float scalevalue = scale.getValuef(); |
8f4e6c99 AG |
258 | int spherytime= STime.Cur(); |
259 | ||
df18145f | 260 | |
8f4e6c99 | 261 | switch (spherytime) { |
1a92d73a | 262 | |
45717f71 | 263 | case 0: t = map(.5*t ,0,.5, 0,1); bpm = .5*bpm; break; |
df18145f | 264 | |
45717f71 | 265 | case 1: t = t; bpm = bpm; break; |
1c44211b | 266 | |
45717f71 | 267 | case 2: t = map(2*t,0,2,0,1); bpm = 2*bpm; break; |
1c44211b | 268 | |
45717f71 | 269 | default: t= t; bpm = bpm; |
8f4e6c99 | 270 | } |
1c44211b | 271 | |
1a92d73a | 272 | //switch(sphery.colorscheme) |
df18145f | 273 | |
1c44211b | 274 | for ( Sphery s: spherys){ |
1a92d73a | 275 | s.setVibrationPeriod(vibrationrate.getValuef()); |
45717f71 | 276 | // s.setVibrationMagnitude(vibration_magnitude.getValuef()); |
df18145f | 277 | |
1c44211b | 278 | } |
1a92d73a AG |
279 | |
280 | ||
281 | sinespin.reset() | |
45717f71 | 282 | // Translate so the center of the car is the origin, offset |
09437b3e | 283 | .center() |
251dcf21 | 284 | .scale(scalevalue, scalevalue, scalevalue) |
1d414e45 | 285 | // Rotate around the origin (now the center of the car) about an y-vector |
e3da2932 | 286 | .rotate(yrot.getValuef(), rotationx.getValuef(), rotationy.getValuef() , rotationz.getValuef()) |
38712136 | 287 | .translate(model.cx, model.cy, model.cz); |
1d414e45 | 288 | |
d8239019 | 289 | |
e0cfbe20 | 290 | |
1d414e45 | 291 | |
d8239019 | 292 | |
09437b3e | 293 | for (LXVector p: sinespin) |
1a92d73a | 294 | // for (Point p: model.points) |
1d414e45 | 295 | { |
7974acd6 MS |
296 | P.set(p.x, p.y, p.z); |
297 | // PVector P = new PVector(p.x, p.y, p.z); | |
298 | color c = #000000; | |
1a92d73a AG |
299 | c = blendIfColor(c, spherys[1].spheryvalue(P), ADD); |
300 | c = blendIfColor(c, spherys[0].spheryvalue(P), ADD); | |
301 | c = blendIfColor(c, spherys[2].spheryvalue(P),ADD); | |
e0cfbe20 | 302 | |
d8239019 | 303 | |
7974acd6 | 304 | colors[p.index] = c; |
e0cfbe20 | 305 | |
d8239019 | 306 | |
e0cfbe20 | 307 | } |
09437b3e AG |
308 | sinespin2.reset() |
309 | .center() | |
251dcf21 | 310 | .scale(scalevalue,scalevalue,scalevalue) |
1a92d73a | 311 | .rotate(yrot2.getValuef(), rotationx.getValuef(), rotationy.getValuef() , rotationz.getValuef()) |
09437b3e | 312 | .translate(model.cx,model.cy,model.cz); |
e0cfbe20 | 313 | |
09437b3e | 314 | for (LXVector p: sinespin2) |
45717f71 | 315 | { color c = 0; |
7974acd6 MS |
316 | // PVector P = new PVector(p.x, p.y, p.z); |
317 | P.set(p.x, p.y, p.z); | |
1a92d73a | 318 | c = blendIfColor(c, spherys[3].spheryvalue(P),ADD); |
7b2faded | 319 | |
7974acd6 | 320 | colors[p.index] = blendIfColor(colors[p.index], c , ADD); |
e0cfbe20 | 321 | |
45717f71 | 322 | } |
1a92d73a AG |
323 | sinespin3.reset() |
324 | .center() | |
251dcf21 | 325 | .scale(scalevalue,scalevalue,scalevalue) |
e88f9c30 | 326 | .rotate(yrot3.getValuef(),-1 + rotationx.getValuef(), rotationy.getValuef(), rotationz.getValuef()) |
1a92d73a AG |
327 | .translate(model.cx, model.cy, model.cz); |
328 | for (LXVector p: sinespin3) | |
45717f71 | 329 | { color c = 0; |
1a92d73a AG |
330 | // PVector P = new PVector(p.x, p.y, p.z); |
331 | P.set(p.x, p.y, p.z); | |
332 | c = blendIfColor(c, spherys[4].spheryvalue(P),ADD); | |
333 | ||
334 | colors[p.index] = blendIfColor(colors[p.index], c , ADD); | |
335 | ||
336 | } | |
337 | ||
338 | ||
e0cfbe20 | 339 | |
610db5fe AG |
340 | |
341 | ||
342 | ||
343 | ||
7974acd6 MS |
344 | } |
345 | ||
346 | color blendIfColor(color c1, color c2, int mode) { | |
347 | if (c2 != 0) { | |
348 | return blendColor(c1, c2, mode); | |
349 | } | |
350 | return c1; | |
a9aad043 | 351 | } |
e27a8652 | 352 | |
a9aad043 | 353 | |
45717f71 | 354 | // color c = 0; |
355 | // c = blendColor(c, spherys[3].ellipsevalue(Px.x, Px.y, Px.z, model.xMax/4, model.yMax/4, model.zMax/4, 3*model.xMax/4, 3*model.yMax/4, 3*model.zMax/4),ADD); | |
356 | // return c; | |
a9aad043 | 357 | // } |
a41f334c | 358 | // return lx.hsb(0,0,0); |
45717f71 | 359 | // // else if(spheremode ==2) |
a9aad043 | 360 | // { color c = 0; |
45717f71 | 361 | // return lx.hsb(CalcCone( (xyz by = new xyz(0,spherys[2].ybounce.getValuef(),0) ), Px, mid) ); |
a9aad043 AG |
362 | |
363 | // } | |
364 | ||
365 | ||
45717f71 | 366 | // } |
a9aad043 AG |
367 | |
368 | } | |
8f4e6c99 | 369 | /*This just takes all of Dan Horwitz's code that I want to inherit and leaves the rest behind. |
45717f71 | 370 | A work in progress. */ |
a9aad043 | 371 | |
610db5fe | 372 | public class APat extends SCPattern |
8f4e6c99 AG |
373 | |
374 | ||
610db5fe | 375 | { |
45717f71 | 376 | ArrayList<Pick> picks = new ArrayList<Pick> (); |
377 | ArrayList<DBool> bools = new ArrayList<DBool> (); | |
378 | ||
379 | PVector mMax, mCtr, mHalf; | |
380 | ||
381 | MidiOutput APCOut; | |
382 | int nMaxRow = 53; | |
383 | float LastJog = -1; | |
384 | float[] xWaveNz, yWaveNz; | |
385 | int nPoint , nPoints; | |
386 | PVector xyzJog = new PVector(), modmin; | |
387 | ||
388 | float NoiseMove = random(10000); | |
389 | BasicParameter pSpark, pWave, pRotX, pRotY, pRotZ, pSpin, pTransX, pTransY; | |
390 | DBool pXsym, pYsym, pRsym, pXdup, pXtrip, pJog, pGrey; | |
391 | ||
392 | float lxh () { return lx.getBaseHuef(); } | |
393 | int c1c (float a) { return round(100*constrain(a,0,1)); } | |
394 | float interpWv(float i, float[] vals) { return interp(i-floor(i), vals[floor(i)], vals[ceil(i)]); } | |
395 | void setNorm (PVector vec) { vec.set(vec.x/mMax.x, vec.y/mMax.y, vec.z/mMax.z); } | |
396 | void setRand (PVector vec) { vec.set(random(mMax.x), random(mMax.y), random(mMax.z)); } | |
397 | void setVec (PVector vec, LXPoint p) { vec.set(p.x, p.y, p.z); } | |
398 | void interpolate(float i, PVector a, PVector b) { a.set(interp(i,a.x,b.x), interp(i,a.y,b.y), interp(i,a.z,b.z)); } | |
399 | void StartRun(double deltaMs) { } | |
400 | float val (BasicParameter p) { return p.getValuef(); } | |
401 | color CalcPoint(PVector p) { return lx.hsb(0,0,0); } | |
402 | color blend3(color c1, color c2, color c3) { return blendColor(c1,blendColor(c2,c3,ADD),ADD); } | |
403 | ||
404 | void rotateZ (PVector p, PVector o, float nSin, float nCos) { p.set( nCos*(p.x-o.x) - nSin*(p.y-o.y) + o.x , nSin*(p.x-o.x) + nCos*(p.y-o.y) + o.y,p.z); } | |
405 | void rotateX (PVector p, PVector o, float nSin, float nCos) { p.set(p.x,nCos*(p.y-o.y) - nSin*(p.z-o.z) + o.y , nSin*(p.y-o.y) + nCos*(p.z-o.z) + o.z ); } | |
406 | void rotateY (PVector p, PVector o, float nSin, float nCos) { p.set( nSin*(p.z-o.z) + nCos*(p.x-o.x) + o.x,p.y, nCos*(p.z-o.z) - nSin*(p.x-o.x) + o.z ); } | |
407 | ||
408 | BasicParameter addParam(String label, double value) { BasicParameter p = new BasicParameter(label, value); addParameter(p); return p; } | |
409 | ||
410 | PVector vT1 = new PVector(), vT2 = new PVector(); | |
411 | float calcCone (PVector v1, PVector v2, PVector c) { vT1.set(v1); vT2.set(v2); vT1.sub(c); vT2.sub(c); | |
610db5fe AG |
412 | return degrees(PVector.angleBetween(vT1,vT2)); } |
413 | ||
45717f71 | 414 | Pick addPick(String name, int def, int _max, String[] desc) { |
415 | Pick P = new Pick(name, def, _max+1, nMaxRow, desc); | |
416 | nMaxRow = P.EndRow + 1; | |
610db5fe AG |
417 | picks.add(P); |
418 | return P; | |
419 | } | |
420 | ||
45717f71 | 421 | boolean noteOff(Note note) { |
610db5fe AG |
422 | int row = note.getPitch(), col = note.getChannel(); |
423 | for (int i=0; i<bools.size(); i++) if (bools.get(i).set(row, col, false)) { presetManager.dirty(this); return true; } | |
424 | updateLights(); return false; | |
425 | } | |
426 | ||
45717f71 | 427 | boolean noteOn(Note note) { |
610db5fe | 428 | int row = note.getPitch(), col = note.getChannel(); |
45717f71 | 429 | for (int i=0; i<picks.size(); i++) if (picks.get(i).set(row, col)) { presetManager.dirty(this); return true; } |
430 | for (int i=0; i<bools.size(); i++) if (bools.get(i).set(row, col, true)) { presetManager.dirty(this); return true; } | |
431 | println("row: " + row + " col: " + col); return false; | |
610db5fe AG |
432 | } |
433 | ||
45717f71 | 434 | void onInactive() { uiDebugText.setText(""); } |
435 | void onReset() { | |
610db5fe AG |
436 | for (int i=0; i<bools .size(); i++) bools.get(i).reset(); |
437 | for (int i=0; i<picks .size(); i++) picks.get(i).reset(); | |
45717f71 | 438 | presetManager.dirty(this); |
439 | updateLights(); | |
610db5fe AG |
440 | } |
441 | ||
21dffb1b MS |
442 | APat(LX lx) { |
443 | super(lx); | |
610db5fe AG |
444 | |
445 | ||
446 | ||
45717f71 | 447 | nPoints = model.points.size(); |
448 | pXsym = new DBool("X-SYM", false, 48, 0); bools.add(pXsym ); | |
449 | pYsym = new DBool("Y-SYM", false, 48, 1); bools.add(pYsym ); | |
450 | pRsym = new DBool("R-SYM", false, 48, 2); bools.add(pRsym ); | |
451 | pXdup = new DBool("X-DUP", false, 48, 3); bools.add(pXdup ); | |
452 | pJog = new DBool("JOG" , false, 48, 4); bools.add(pJog ); | |
453 | pGrey = new DBool("GREY" , false, 48, 5); bools.add(pGrey ); | |
454 | ||
455 | modmin = new PVector(model.xMin, model.yMin, model.zMin); | |
456 | mMax = new PVector(model.xMax, model.yMax, model.zMax); mMax.sub(modmin); | |
457 | mCtr = new PVector(); mCtr.set(mMax); mCtr.mult(.5); | |
458 | mHalf = new PVector(.5,.5,.5); | |
459 | xWaveNz = new float[ceil(mMax.y)+1]; | |
460 | yWaveNz = new float[ceil(mMax.x)+1]; | |
461 | ||
462 | //println (model.xMin + " " + model.yMin + " " + model.zMin); | |
463 | //println (model.xMax + " " + model.yMax + " " + model.zMax); | |
610db5fe AG |
464 | //for (MidiOutputDevice o: RWMidi.getOutputDevices()) { if (o.toString().contains("APC")) { APCOut = o.createOutput(); break;}} |
465 | } | |
466 | ||
467 | float spin() { | |
468 | float raw = val(pSpin); | |
469 | if (raw <= 0.45) { | |
470 | return raw + 0.05; | |
471 | } else if (raw >= 0.55) { | |
472 | return raw - 0.05; | |
473 | } | |
474 | return 0.5; | |
475 | } | |
476 | ||
477 | void setAPCOutput(MidiOutput output) { | |
478 | APCOut = output; | |
479 | } | |
480 | ||
481 | void updateLights() { if (APCOut == null) return; | |
45717f71 | 482 | for (int i = 0; i < NumApcRows; ++i) |
483 | for (int j = 0; j < 8; ++j) APCOut.sendNoteOn(j, 53+i, 0); | |
484 | for (int i=0; i<picks .size(); i++) APCOut.sendNoteOn(picks.get(i).CurCol, picks.get(i).CurRow, 3); | |
485 | for (int i=0; i<bools .size(); i++) if (bools.get(i).b) APCOut.sendNoteOn (bools.get(i).col, bools.get(i).row, 1); | |
486 | else APCOut.sendNoteOff (bools.get(i).col, bools.get(i).row, 0); | |
610db5fe AG |
487 | } |
488 | ||
489 | void run(double deltaMs) | |
490 | { | |
491 | if (deltaMs > 100) return; | |
492 | ||
493 | if (this == midiEngine.getFocusedDeck().getActivePattern()) { | |
494 | String Text1="", Text2=""; | |
45717f71 | 495 | for (int i=0; i<bools.size(); i++) if (bools.get(i).b) Text1 += " " + bools.get(i).tag + " "; |
496 | for (int i=0; i<picks.size(); i++) Text1 += picks.get(i).tag + ": " + picks.get(i).CurDesc() + " "; | |
610db5fe AG |
497 | uiDebugText.setText(Text1, Text2); |
498 | } | |
499 | ||
45717f71 | 500 | NoiseMove += deltaMs; NoiseMove = NoiseMove % 1e7; |
501 | StartRun (deltaMs); | |
502 | PVector P = new PVector(), tP = new PVector(), pSave = new PVector(); | |
503 | PVector pTrans = new PVector(val(pTransX)*200-100, val(pTransY)*100-50,0); | |
504 | nPoint = 0; | |
505 | ||
506 | if (pJog.b) { | |
507 | float tRamp = (lx.tempo.rampf() % .25); | |
508 | if (tRamp < LastJog) xyzJog.set(randctr(mMax.x*.2), randctr(mMax.y*.2), randctr(mMax.z*.2)); | |
509 | LastJog = tRamp; | |
510 | } | |
511 | ||
512 | // precalculate this stuff | |
513 | float wvAmp = val(pWave), sprk = val(pSpark); | |
514 | if (wvAmp > 0) { | |
515 | for (int i=0; i<ceil(mMax.x)+1; i++) | |
516 | yWaveNz[i] = wvAmp * (noise(i/(mMax.x*.3)-(2e3+NoiseMove)/1500.) - .5) * (mMax.y/2.); | |
517 | ||
518 | for (int i=0; i<ceil(mMax.y)+1; i++) | |
519 | xWaveNz[i] = wvAmp * (noise(i/(mMax.y*.3)-(1e3+NoiseMove)/1500.) - .5) * (mMax.x/2.); | |
520 | } | |
521 | ||
522 | for (LXPoint p : model.points) { nPoint++; | |
523 | setVec(P,p); | |
524 | P.sub(modmin); | |
525 | P.sub(pTrans); | |
526 | if (sprk > 0) {P.y += sprk*randctr(50); P.x += sprk*randctr(50); P.z += sprk*randctr(50); } | |
527 | if (wvAmp > 0) P.y += interpWv(p.x-modmin.x, yWaveNz); | |
528 | if (wvAmp > 0) P.x += interpWv(p.y-modmin.y, xWaveNz); | |
529 | if (pJog.b) P.add(xyzJog); | |
530 | ||
531 | ||
532 | color cNew, cOld = colors[p.index]; | |
533 | { tP.set(P); cNew = CalcPoint(tP); } | |
534 | if (pXsym.b) { tP.set(mMax.x-P.x,P.y,P.z); cNew = blendColor(cNew, CalcPoint(tP), ADD); } | |
535 | if (pYsym.b) { tP.set(P.x,mMax.y-P.y,P.z); cNew = blendColor(cNew, CalcPoint(tP), ADD); } | |
536 | if (pRsym.b) { tP.set(mMax.x-P.x,mMax.y-P.y,mMax.z-P.z); cNew = blendColor(cNew, CalcPoint(tP), ADD); } | |
537 | if (pXdup.b) { tP.set((P.x+mMax.x*.5)%mMax.x,P.y,P.z); cNew = blendColor(cNew, CalcPoint(tP), ADD); } | |
538 | if (pGrey.b) { cNew = lx.hsb(0, 0, lx.b(cNew)); } | |
539 | colors[p.index] = cNew; | |
540 | } | |
610db5fe AG |
541 | } |
542 | } | |
543 | ||
5bc92bc2 | 544 | class CubeCurl extends SCPattern{ |
b30f14fd AG |
545 | float CH, CW, diag; |
546 | ArrayList<PVector> cubeorigin = new ArrayList<PVector>(); | |
547 | ArrayList<PVector> centerlist = new ArrayList<PVector>(); | |
45717f71 | 548 | private SinLFO curl = new SinLFO(0, Cube.EDGE_HEIGHT, 5000 ); |
5bc92bc2 AG |
549 | |
550 | private SinLFO bg = new SinLFO(180, 220, 3000); | |
551 | ||
dde75983 MS |
552 | CubeCurl(LX lx){ |
553 | super(lx); | |
5bc92bc2 AG |
554 | addModulator(curl).trigger(); |
555 | addModulator(bg).trigger(); | |
7c7625ec AG |
556 | this.CH = Cube.EDGE_HEIGHT; |
557 | this.CW = Cube.EDGE_WIDTH; | |
f1370a0b | 558 | this.diag = sqrt(CW*CW + CW*CW); |
b30f14fd | 559 | |
7c7625ec | 560 | |
b30f14fd | 561 | ArrayList<PVector> centerlistrelative = new ArrayList<PVector>(); |
7c7625ec | 562 | for (int i = 0; i < model.cubes.size(); i++){ |
b30f14fd AG |
563 | Cube a = model.cubes.get(i); |
564 | cubeorigin.add(new PVector(a.x, a.y, a.z)); | |
e0cfbe20 | 565 | centerlist.add(new PVector(a.cx, a.cy, a.cz) ); |
b30f14fd | 566 | |
45717f71 | 567 | } |
5bc92bc2 AG |
568 | |
569 | } | |
7c7625ec | 570 | //there is definitely a better way of doing this! |
45717f71 | 571 | PVector centerofcube(int i) { |
7c7625ec | 572 | Cube c = model.cubes.get(i); |
df18145f | 573 | PVector cubecenter = new PVector(c.cx, c.cy, c.cz); |
f1370a0b | 574 | |
b30f14fd | 575 | return cubecenter; |
7c7625ec AG |
576 | } |
577 | ||
5bc92bc2 AG |
578 | |
579 | void run(double deltaMs){ | |
45717f71 | 580 | for (int i =0; i < model.cubes.size(); i++) { |
5bc92bc2 AG |
581 | Cube c = model.cubes.get(i); |
582 | float cfloor = c.y; | |
45717f71 | 583 | |
f1370a0b | 584 | // if (i%3 == 0){ |
5bc92bc2 | 585 | |
2bb56822 | 586 | // for (LXPoint p : c.points ){ |
45717f71 | 587 | // // colors[p.index]=color(0,0,0); |
588 | // //float dif = (p.y - c.y); | |
589 | // //colors[p.index] = color( bg.getValuef() , 80 , dif < curl.getValuef() ? 80 : 0, ADD); | |
590 | // } | |
591 | // } | |
5bc92bc2 | 592 | |
f1370a0b | 593 | // else if (i%3 == 1) { |
5bc92bc2 | 594 | |
45717f71 | 595 | // for (LXPoint p: c.points){ |
596 | // colors[p.index]=color(0,0,0); | |
597 | // float dif = (p.y - c.y); | |
598 | // // colors[p.index] = | |
599 | // // color(bg.getValuef(), | |
600 | // // map(curl.getValuef(), 0, Cube.EDGE_HEIGHT, 20, 100), | |
601 | // // 100 - 10*abs(dif - curl.getValuef()), ADD ); | |
602 | // } | |
603 | // } | |
f1370a0b | 604 | // else if (i%3 == 2){ |
b30f14fd | 605 | // centerlist[i].sub(cubeorigin(i); |
2bb56822 | 606 | for (LXPoint p: c.points) { |
b30f14fd | 607 | PVector pv = new PVector(p.x, p.y, p.z); |
45717f71 | 608 | colors[p.index] =color( constrain(4* pv.dist(centerlist.get(i)), 0, 360) , 50, 100 ); |
609 | // colors[p.index] =color(constrain(centerlist[i].x, 0, 360), constrain(centerlist[i].y, 0, 100), ); | |
5bc92bc2 AG |
610 | |
611 | ||
b30f14fd | 612 | } |
5bc92bc2 AG |
613 | |
614 | ||
f1370a0b | 615 | //} |
5bc92bc2 AG |
616 | |
617 | } | |
618 | } | |
619 | } | |
45717f71 | 620 | JGraphAdapterDemo graph1; |
621 | ||
622 | ||
623 | // class SpinningCube extends SCPattern{ | |
624 | // LXProjection spin1, spin2, spin3; | |
625 | // SawLFO | |
626 | ||
627 | //} | |
628 | ||
629 | ||
630 | ||
631 | ||
632 | ||
633 | class PixelGraph implements EdgeFactory<dPixel, dVertex> { | |
634 | ||
635 | dPixel p0; dPixel p1; dVertex v0; | |
636 | ||
637 | public dVertex createEdge(dPixel p0, dPixel p1) { | |
638 | ||
639 | return v0; | |
640 | ||
641 | } | |
642 | ||
643 | ||
644 | } | |
645 | ||
646 | class GraphTest extends SCPattern { | |
647 | JGraphAdapterDemo graph1; | |
648 | ||
649 | GraphTest( LX lx) {super(lx); JGraphAdapterDemo graph1 = new JGraphAdapterDemo();} | |
650 | ||
651 | void run(double deltaMs){ | |
652 | } | |
653 | } | |
654 | ||
655 | class SpinningCube extends SCPattern{ | |
656 | ||
657 | LXProjection spin1, spin2, spin3; | |
658 | SawLFO spinx, spiny, spinz; | |
659 | SinLFO spinx1, spiny1, spinz1, cubesize; | |
660 | BasicParameter xoff = new BasicParameter("xoff", 10, 0, 100); | |
661 | BasicParameter toff = new BasicParameter("toff", 10,0,1000); | |
662 | BasicParameter huev = new BasicParameter("hue", 200, 0, 360); | |
663 | BasicParameter density = new BasicParameter("density", 0, 0, 1); | |
664 | BasicParameter Vsize = new BasicParameter("size", model.xMax/3,0, model.xMax); | |
665 | VirtualCube V1, V2, V3; | |
666 | PVector P = new PVector(); | |
667 | float noisetime=0.; | |
668 | class VirtualCube { | |
669 | float x,y,z,d; | |
670 | PVector center; | |
671 | ||
672 | VirtualCube(float x, float y, float z, float d) { | |
673 | this.x=x; | |
674 | this.y= y; | |
675 | this.z=z; | |
676 | this.d=d; | |
677 | this.center=new PVector(x,y,z); | |
678 | } | |
679 | ||
680 | color getcolor(LXVector q) { | |
681 | if ( q.x > this.x + d/2 || q.x < this.x - d/2 || q.y > this.y + d/2 || q.y < this.y - d/2 || q.z > this.z + d/2 || q.z < this.z - d/2 ) | |
682 | {return 0;} | |
683 | else { | |
684 | return lx.hsb(huev.getValuef()*noise(xoff.getValuef()*.001*noisetime ) , constrain(100*noise(xoff.getValuef()*.001*q.x*noisetime), 0, 100), max(100*(noise(xoff.getValuef()*.001*q.x*noisetime)-density.getValuef()), 0) ); | |
685 | } | |
686 | } | |
687 | void setcenter(float x, float y, float z) {this.x=x; this.y = y; this.z=z; } | |
688 | void setsize(float din){ this.d=din ; } | |
689 | ||
690 | } | |
691 | ||
692 | SpinningCube(LX lx) { | |
693 | super(lx); | |
694 | addParameter(xoff); | |
695 | addParameter(toff); | |
696 | addParameter(Vsize); | |
697 | addParameter(huev); | |
698 | addParameter(density); | |
699 | //addModulator() | |
700 | V1 = new VirtualCube(model.cx, model.cy, model.cz, model.xMax/2); | |
701 | spinx= new SawLFO(0, TWO_PI, 8000); | |
702 | spin1 = new LXProjection(model); | |
703 | ||
704 | } | |
705 | ||
706 | ||
707 | void run(double deltaMs) { | |
708 | ||
709 | noisetime+= deltaMs*.0001*toff.getValuef(); | |
710 | ||
711 | spin1.reset() | |
712 | .center() | |
713 | //.scale () | |
714 | .rotate(spinx.getValuef(),0, 1, 0) | |
715 | .translate(model.cx, model.cy, model.cz); | |
716 | ||
717 | for (LXVector p: spin1) { | |
718 | P.set(p.x, p.y, p.z); | |
719 | ||
720 | colors[p.index] = V1.getcolor(p); | |
721 | ||
722 | } | |
723 | ||
724 | V1.setsize(Vsize.getValuef()); | |
725 | ||
726 | ||
727 | }; | |
728 | ||
729 | ||
730 | } | |
731 | ||
732 | ||
733 | ||
734 | ||
735 | ||
5bc92bc2 | 736 | |
a9aad043 AG |
737 | class HueTestHSB extends SCPattern{ |
738 | BasicParameter HueT = new BasicParameter("Hue", .5); | |
739 | BasicParameter SatT = new BasicParameter("Sat", .5); | |
740 | BasicParameter BriT = new BasicParameter("Bright", .5); | |
741 | ||
dde75983 MS |
742 | HueTestHSB(LX lx) { |
743 | super(lx); | |
a9aad043 AG |
744 | addParameter(HueT); |
745 | addParameter(SatT); | |
746 | addParameter(BriT); | |
747 | } | |
748 | void run(double deltaMs){ | |
749 | ||
2bb56822 | 750 | for (LXPoint p : model.points) { |
a9aad043 | 751 | color c = 0; |
a41f334c | 752 | c = blendColor(c, lx.hsb(360*HueT.getValuef(), 100*SatT.getValuef(), 100*BriT.getValuef()), ADD); |
a9aad043 AG |
753 | colors[p.index]= c; |
754 | } | |
755 | int now= millis(); | |
756 | if (now % 1000 <= 20) | |
757 | { | |
45717f71 | 758 | println("Hue: " + 360*HueT.getValuef() + "Sat: " + 100*SatT.getValuef() + "Bright: " + 100*BriT.getValuef()); |
a9aad043 AG |
759 | } |
760 | } | |
0b1785e3 | 761 | |
a41f334c | 762 | } |