Commit | Line | Data |
---|---|---|
918da6fe MES |
1 | // Port of a pattern from Fadecandy. Micah Elizabeth Scott, November 2013. |
2 | class Rings extends SCPattern { | |
3 | ||
4 | float dx, dy, dz; | |
b85e32c7 | 5 | float angleParam, spacingParam; |
918da6fe MES |
6 | float dzParam, centerParam; |
7 | ||
b85e32c7 MES |
8 | BasicParameter pDepth = new BasicParameter("DEPTH", 0.6); |
9 | BasicParameter pBright = new BasicParameter("BRT", 0.75); | |
10 | BasicParameter pHue = new BasicParameter("HUE", 0.39); | |
11 | BasicParameter pSaturation = new BasicParameter("SAT", 0.5); | |
12 | ||
13 | BasicParameter pSpeed1 = new BasicParameter("SPD1", 0.2); | |
14 | BasicParameter pSpeed2 = new BasicParameter("SPD2", 0.4); | |
15 | BasicParameter pScale = new BasicParameter("SCALE", 0.15); | |
16 | ||
17 | public Rings(LX lx) { | |
18 | super(lx); | |
19 | addParameter(pDepth); | |
20 | addParameter(pBright); | |
21 | addParameter(pHue); | |
22 | addParameter(pSaturation); | |
8777eaa2 | 23 | |
8777eaa2 MES |
24 | addParameter(pSpeed1); |
25 | addParameter(pSpeed2); | |
26 | addParameter(pScale); | |
918da6fe MES |
27 | } |
28 | ||
29 | public void run(double deltaMs) { | |
30 | ||
b85e32c7 | 31 | float xyspeed = pSpeed1.getValuef() * 0.01; |
8777eaa2 MES |
32 | float zspeed = pSpeed1.getValuef() * 0.08; |
33 | float scale = pScale.getValuef() * 20.0; | |
b85e32c7 MES |
34 | float br = pBright.getValuef() * 3.0; |
35 | float gamma = 3.0; | |
36 | float depth = 1.0 - pDepth.getValuef(); | |
37 | float hue = pHue.getValuef() * 360.0; | |
38 | float saturation = pSaturation.getValuef() * 100; | |
918da6fe | 39 | |
8777eaa2 MES |
40 | float angleSpeed = pSpeed1.getValuef() * 0.002; |
41 | angleParam = (float)((angleParam + angleSpeed * deltaMs) % (2*PI)); | |
918da6fe MES |
42 | float angle = sin(angleParam); |
43 | ||
b85e32c7 | 44 | spacingParam += deltaMs * pSpeed2.getValuef() * 0.001; |
918da6fe | 45 | dzParam += deltaMs * 0.000014; |
b85e32c7 | 46 | centerParam += deltaMs * pSpeed2.getValuef() * 0.001; |
918da6fe | 47 | |
918da6fe MES |
48 | float spacing = noise(spacingParam) * 50; |
49 | ||
8777eaa2 MES |
50 | dx += cos(angle) * xyspeed; |
51 | dy += sin(angle) * xyspeed; | |
918da6fe MES |
52 | dz += (pow(noise(dzParam), 1.8) - 0.5) * zspeed; |
53 | ||
54 | float centerx = map(noise(centerParam, 100), 0, 1, -0.1, 1.1); | |
55 | float centery = map(noise(centerParam, 200), 0, 1, -0.1, 1.1); | |
56 | float centerz = map(noise(centerParam, 300), 0, 1, -0.1, 1.1); | |
57 | ||
58 | float coordMin = min(model.xMin, min(model.yMin, model.zMin)); | |
59 | float coordMax = max(model.xMax, max(model.yMax, model.zMax)); | |
60 | ||
61 | for (LXPoint p : model.points) { | |
62 | ||
63 | // Scale while preserving aspect ratio | |
64 | float x = map(p.x, coordMin, coordMax, 0, 1); | |
65 | float y = map(p.y, coordMin, coordMax, 0, 1); | |
66 | float z = map(p.z, coordMin, coordMax, 0, 1); | |
67 | ||
68 | float dist = sqrt(sq(x - centerx) + sq(y - centery) + sq(z - centerz)); | |
69 | float pulse = (sin(dz + dist * spacing) - 0.3) * 0.6; | |
70 | ||
71 | noiseDetail(4); | |
b85e32c7 MES |
72 | float n = map(noise(dx + (x - centerx) * scale + centerx + pulse, |
73 | dy + (y - centery) * scale + centery, | |
74 | dz + (z - centerz) * scale + centerz) | |
75 | - depth, 0, 1, 0, 2.0); | |
76 | float m = map(noise(dx + (x - centerx) * scale + centerx, | |
77 | dy + (y - centery) * scale + centery, | |
78 | dz + (z - centerz) * scale + centerz), | |
79 | 0, 1, 0, 300); | |
918da6fe MES |
80 | noiseDetail(1); |
81 | ||
82 | colors[p.index] = lx.hsb( | |
83 | (hue + m) % 360.0, | |
84 | saturation, | |
8777eaa2 | 85 | 100 * constrain(pow(br * n, gamma), 0, 1.0) |
918da6fe MES |
86 | ); |
87 | } | |
88 | } | |
89 | }; |