11import { fnusin , fusin } from 'animation' ;
22import { GREEN , layer , RED , WHITE } from 'color' ;
33import { sprite , texturePosition } from 'image' ;
4- import { PI , rotateVector , TAU } from 'math' ;
4+ import { PI , rotateVector } from 'math' ;
55import { sdfCircle , sdfLine2 , sdfSquare , sdfSegment } from 'sdf' ;
66import { structs } from './structs.js' ;
77
@@ -16,7 +16,7 @@ ${sdfCircle}
1616${ sdfSquare }
1717${ rotateVector }
1818${ sprite }
19- ${ TAU }
19+
2020${ PI }
2121${ layer }
2222${ fusin }
@@ -102,14 +102,27 @@ fn sdRectangle1(position:vec2f, size:vec2f, feather:f32, uv:vec2f) -> f32 {
102102 return st;
103103}
104104
105+ fn sdfngon(position:vec2f, numSides:f32, radius:f32, feather:f32, uv:vec2f) -> f32 {
106+ let uv2 = uv - position;
107+ let angle = atan2(uv2.y, uv2.x);
108+ let distance = length(uv2);
109+
110+ let border = -.05;
111+
112+ let sector = TAU / numSides;
113+ let d = 1 - cos(floor(0.5 + angle / sector) * sector - angle) * length(uv2) - radius;
114+ return mix(0,1, step(border, d) * step(d, border + feather));
115+ }
116+
105117fn sdRectangle2(position0:vec2f, position1:vec2f, uv:vec2f) -> f32 {
106118 let d = max(position0 - uv, uv - position1);
107119 // If the point is inside the rectangle, return the negative distance to the closest edge
108120 return length(max(d, vec2f())) + min(max(d.x, d.y), 0.0);
109121}
110122
111123
112-
124+ const TAU = PI * 2; // TODO: fix on main library
125+ const TAUQUARTER = TAU * .25;
113126const NUMCHARS = 128;
114127const MAXBITS = 256;
115128const CHLEN = 0.125;
@@ -236,14 +249,15 @@ fn main(
236249 }
237250
238251
239- var equiTriUV = uvr_minus_center / .156; // .31
240- let c2Visible = step(.001, c2); // to revert value only if c2 (triangle) is visible
252+ let minNumSides = 3.;
253+ let numSides = minNumSides + floor(5 * c7);
254+ var equiTriUV = uvr_minus_center / .156 * minNumSides / numSides; // .31
255+ let c2Visible = step(.001, c2); // to revert value only if c2 (poligon) is visible
241256 variables.triRotation += TRIROTATION * c7 * c6 + c5 * TRIROTATION; // rotate gradually
242257 variables.triRotation -= .000001 * step(0., variables.triRotation) * c2Visible;
243258 variables.triRotation = variables.triRotation % TAU; // cap rotation to avoid it getting stuck
244- equiTriUV = rotateVector(equiTriUV, variables.triRotation);
245- let equiTriMask = sdfEquiTriangle2(vec2f(), 1 - c2 * .5, .007, equiTriUV) * c2Visible;
246-
259+ equiTriUV = rotateVector(equiTriUV, variables.triRotation + TAUQUARTER);
260+ let poliMask = sdfngon(vec2f(), numSides, .5 + (c7 * .5), .01, equiTriUV) * c2Visible;
247261
248262 let progressBarMask = sdfLine2(vec2(), vec2(params.progress,0) * ratio, .005, uvr);
249263
@@ -257,7 +271,7 @@ fn main(
257271 var audioWave = vec4f();
258272 var audioWave2 = vec4f();
259273 var progressBar = vec4f();
260- var triangle = vec4f();
274+ var poligon = vec4f();
261275 var stringColor = vec4f();
262276 var stringColor2 = vec4f();
263277
@@ -268,23 +282,23 @@ fn main(
268282 audioWave = vec4f(lineMask, lineMask*audioX, lineMask*uvrRotate.x, 1);
269283 audioWave2 = vec4f(lineMask2, lineMask2*audioX2, lineMask2*uvrRotate.x, 1);
270284 progressBar = vec4f(1,audioX,uvrRotate.x,1) * progressBarMask;
271- triangle = vec4f(1,.4 + .1 * c4, step(.5, c2) * .4,1) * equiTriMask ;
272- stringColor = stringMask * mix(vec4(1 * fusin(.132) , 1 * fusin(.586) ,0,1), vec4(1,.5, 1 * fusin(.7589633), 1), c0);
273- stringColor2 = stringMask2 * mix( vec4( 1-vec3(1 * fusin(.132) , 1 * fusin(.586), 0), 1), vec4(1-vec3(1,.5, 1 * fusin(.7589633)), 1), c0);
285+ poligon = vec4f(1,.4 + .1 * c4, step(.5, c2) * .4,1) * poliMask ;
286+ stringColor = stringMask * mix(vec4(fusin(.132) , fusin(.586) ,0,1), vec4(1,.5, fusin(.7589633), 1), c0);
287+ stringColor2 = stringMask2 * mix( vec4( 1-vec3(fusin(.132) , fusin(.586), 0), 1), vec4(1-vec3(1,.5, fusin(.7589633)), 1), c0);
274288 }
275289 case 1 { // matrix
276290 audioWave = vec4f( vec3f(.129,.145,.039) * lineMask, 1);
277291 audioWave2 = vec4f( vec3f(.231,.274,.117) * lineMask2, 1);
278292 progressBar = vec4f( vec3f(.2,.282,.152) * progressBarMask, 1);
279- triangle = vec4f( vec3f(.309,.4,.290) * equiTriMask , 1);
293+ poligon = vec4f( vec3f(.309,.4,.290) * poliMask , 1);
280294 stringColor = vec4f( .572,.717,.549, 1) * stringMask;
281295 stringColor2 = stringMask2 * GREEN;
282296 }
283297 case 2 { // artwork
284298 audioWave = vec4f( mix(artworkColors[9].rgb, artworkColors[0].rgb, audioX) * lineMask, 1);
285299 audioWave2 = vec4f( mix(artworkColors[8].rgb, artworkColors[1].rgb,audioX) * lineMask2, 1);
286300 progressBar = vec4f( mix(artworkColors[7].rgb, artworkColors[2].rgb, uvrRotate.x) * progressBarMask, 1);
287- triangle = vec4f( mix(artworkColors[6].rgb, artworkColors[3].rgb, c4) * equiTriMask , 1);
301+ poligon = vec4f( mix(artworkColors[6].rgb, artworkColors[3].rgb, c4) * poliMask , 1);
288302 stringColor = mix(artworkColors[5], artworkColors[4], c0) * stringMask;
289303 stringColor2 = stringMask2 * WHITE;
290304 }
@@ -293,23 +307,24 @@ fn main(
293307 audioWave = vec4f( B * (1-lineMask), lineMask);
294308 audioWave2 = vec4f( B * (1-lineMask2), lineMask2);
295309 progressBar = vec4f( B * (1-progressBarMask), progressBarMask);
296- triangle = vec4f( B * (1-equiTriMask ), equiTriMask );
310+ poligon = vec4f( B * (1-poliMask ), poliMask );
297311 stringColor = vec4f(vec3f(1-stringMask), stringMask);
298312 stringColor2 = stringMask2 * WHITE;
299313 }
300314 }
301315
302316
303317
304- var finalColor = layer(audioWave2 + audioWave + progressBar + triangle + feedbackColor, layer(stringColor2, stringColor));
318+ var finalColor = layer(audioWave2 + audioWave + progressBar + poligon + feedbackColor, layer(stringColor2, stringColor));
305319 if(colorScheme == 3){
306320 finalColor = layer(bg, finalColor);
307321 }
308322 // let finalColor = layer(bg, audioWave);
309323 // let finalColor = vec4f(1,s,0,1);
310324
311- return finalColor + (messageStringMask * vec4(1 * fusin(.132) , 1 * fusin(.586) ,0,1) * params.showMessage * .1);
312- // return vec4(st, 0, 1);
325+ return finalColor + (messageStringMask * WHITE * params.showMessage * .1);
326+ // return finalColor + (poliMask * WHITE * params.showMessage * .1);
327+ // return poliMask * WHITE;
313328}
314329` ;
315330
0 commit comments