From 918da6fe989762f127263703a2be433bcd317777 Mon Sep 17 00:00:00 2001 From: Micah Elizabeth Scott Date: Sat, 22 Feb 2014 15:39:38 -0800 Subject: [PATCH] Work-in-progress "Rings" effect, ported from Fadecandy --- MicahScott.pde | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ SugarCubes.pde | 3 +++ 2 files changed, 69 insertions(+) create mode 100644 MicahScott.pde diff --git a/MicahScott.pde b/MicahScott.pde new file mode 100644 index 0000000..916bf68 --- /dev/null +++ b/MicahScott.pde @@ -0,0 +1,66 @@ +// Port of a pattern from Fadecandy. Micah Elizabeth Scott, November 2013. +class Rings extends SCPattern { + + float dx, dy, dz; + float angleParam, z, hue, satParam, spacingParam; + float dzParam, centerParam; + + public Rings(GLucose glucose) { + super(glucose); + } + + public void run(double deltaMs) { + + float noiseScale = 0.02; + float speed = 0.002; + float zspeed = 0.04; + float scale = 1.0; + + angleParam += (deltaMs * 0.001) % (2*PI); + float angle = sin(angleParam); + + z += deltaMs * 0.0008; + hue += (deltaMs * 0.036) % 360; + + satParam += deltaMs * 0.000122; + spacingParam += deltaMs * 0.000124; + dzParam += deltaMs * 0.000014; + centerParam += deltaMs * 0.000125; + + float saturation = 100 * constrain(pow(1.9 * noise(satParam), 2.5), 0, 1); + float spacing = noise(spacingParam) * 50; + + dx += cos(angle) * speed; + dy += sin(angle) * speed; + dz += (pow(noise(dzParam), 1.8) - 0.5) * zspeed; + + float centerx = map(noise(centerParam, 100), 0, 1, -0.1, 1.1); + float centery = map(noise(centerParam, 200), 0, 1, -0.1, 1.1); + float centerz = map(noise(centerParam, 300), 0, 1, -0.1, 1.1); + + float coordMin = min(model.xMin, min(model.yMin, model.zMin)); + float coordMax = max(model.xMax, max(model.yMax, model.zMax)); + + for (LXPoint p : model.points) { + + // Scale while preserving aspect ratio + float x = map(p.x, coordMin, coordMax, 0, 1); + float y = map(p.y, coordMin, coordMax, 0, 1); + float z = map(p.z, coordMin, coordMax, 0, 1); + + float dist = sqrt(sq(x - centerx) + sq(y - centery) + sq(z - centerz)); + float pulse = (sin(dz + dist * spacing) - 0.3) * 0.6; + + noiseDetail(4); + float n = map(noise(dx + x*scale + pulse, dy + y*scale, dz + z*scale), 0, 1, -0.65, 1); + float m = map(noise(dx + x*scale, dy + y*scale, dz + z*scale), 0, 1, 0, 300); + noiseDetail(1); + + colors[p.index] = lx.hsb( + (hue + m) % 360.0, + saturation, + 100 * constrain(pow(3.0 * n, 3.5), 0, 1.0) + ); + } + } +}; diff --git a/SugarCubes.pde b/SugarCubes.pde index ff85065..fb24acb 100644 --- a/SugarCubes.pde +++ b/SugarCubes.pde @@ -118,6 +118,9 @@ LXPattern[] patterns(GLucose glucose) { new AbstractPainting(glucose), new Spirality(glucose), + // Micah + new Rings(glucose), + // Basic test patterns for reference, not art new TestCubePattern(glucose), new TestTowerPattern(glucose), -- 2.34.1