1 // Port of a pattern from Fadecandy. Micah Elizabeth Scott, November 2013.
2 class Rings extends SCPattern {
5 float angleParam, hue, satParam, spacingParam;
6 float dzParam, centerParam;
8 BasicParameter pSpeed1 = new BasicParameter("SPD1", 0.15);
9 BasicParameter pSpeed2 = new BasicParameter("SPD2", 0.46);
10 BasicParameter pRGB = new BasicParameter("RGB", 0.73);
11 BasicParameter pScale = new BasicParameter("SCALE", 0.09);
12 BasicParameter pDepth = new BasicParameter("DEPTH", 0.40);
13 BasicParameter pBright = new BasicParameter("BRT", 0.66);
14 BasicParameter pGamma = new BasicParameter("GAMMA", 0.12);
16 public Rings(GLucose glucose) {
18 addParameter(pSpeed1);
19 addParameter(pSpeed2);
23 addParameter(pBright);
27 public void run(double deltaMs) {
29 float xyspeed = pSpeed1.getValuef() * 0.004;
30 float zspeed = pSpeed1.getValuef() * 0.08;
31 float scale = pScale.getValuef() * 20.0;
33 float angleSpeed = pSpeed1.getValuef() * 0.002;
34 angleParam = (float)((angleParam + angleSpeed * deltaMs) % (2*PI));
35 float angle = sin(angleParam);
37 hue += (deltaMs * pRGB.getValuef() * 0.3) % 360;
38 satParam += deltaMs * pRGB.getValuef() * 0.002;
39 spacingParam += deltaMs * pSpeed2.getValuef() * 0.0005;
40 dzParam += deltaMs * 0.000014;
41 centerParam += deltaMs * pSpeed2.getValuef() * 0.0005;
43 float saturation = 100 * constrain(pow(1.9 * noise(satParam), 2.5), 0, 1);
44 float spacing = noise(spacingParam) * 50;
46 dx += cos(angle) * xyspeed;
47 dy += sin(angle) * xyspeed;
48 dz += (pow(noise(dzParam), 1.8) - 0.5) * zspeed;
50 float centerx = map(noise(centerParam, 100), 0, 1, -0.1, 1.1);
51 float centery = map(noise(centerParam, 200), 0, 1, -0.1, 1.1);
52 float centerz = map(noise(centerParam, 300), 0, 1, -0.1, 1.1);
54 float coordMin = min(model.xMin, min(model.yMin, model.zMin));
55 float coordMax = max(model.xMax, max(model.yMax, model.zMax));
57 float br = pBright.getValuef() * 3.0;
58 float gamma = pGamma.getValuef() * 20.0;
60 for (LXPoint p : model.points) {
62 // Scale while preserving aspect ratio
63 float x = map(p.x, coordMin, coordMax, 0, 1);
64 float y = map(p.y, coordMin, coordMax, 0, 1);
65 float z = map(p.z, coordMin, coordMax, 0, 1);
67 float dist = sqrt(sq(x - centerx) + sq(y - centery) + sq(z - centerz));
68 float pulse = (sin(dz + dist * spacing) - 0.3) * 0.6;
71 float n = map(noise(dx + x*scale + pulse, dy + y*scale, dz + z*scale) - pDepth.getValuef(), 0, 1,
73 float m = map(noise(dx + x*scale, dy + y*scale, dz + z*scale), 0, 1, 0, 300);
76 colors[p.index] = lx.hsb(
79 100 * constrain(pow(br * n, gamma), 0, 1.0)