@guinetik/gcanvas 1.0.5 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/dist/aizawa.html +27 -0
  2. package/dist/clifford.html +25 -0
  3. package/dist/cmb.html +24 -0
  4. package/dist/dadras.html +26 -0
  5. package/dist/dejong.html +25 -0
  6. package/dist/gcanvas.es.js +5130 -372
  7. package/dist/gcanvas.es.min.js +1 -1
  8. package/dist/gcanvas.umd.js +1 -1
  9. package/dist/gcanvas.umd.min.js +1 -1
  10. package/dist/halvorsen.html +27 -0
  11. package/dist/index.html +96 -48
  12. package/dist/js/aizawa.js +425 -0
  13. package/dist/js/bezier.js +5 -5
  14. package/dist/js/clifford.js +236 -0
  15. package/dist/js/cmb.js +594 -0
  16. package/dist/js/dadras.js +405 -0
  17. package/dist/js/dejong.js +257 -0
  18. package/dist/js/halvorsen.js +405 -0
  19. package/dist/js/isometric.js +34 -46
  20. package/dist/js/lorenz.js +425 -0
  21. package/dist/js/painter.js +8 -8
  22. package/dist/js/rossler.js +480 -0
  23. package/dist/js/schrodinger.js +314 -18
  24. package/dist/js/thomas.js +394 -0
  25. package/dist/lorenz.html +27 -0
  26. package/dist/rossler.html +27 -0
  27. package/dist/scene-interactivity-test.html +220 -0
  28. package/dist/thomas.html +27 -0
  29. package/package.json +1 -1
  30. package/readme.md +30 -22
  31. package/src/game/objects/go.js +7 -0
  32. package/src/game/objects/index.js +2 -0
  33. package/src/game/objects/isometric-scene.js +53 -3
  34. package/src/game/objects/layoutscene.js +57 -0
  35. package/src/game/objects/mask.js +241 -0
  36. package/src/game/objects/scene.js +19 -0
  37. package/src/game/objects/wrapper.js +14 -2
  38. package/src/game/pipeline.js +17 -0
  39. package/src/game/ui/button.js +101 -16
  40. package/src/game/ui/theme.js +0 -6
  41. package/src/game/ui/togglebutton.js +25 -14
  42. package/src/game/ui/tooltip.js +12 -4
  43. package/src/index.js +3 -0
  44. package/src/io/gesture.js +409 -0
  45. package/src/io/index.js +4 -1
  46. package/src/io/keys.js +9 -1
  47. package/src/io/screen.js +476 -0
  48. package/src/math/attractors.js +664 -0
  49. package/src/math/heat.js +106 -0
  50. package/src/math/index.js +1 -0
  51. package/src/mixins/draggable.js +15 -19
  52. package/src/painter/painter.shapes.js +11 -5
  53. package/src/particle/particle-system.js +165 -1
  54. package/src/physics/index.js +26 -0
  55. package/src/physics/physics-updaters.js +333 -0
  56. package/src/physics/physics.js +375 -0
  57. package/src/shapes/image.js +5 -5
  58. package/src/shapes/index.js +2 -0
  59. package/src/shapes/parallelogram.js +147 -0
  60. package/src/shapes/righttriangle.js +115 -0
  61. package/src/shapes/svg.js +281 -100
  62. package/src/shapes/text.js +22 -6
  63. package/src/shapes/transformable.js +5 -0
  64. package/src/sound/effects.js +807 -0
  65. package/src/sound/index.js +13 -0
  66. package/src/webgl/index.js +7 -0
  67. package/src/webgl/shaders/clifford-point-shaders.js +131 -0
  68. package/src/webgl/shaders/dejong-point-shaders.js +131 -0
  69. package/src/webgl/shaders/point-sprite-shaders.js +152 -0
  70. package/src/webgl/webgl-clifford-renderer.js +477 -0
  71. package/src/webgl/webgl-dejong-renderer.js +472 -0
  72. package/src/webgl/webgl-line-renderer.js +391 -0
  73. package/src/webgl/webgl-particle-renderer.js +410 -0
  74. package/types/index.d.ts +30 -2
  75. package/types/io.d.ts +217 -0
  76. package/types/physics.d.ts +299 -0
  77. package/types/shapes.d.ts +8 -0
  78. package/types/webgl.d.ts +188 -109
@@ -15,3 +15,16 @@ export { SynthEnvelope } from "./synth.envelope.js";
15
15
  export { SynthNoise } from "./synth.noise.js";
16
16
  export { SynthMusical } from "./synth.musical.js";
17
17
  export { SynthAnalyzer } from "./synth.analyzer.js";
18
+
19
+ // Audio effect primitives
20
+ export {
21
+ Flanger,
22
+ DJFilter,
23
+ EQFilterBank,
24
+ HighShelf,
25
+ AdvancedDelay,
26
+ AdvancedDistortion,
27
+ AdvancedTremolo,
28
+ Limiter,
29
+ MasterGain,
30
+ } from "./effects.js";
@@ -6,4 +6,11 @@
6
6
  */
7
7
 
8
8
  export { WebGLRenderer } from "./webgl-renderer.js";
9
+ export { WebGLParticleRenderer } from "./webgl-particle-renderer.js";
10
+ export { WebGLLineRenderer } from "./webgl-line-renderer.js";
11
+ export { WebGLDeJongRenderer } from "./webgl-dejong-renderer.js";
12
+ export { WebGLCliffordRenderer } from "./webgl-clifford-renderer.js";
9
13
  export { SPHERE_SHADERS } from "./shaders/sphere-shaders.js";
14
+ export * from "./shaders/point-sprite-shaders.js";
15
+ export * from "./shaders/dejong-point-shaders.js";
16
+ export * from "./shaders/clifford-point-shaders.js";
@@ -0,0 +1,131 @@
1
+ /**
2
+ * @module webgl/shaders/clifford-point-shaders
3
+ * @description Procedural Clifford attractor shaders (GL_POINTS).
4
+ *
5
+ * This shader iterates the Clifford map directly in the vertex shader.
6
+ * The attribute buffer contains random seeds in \([-1,1]\).
7
+ *
8
+ * Unlike `point-sprite-shaders.js` (which expects CPU-provided screen-space points),
9
+ * these shaders generate positions procedurally on the GPU.
10
+ *
11
+ * Clifford equations:
12
+ * x_{n+1} = sin(a·y_n) + c·cos(a·x_n)
13
+ * y_{n+1} = sin(b·x_n) + d·cos(b·y_n)
14
+ */
15
+
16
+ import {
17
+ POINT_SPRITE_CIRCLE_FRAGMENT,
18
+ POINT_SPRITE_GLOW_FRAGMENT,
19
+ POINT_SPRITE_SOFT_SQUARE_FRAGMENT,
20
+ POINT_SPRITE_SQUARE_FRAGMENT,
21
+ } from "./point-sprite-shaders.js";
22
+
23
+ /**
24
+ * Maximum iterations supported by the vertex shader.
25
+ * Increase carefully: higher values cost GPU time.
26
+ * @type {number}
27
+ */
28
+ export const CLIFFORD_MAX_ITERATIONS = 200;
29
+
30
+ /**
31
+ * Procedural Clifford vertex shader.
32
+ *
33
+ * Uniforms:
34
+ * - `uTime`: seconds
35
+ * - `uParams`: vec4(a,b,c,d)
36
+ * - `uIterations`: number of iterations to apply (0..CLIFFORD_MAX_ITERATIONS)
37
+ * - `uTransform`: 2D transform in clip space (mat3)
38
+ * - `uZoom`: zoom factor (multiplies the attractor)
39
+ * - `uPointScale`: base scale mapping attractor space to clip space
40
+ * - `uPointSize`: gl_PointSize (pixels)
41
+ * - `uColorMode`: 0 = flat `uColor`, 1 = Lorenz-style speed→hue ramp
42
+ * - `uColor`: RGBA (0..1) used when `uColorMode=0`
43
+ * - `uHueRange`: vec2(minHue, maxHue) degrees (fast→slow mapping like Lorenz)
44
+ * - `uMaxSpeed`: speed normalization threshold
45
+ * - `uSaturation`: 0..1
46
+ * - `uLightness`: 0..1
47
+ * - `uAlpha`: 0..1
48
+ * - `uHueOffset`: degrees (e.g. time*hueShiftSpeed)
49
+ */
50
+ export const CLIFFORD_POINT_VERTEX = `
51
+ precision highp float;
52
+
53
+ attribute vec2 aPosition; // random seed in [-1, 1]
54
+
55
+ uniform float uTime;
56
+ uniform vec4 uParams; // (a, b, c, d)
57
+ uniform int uIterations; // 0..${CLIFFORD_MAX_ITERATIONS}
58
+ uniform mat3 uTransform; // clip-space transform
59
+ uniform float uZoom;
60
+ uniform float uPointScale;
61
+ uniform float uPointSize;
62
+ uniform int uColorMode;
63
+ uniform vec4 uColor; // non-premultiplied RGBA (0..1)
64
+ uniform vec2 uHueRange; // (minHue, maxHue)
65
+ uniform float uMaxSpeed;
66
+ uniform float uSaturation; // 0..1
67
+ uniform float uLightness; // 0..1
68
+ uniform float uAlpha; // 0..1
69
+ uniform float uHueOffset; // degrees
70
+
71
+ varying vec4 vColor;
72
+
73
+ // HSL to RGB (all 0..1). Based on a compact shader formulation.
74
+ vec3 hsl2rgb(vec3 hsl) {
75
+ vec3 rgb = clamp(abs(mod(hsl.x * 6.0 + vec3(0.0, 4.0, 2.0), 6.0) - 3.0) - 1.0, 0.0, 1.0);
76
+ rgb = rgb * rgb * (3.0 - 2.0 * rgb);
77
+ float c = (1.0 - abs(2.0 * hsl.z - 1.0)) * hsl.y;
78
+ return (rgb - 0.5) * c + hsl.z;
79
+ }
80
+
81
+ void main() {
82
+ vec2 p = aPosition;
83
+ vec2 lastDelta = vec2(0.0);
84
+
85
+ // Clifford iterative map
86
+ // x' = sin(a*y) + c*cos(a*x)
87
+ // y' = sin(b*x) + d*cos(b*y)
88
+ for (int i = 0; i < ${CLIFFORD_MAX_ITERATIONS}; i++) {
89
+ if (i >= uIterations) break;
90
+ vec2 prev = p;
91
+ float x = sin(uParams.x * p.y) + uParams.z * cos(uParams.x * p.x);
92
+ float y = sin(uParams.y * p.x) + uParams.w * cos(uParams.y * p.y);
93
+ p = vec2(x, y);
94
+ lastDelta = p - prev;
95
+ }
96
+
97
+ // Map attractor space into clip space
98
+ vec3 transformed = uTransform * vec3(p * uPointScale * uZoom, 1.0);
99
+ gl_Position = vec4(transformed.xy, 0.0, 1.0);
100
+ gl_PointSize = uPointSize;
101
+
102
+ // Color
103
+ vec4 c;
104
+ if (uColorMode == 1) {
105
+ float speed = length(lastDelta);
106
+ float speedNorm = clamp(speed / max(uMaxSpeed, 0.0001), 0.0, 1.0);
107
+ float baseHue = uHueRange.y - speedNorm * (uHueRange.y - uHueRange.x);
108
+ float hue = mod(baseHue + uHueOffset, 360.0);
109
+ vec3 rgb = hsl2rgb(vec3(hue / 360.0, clamp(uSaturation, 0.0, 1.0), clamp(uLightness, 0.0, 1.0)));
110
+ c = vec4(rgb, clamp(uAlpha, 0.0, 1.0));
111
+ } else {
112
+ c = uColor;
113
+ }
114
+
115
+ // Premultiply in shader (renderer uses premultipliedAlpha for compositing)
116
+ c.rgb *= c.a;
117
+ vColor = c;
118
+ }
119
+ `;
120
+
121
+ /**
122
+ * Fragment shaders for procedural points.
123
+ * Re-uses the point sprite shapes.
124
+ */
125
+ export const CLIFFORD_POINT_FRAGMENTS = {
126
+ circle: POINT_SPRITE_CIRCLE_FRAGMENT,
127
+ glow: POINT_SPRITE_GLOW_FRAGMENT,
128
+ square: POINT_SPRITE_SQUARE_FRAGMENT,
129
+ softSquare: POINT_SPRITE_SOFT_SQUARE_FRAGMENT,
130
+ };
131
+
@@ -0,0 +1,131 @@
1
+ /**
2
+ * @module webgl/shaders/dejong-point-shaders
3
+ * @description Procedural De Jong attractor shaders (GL_POINTS).
4
+ *
5
+ * This shader iterates the De Jong map directly in the vertex shader.
6
+ * The attribute buffer contains random seeds in \([-1,1]\).
7
+ *
8
+ * Unlike `point-sprite-shaders.js` (which expects CPU-provided screen-space points),
9
+ * these shaders generate positions procedurally on the GPU.
10
+ *
11
+ * References:
12
+ * - `D:/Developer/studies/DeJong-Attractor` (GPU iteration workflow)
13
+ */
14
+
15
+ import {
16
+ POINT_SPRITE_CIRCLE_FRAGMENT,
17
+ POINT_SPRITE_GLOW_FRAGMENT,
18
+ POINT_SPRITE_SOFT_SQUARE_FRAGMENT,
19
+ POINT_SPRITE_SQUARE_FRAGMENT,
20
+ } from "./point-sprite-shaders.js";
21
+
22
+ /**
23
+ * Maximum iterations supported by the vertex shader.
24
+ * Increase carefully: higher values cost GPU time.
25
+ * @type {number}
26
+ */
27
+ export const DEJONG_MAX_ITERATIONS = 200;
28
+
29
+ /**
30
+ * Procedural De Jong vertex shader.
31
+ *
32
+ * Uniforms:
33
+ * - `uTime`: seconds
34
+ * - `uParams`: vec4(a,b,c,d)
35
+ * - `uIterations`: number of iterations to apply (0..DEJONG_MAX_ITERATIONS)
36
+ * - `uTransform`: 2D transform in clip space (mat3)
37
+ * - `uZoom`: zoom factor (multiplies the attractor)
38
+ * - `uPointScale`: base scale mapping attractor space to clip space (like 0.5 in the reference)
39
+ * - `uPointSize`: gl_PointSize (pixels)
40
+ * - `uColorMode`: 0 = flat `uColor`, 1 = Lorenz-style speed→hue ramp
41
+ * - `uColor`: RGBA (0..1) used when `uColorMode=0`
42
+ * - `uHueRange`: vec2(minHue, maxHue) degrees (fast→slow mapping like Lorenz)
43
+ * - `uMaxSpeed`: speed normalization threshold
44
+ * - `uSaturation`: 0..1
45
+ * - `uLightness`: 0..1
46
+ * - `uAlpha`: 0..1
47
+ * - `uHueOffset`: degrees (e.g. time*hueShiftSpeed)
48
+ */
49
+ export const DEJONG_POINT_VERTEX = `
50
+ precision highp float;
51
+
52
+ attribute vec2 aPosition; // random seed in [-1, 1]
53
+
54
+ uniform float uTime;
55
+ uniform vec4 uParams; // (a, b, c, d)
56
+ uniform int uIterations; // 0..${DEJONG_MAX_ITERATIONS}
57
+ uniform mat3 uTransform; // clip-space transform
58
+ uniform float uZoom;
59
+ uniform float uPointScale;
60
+ uniform float uPointSize;
61
+ uniform int uColorMode;
62
+ uniform vec4 uColor; // non-premultiplied RGBA (0..1)
63
+ uniform vec2 uHueRange; // (minHue, maxHue)
64
+ uniform float uMaxSpeed;
65
+ uniform float uSaturation; // 0..1
66
+ uniform float uLightness; // 0..1
67
+ uniform float uAlpha; // 0..1
68
+ uniform float uHueOffset; // degrees
69
+
70
+ varying vec4 vColor;
71
+
72
+ // HSL to RGB (all 0..1). Based on a compact shader formulation.
73
+ vec3 hsl2rgb(vec3 hsl) {
74
+ vec3 rgb = clamp(abs(mod(hsl.x * 6.0 + vec3(0.0, 4.0, 2.0), 6.0) - 3.0) - 1.0, 0.0, 1.0);
75
+ rgb = rgb * rgb * (3.0 - 2.0 * rgb);
76
+ float c = (1.0 - abs(2.0 * hsl.z - 1.0)) * hsl.y;
77
+ return (rgb - 0.5) * c + hsl.z;
78
+ }
79
+
80
+ void main() {
81
+ vec2 p = aPosition;
82
+ vec2 lastDelta = vec2(0.0);
83
+
84
+ // De Jong iterative map
85
+ // x' = sin(a*y) - cos(b*x)
86
+ // y' = sin(c*x) - cos(d*y)
87
+ for (int i = 0; i < ${DEJONG_MAX_ITERATIONS}; i++) {
88
+ if (i >= uIterations) break;
89
+ vec2 prev = p;
90
+ float x = sin(uParams.x * p.y) - cos(uParams.y * p.x);
91
+ float y = sin(uParams.z * p.x) - cos(uParams.w * p.y);
92
+ p = vec2(x, y);
93
+ lastDelta = p - prev;
94
+ }
95
+
96
+ // Map attractor space into clip space
97
+ vec3 transformed = uTransform * vec3(p * uPointScale * uZoom, 1.0);
98
+ gl_Position = vec4(transformed.xy, 0.0, 1.0);
99
+ gl_PointSize = uPointSize;
100
+
101
+ // Color
102
+ vec4 c;
103
+ if (uColorMode == 1) {
104
+ // Lorenz-like mapping: slow → maxHue, fast → minHue
105
+ float speed = length(lastDelta);
106
+ float speedNorm = clamp(speed / max(uMaxSpeed, 0.0001), 0.0, 1.0);
107
+ float baseHue = uHueRange.y - speedNorm * (uHueRange.y - uHueRange.x);
108
+ float hue = mod(baseHue + uHueOffset, 360.0);
109
+ vec3 rgb = hsl2rgb(vec3(hue / 360.0, clamp(uSaturation, 0.0, 1.0), clamp(uLightness, 0.0, 1.0)));
110
+ c = vec4(rgb, clamp(uAlpha, 0.0, 1.0));
111
+ } else {
112
+ c = uColor;
113
+ }
114
+
115
+ // Premultiply in shader (renderer uses premultipliedAlpha for compositing)
116
+ c.rgb *= c.a;
117
+ vColor = c;
118
+ }
119
+ `;
120
+
121
+ /**
122
+ * Fragment shaders for DeJong procedural points.
123
+ * Re-uses the point sprite shapes.
124
+ */
125
+ export const DEJONG_POINT_FRAGMENTS = {
126
+ circle: POINT_SPRITE_CIRCLE_FRAGMENT,
127
+ glow: POINT_SPRITE_GLOW_FRAGMENT,
128
+ square: POINT_SPRITE_SQUARE_FRAGMENT,
129
+ softSquare: POINT_SPRITE_SOFT_SQUARE_FRAGMENT,
130
+ };
131
+
@@ -0,0 +1,152 @@
1
+ /**
2
+ * Point Sprite Shaders for WebGL Particle Rendering
3
+ *
4
+ * These shaders render particles as GL_POINTS with gl_PointSize.
5
+ * Used by WebGLParticleRenderer for GPU-accelerated particle systems.
6
+ */
7
+
8
+ // =============================================================================
9
+ // VERTEX SHADER
10
+ // =============================================================================
11
+
12
+ /**
13
+ * Point sprite vertex shader
14
+ * Takes screen-space positions (already projected by Camera3D on CPU)
15
+ * and converts to clip space for rendering.
16
+ */
17
+ export const POINT_SPRITE_VERTEX = `
18
+ precision highp float;
19
+
20
+ attribute vec2 aPosition; // Screen position (pixels, already projected)
21
+ attribute float aSize; // Point size in pixels
22
+ attribute vec4 aColor; // RGBA color (0-1 range)
23
+
24
+ varying vec4 vColor;
25
+
26
+ uniform vec2 uResolution; // Canvas dimensions
27
+
28
+ void main() {
29
+ // Convert from pixel coords to clip space (-1 to 1)
30
+ vec2 clipPos = (aPosition / uResolution) * 2.0 - 1.0;
31
+ clipPos.y = -clipPos.y; // Flip Y (canvas Y is down, GL Y is up)
32
+
33
+ gl_Position = vec4(clipPos, 0.0, 1.0);
34
+ gl_PointSize = aSize;
35
+ vColor = aColor;
36
+ }
37
+ `;
38
+
39
+ // =============================================================================
40
+ // FRAGMENT SHADERS
41
+ // =============================================================================
42
+
43
+ /**
44
+ * Circle fragment shader with soft anti-aliased edge
45
+ * Most common particle shape - smooth circular particles
46
+ */
47
+ export const POINT_SPRITE_CIRCLE_FRAGMENT = `
48
+ precision mediump float;
49
+
50
+ varying vec4 vColor;
51
+
52
+ void main() {
53
+ // gl_PointCoord is 0-1 UV within the point quad
54
+ vec2 coord = gl_PointCoord - vec2(0.5);
55
+ float dist = length(coord);
56
+
57
+ // Discard pixels outside circle
58
+ if (dist > 0.5) {
59
+ discard;
60
+ }
61
+
62
+ // Soft edge for anti-aliasing
63
+ float alpha = vColor.a * (1.0 - smoothstep(0.4, 0.5, dist));
64
+ gl_FragColor = vec4(vColor.rgb, alpha);
65
+ }
66
+ `;
67
+
68
+ /**
69
+ * Circle fragment shader with glow effect
70
+ * Particles have a bright core that fades outward
71
+ */
72
+ export const POINT_SPRITE_GLOW_FRAGMENT = `
73
+ precision mediump float;
74
+
75
+ varying vec4 vColor;
76
+
77
+ void main() {
78
+ vec2 coord = gl_PointCoord - vec2(0.5);
79
+ float dist = length(coord);
80
+
81
+ if (dist > 0.5) {
82
+ discard;
83
+ }
84
+
85
+ // Radial falloff for glow effect
86
+ float glow = 1.0 - (dist * 2.0);
87
+ glow = glow * glow; // Quadratic falloff
88
+
89
+ float alpha = vColor.a * glow;
90
+ vec3 color = vColor.rgb * (0.5 + glow * 0.5); // Brighten center
91
+
92
+ gl_FragColor = vec4(color, alpha);
93
+ }
94
+ `;
95
+
96
+ /**
97
+ * Square fragment shader (no clipping)
98
+ * Fastest option - just outputs the color directly
99
+ */
100
+ export const POINT_SPRITE_SQUARE_FRAGMENT = `
101
+ precision mediump float;
102
+
103
+ varying vec4 vColor;
104
+
105
+ void main() {
106
+ gl_FragColor = vColor;
107
+ }
108
+ `;
109
+
110
+ /**
111
+ * Soft square fragment shader with rounded corners
112
+ */
113
+ export const POINT_SPRITE_SOFT_SQUARE_FRAGMENT = `
114
+ precision mediump float;
115
+
116
+ varying vec4 vColor;
117
+
118
+ void main() {
119
+ vec2 coord = abs(gl_PointCoord - vec2(0.5)) * 2.0; // 0 at center, 1 at edge
120
+ float d = max(coord.x, coord.y);
121
+
122
+ // Soft edge
123
+ float alpha = vColor.a * (1.0 - smoothstep(0.8, 1.0, d));
124
+ gl_FragColor = vec4(vColor.rgb, alpha);
125
+ }
126
+ `;
127
+
128
+ // =============================================================================
129
+ // SHADER PRESETS
130
+ // =============================================================================
131
+
132
+ /**
133
+ * Pre-configured shader combinations for common use cases
134
+ */
135
+ export const POINT_SPRITE_PRESETS = {
136
+ circle: {
137
+ vertex: POINT_SPRITE_VERTEX,
138
+ fragment: POINT_SPRITE_CIRCLE_FRAGMENT,
139
+ },
140
+ glow: {
141
+ vertex: POINT_SPRITE_VERTEX,
142
+ fragment: POINT_SPRITE_GLOW_FRAGMENT,
143
+ },
144
+ square: {
145
+ vertex: POINT_SPRITE_VERTEX,
146
+ fragment: POINT_SPRITE_SQUARE_FRAGMENT,
147
+ },
148
+ softSquare: {
149
+ vertex: POINT_SPRITE_VERTEX,
150
+ fragment: POINT_SPRITE_SOFT_SQUARE_FRAGMENT,
151
+ },
152
+ };