X-Git-Url: https://git.piment-noir.org/?p=SugarCubes.git;a=blobdiff_plain;f=TobySegaran.pde;h=8769b101ef17b728d1281d169bef79eb6aff036a;hp=5735cc383dcf7d49816717739b47d313ae0fc461;hb=7d60f6f6ea82fd5c9794524ce11d40e7d6c00bf7;hpb=b4aaf4e4026e0ecc81b8d18ae4afdc65d89ab63a diff --git a/TobySegaran.pde b/TobySegaran.pde index 5735cc3..8769b10 100644 --- a/TobySegaran.pde +++ b/TobySegaran.pde @@ -1,4 +1,4 @@ -class WarmPlasma extends SCPattern { +class GlitchPlasma extends SCPattern { private int pos = 0; private float satu = 100; private float speed = 1; @@ -7,8 +7,8 @@ class WarmPlasma extends SCPattern { BasicParameter speedParameter = new BasicParameter("SPEED", 0.1); BasicParameter glitchParameter = new BasicParameter("GLITCH", 0.0); - public WarmPlasma(GLucose glucose) { - super(glucose); + public GlitchPlasma(LX lx) { + super(lx); addParameter(saturationParameter); addParameter(speedParameter); addParameter(glitchParameter); @@ -17,23 +17,23 @@ class WarmPlasma extends SCPattern { if (parameter == saturationParameter) { satu = 100*parameter.getValuef(); } else if (parameter == speedParameter) { - speed = 10*parameter.getValuef(); + speed = 8*parameter.getValuef(); } else if (parameter == glitchParameter) { glitch = parameter.getValuef(); } } - public void run(int deltaMs) { - for (Point p : model.points) { - float hv = sin(dist(p.fx + pos, p.fy, 128.0, 128.0) / 8.0) - + sin(dist(p.fx, p.fy, 64.0, 64.0) / 8.0) - + sin(dist(p.fx, p.fy + pos / 7, 192.0, 64.0) / 7.0) - + sin(dist(p.fx, p.fz + pos, 192.0, 100.0) / 8.0); + public void run(double deltaMs) { + for (LXPoint p : model.points) { + float hv = sin(dist(p.x + pos, p.y, 128.0, 128.0) / 8.0) + + sin(dist(p.x, p.y, 64.0, 64.0) / 8.0) + + sin(dist(p.x, p.y + pos / 7, 192.0, 64.0) / 7.0) + + sin(dist(p.x, p.z + pos, 192.0, 100.0) / 8.0); float bv = 100; - colors[p.index] = color((hv+2)*25, satu, bv); + colors[p.index] = lx.hsb((hv+2)*50, satu, bv); } - if (random(1.0)= MAX_INT-1) pos=0; @@ -49,8 +49,8 @@ class FireEffect extends SCPattern { private int ym; BasicParameter decayParameter = new BasicParameter("DECAY", 0.3); - public FireEffect(GLucose glucose) { - super(glucose); + public FireEffect(LX lx) { + super(lx); xm = int(model.xMax); ym = int(model.yMax); @@ -63,11 +63,11 @@ class FireEffect extends SCPattern { } } private color flameColor(float level) { - if (level<=0) return color(0,0,0); + if (level<=0) return lx.hsb(0,0,0); float br=min(100,sqrt(level)*15); - return color(level/1.7,100,br); + return lx.hsb(level/1.7,100,br); } - public void run(int deltaMs) { + public void run(double deltaMs) { for (int x=10;x45 || x%50<5) { intensity[x][ym-1] = random(30,100); @@ -81,9 +81,9 @@ class FireEffect extends SCPattern { } } - for (Point p : model.points) { - int x = max(0,(int(p.fx)+int(p.fz))%xm); - int y = constrain(ym-int(p.fy),0,ym-1); + for (LXPoint p : model.points) { + int x = max(0,(int(p.x)+int(p.z))%xm); + int y = constrain(ym-int(p.y),0,ym-1); colors[p.index] = flameColor(intensity[x][y]); } } @@ -97,8 +97,8 @@ class StripBounce extends SCPattern { SinLFO[] sat = new SinLFO[numOsc]; float[] colorOffset = new float[numOsc]; - public StripBounce(GLucose glucose) { - super(glucose); + public StripBounce(LX lx) { + super(lx); for (int i=0;ibright[p.index]) { - colors[p.index] = color(hv,sat[i].getValuef(),br); + colors[p.index] = lx.hsb(hv,sat[i].getValuef(),br); bright[p.index] = br; } } } } - for (Point p : model.points) { - if (bright[p.index]==0) { - colors[p.index]=color(0,0,0); + } +} + +class SoundRain extends SCPattern { + + private FFT fft = null; + private LinearEnvelope[] bandVals = null; + private float[] lightVals = null; + private int avgSize; + private float gain = 25; + SawLFO pos = new SawLFO(0, 9, 8000); + SinLFO col1 = new SinLFO(0, model.xMax, 5000); + BasicParameter gainParameter = new BasicParameter("GAIN", 0.5); + + public SoundRain(LX lx) { + super(lx); + addModulator(pos).trigger(); + addModulator(col1).trigger(); + addParameter(gainParameter); + } + + public void onParameterChanged(LXParameter parameter) { + if (parameter == gainParameter) { + gain = 50*parameter.getValuef(); + } + } + void onActive() { + if (this.fft == null) { + this.fft = new FFT(lx.audioInput().bufferSize(), lx.audioInput().sampleRate()); + this.fft.window(FFT.HAMMING); + this.fft.logAverages(40, 1); + this.avgSize = this.fft.avgSize(); + this.bandVals = new LinearEnvelope[this.avgSize]; + for (int i = 0; i < this.bandVals.length; ++i) { + this.addModulator(this.bandVals[i] = (new LinearEnvelope(0, 0, 700+i*4))).trigger(); + } + lightVals = new float[avgSize]; + } + } + + public void run(double deltaMs) { + this.fft.forward(this.lx.audioInput().mix); + for (int i = 0; i < avgSize; ++i) { + float value = this.fft.getAvg(i); + this.bandVals[i].setEndVal(value,40).trigger(); + float lv = min(value*gain,100); + if (lv>lightVals[i]) { + lightVals[i]=min(lightVals[i]+15,lv,100); + } else { + lightVals[i]=max(lv,lightVals[i]-5,0); + } + } + for (Cube c : model.cubes) { + for (int j=0; jlightVals[i]) { + lightVals[i]=min(lightVals[i]+30,lv,model.yMax+10); + } else { + lightVals[i]=max(lv,lightVals[i]-10,0); + } + } + int i = 0; + for (Cube c : model.cubes) { + for (int j=0; javgSize) seq=avgSize-seq; + seq=constrain(seq,0,avgSize-1); + float br=max(0, lightVals[seq]-p.y); + colors[p.index] = lx.hsb((dis*avgSize*65)/model.xMax,90,br); + } + } + } + } + } } +