Skip to content

Commit 626cead

Browse files
authored
Merge pull request #25 from Absulit/dev
New Cycle color scheme
2 parents 05d5018 + cc3de95 commit 626cead

3 files changed

Lines changed: 27 additions & 29 deletions

File tree

src/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const colorSchemes = {
3737
Artwork: 2,
3838
Negative: 3,
3939
Rainbow: 4,
40+
Cycle: 5
4041
}
4142
folderOptions.add(selectedScheme, 'Color Scheme', colorSchemes).onChange(v => {
4243
points.setUniform('colorScheme', v)

src/points

src/renderpasses/renderpass0/frag.js

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { fnusin, fusin } from 'animation';
22
import { GREEN, layer, RED, RGBAFromHSV, WHITE } from 'color';
33
import { sprite, texturePosition } from 'image';
4-
import { PHI, PI, rotateVector } from 'math';
4+
import { PHI, PI, rotateVector, TAU } from 'math';
55
import { sdfCircle, sdfLine2, sdfSquare, sdfSegment } from 'sdf';
66
import { structs } from './structs.js';
77

@@ -17,6 +17,7 @@ ${sdfSquare}
1717
${rotateVector}
1818
${sprite}
1919
${PHI}
20+
${TAU}
2021
${PI}
2122
${layer}
2223
${fusin}
@@ -70,22 +71,10 @@ fn sdfEquiTriangle2( position:vec2f, radius:f32, feather: f32, uv:vec2f ) -> f32
7071
return st;
7172
}
7273
73-
74-
// fn opOnion( p: vec2f, r:f32 ) -> f32 {
75-
// return abs(sdfEquiTriangle(p,r)) - r;
76-
// }
77-
7874
fn sdfRectangle( position0:vec2f, position1:vec2f, uv:vec2f ) -> f32 {
79-
var r = 0.;
80-
// if(uv.x > position0.x && uv.x < position1.x && uv.y > position0.y && uv.y < position1.y){
81-
// r = 1.;
82-
// }
83-
// r = step(position0.x, uv.x) * step(uv.x, position1.x) * step(position0.y, uv.y) * step(uv.y, position1.y);
84-
r = step(0.0, uv.x - position0.x) * step(0.0, position1.x - uv.x) * step(0.0, uv.y - position0.y) * step(0.0, position1.y - uv.y);
85-
return r;
75+
return step(0.0, uv.x - position0.x) * step(0.0, position1.x - uv.x) * step(0.0, uv.y - position0.y) * step(0.0, position1.y - uv.y);
8676
}
8777
88-
8978
fn sdRectangle1(position:vec2f, size:vec2f, feather:f32, uv:vec2f) -> f32 {
9079
let d = abs(uv - position) - size * 0.5;
9180
let m = max(d.x, d.y);
@@ -127,8 +116,6 @@ const MATRIX2 = vec3f(.2,.282,.152);
127116
const MATRIX3 = vec3f(.309,.4,.290) ;
128117
const MATRIX4 = vec4f(.572,.717,.549, 1);
129118
130-
131-
const TAU = PI * 2; // TODO: fix on main library
132119
const TAUQUARTER = TAU * .25;
133120
const MAXBYTES = 256;
134121
const CHLEN = 0.125;
@@ -144,6 +131,7 @@ const charSize = vec2(8u,22u);
144131
const charOffset = 32u; // A is 33
145132
const maxCircleRadius = .9;
146133
const audioLength = 826.; // 800. 826. 550.
134+
const minNumSides = 3.;
147135
148136
@fragment
149137
fn main(
@@ -239,29 +227,23 @@ fn main(
239227
let charSizeF32 = vec2(f32(charSize.x) / params.screen.x, f32(charSize.y) / params.screen.y);
240228
241229
242-
var stringMask = 0.;
243-
var stringMask2 = 0.;
244230
let textScale = 2.476 + c0;
245231
let textUVR = uvr / textScale / ratioWidth;
246-
247-
stringMask = texturePosition(songName, textImageSampler, fontPosition, textUVR, false).r;
248-
stringMask2 = texturePosition(songName, textImageSampler, fontPosition, textUVR + .001 / ratioWidth, false).r;
249-
232+
let stringMask = texturePosition(songName, textImageSampler, fontPosition, textUVR, false).r;
233+
let stringMask2 = texturePosition(songName, textImageSampler, fontPosition, textUVR + .001 / ratioWidth, false).r;
250234
251235
var messageStringMask = 0.;
252236
if(params.showMessage == 1.){
253237
let messageScale = mix(textScale, ratioWidth, isPortrait);
254238
let dims:vec2u = textureDimensions(messageString, 0);
255239
let dimsF32 = vec2f(dims) * messageScale;
256-
let dimWidth = dimsF32.x / params.screen.x;
240+
let dimWidth = dimsF32.x / params.screen.x * messageScale;
257241
258-
var messageUVR = ( (uvr - center) + vec2f(dimWidth * .5, 0)) / messageScale;
259-
messageUVR = vec2f(messageUVR.x, messageUVR.y + sin(params.time + messageUVR.x * 10 ) * .01);
242+
var messageUVR = ( (uvr - center) + vec2f(dimWidth * .5, 0));
243+
messageUVR = vec2f(messageUVR.x, messageUVR.y + sin(params.time + messageUVR.x * 10 ) * .01) / messageScale;
260244
messageStringMask = texturePosition(messageString, textImageSampler, vec2f(), messageUVR, false).r;
261245
}
262246
263-
264-
let minNumSides = 3.;
265247
let numSides = minNumSides + floor(5 * c7);
266248
var equiTriUV = uvr_minus_center / .156 * minNumSides / numSides; // .31
267249
let c2Visible = step(.001, c2); // to revert value only if c2 (poligon) is visible
@@ -286,6 +268,7 @@ fn main(
286268
var poligon = vec4f();
287269
var stringColor = vec4f();
288270
var stringColor2 = vec4f();
271+
var messageStringColor = vec4f();
289272
290273
var bg = vec4f();
291274
@@ -297,6 +280,7 @@ fn main(
297280
poligon = vec4f(1, .4 + .1 * c4, step(.5, c2) * .4, 1) * poliMask;
298281
stringColor = stringMask * mix(vec4(fusin(.132) , fusin(.586) ,0,1), vec4(1,.5, fusin(.7589633), 1), c0);
299282
stringColor2 = stringMask2 * mix( vec4( 1-vec3(fusin(.132) , fusin(.586), 0), 1), vec4(1-vec3(1,.5, fusin(.7589633)), 1), c0);
283+
messageStringColor = messageStringMask * WHITE;
300284
}
301285
case 1 { // matrix
302286
audioWave = vec4f(MATRIX0 * lineMask, 1);
@@ -305,6 +289,7 @@ fn main(
305289
poligon = vec4f(MATRIX3 * poliMask, 1);
306290
stringColor = MATRIX4 * stringMask;
307291
stringColor2 = stringMask2 * GREEN;
292+
messageStringColor = messageStringMask * GREEN;
308293
}
309294
case 2 { // artwork
310295
audioWave = vec4f( mix(artworkColors[9].rgb, artworkColors[0].rgb, audioX) * lineMask, 1);
@@ -313,6 +298,7 @@ fn main(
313298
poligon = vec4f( mix(artworkColors[6].rgb, artworkColors[3].rgb, c4) * poliMask, 1);
314299
stringColor = mix(artworkColors[5], artworkColors[4], c0) * stringMask;
315300
stringColor2 = stringMask2 * WHITE;
301+
messageStringColor = messageStringMask * WHITE;
316302
}
317303
case 3 { // white bg
318304
bg = DWHITE;
@@ -322,6 +308,7 @@ fn main(
322308
poligon = vec4f( B * (1-poliMask), poliMask);
323309
stringColor = vec4f(vec3f(1-stringMask), stringMask);
324310
stringColor2 = stringMask2 * WHITE;
311+
messageStringColor = vec4f(B-messageStringMask, messageStringMask);
325312
}
326313
case 4 { // rainbow
327314
audioWave = RGBAFromHSV(lineMask * c0, lineMask * c1, lineMask * c2);
@@ -330,6 +317,16 @@ fn main(
330317
poligon = RGBAFromHSV(poliMask * uvrRotate.x, poliMask * uvrRotate.y, poliMask);
331318
stringColor = stringMask * RGBAFromHSV(stringMask * c5, stringMask * c0, stringMask * c7);
332319
stringColor2 = stringMask2 * WHITE;
320+
messageStringColor = messageStringMask * GREEN;
321+
}
322+
case 5 { // cycle
323+
audioWave = RGBAFromHSV(lineMask * (params.time % 1), lineMask, lineMask);
324+
audioWave2 = RGBAFromHSV(lineMask2 * (params.time % 1), lineMask2, lineMask2);
325+
progressBar = RGBAFromHSV(progressBarMask * c4, progressBarMask * c3, progressBarMask * c1);
326+
poligon = RGBAFromHSV(poliMask * c4, poliMask, poliMask);
327+
stringColor = stringMask * RGBAFromHSV(stringMask * c0, stringMask, stringMask);
328+
stringColor2 = stringMask2 * WHITE;
329+
messageStringColor = messageStringMask * GREEN;
333330
}
334331
}
335332
@@ -342,7 +339,7 @@ fn main(
342339
// let finalColor = layer(bg, audioWave);
343340
// let finalColor = vec4f(1,s,0,1);
344341
345-
return finalColor + (messageStringMask * WHITE * params.showMessage * .1);
342+
return finalColor + (messageStringColor * params.showMessage * .1);
346343
// return finalColor + (poliMask * WHITE * params.showMessage * .1);
347344
// return poliMask * WHITE;
348345
}

0 commit comments

Comments
 (0)