Parameters and good defaults for Rings
[SugarCubes.git] / MicahScott.pde
CommitLineData
918da6fe
MES
1// Port of a pattern from Fadecandy. Micah Elizabeth Scott, November 2013.
2class Rings extends SCPattern {
3
4 float dx, dy, dz;
8777eaa2 5 float angleParam, hue, satParam, spacingParam;
918da6fe
MES
6 float dzParam, centerParam;
7
8777eaa2
MES
8 BasicParameter pSpeed1 = new BasicParameter("SPD1", 0.5);
9 BasicParameter pSpeed2 = new BasicParameter("SPD2", 0.5);
10 BasicParameter pRGB = new BasicParameter("RGB", 0.1);
11 BasicParameter pScale = new BasicParameter("SCALE", 0.1);
12 BasicParameter pDepth = new BasicParameter("DEPTH", 0.25);
13 BasicParameter pBright = new BasicParameter("BRT", 0.46);
14 BasicParameter pGamma = new BasicParameter("GAMMA", 0.27);
15
918da6fe
MES
16 public Rings(GLucose glucose) {
17 super(glucose);
8777eaa2
MES
18 addParameter(pSpeed1);
19 addParameter(pSpeed2);
20 addParameter(pScale);
21 addParameter(pDepth);
22 addParameter(pRGB);
23 addParameter(pBright);
24 addParameter(pGamma);
918da6fe
MES
25 }
26
27 public void run(double deltaMs) {
28
8777eaa2
MES
29 float xyspeed = pSpeed1.getValuef() * 0.004;
30 float zspeed = pSpeed1.getValuef() * 0.08;
31 float scale = pScale.getValuef() * 20.0;
918da6fe 32
8777eaa2
MES
33 float angleSpeed = pSpeed1.getValuef() * 0.002;
34 angleParam = (float)((angleParam + angleSpeed * deltaMs) % (2*PI));
918da6fe
MES
35 float angle = sin(angleParam);
36
8777eaa2
MES
37 hue += (deltaMs * pRGB.getValuef() * 0.3) % 360;
38 satParam += deltaMs * pRGB.getValuef() * 0.002;
39 spacingParam += deltaMs * pSpeed2.getValuef() * 0.0005;
918da6fe 40 dzParam += deltaMs * 0.000014;
8777eaa2 41 centerParam += deltaMs * pSpeed2.getValuef() * 0.0005;
918da6fe
MES
42
43 float saturation = 100 * constrain(pow(1.9 * noise(satParam), 2.5), 0, 1);
44 float spacing = noise(spacingParam) * 50;
45
8777eaa2
MES
46 dx += cos(angle) * xyspeed;
47 dy += sin(angle) * xyspeed;
918da6fe
MES
48 dz += (pow(noise(dzParam), 1.8) - 0.5) * zspeed;
49
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);
53
54 float coordMin = min(model.xMin, min(model.yMin, model.zMin));
55 float coordMax = max(model.xMax, max(model.yMax, model.zMax));
56
8777eaa2
MES
57 float br = pBright.getValuef() * 3.0;
58 float gamma = pGamma.getValuef() * 20.0;
59
918da6fe
MES
60 for (LXPoint p : model.points) {
61
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);
66
67 float dist = sqrt(sq(x - centerx) + sq(y - centery) + sq(z - centerz));
68 float pulse = (sin(dz + dist * spacing) - 0.3) * 0.6;
69
70 noiseDetail(4);
8777eaa2
MES
71 float n = map(noise(dx + x*scale + pulse, dy + y*scale, dz + z*scale) - pDepth.getValuef(), 0, 1,
72 0, 2.0);
918da6fe
MES
73 float m = map(noise(dx + x*scale, dy + y*scale, dz + z*scale), 0, 1, 0, 300);
74 noiseDetail(1);
75
76 colors[p.index] = lx.hsb(
77 (hue + m) % 360.0,
78 saturation,
8777eaa2 79 100 * constrain(pow(br * n, gamma), 0, 1.0)
918da6fe
MES
80 );
81 }
82 }
83};