From 4a60ba58e4ecdb91a1d35b07f39d144ffece0765 Mon Sep 17 00:00:00 2001 From: jackie Date: Sat, 23 Nov 2013 16:28:04 -0800 Subject: [PATCH] Add JackieLines and JackieDots Squashed commit of the following: commit 95c8cfef57ac4702614f0b34b0c1e2829ba7fc7a Author: jackie Date: Sat Nov 23 16:27:07 2013 -0800 dots tuned commit 46b01100d1cce8c958b54054015498166e6bf230 Author: jackie Date: Sat Nov 23 00:08:13 2013 -0800 added lines --- JackieBavaro.pde | 178 ++++++++++++++++++++++++++++++++++++++++++++++- SugarCubes.pde | 3 + 2 files changed, 180 insertions(+), 1 deletion(-) diff --git a/JackieBavaro.pde b/JackieBavaro.pde index 94ff518..fc1576a 100644 --- a/JackieBavaro.pde +++ b/JackieBavaro.pde @@ -1,6 +1,5 @@ class JackieSquares extends SCPattern { private BasicParameter rateParameter = new BasicParameter("RATE", 0.25); - private BasicParameter maxSpreadParameter = new BasicParameter("SPREAD", 0.25); private BasicParameter attackParameter = new BasicParameter("ATTK", 0.3); private BasicParameter decayParameter = new BasicParameter("DECAY", 0.2); private BasicParameter saturationParameter = new BasicParameter("SAT", 0.7); @@ -87,3 +86,180 @@ class JackieSquares extends SCPattern { } } + +class JackieLines extends SCPattern { + private BasicParameter rateParameter = new BasicParameter("RATE", 0.25); + private BasicParameter attackParameter = new BasicParameter("ATTK", 0.3); + private BasicParameter decayParameter = new BasicParameter("DECAY", 0.2); + private BasicParameter saturationParameter = new BasicParameter("SAT", 0.7); + + SinLFO hueMod = new SinLFO(0, 360, 4000); + SinLFO spreadMod = new SinLFO(1, 10, 8000); + + + class StripFlash { + Strip f; + float value; + float hue; + boolean hasPeaked; + + StripFlash(int n) { + f = model.strips.get(n % model.strips.size()); + hue = random(360); + boolean infiniteAttack = (attackParameter.getValuef() > 0.999); + hasPeaked = infiniteAttack; + value = (infiniteAttack ? 1 : 0); + } + + // returns TRUE if this should die + boolean age(double ms) { + if (!hasPeaked) { + value = value + (float) (ms / 1000.0f * ((attackParameter.getValuef() + 0.01) * 5)); + if (value >= 1.0) { + value = 1.0; + hasPeaked = true; + } + return false; + } else { + value = value - (float) (ms / 1000.0f * ((decayParameter.getValuef() + 0.01) * 10)); + return value <= 0; + } + } + } + + private float leftoverMs = 0; + private List flashes; + private int stripNum = 0; + + public JackieLines(GLucose glucose) { + super(glucose); + addParameter(rateParameter); + addParameter(attackParameter); + addParameter(decayParameter); + addParameter(saturationParameter); + addModulator(hueMod).trigger(); + addModulator(spreadMod).trigger(); + + flashes = new LinkedList(); + } + + public void run(double deltaMs) { + leftoverMs += deltaMs; + float msPerFlash = 1000 / ((rateParameter.getValuef() + .01) * 100); + while (leftoverMs > msPerFlash) { + leftoverMs -= msPerFlash; + stripNum += int(spreadMod.getValuef()); + flashes.add(new StripFlash(stripNum)); + } + + for (LXPoint p : model.points) { + colors[p.index] = 0; + } + + for (StripFlash flash : flashes) { + float hue = (hueMod.getValuef() + flash.hue) % 360.0; + color c = lx.hsb(hue, saturationParameter.getValuef() * 100, (flash.value) * 100); + for (LXPoint p : flash.f.points) { + colors[p.index] = c; + } + } + + Iterator i = flashes.iterator(); + while (i.hasNext()) { + StripFlash flash = i.next(); + boolean dead = flash.age(deltaMs); + if (dead) { + i.remove(); + } + } + } +} + + + +class JackieDots extends SCPattern { + private BasicParameter rateParameter = new BasicParameter("RATE", 0.15); + private BasicParameter attackParameter = new BasicParameter("ATTK", 0.3); + private BasicParameter decayParameter = new BasicParameter("DECAY", 0.2); + private BasicParameter saturationParameter = new BasicParameter("SAT", 0.7); + + SinLFO hueMod = new SinLFO(0, 360, 4000); + SinLFO spreadMod = new SinLFO(1, 10, 16000); + + + class PointFlash { + LXPoint f; + float value; + float hue; + boolean hasPeaked; + + PointFlash(int n) { + f = model.points.get(n % model.points.size()); + hue = random(360); + boolean infiniteAttack = (attackParameter.getValuef() > 0.999); + hasPeaked = infiniteAttack; + value = (infiniteAttack ? 1 : 0); + } + + // returns TRUE if this should die + boolean age(double ms) { + if (!hasPeaked) { + value = value + (float) (ms / 1000.0f * ((attackParameter.getValuef() + 0.01) * 5)); + if (value >= 1.0) { + value = 1.0; + hasPeaked = true; + } + return false; + } else { + value = value - (float) (ms / 1000.0f * ((decayParameter.getValuef() + 0.01) * 10)); + return value <= 0; + } + } + } + + private float leftoverMs = 0; + private List flashes; + private int pointNum = 0; + + public JackieDots(GLucose glucose) { + super(glucose); + addParameter(rateParameter); + addParameter(attackParameter); + addParameter(decayParameter); + addParameter(saturationParameter); + addModulator(hueMod).trigger(); + addModulator(spreadMod).trigger(); + + flashes = new LinkedList(); + } + + public void run(double deltaMs) { + leftoverMs += deltaMs; + float msPerFlash = 1000 / ((rateParameter.getValuef() + .01) * 5000); + while (leftoverMs > msPerFlash) { + leftoverMs -= msPerFlash; + pointNum += int(spreadMod.getValuef()); + flashes.add(new PointFlash(pointNum)); + } + + for (LXPoint p : model.points) { + colors[p.index] = 0; + } + + for (PointFlash flash : flashes) { + float hue = (hueMod.getValuef() + flash.hue) % 360.0; + color c = lx.hsb(hue, saturationParameter.getValuef() * 100, (flash.value) * 100); + colors[flash.f.index] = c; + } + + Iterator i = flashes.iterator(); + while (i.hasNext()) { + PointFlash flash = i.next(); + boolean dead = flash.age(deltaMs); + if (dead) { + i.remove(); + } + } + } +} + diff --git a/SugarCubes.pde b/SugarCubes.pde index 8d9219d..2024c40 100644 --- a/SugarCubes.pde +++ b/SugarCubes.pde @@ -67,6 +67,9 @@ LXPattern[] patterns(GLucose glucose) { // Jackie new JackieSquares(glucose), + new JackieLines(glucose), + new JackieDots(glucose), + // Toby -- 2.34.1