@guinetik/gcanvas 1.0.2 → 1.0.4
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.
- package/dist/gcanvas.es.js +25656 -0
- package/dist/gcanvas.es.min.js +1 -0
- package/dist/gcanvas.umd.js +1 -0
- package/dist/gcanvas.umd.min.js +1 -0
- package/package.json +23 -6
- package/src/game/objects/index.js +1 -0
- package/src/game/objects/spritesheet.js +260 -0
- package/src/game/ui/theme.js +6 -0
- package/src/io/keys.js +9 -1
- package/src/math/boolean.js +481 -0
- package/src/math/index.js +1 -0
- package/.github/workflows/release.yaml +0 -70
- package/.jshintrc +0 -4
- package/.vscode/settings.json +0 -22
- package/CLAUDE.md +0 -310
- package/blackhole.jpg +0 -0
- package/demo.png +0 -0
- package/demos/CNAME +0 -1
- package/demos/animations.html +0 -31
- package/demos/basic.html +0 -38
- package/demos/baskara.html +0 -31
- package/demos/bezier.html +0 -35
- package/demos/beziersignature.html +0 -29
- package/demos/blackhole.html +0 -28
- package/demos/blob.html +0 -35
- package/demos/coordinates.html +0 -698
- package/demos/cube3d.html +0 -23
- package/demos/demos.css +0 -303
- package/demos/dino.html +0 -42
- package/demos/easing.html +0 -28
- package/demos/events.html +0 -195
- package/demos/fluent.html +0 -647
- package/demos/fluid-simple.html +0 -22
- package/demos/fluid.html +0 -37
- package/demos/fractals.html +0 -36
- package/demos/gameobjects.html +0 -626
- package/demos/genart.html +0 -26
- package/demos/gendream.html +0 -26
- package/demos/group.html +0 -36
- package/demos/home.html +0 -587
- package/demos/index.html +0 -376
- package/demos/isometric.html +0 -34
- package/demos/js/animations.js +0 -452
- package/demos/js/basic.js +0 -204
- package/demos/js/baskara.js +0 -751
- package/demos/js/bezier.js +0 -692
- package/demos/js/beziersignature.js +0 -241
- package/demos/js/blackhole/accretiondisk.obj.js +0 -379
- package/demos/js/blackhole/blackhole.obj.js +0 -318
- package/demos/js/blackhole/index.js +0 -409
- package/demos/js/blackhole/particle.js +0 -56
- package/demos/js/blackhole/starfield.obj.js +0 -218
- package/demos/js/blob.js +0 -2276
- package/demos/js/coordinates.js +0 -840
- package/demos/js/cube3d.js +0 -789
- package/demos/js/dino.js +0 -1420
- package/demos/js/easing.js +0 -477
- package/demos/js/fluent.js +0 -183
- package/demos/js/fluid-simple.js +0 -253
- package/demos/js/fluid.js +0 -527
- package/demos/js/fractals.js +0 -931
- package/demos/js/fractalworker.js +0 -93
- package/demos/js/gameobjects.js +0 -176
- package/demos/js/genart.js +0 -268
- package/demos/js/gendream.js +0 -209
- package/demos/js/group.js +0 -140
- package/demos/js/info-toggle.js +0 -25
- package/demos/js/isometric.js +0 -863
- package/demos/js/kerr.js +0 -1556
- package/demos/js/lavalamp.js +0 -590
- package/demos/js/layout.js +0 -354
- package/demos/js/mondrian.js +0 -285
- package/demos/js/opacity.js +0 -275
- package/demos/js/painter.js +0 -484
- package/demos/js/particles-showcase.js +0 -514
- package/demos/js/particles.js +0 -299
- package/demos/js/patterns.js +0 -397
- package/demos/js/penrose/artifact.js +0 -69
- package/demos/js/penrose/blackhole.js +0 -121
- package/demos/js/penrose/constants.js +0 -73
- package/demos/js/penrose/game.js +0 -943
- package/demos/js/penrose/lore.js +0 -278
- package/demos/js/penrose/penrosescene.js +0 -892
- package/demos/js/penrose/ship.js +0 -216
- package/demos/js/penrose/sounds.js +0 -211
- package/demos/js/penrose/voidparticle.js +0 -55
- package/demos/js/penrose/voidscene.js +0 -258
- package/demos/js/penrose/voidship.js +0 -144
- package/demos/js/penrose/wormhole.js +0 -46
- package/demos/js/pipeline.js +0 -555
- package/demos/js/plane3d.js +0 -256
- package/demos/js/platformer.js +0 -1579
- package/demos/js/scene.js +0 -304
- package/demos/js/scenes.js +0 -320
- package/demos/js/schrodinger.js +0 -410
- package/demos/js/schwarzschild.js +0 -1023
- package/demos/js/shapes.js +0 -628
- package/demos/js/space/alien.js +0 -171
- package/demos/js/space/boom.js +0 -98
- package/demos/js/space/boss.js +0 -353
- package/demos/js/space/buff.js +0 -73
- package/demos/js/space/bullet.js +0 -102
- package/demos/js/space/constants.js +0 -85
- package/demos/js/space/game.js +0 -1884
- package/demos/js/space/hud.js +0 -112
- package/demos/js/space/laserbeam.js +0 -179
- package/demos/js/space/lightning.js +0 -277
- package/demos/js/space/minion.js +0 -192
- package/demos/js/space/missile.js +0 -212
- package/demos/js/space/player.js +0 -430
- package/demos/js/space/powerup.js +0 -90
- package/demos/js/space/starfield.js +0 -58
- package/demos/js/space/starpower.js +0 -90
- package/demos/js/spacetime.js +0 -559
- package/demos/js/sphere3d.js +0 -229
- package/demos/js/sprite.js +0 -473
- package/demos/js/svgtween.js +0 -204
- package/demos/js/tde/accretiondisk.js +0 -471
- package/demos/js/tde/blackhole.js +0 -219
- package/demos/js/tde/blackholescene.js +0 -209
- package/demos/js/tde/config.js +0 -59
- package/demos/js/tde/index.js +0 -820
- package/demos/js/tde/jets.js +0 -290
- package/demos/js/tde/lensedstarfield.js +0 -154
- package/demos/js/tde/tdestar.js +0 -297
- package/demos/js/tde/tidalstream.js +0 -372
- package/demos/js/tde_old/blackhole.obj.js +0 -354
- package/demos/js/tde_old/debris.obj.js +0 -791
- package/demos/js/tde_old/flare.obj.js +0 -239
- package/demos/js/tde_old/index.js +0 -448
- package/demos/js/tde_old/star.obj.js +0 -812
- package/demos/js/tiles.js +0 -312
- package/demos/js/tweendemo.js +0 -79
- package/demos/js/visibility.js +0 -102
- package/demos/kerr.html +0 -28
- package/demos/lavalamp.html +0 -27
- package/demos/layouts.html +0 -37
- package/demos/logo.svg +0 -4
- package/demos/loop.html +0 -84
- package/demos/mondrian.html +0 -32
- package/demos/og_image.png +0 -0
- package/demos/opacity.html +0 -36
- package/demos/painter.html +0 -39
- package/demos/particles-showcase.html +0 -28
- package/demos/particles.html +0 -24
- package/demos/patterns.html +0 -33
- package/demos/penrose-game.html +0 -31
- package/demos/pipeline.html +0 -737
- package/demos/plane3d.html +0 -24
- package/demos/platformer.html +0 -43
- package/demos/scene.html +0 -33
- package/demos/scenes.html +0 -96
- package/demos/schrodinger.html +0 -27
- package/demos/schwarzschild.html +0 -27
- package/demos/shapes.html +0 -16
- package/demos/space.html +0 -85
- package/demos/spacetime.html +0 -27
- package/demos/sphere3d.html +0 -24
- package/demos/sprite.html +0 -18
- package/demos/svgtween.html +0 -29
- package/demos/tde.html +0 -28
- package/demos/tiles.html +0 -28
- package/demos/transforms.html +0 -400
- package/demos/tween.html +0 -45
- package/demos/visibility.html +0 -33
- package/docs/README.md +0 -230
- package/docs/api/FluidSystem.md +0 -173
- package/docs/concepts/architecture-overview.md +0 -204
- package/docs/concepts/coordinate-system.md +0 -384
- package/docs/concepts/lifecycle.md +0 -255
- package/docs/concepts/rendering-pipeline.md +0 -279
- package/docs/concepts/shapes-vs-gameobjects.md +0 -187
- package/docs/concepts/tde-zorder.md +0 -106
- package/docs/concepts/two-layer-architecture.md +0 -229
- package/docs/fluid-dynamics.md +0 -99
- package/docs/getting-started/first-game.md +0 -354
- package/docs/getting-started/hello-world.md +0 -269
- package/docs/getting-started/installation.md +0 -175
- package/docs/modules/collision/README.md +0 -453
- package/docs/modules/fluent/README.md +0 -1075
- package/docs/modules/game/README.md +0 -303
- package/docs/modules/isometric-camera.md +0 -210
- package/docs/modules/isometric.md +0 -275
- package/docs/modules/painter/README.md +0 -328
- package/docs/modules/particle/README.md +0 -559
- package/docs/modules/shapes/README.md +0 -221
- package/docs/modules/shapes/base/euclidian.md +0 -123
- package/docs/modules/shapes/base/geometry2d.md +0 -204
- package/docs/modules/shapes/base/renderable.md +0 -215
- package/docs/modules/shapes/base/shape.md +0 -262
- package/docs/modules/shapes/base/transformable.md +0 -243
- package/docs/modules/shapes/hierarchy.md +0 -218
- package/docs/modules/state/README.md +0 -577
- package/docs/modules/util/README.md +0 -99
- package/docs/modules/util/camera3d.md +0 -412
- package/docs/modules/util/scene3d.md +0 -395
- package/index.html +0 -17
- package/jsdoc.json +0 -50
- package/scripts/build-demo.js +0 -69
- package/scripts/bundle4llm.js +0 -276
- package/scripts/clearconsole.js +0 -48
- package/test/math/orbital.test.js +0 -61
- package/test/math/tensor.test.js +0 -114
- package/test/particle/emitter.test.js +0 -204
- package/test/particle/particle-system.test.js +0 -310
- package/test/particle/particle.test.js +0 -116
- package/test/particle/updaters.test.js +0 -386
- package/test/setup.js +0 -120
- package/test/shapes/euclidian.test.js +0 -44
- package/test/shapes/geometry.test.js +0 -86
- package/test/shapes/group.test.js +0 -86
- package/test/shapes/rectangle.test.js +0 -64
- package/test/shapes/transform.test.js +0 -379
- package/test/util/camera3d.test.js +0 -428
- package/test/util/scene3d.test.js +0 -352
- package/vite.config.js +0 -50
- package/vitest.config.js +0 -13
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Worker for the fractal demo.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Handle messages from the main thread.
|
|
7
|
-
* @param {MessageEvent} e - The message event.
|
|
8
|
-
*/
|
|
9
|
-
self.onmessage = function (e) {
|
|
10
|
-
if (e.data.taskName === "generateFractal") {
|
|
11
|
-
//console.time("generateFractal");
|
|
12
|
-
const { width, height } = e.data.params;
|
|
13
|
-
//console.log("fractalworker", e.data.params);
|
|
14
|
-
// Generate the raw fractal data
|
|
15
|
-
const rawData = generateFractalData(width, height, e.data.params.fractalFunction, e.data.params.args);
|
|
16
|
-
//console.log("rawData", e.data.params.args);
|
|
17
|
-
// Create and fill the image data
|
|
18
|
-
const imageData = new ImageData(width, height);
|
|
19
|
-
// Apply color scheme
|
|
20
|
-
const coloredData = applyColorScheme(rawData, imageData, e.data.params.colorFunction, e.data.params.colorArgs);
|
|
21
|
-
//console.log("coloredData", coloredData);
|
|
22
|
-
// Send back the completed image data using the format TaskManager expects
|
|
23
|
-
self.postMessage(
|
|
24
|
-
{
|
|
25
|
-
taskId: e.data.taskId, // Include the taskId
|
|
26
|
-
status: 'complete', // Use 'complete' status
|
|
27
|
-
result: { // Put the data inside 'result'
|
|
28
|
-
image: coloredData,
|
|
29
|
-
settings: e.data.params
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
[coloredData.data.buffer]
|
|
33
|
-
);
|
|
34
|
-
//console.timeEnd("generateFractal");
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Generate the raw fractal data.
|
|
40
|
-
* @param {number} width - The width of the fractal.
|
|
41
|
-
* @param {number} height - The height of the fractal.
|
|
42
|
-
* @param {string} fractalFunction - The fractal function.
|
|
43
|
-
* @param {Array} fractalArgs - The arguments for the fractal function.
|
|
44
|
-
* @returns {Array} The raw fractal data.
|
|
45
|
-
*/
|
|
46
|
-
function generateFractalData(width, height, fractalFunction, fractalArgs) {
|
|
47
|
-
try {
|
|
48
|
-
// For class methods, we need to convert to a standalone function
|
|
49
|
-
// This extracts just the function part without the name
|
|
50
|
-
const functionStr = fractalFunction.replace(/^[^(]+/, "function");
|
|
51
|
-
// Create the function from the string
|
|
52
|
-
const f = new Function("return (" + functionStr + ")")();
|
|
53
|
-
// Execute the function with our parameters
|
|
54
|
-
return f(width, height, ...fractalArgs);
|
|
55
|
-
} catch (error) {
|
|
56
|
-
console.error("Error evaluating fractal function:", error);
|
|
57
|
-
console.log("Function string:", fractalFunction);
|
|
58
|
-
throw error;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function applyColorScheme(rawData, imageData, colorFunction, colorArgs) {
|
|
63
|
-
try {
|
|
64
|
-
const functionStr = colorFunction.replace(/^[^(]+/, "function");
|
|
65
|
-
|
|
66
|
-
// Create the function from the string
|
|
67
|
-
const f = new Function("return (" + functionStr + ")")();
|
|
68
|
-
// Execute the function with our parameters
|
|
69
|
-
return f(rawData, imageData, ...colorArgs, hslToRgb);
|
|
70
|
-
} catch (error) {
|
|
71
|
-
console.error("Error evaluating color function:", error);
|
|
72
|
-
console.log("Function string:", colorFunction);
|
|
73
|
-
throw error;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Copied from Painter.colors for convenience.
|
|
78
|
-
function hslToRgb(h, s, l) {
|
|
79
|
-
const c = (1 - Math.abs(2 * l - 1)) * s;
|
|
80
|
-
const hPrime = h / 60;
|
|
81
|
-
const x = c * (1 - Math.abs((hPrime % 2) - 1));
|
|
82
|
-
let [r, g, b] = [0, 0, 0];
|
|
83
|
-
|
|
84
|
-
if (hPrime >= 0 && hPrime < 1) [r, g, b] = [c, x, 0];
|
|
85
|
-
else if (hPrime >= 1 && hPrime < 2) [r, g, b] = [x, c, 0];
|
|
86
|
-
else if (hPrime >= 2 && hPrime < 3) [r, g, b] = [0, c, x];
|
|
87
|
-
else if (hPrime >= 3 && hPrime < 4) [r, g, b] = [0, x, c];
|
|
88
|
-
else if (hPrime >= 4 && hPrime < 5) [r, g, b] = [x, 0, c];
|
|
89
|
-
else if (hPrime >= 5 && hPrime < 6) [r, g, b] = [c, 0, x];
|
|
90
|
-
|
|
91
|
-
const m = l - c / 2;
|
|
92
|
-
return [(r + m) * 255, (g + m) * 255, (b + m) * 255];
|
|
93
|
-
}
|
package/demos/js/gameobjects.js
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Gameobjects.html - Live demos for Shapes vs GameObjects documentation
|
|
3
|
-
*/
|
|
4
|
-
import {
|
|
5
|
-
Circle,
|
|
6
|
-
Game,
|
|
7
|
-
Group,
|
|
8
|
-
Painter,
|
|
9
|
-
Rectangle,
|
|
10
|
-
Scene,
|
|
11
|
-
ShapeGOFactory,
|
|
12
|
-
Sprite,
|
|
13
|
-
} from "../../src/index.js";
|
|
14
|
-
|
|
15
|
-
// ==================== Demo 1: Shapes Only ====================
|
|
16
|
-
// Even "shapes only" needs Painter initialized, so we use a minimal Game
|
|
17
|
-
class ShapesDemo extends Game {
|
|
18
|
-
constructor(canvas) {
|
|
19
|
-
super(canvas);
|
|
20
|
-
this.backgroundColor = "#050505";
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
init() {
|
|
24
|
-
super.init();
|
|
25
|
-
// Shapes are created and rendered in render() below
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
render() {
|
|
29
|
-
super.render(); // Clears canvas
|
|
30
|
-
|
|
31
|
-
const centerY = this.canvas.height / 2;
|
|
32
|
-
|
|
33
|
-
// Create shapes - spread across canvas
|
|
34
|
-
const circle = new Circle(35, { x: this.canvas.width * 0.2, y: centerY, color: "#0f0" });
|
|
35
|
-
const rect = new Rectangle({ x: this.canvas.width * 0.5, y: centerY, width: 80, height: 50, color: "#0ff" });
|
|
36
|
-
|
|
37
|
-
// Group with rotation
|
|
38
|
-
const group = new Group({ x: this.canvas.width * 0.8, y: centerY, rotation: Math.PI / 4 });
|
|
39
|
-
group.add(new Circle(20, { color: "#f0f" }));
|
|
40
|
-
group.add(new Rectangle({ y: 30, width: 40, height: 20, color: "#ff0" }));
|
|
41
|
-
|
|
42
|
-
// Render directly - calling render() on shapes, not using pipeline
|
|
43
|
-
circle.render();
|
|
44
|
-
rect.render();
|
|
45
|
-
group.render();
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function initShapesDemo() {
|
|
50
|
-
const canvas = document.getElementById("shapes-canvas");
|
|
51
|
-
if (!canvas) return;
|
|
52
|
-
|
|
53
|
-
const rect = canvas.getBoundingClientRect();
|
|
54
|
-
canvas.width = rect.width;
|
|
55
|
-
canvas.height = rect.height;
|
|
56
|
-
|
|
57
|
-
const demo = new ShapesDemo(canvas);
|
|
58
|
-
demo.start();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// ==================== Demo 2: GameObjects with Pipeline ====================
|
|
62
|
-
class GameObjectsDemo extends Game {
|
|
63
|
-
constructor(canvas) {
|
|
64
|
-
super(canvas);
|
|
65
|
-
this.backgroundColor = "#050505";
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
init() {
|
|
69
|
-
super.init();
|
|
70
|
-
|
|
71
|
-
const centerX = this.canvas.width / 2;
|
|
72
|
-
const centerY = this.canvas.height / 2;
|
|
73
|
-
|
|
74
|
-
// Create a scene (GameObject container)
|
|
75
|
-
this.scene = new Scene(this, { x: centerX, y: centerY });
|
|
76
|
-
|
|
77
|
-
// Create a sprite with animation (GameObject)
|
|
78
|
-
this.player = new Sprite(this, { frameRate: 8, loop: true, autoPlay: true });
|
|
79
|
-
|
|
80
|
-
// Add frames - pulsing circle animation
|
|
81
|
-
const colors = ["#0f0", "#0ff", "#0f0", "#ff0", "#0f0"];
|
|
82
|
-
const sizes = [20, 25, 30, 25, 20];
|
|
83
|
-
colors.forEach((color, i) => {
|
|
84
|
-
this.player.addFrame(new Circle(sizes[i], { color, stroke: "#fff", lineWidth: 2 }));
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
// Add to scene
|
|
88
|
-
this.scene.add(this.player);
|
|
89
|
-
|
|
90
|
-
// Add scene to pipeline - now it's managed
|
|
91
|
-
this.pipeline.add(this.scene);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function initGameObjectsDemo() {
|
|
96
|
-
const canvas = document.getElementById("gameobjects-canvas");
|
|
97
|
-
if (!canvas) return;
|
|
98
|
-
|
|
99
|
-
// Set actual canvas size
|
|
100
|
-
const rect = canvas.getBoundingClientRect();
|
|
101
|
-
canvas.width = rect.width;
|
|
102
|
-
canvas.height = rect.height;
|
|
103
|
-
|
|
104
|
-
const demo = new GameObjectsDemo(canvas);
|
|
105
|
-
demo.start();
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// ==================== Demo 3: Bridging Shape to GameObject ====================
|
|
109
|
-
class BridgingDemo extends Game {
|
|
110
|
-
constructor(canvas) {
|
|
111
|
-
super(canvas);
|
|
112
|
-
this.backgroundColor = "#050505";
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
init() {
|
|
116
|
-
super.init();
|
|
117
|
-
|
|
118
|
-
const centerX = this.canvas.width / 2;
|
|
119
|
-
const centerY = this.canvas.height / 2;
|
|
120
|
-
|
|
121
|
-
// Create a Group of shapes (like a simple avatar)
|
|
122
|
-
const avatar = new Group();
|
|
123
|
-
avatar.add(new Circle(25, { y: -30, color: "#0f0", stroke: "#0a0", lineWidth: 2 })); // head
|
|
124
|
-
avatar.add(new Rectangle({ y: 20, width: 40, height: 50, color: "#0f0", stroke: "#0a0", lineWidth: 2 })); // body
|
|
125
|
-
|
|
126
|
-
// Wrap it as a GameObject so it can join the pipeline
|
|
127
|
-
const avatarGO = ShapeGOFactory.create(this, avatar, {
|
|
128
|
-
x: centerX,
|
|
129
|
-
y: centerY,
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
// Now it's a proper GameObject - add to pipeline
|
|
133
|
-
this.pipeline.add(avatarGO);
|
|
134
|
-
|
|
135
|
-
// Add a second avatar to show multiple instances
|
|
136
|
-
const avatar2 = new Group();
|
|
137
|
-
avatar2.add(new Circle(20, { y: -25, color: "#0ff", stroke: "#0aa", lineWidth: 2 }));
|
|
138
|
-
avatar2.add(new Rectangle({ y: 15, width: 30, height: 40, color: "#0ff", stroke: "#0aa", lineWidth: 2 }));
|
|
139
|
-
|
|
140
|
-
const avatar2GO = ShapeGOFactory.create(this, avatar2, {
|
|
141
|
-
x: centerX + 100,
|
|
142
|
-
y: centerY,
|
|
143
|
-
});
|
|
144
|
-
this.pipeline.add(avatar2GO);
|
|
145
|
-
|
|
146
|
-
// Third one with rotation
|
|
147
|
-
const avatar3 = new Group({ rotation: 0.2 });
|
|
148
|
-
avatar3.add(new Circle(18, { y: -22, color: "#f0f", stroke: "#a0a", lineWidth: 2 }));
|
|
149
|
-
avatar3.add(new Rectangle({ y: 12, width: 25, height: 35, color: "#f0f", stroke: "#a0a", lineWidth: 2 }));
|
|
150
|
-
|
|
151
|
-
const avatar3GO = ShapeGOFactory.create(this, avatar3, {
|
|
152
|
-
x: centerX - 100,
|
|
153
|
-
y: centerY,
|
|
154
|
-
});
|
|
155
|
-
this.pipeline.add(avatar3GO);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
function initBridgingDemo() {
|
|
160
|
-
const canvas = document.getElementById("bridging-canvas");
|
|
161
|
-
if (!canvas) return;
|
|
162
|
-
|
|
163
|
-
const rect = canvas.getBoundingClientRect();
|
|
164
|
-
canvas.width = rect.width;
|
|
165
|
-
canvas.height = rect.height;
|
|
166
|
-
|
|
167
|
-
const demo = new BridgingDemo(canvas);
|
|
168
|
-
demo.start();
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// ==================== Initialize ====================
|
|
172
|
-
window.addEventListener("load", () => {
|
|
173
|
-
initShapesDemo();
|
|
174
|
-
initGameObjectsDemo();
|
|
175
|
-
initBridgingDemo();
|
|
176
|
-
});
|
package/demos/js/genart.js
DELETED
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hypnotic Mandala - Generative Art Demo
|
|
3
|
-
*
|
|
4
|
-
* A trippy, psychedelic mandala using the gcanvas fluent API.
|
|
5
|
-
* Features:
|
|
6
|
-
* - Concentric rings of shapes rotating at different speeds
|
|
7
|
-
* - HSL color cycling based on time and position
|
|
8
|
-
* - Pulsing and breathing effects
|
|
9
|
-
* - Responsive scaling for mobile
|
|
10
|
-
* - 3D rotation with inertia (drag to rotate!)
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { gcanvas, Camera3D } from '../../src/index.js';
|
|
14
|
-
|
|
15
|
-
// Configuration - base values at 800px reference size
|
|
16
|
-
const CONFIG = {
|
|
17
|
-
referenceSize: 800, // Design reference size
|
|
18
|
-
minScale: 0.4, // Minimum scale on small screens
|
|
19
|
-
rings: 6,
|
|
20
|
-
shapesPerRing: [8, 12, 16, 20, 24, 32],
|
|
21
|
-
baseRadius: 50,
|
|
22
|
-
ringSpacing: 45,
|
|
23
|
-
rotationSpeeds: [0.8, -0.6, 0.5, -0.4, 0.3, -0.2],
|
|
24
|
-
pulseAmplitudes: [0.12, 0.1, 0.08, 0.06, 0.05, 0.04],
|
|
25
|
-
colorOffsets: [0, 60, 120, 180, 240, 300],
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
// Calculate scale factor based on screen size
|
|
29
|
-
function getScaleFactor(width, height) {
|
|
30
|
-
const minDimension = Math.min(width, height);
|
|
31
|
-
const scale = minDimension / CONFIG.referenceSize;
|
|
32
|
-
return Math.max(CONFIG.minScale, Math.min(1.2, scale));
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Shape factory functions
|
|
36
|
-
const shapeTypes = ['circle', 'star', 'triangle', 'hexagon', 'diamond', 'ring'];
|
|
37
|
-
|
|
38
|
-
function getShapeConfig(ringIndex, shapeIndex) {
|
|
39
|
-
const type = shapeTypes[ringIndex % shapeTypes.length];
|
|
40
|
-
const baseSize = 12 - ringIndex;
|
|
41
|
-
|
|
42
|
-
switch (type) {
|
|
43
|
-
case 'circle':
|
|
44
|
-
return { method: 'circle', opts: { radius: baseSize } };
|
|
45
|
-
case 'star':
|
|
46
|
-
return { method: 'star', opts: { radius: baseSize, points: 5 + (ringIndex % 3), inset: 0.5 } };
|
|
47
|
-
case 'triangle':
|
|
48
|
-
return { method: 'triangle', opts: { size: baseSize * 1.8 } };
|
|
49
|
-
case 'hexagon':
|
|
50
|
-
return { method: 'hexagon', opts: { radius: baseSize } };
|
|
51
|
-
case 'diamond':
|
|
52
|
-
return { method: 'diamond', opts: { width: baseSize, height: baseSize * 1.5 } };
|
|
53
|
-
case 'ring':
|
|
54
|
-
return { method: 'ring', opts: { innerRadius: baseSize * 0.5, outerRadius: baseSize } };
|
|
55
|
-
default:
|
|
56
|
-
return { method: 'circle', opts: { radius: baseSize } };
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Initialize the mandala
|
|
61
|
-
window.addEventListener('load', () => {
|
|
62
|
-
const canvas = document.getElementById('game');
|
|
63
|
-
if (!canvas) return;
|
|
64
|
-
|
|
65
|
-
const game = gcanvas({ canvas, bg: '#0a0a0f', fluid: true });
|
|
66
|
-
const scene = game.scene('mandala');
|
|
67
|
-
|
|
68
|
-
// Create 3D camera with inertia for interactive rotation
|
|
69
|
-
const camera = new Camera3D({
|
|
70
|
-
rotationX: 0, // Start flat
|
|
71
|
-
rotationY: 0,
|
|
72
|
-
perspective: 600,
|
|
73
|
-
sensitivity: 0.008,
|
|
74
|
-
inertia: true,
|
|
75
|
-
friction: 0.96, // Higher = more drift before stopping
|
|
76
|
-
velocityScale: 2.5, // More momentum on fast flicks
|
|
77
|
-
autoRotate: false, // No auto-rotation - stays where user leaves it
|
|
78
|
-
clampX: false, // Free rotation in all directions
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
// Enable mouse/touch drag to rotate
|
|
82
|
-
camera.enableMouseControl(canvas);
|
|
83
|
-
|
|
84
|
-
// Store shape references for animation
|
|
85
|
-
const allShapes = [];
|
|
86
|
-
|
|
87
|
-
// Create center piece - a pulsing core (position will be updated dynamically)
|
|
88
|
-
scene.go({ x: 0, y: 0, name: 'core' })
|
|
89
|
-
.star({ radius: 25, points: 8, inset: 0.6, fill: '#fff' });
|
|
90
|
-
allShapes.push({ name: 'core', ring: -1, index: 0 });
|
|
91
|
-
|
|
92
|
-
// Create concentric rings
|
|
93
|
-
for (let ring = 0; ring < CONFIG.rings; ring++) {
|
|
94
|
-
const shapesInRing = CONFIG.shapesPerRing[ring];
|
|
95
|
-
const ringRadius = CONFIG.baseRadius + ring * CONFIG.ringSpacing;
|
|
96
|
-
|
|
97
|
-
for (let i = 0; i < shapesInRing; i++) {
|
|
98
|
-
const angle = (i / shapesInRing) * Math.PI * 2;
|
|
99
|
-
const name = `r${ring}_s${i}`;
|
|
100
|
-
|
|
101
|
-
const shapeConfig = getShapeConfig(ring, i);
|
|
102
|
-
const goBuilder = scene.go({ x: 0, y: 0, name });
|
|
103
|
-
|
|
104
|
-
// Apply the shape with initial color
|
|
105
|
-
const hue = (ring * 60 + i * (360 / shapesInRing)) % 360;
|
|
106
|
-
goBuilder[shapeConfig.method]({
|
|
107
|
-
...shapeConfig.opts,
|
|
108
|
-
fill: `hsl(${hue}, 80%, 60%)`
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
allShapes.push({
|
|
112
|
-
name,
|
|
113
|
-
ring,
|
|
114
|
-
index: i,
|
|
115
|
-
baseAngle: angle,
|
|
116
|
-
ringRadius,
|
|
117
|
-
shapeConfig
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Create outer particle ring
|
|
123
|
-
const particleCount = 48;
|
|
124
|
-
const particleRadius = CONFIG.baseRadius + CONFIG.rings * CONFIG.ringSpacing + 40;
|
|
125
|
-
|
|
126
|
-
for (let i = 0; i < particleCount; i++) {
|
|
127
|
-
const angle = (i / particleCount) * Math.PI * 2;
|
|
128
|
-
const name = `particle_${i}`;
|
|
129
|
-
|
|
130
|
-
scene.go({ x: 0, y: 0, name })
|
|
131
|
-
.circle({ radius: 3, fill: '#fff' });
|
|
132
|
-
|
|
133
|
-
allShapes.push({
|
|
134
|
-
name,
|
|
135
|
-
ring: CONFIG.rings,
|
|
136
|
-
index: i,
|
|
137
|
-
baseAngle: angle,
|
|
138
|
-
ringRadius: particleRadius,
|
|
139
|
-
isParticle: true
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Animation update loop
|
|
144
|
-
let time = 0;
|
|
145
|
-
|
|
146
|
-
// Get reference to underlying game for live dimensions
|
|
147
|
-
const gameInstance = game.game;
|
|
148
|
-
|
|
149
|
-
// Override clear for trail effect (like particles.js)
|
|
150
|
-
gameInstance.clear = function() {
|
|
151
|
-
this.ctx.fillStyle = 'rgba(10, 10, 15, 0.15)';
|
|
152
|
-
this.ctx.fillRect(0, 0, this.width, this.height);
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
game.on('update', (dt, ctx) => {
|
|
156
|
-
time += dt;
|
|
157
|
-
|
|
158
|
-
// Update camera (handles inertia and auto-rotation)
|
|
159
|
-
camera.update(dt);
|
|
160
|
-
|
|
161
|
-
// Get dynamic center and scale based on LIVE canvas size
|
|
162
|
-
const cx = gameInstance.width / 2;
|
|
163
|
-
const cy = gameInstance.height / 2;
|
|
164
|
-
const scaleFactor = getScaleFactor(gameInstance.width, gameInstance.height);
|
|
165
|
-
|
|
166
|
-
// Animate core - project through 3D camera
|
|
167
|
-
const core = ctx.refs.core;
|
|
168
|
-
if (core) {
|
|
169
|
-
// Core at the tip of the cone (closest), with breathing pulse
|
|
170
|
-
const coreZ = Math.sin(time * 2) * 40 - 150; // Oscillates at the front tip
|
|
171
|
-
const projected = camera.project(0, 0, coreZ);
|
|
172
|
-
core.x = cx + projected.x;
|
|
173
|
-
core.y = cy + projected.y;
|
|
174
|
-
const coreScale = (1 + Math.sin(time * 4) * 0.25) * scaleFactor * projected.scale;
|
|
175
|
-
core.scaleX = coreScale;
|
|
176
|
-
core.scaleY = coreScale;
|
|
177
|
-
core.rotation = time * 1.5;
|
|
178
|
-
|
|
179
|
-
// Update core color
|
|
180
|
-
if (core._fluentShape) {
|
|
181
|
-
const coreHue = (time * 100) % 360;
|
|
182
|
-
core._fluentShape.color = `hsl(${coreHue}, 100%, 70%)`;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// Animate each ring with 3D projection
|
|
187
|
-
for (const shape of allShapes) {
|
|
188
|
-
if (shape.ring < 0) continue; // Skip core
|
|
189
|
-
|
|
190
|
-
const go = ctx.refs[shape.name];
|
|
191
|
-
if (!go) continue;
|
|
192
|
-
|
|
193
|
-
if (shape.isParticle) {
|
|
194
|
-
// Particle animation - orbit and twinkle
|
|
195
|
-
const particleSpeed = 0.15;
|
|
196
|
-
const newAngle = shape.baseAngle + time * particleSpeed;
|
|
197
|
-
const wobble = Math.sin(time * 2 + shape.index * 0.3) * 8 * scaleFactor;
|
|
198
|
-
const scaledRadius = shape.ringRadius * scaleFactor;
|
|
199
|
-
|
|
200
|
-
// Calculate 2D position on the mandala plane
|
|
201
|
-
const localX = Math.cos(newAngle) * (scaledRadius + wobble);
|
|
202
|
-
const localY = Math.sin(newAngle) * (scaledRadius + wobble);
|
|
203
|
-
|
|
204
|
-
// Project through 3D camera (particles at base of cone, furthest back)
|
|
205
|
-
const projected = camera.project(localX, localY, 300);
|
|
206
|
-
go.x = cx + projected.x;
|
|
207
|
-
go.y = cy + projected.y;
|
|
208
|
-
|
|
209
|
-
// Scale particle size with perspective
|
|
210
|
-
go.scaleX = scaleFactor * projected.scale;
|
|
211
|
-
go.scaleY = scaleFactor * projected.scale;
|
|
212
|
-
|
|
213
|
-
// Twinkle effect
|
|
214
|
-
const alpha = 0.4 + Math.abs(Math.sin(time * 8 + shape.index * 0.3)) * 0.6;
|
|
215
|
-
if (go._fluentShape) {
|
|
216
|
-
go._fluentShape.opacity = alpha;
|
|
217
|
-
}
|
|
218
|
-
} else {
|
|
219
|
-
// Ring shape animation
|
|
220
|
-
const ringIndex = shape.ring;
|
|
221
|
-
const rotationSpeed = CONFIG.rotationSpeeds[ringIndex];
|
|
222
|
-
const pulseAmp = CONFIG.pulseAmplitudes[ringIndex];
|
|
223
|
-
|
|
224
|
-
// Rotate around center - smooth continuous rotation
|
|
225
|
-
const newAngle = shape.baseAngle + time * rotationSpeed;
|
|
226
|
-
|
|
227
|
-
// Gentle breathing effect on radius (scaled)
|
|
228
|
-
const breathPhase = time * 0.8 + ringIndex * 0.5;
|
|
229
|
-
const scaledRadius = shape.ringRadius * scaleFactor;
|
|
230
|
-
const breathRadius = scaledRadius + Math.sin(breathPhase) * 8 * scaleFactor;
|
|
231
|
-
|
|
232
|
-
// Calculate 2D position on the mandala plane
|
|
233
|
-
const localX = Math.cos(newAngle) * breathRadius;
|
|
234
|
-
const localY = Math.sin(newAngle) * breathRadius;
|
|
235
|
-
|
|
236
|
-
// Project through 3D camera - CONE shape: inner rings close, outer rings far
|
|
237
|
-
const ringDepth = ringIndex * 60 - 50; // Ring 0 at -50, Ring 5 at 250
|
|
238
|
-
const projected = camera.project(localX, localY, ringDepth);
|
|
239
|
-
go.x = cx + projected.x;
|
|
240
|
-
go.y = cy + projected.y;
|
|
241
|
-
|
|
242
|
-
// Smooth pulse scale with perspective
|
|
243
|
-
const pulsePhase = time * 2 + ringIndex * 0.3;
|
|
244
|
-
const scale = (1 + Math.sin(pulsePhase) * pulseAmp) * scaleFactor * projected.scale;
|
|
245
|
-
go.scaleX = scale;
|
|
246
|
-
go.scaleY = scale;
|
|
247
|
-
|
|
248
|
-
// Rotate individual shapes - smooth spin
|
|
249
|
-
go.rotation = time * (ringIndex % 2 === 0 ? 2 : -2);
|
|
250
|
-
|
|
251
|
-
// Color cycling - psychedelic HSL animation
|
|
252
|
-
if (go._fluentShape) {
|
|
253
|
-
const baseHue = CONFIG.colorOffsets[ringIndex];
|
|
254
|
-
const hueShift = time * 60; // Faster color rotation
|
|
255
|
-
const positionHue = shape.index * (360 / CONFIG.shapesPerRing[ringIndex]);
|
|
256
|
-
|
|
257
|
-
const finalHue = (baseHue + hueShift + positionHue) % 360;
|
|
258
|
-
const saturation = 85;
|
|
259
|
-
const lightness = 55 + Math.sin(time * 3 + ringIndex) * 10;
|
|
260
|
-
|
|
261
|
-
go._fluentShape.color = `hsl(${finalHue}, ${saturation}%, ${lightness}%)`;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
game.start();
|
|
268
|
-
});
|