-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhydra-gradient.js
155 lines (152 loc) · 4.14 KB
/
hydra-gradient.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
{
const getHydra = function () {
const whereami = window.choo?.state?.hydra
? "editor"
: window.atom?.packages
? "atom"
: "idk";
switch (whereami) {
case "editor":
return choo.state.hydra.hydra;
case "atom":
return global.atom.packages.loadedPackages["atom-hydra"]
.mainModule.main.hydra;
case "idk":
let _h = undefined;
_h = window._hydra?.regl ? window._hydra : _h;
_h = window.hydra?.regl ? window.hydra : _h;
_h = window.h?.regl ? window.h : _h;
_h = window.H?.regl ? window.H : _h;
_h = window.hy?.regl ? window.hy : _h;
return _h;
}
};
window._hydra = getHydra();
window._hydraScope = _hydra.sandbox.makeGlobal ? window : _hydra.synth;
}
window.gradient2_ = (c0 = [1,0,0], c1 = [0,0,1], ...args) => {
all = c0.concat(c1.concat(args));
return gradient2(...all);
};
window.gradient3_ = (c0 = [1,0,0], c1 = [0,0,1], c2 = [0,1,0], ...args) => {
all = c0.concat(c1.concat(c2.concat(args)));
return gradient3(...all);
};
[
{
name: "gradient2",
type: "src",
inputs: [
{
type: "float",
name: "r0",
default: 1,
},
{
type: "float",
name: "g0",
default: 0,
},
{
type: "float",
name: "b0",
default: 0,
},
{
type: "float",
name: "r1",
default: 0,
},
{
type: "float",
name: "g1",
default: 0,
},
{
type: "float",
name: "b1",
default: 1,
},
{
type: "float",
name: "speed",
default: 0,
},
],
glsl:
` float x = _st.x+time*speed;
float i = 1.0-abs((x - 2.0*(floor(x/2.0)))-1.0);
vec3 c0 = vec3(r0,g0,b0);
vec3 c1 = vec3(r1,g1,b1);
return vec4(mix(c0,c1,i), 1.0);`
},
{
name: "gradient3",
type: "src",
inputs: [
{
type: "float",
name: "r0",
default: 1,
},
{
type: "float",
name: "g0",
default: 0,
},
{
type: "float",
name: "b0",
default: 0,
},
{
type: "float",
name: "r1",
default: 0,
},
{
type: "float",
name: "g1",
default: 0,
},
{
type: "float",
name: "b1",
default: 1,
},
{
type: "float",
name: "r2",
default: 0,
},
{
type: "float",
name: "g2",
default: 1,
},
{
type: "float",
name: "b2",
default: 0,
},
{
type: "float",
name: "speed",
default: 0,
},
],
glsl:
` float x = _st.x+time*speed;
float i = x - 1.5*(floor(x/1.5));
vec3 c0 = vec3(r0,g0,b0);
vec3 c1 = vec3(r1,g1,b1);
vec3 c2 = vec3(r2,g2,b2);
vec3 seg = vec3(float(i<=0.5),
float(i>0.5 && i<=1.0),
float(i>1.0));
float w0 = seg[0]*(1.0-(i*2.0)) + seg[2]*(i*2.0-2.0);
float w1 = seg[0]*i*2.0 + seg[1]*(1.0-(i*2.0-1.0));
float w2 = seg[1]*(i*2.0-1.0) + seg[2]*(1.0-(i*2.0-2.0));
return vec4(c0*w0+c1*w1+c2*w2, 1.0);`
},
].forEach((x) => _hydra.synth.setFunction(x));