916bf68a66b34d10d8d27d8eb57881ef0eab6f35
[SugarCubes.git] / MicahScott.pde
1 // Port of a pattern from Fadecandy. Micah Elizabeth Scott, November 2013.
2 class Rings extends SCPattern {
3
4 float dx, dy, dz;
5 float angleParam, z, hue, satParam, spacingParam;
6 float dzParam, centerParam;
7
8 public Rings(GLucose glucose) {
9 super(glucose);
10 }
11
12 public void run(double deltaMs) {
13
14 float noiseScale = 0.02;
15 float speed = 0.002;
16 float zspeed = 0.04;
17 float scale = 1.0;
18
19 angleParam += (deltaMs * 0.001) % (2*PI);
20 float angle = sin(angleParam);
21
22 z += deltaMs * 0.0008;
23 hue += (deltaMs * 0.036) % 360;
24
25 satParam += deltaMs * 0.000122;
26 spacingParam += deltaMs * 0.000124;
27 dzParam += deltaMs * 0.000014;
28 centerParam += deltaMs * 0.000125;
29
30 float saturation = 100 * constrain(pow(1.9 * noise(satParam), 2.5), 0, 1);
31 float spacing = noise(spacingParam) * 50;
32
33 dx += cos(angle) * speed;
34 dy += sin(angle) * speed;
35 dz += (pow(noise(dzParam), 1.8) - 0.5) * zspeed;
36
37 float centerx = map(noise(centerParam, 100), 0, 1, -0.1, 1.1);
38 float centery = map(noise(centerParam, 200), 0, 1, -0.1, 1.1);
39 float centerz = map(noise(centerParam, 300), 0, 1, -0.1, 1.1);
40
41 float coordMin = min(model.xMin, min(model.yMin, model.zMin));
42 float coordMax = max(model.xMax, max(model.yMax, model.zMax));
43
44 for (LXPoint p : model.points) {
45
46 // Scale while preserving aspect ratio
47 float x = map(p.x, coordMin, coordMax, 0, 1);
48 float y = map(p.y, coordMin, coordMax, 0, 1);
49 float z = map(p.z, coordMin, coordMax, 0, 1);
50
51 float dist = sqrt(sq(x - centerx) + sq(y - centery) + sq(z - centerz));
52 float pulse = (sin(dz + dist * spacing) - 0.3) * 0.6;
53
54 noiseDetail(4);
55 float n = map(noise(dx + x*scale + pulse, dy + y*scale, dz + z*scale), 0, 1, -0.65, 1);
56 float m = map(noise(dx + x*scale, dy + y*scale, dz + z*scale), 0, 1, 0, 300);
57 noiseDetail(1);
58
59 colors[p.index] = lx.hsb(
60 (hue + m) % 360.0,
61 saturation,
62 100 * constrain(pow(3.0 * n, 3.5), 0, 1.0)
63 );
64 }
65 }
66 };