@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
package/demos/js/easing.js
DELETED
|
@@ -1,477 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Circle,
|
|
3
|
-
Easing,
|
|
4
|
-
FPSCounter,
|
|
5
|
-
Game,
|
|
6
|
-
GameObject,
|
|
7
|
-
Painter,
|
|
8
|
-
TextShape,
|
|
9
|
-
TileLayout,
|
|
10
|
-
Rectangle,
|
|
11
|
-
Tweenetik,
|
|
12
|
-
ToggleButton,
|
|
13
|
-
Tooltip,
|
|
14
|
-
Position,
|
|
15
|
-
} from "../../src/index";
|
|
16
|
-
|
|
17
|
-
// Formulas for each easing function
|
|
18
|
-
const EASING_FORMULAS = {
|
|
19
|
-
linear: "f(t) = t",
|
|
20
|
-
smoothstep: "f(t) = t² × (3 - 2t)",
|
|
21
|
-
smootherstep: "f(t) = t³ × (t × (6t - 15) + 10)",
|
|
22
|
-
easeInQuad: "f(t) = t²",
|
|
23
|
-
easeOutQuad: "f(t) = t × (2 - t)",
|
|
24
|
-
easeInOutQuad: "f(t) = t < 0.5 ? 2t² : -1 + (4 - 2t) × t",
|
|
25
|
-
easeInCubic: "f(t) = t³",
|
|
26
|
-
easeOutCubic: "f(t) = (t - 1)³ + 1",
|
|
27
|
-
easeInOutCubic: "f(t) = t < 0.5 ? 4t³ : (t-1)(2t-2)² + 1",
|
|
28
|
-
easeInQuart: "f(t) = t⁴",
|
|
29
|
-
easeOutQuart: "f(t) = 1 - (t - 1)⁴",
|
|
30
|
-
easeInOutQuart: "f(t) = t < 0.5 ? 8t⁴ : 1 - 8(t-1)⁴",
|
|
31
|
-
easeInSine: "f(t) = 1 - cos(t × π/2)",
|
|
32
|
-
easeOutSine: "f(t) = sin(t × π/2)",
|
|
33
|
-
easeInOutSine: "f(t) = -(cos(πt) - 1) / 2",
|
|
34
|
-
easeInExpo: "f(t) = 2^(10(t - 1))",
|
|
35
|
-
easeOutExpo: "f(t) = 1 - 2^(-10t)",
|
|
36
|
-
easeInOutExpo: "f(t) = ½×2^(20t-10) or 1 - ½×2^(-20t+10)",
|
|
37
|
-
easeInCirc: "f(t) = 1 - √(1 - t²)",
|
|
38
|
-
easeOutCirc: "f(t) = √(1 - (t-1)²)",
|
|
39
|
-
easeInOutCirc: "t<½ ? ½(1-√(1-4t²)) : ½(√(-(2t-3)(2t-1))+1)",
|
|
40
|
-
easeInElastic: "f(t) = -2^(10(t-1)) × sin(2π(t-1-s)/p)",
|
|
41
|
-
easeOutElastic: "f(t) = 2^(-10t) × sin(2π(t-s)/p) + 1",
|
|
42
|
-
easeInOutElastic: "t<½ ? easeIn : easeOut (mirrored)",
|
|
43
|
-
easeInBack: "f(t) = t²((s+1)t - s) where s≈1.7",
|
|
44
|
-
easeOutBack: "f(t) = (t-1)²((s+1)(t-1) + s) + 1",
|
|
45
|
-
easeInOutBack: "t<½ ? easeIn(2t)/2 : easeOut(2t-1)/2 + ½",
|
|
46
|
-
easeInBounce: "f(t) = 1 - easeOutBounce(1-t)",
|
|
47
|
-
easeOutBounce: "4 parabolas: 7.5625(t-c)² + k",
|
|
48
|
-
easeInOutBounce: "t<½ ? easeIn(2t)/2 : easeOut(2t-1)/2 + ½",
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* EasingBox: A tile showing an easing curve graph with animated circle
|
|
53
|
-
*/
|
|
54
|
-
class EasingBox extends GameObject {
|
|
55
|
-
constructor(game, label, easingFn, formula, tooltip, options = {}) {
|
|
56
|
-
super(game, options);
|
|
57
|
-
this.label = label;
|
|
58
|
-
this.easingFn = easingFn;
|
|
59
|
-
this.formula = formula;
|
|
60
|
-
this.tooltip = tooltip;
|
|
61
|
-
this.animTime = 0;
|
|
62
|
-
this.duration = 1;
|
|
63
|
-
this.pauseDuration = 0.3;
|
|
64
|
-
this.isPlaying = false;
|
|
65
|
-
this.inPausePhase = true; // Start with ball hidden
|
|
66
|
-
this.interactive = true;
|
|
67
|
-
|
|
68
|
-
// Background box
|
|
69
|
-
this.bg = new Rectangle({
|
|
70
|
-
width: 100,
|
|
71
|
-
height: 100,
|
|
72
|
-
color: "rgba(0, 0, 0, 0.1)",
|
|
73
|
-
stroke: "rgba(255, 255, 255, 0.3)",
|
|
74
|
-
lineWidth: 1,
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
// Label
|
|
78
|
-
this.labelText = new TextShape(this.label, {
|
|
79
|
-
x: 0,
|
|
80
|
-
y: 44,
|
|
81
|
-
font: "11px monospace",
|
|
82
|
-
color: "white",
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
// Glow circle
|
|
86
|
-
this.glowCircle = new Circle(8, {
|
|
87
|
-
color: "rgba(0, 255, 0, 0.3)",
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
// Animated circle
|
|
91
|
-
this.animCircle = new Circle(4, {
|
|
92
|
-
color: "#0f0",
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
// Cache scale values
|
|
96
|
-
this.graphScale = 1;
|
|
97
|
-
this.graphOffset = 0;
|
|
98
|
-
this.scaleCalculated = false;
|
|
99
|
-
|
|
100
|
-
// Flag for "play all" mode (controlled by toggle button)
|
|
101
|
-
this.playAll = false;
|
|
102
|
-
|
|
103
|
-
// Setup hover/touch events to play animation
|
|
104
|
-
this.on("mouseover", (e) => {
|
|
105
|
-
this.isHovered = true;
|
|
106
|
-
if (!this.playAll) {
|
|
107
|
-
this.isPlaying = true;
|
|
108
|
-
this.animTime = 0; // restart from beginning
|
|
109
|
-
}
|
|
110
|
-
// Scale up effect like shapes.js
|
|
111
|
-
Tweenetik.to(
|
|
112
|
-
this,
|
|
113
|
-
{ scaleX: 1.15, scaleY: 1.15 },
|
|
114
|
-
0.6,
|
|
115
|
-
Easing.easeOutElastic
|
|
116
|
-
);
|
|
117
|
-
// Show tooltip with formula
|
|
118
|
-
if (this.tooltip && this.formula) {
|
|
119
|
-
this.tooltip.show(this.formula, e.x, e.y);
|
|
120
|
-
}
|
|
121
|
-
// Change cursor to pointer
|
|
122
|
-
this.game.canvas.style.cursor = "pointer";
|
|
123
|
-
});
|
|
124
|
-
this.on("mouseout", () => {
|
|
125
|
-
this.isHovered = false;
|
|
126
|
-
if (!this.playAll) {
|
|
127
|
-
this.isPlaying = false;
|
|
128
|
-
}
|
|
129
|
-
// Scale back down
|
|
130
|
-
Tweenetik.to(
|
|
131
|
-
this,
|
|
132
|
-
{ scaleX: 1, scaleY: 1 },
|
|
133
|
-
0.6,
|
|
134
|
-
Easing.easeOutElastic
|
|
135
|
-
);
|
|
136
|
-
// Hide tooltip
|
|
137
|
-
if (this.tooltip) {
|
|
138
|
-
this.tooltip.hide();
|
|
139
|
-
}
|
|
140
|
-
// Reset cursor
|
|
141
|
-
this.game.canvas.style.cursor = "default";
|
|
142
|
-
});
|
|
143
|
-
// For touch devices - play on touch, stop when touch ends
|
|
144
|
-
this.on("inputdown", () => {
|
|
145
|
-
if (!this.playAll) {
|
|
146
|
-
this.isPlaying = true;
|
|
147
|
-
this.animTime = 0;
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Set play all mode - when true, animation plays continuously
|
|
154
|
-
*/
|
|
155
|
-
setPlayAll(playAll) {
|
|
156
|
-
this.playAll = playAll;
|
|
157
|
-
if (playAll) {
|
|
158
|
-
this.isPlaying = true;
|
|
159
|
-
this.animTime = 0;
|
|
160
|
-
} else {
|
|
161
|
-
// Only keep playing if currently hovered
|
|
162
|
-
this.isPlaying = this.isHovered || false;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
update(dt) {
|
|
167
|
-
super.update(dt);
|
|
168
|
-
|
|
169
|
-
// Calculate graph dimensions
|
|
170
|
-
const size = 100;
|
|
171
|
-
const padding = 10;
|
|
172
|
-
const labelSpace = 14;
|
|
173
|
-
const graphSize = size - padding * 2 - labelSpace;
|
|
174
|
-
const startX = -size / 2 + padding;
|
|
175
|
-
const startY = size / 2 - padding - labelSpace;
|
|
176
|
-
|
|
177
|
-
// Only animate when playing
|
|
178
|
-
if (this.isPlaying) {
|
|
179
|
-
this.animTime += dt;
|
|
180
|
-
|
|
181
|
-
const totalCycle = this.duration + this.pauseDuration;
|
|
182
|
-
if (this.animTime > totalCycle) {
|
|
183
|
-
this.animTime = 0;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// Check if we're in the pause phase (animation finished, waiting to restart)
|
|
187
|
-
this.inPausePhase = this.animTime > this.duration;
|
|
188
|
-
|
|
189
|
-
if (!this.inPausePhase) {
|
|
190
|
-
const t = this.animTime / this.duration;
|
|
191
|
-
const easedT = this.easingFn(t);
|
|
192
|
-
const scaledEasedT = easedT * this.graphScale + this.graphOffset;
|
|
193
|
-
|
|
194
|
-
const circleX = startX + t * graphSize;
|
|
195
|
-
const circleY = startY - scaledEasedT * graphSize;
|
|
196
|
-
|
|
197
|
-
// Update circle positions
|
|
198
|
-
this.glowCircle.x = circleX;
|
|
199
|
-
this.glowCircle.y = circleY;
|
|
200
|
-
this.animCircle.x = circleX;
|
|
201
|
-
this.animCircle.y = circleY;
|
|
202
|
-
}
|
|
203
|
-
} else {
|
|
204
|
-
this.inPausePhase = true; // Hide when not playing
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
draw() {
|
|
209
|
-
super.draw();
|
|
210
|
-
|
|
211
|
-
// Calculate scale values once on first draw
|
|
212
|
-
if (!this.scaleCalculated) {
|
|
213
|
-
let minVal = 0;
|
|
214
|
-
let maxVal = 1;
|
|
215
|
-
for (let i = 0; i <= 100; i++) {
|
|
216
|
-
const t = i / 100;
|
|
217
|
-
const val = this.easingFn(t);
|
|
218
|
-
if (val < minVal) minVal = val;
|
|
219
|
-
if (val > maxVal) maxVal = val;
|
|
220
|
-
}
|
|
221
|
-
const range = maxVal - minVal;
|
|
222
|
-
this.graphScale = range > 1 ? 1 / range : 1;
|
|
223
|
-
this.graphOffset = minVal < 0 ? -minVal * this.graphScale : 0;
|
|
224
|
-
this.scaleCalculated = true;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// 1. Draw background first
|
|
228
|
-
this.bg.render();
|
|
229
|
-
|
|
230
|
-
const size = 100;
|
|
231
|
-
const padding = 10;
|
|
232
|
-
const labelSpace = 14;
|
|
233
|
-
const graphSize = size - padding * 2 - labelSpace;
|
|
234
|
-
const startX = -size / 2 + padding;
|
|
235
|
-
const startY = size / 2 - padding - labelSpace;
|
|
236
|
-
|
|
237
|
-
// 2. Draw axes and curve using Painter.useCtx for automatic cleanup
|
|
238
|
-
Painter.useCtx((ctx) => {
|
|
239
|
-
// Draw axes
|
|
240
|
-
ctx.strokeStyle = "rgba(255, 255, 255, 0.2)";
|
|
241
|
-
ctx.lineWidth = 1;
|
|
242
|
-
ctx.moveTo(startX, startY - graphSize);
|
|
243
|
-
ctx.lineTo(startX, startY);
|
|
244
|
-
ctx.lineTo(startX + graphSize, startY);
|
|
245
|
-
ctx.stroke();
|
|
246
|
-
|
|
247
|
-
// Draw the easing curve
|
|
248
|
-
ctx.beginPath();
|
|
249
|
-
ctx.strokeStyle = "white";
|
|
250
|
-
ctx.lineWidth = 2;
|
|
251
|
-
ctx.lineCap = "round";
|
|
252
|
-
ctx.lineJoin = "round";
|
|
253
|
-
|
|
254
|
-
for (let i = 0; i <= graphSize; i++) {
|
|
255
|
-
const t = i / graphSize;
|
|
256
|
-
const easedT = this.easingFn(t);
|
|
257
|
-
const scaledEasedT = easedT * this.graphScale + this.graphOffset;
|
|
258
|
-
const x = startX + i;
|
|
259
|
-
const y = startY - scaledEasedT * graphSize;
|
|
260
|
-
|
|
261
|
-
if (i === 0) {
|
|
262
|
-
ctx.moveTo(x, y);
|
|
263
|
-
} else {
|
|
264
|
-
ctx.lineTo(x, y);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
ctx.stroke();
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
// 3. Draw label
|
|
271
|
-
this.labelText.render();
|
|
272
|
-
|
|
273
|
-
// 4. Draw circles on top (hidden during pause phase)
|
|
274
|
-
if (!this.inPausePhase) {
|
|
275
|
-
this.glowCircle.render();
|
|
276
|
-
this.animCircle.render();
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* EasingDemo: A TileLayout grid displaying all easing function curves
|
|
283
|
-
*/
|
|
284
|
-
class EasingDemo extends TileLayout {
|
|
285
|
-
constructor(game, tooltip, options = {}) {
|
|
286
|
-
super(game, options);
|
|
287
|
-
this.tooltip = tooltip;
|
|
288
|
-
this.cellSize = 120;
|
|
289
|
-
this.maxColumns = 6;
|
|
290
|
-
|
|
291
|
-
// All easing functions organized by type (In, Out, InOut for each)
|
|
292
|
-
this.easingDefinitions = [
|
|
293
|
-
// Basics
|
|
294
|
-
{ label: "linear", fn: Easing.linear },
|
|
295
|
-
{ label: "smoothstep", fn: Easing.smoothstep },
|
|
296
|
-
{ label: "smootherstep", fn: Easing.smootherstep },
|
|
297
|
-
|
|
298
|
-
// Quadratic
|
|
299
|
-
{ label: "easeInQuad", fn: Easing.easeInQuad },
|
|
300
|
-
{ label: "easeOutQuad", fn: Easing.easeOutQuad },
|
|
301
|
-
{ label: "easeInOutQuad", fn: Easing.easeInOutQuad },
|
|
302
|
-
|
|
303
|
-
// Cubic
|
|
304
|
-
{ label: "easeInCubic", fn: Easing.easeInCubic },
|
|
305
|
-
{ label: "easeOutCubic", fn: Easing.easeOutCubic },
|
|
306
|
-
{ label: "easeInOutCubic", fn: Easing.easeInOutCubic },
|
|
307
|
-
|
|
308
|
-
// Quartic
|
|
309
|
-
{ label: "easeInQuart", fn: Easing.easeInQuart },
|
|
310
|
-
{ label: "easeOutQuart", fn: Easing.easeOutQuart },
|
|
311
|
-
{ label: "easeInOutQuart", fn: Easing.easeInOutQuart },
|
|
312
|
-
|
|
313
|
-
// Sine
|
|
314
|
-
{ label: "easeInSine", fn: Easing.easeInSine },
|
|
315
|
-
{ label: "easeOutSine", fn: Easing.easeOutSine },
|
|
316
|
-
{ label: "easeInOutSine", fn: Easing.easeInOutSine },
|
|
317
|
-
|
|
318
|
-
// Exponential
|
|
319
|
-
{ label: "easeInExpo", fn: Easing.easeInExpo },
|
|
320
|
-
{ label: "easeOutExpo", fn: Easing.easeOutExpo },
|
|
321
|
-
{ label: "easeInOutExpo", fn: Easing.easeInOutExpo },
|
|
322
|
-
|
|
323
|
-
// Circular
|
|
324
|
-
{ label: "easeInCirc", fn: Easing.easeInCirc },
|
|
325
|
-
{ label: "easeOutCirc", fn: Easing.easeOutCirc },
|
|
326
|
-
{ label: "easeInOutCirc", fn: Easing.easeInOutCirc },
|
|
327
|
-
|
|
328
|
-
// Elastic
|
|
329
|
-
{ label: "easeInElastic", fn: (t) => Easing.easeInElastic(t) },
|
|
330
|
-
{ label: "easeOutElastic", fn: (t) => Easing.easeOutElastic(t) },
|
|
331
|
-
{ label: "easeInOutElastic", fn: (t) => Easing.easeInOutElastic(t) },
|
|
332
|
-
|
|
333
|
-
// Back
|
|
334
|
-
{ label: "easeInBack", fn: (t) => Easing.easeInBack(t) },
|
|
335
|
-
{ label: "easeOutBack", fn: (t) => Easing.easeOutBack(t) },
|
|
336
|
-
{ label: "easeInOutBack", fn: (t) => Easing.easeInOutBack(t) },
|
|
337
|
-
|
|
338
|
-
// Bounce
|
|
339
|
-
{ label: "easeInBounce", fn: Easing.easeInBounce },
|
|
340
|
-
{ label: "easeOutBounce", fn: Easing.easeOutBounce },
|
|
341
|
-
{ label: "easeInOutBounce", fn: Easing.easeInOutBounce },
|
|
342
|
-
];
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
init() {
|
|
346
|
-
this.boxes = this.easingDefinitions.map((def) => {
|
|
347
|
-
const formula = EASING_FORMULAS[def.label] || "";
|
|
348
|
-
const box = new EasingBox(
|
|
349
|
-
this.game,
|
|
350
|
-
def.label,
|
|
351
|
-
def.fn,
|
|
352
|
-
formula,
|
|
353
|
-
this.tooltip,
|
|
354
|
-
{ width: 100, height: 100 }
|
|
355
|
-
);
|
|
356
|
-
box.transform.size(100, 100);
|
|
357
|
-
this.add(box);
|
|
358
|
-
return box;
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
onResize() {
|
|
363
|
-
const margin = 40;
|
|
364
|
-
const availableWidth = this.game.width - margin;
|
|
365
|
-
const columns = Math.min(
|
|
366
|
-
this.maxColumns,
|
|
367
|
-
Math.max(1, Math.floor(availableWidth / this.cellSize))
|
|
368
|
-
);
|
|
369
|
-
|
|
370
|
-
if (this.columns !== columns) {
|
|
371
|
-
this.columns = columns;
|
|
372
|
-
this.markBoundsDirty();
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
// Center the layout
|
|
376
|
-
this.transform.position(
|
|
377
|
-
Math.round(this.game.width / 2),
|
|
378
|
-
Math.round(this.game.height / 2)
|
|
379
|
-
);
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
/**
|
|
384
|
-
* MyGame: Main game class
|
|
385
|
-
*/
|
|
386
|
-
export class MyGame extends Game {
|
|
387
|
-
constructor(canvas) {
|
|
388
|
-
super(canvas);
|
|
389
|
-
this.backgroundColor = "black";
|
|
390
|
-
this.enableFluidSize();
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
init() {
|
|
394
|
-
super.init();
|
|
395
|
-
|
|
396
|
-
// Create tooltip for showing formulas
|
|
397
|
-
this.tooltip = new Tooltip(this, {
|
|
398
|
-
font: "14px monospace",
|
|
399
|
-
textColor: "#0f0",
|
|
400
|
-
bgColor: "rgba(0, 0, 0, 0.9)",
|
|
401
|
-
borderColor: "rgba(0, 255, 0, 0.5)",
|
|
402
|
-
padding: 12,
|
|
403
|
-
});
|
|
404
|
-
|
|
405
|
-
// Toggle button to play all animations
|
|
406
|
-
this.toggleBtn = new ToggleButton(this, {
|
|
407
|
-
text: "Play All",
|
|
408
|
-
anchor: Position.BOTTOM_LEFT,
|
|
409
|
-
width: 100,
|
|
410
|
-
height: 32,
|
|
411
|
-
colorDefaultBg: "rgba(0, 0, 0, 0.9)",
|
|
412
|
-
colorDefaultStroke: "rgba(0, 255, 0, 0.5)",
|
|
413
|
-
colorDefaultText: "#0f0",
|
|
414
|
-
colorActiveBg: "rgba(0, 255, 0, 1)",
|
|
415
|
-
colorActiveStroke: "orange",
|
|
416
|
-
colorActiveText: "#FFFFFF",
|
|
417
|
-
colorHoverBg: "rgba(0, 255, 0, 0.5)",
|
|
418
|
-
colorHoverStroke: "rgba(0, 255, 0, 0.5)",
|
|
419
|
-
colorHoverText: "#0f0",
|
|
420
|
-
colorPressedBg: "rgba(0, 255, 0, 0.5)",
|
|
421
|
-
colorPressedStroke: "rgba(0, 255, 0, 0.5)",
|
|
422
|
-
colorPressedText: "#0f0",
|
|
423
|
-
startToggled: false,
|
|
424
|
-
onToggle: (isOn) => {
|
|
425
|
-
this.setPlayAll(isOn);
|
|
426
|
-
},
|
|
427
|
-
});
|
|
428
|
-
this.pipeline.add(this.toggleBtn);
|
|
429
|
-
|
|
430
|
-
// Calculate initial columns based on screen width
|
|
431
|
-
const cellSize = 120;
|
|
432
|
-
const maxColumns = 6;
|
|
433
|
-
const margin = 40;
|
|
434
|
-
const initialColumns = Math.min(
|
|
435
|
-
maxColumns,
|
|
436
|
-
Math.max(1, Math.floor((this.width - margin) / cellSize))
|
|
437
|
-
);
|
|
438
|
-
|
|
439
|
-
this.easingDemo = new EasingDemo(this, this.tooltip, {
|
|
440
|
-
debug: false,
|
|
441
|
-
anchor: "center",
|
|
442
|
-
spacing: 20,
|
|
443
|
-
columns: initialColumns,
|
|
444
|
-
padding: 30,
|
|
445
|
-
align: "center",
|
|
446
|
-
});
|
|
447
|
-
this.pipeline.add(this.easingDemo);
|
|
448
|
-
|
|
449
|
-
this.pipeline.add(
|
|
450
|
-
new FPSCounter(this, {
|
|
451
|
-
anchor: "bottom-right",
|
|
452
|
-
})
|
|
453
|
-
);
|
|
454
|
-
|
|
455
|
-
// Add tooltip last so it renders on top
|
|
456
|
-
this.pipeline.add(this.tooltip);
|
|
457
|
-
|
|
458
|
-
this.easingDemo.onResize();
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
/**
|
|
462
|
-
* Toggle all animations on/off
|
|
463
|
-
*/
|
|
464
|
-
setPlayAll(playAll) {
|
|
465
|
-
if (this.easingDemo && this.easingDemo.boxes) {
|
|
466
|
-
this.easingDemo.boxes.forEach((box) => {
|
|
467
|
-
box.setPlayAll(playAll);
|
|
468
|
-
});
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
onResize() {
|
|
473
|
-
if (this.easingDemo) {
|
|
474
|
-
this.easingDemo.onResize();
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
}
|
package/demos/js/fluent.js
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Fluent API Demo Initializations
|
|
3
|
-
*
|
|
4
|
-
* Each function creates a demo on a specific canvas element,
|
|
5
|
-
* showcasing different aspects of the Fluent API.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { gcanvas, sketch } from '../../src/index.js';
|
|
9
|
-
|
|
10
|
-
// ─────────────────────────────────────────────────────────
|
|
11
|
-
// Demo 1: Hello World
|
|
12
|
-
// ─────────────────────────────────────────────────────────
|
|
13
|
-
|
|
14
|
-
function initHelloDemo() {
|
|
15
|
-
const canvas = document.getElementById('hello-canvas');
|
|
16
|
-
if (!canvas) return;
|
|
17
|
-
gcanvas({ canvas, bg: '#111' })
|
|
18
|
-
.scene('game')
|
|
19
|
-
.go({ x: 200, y: 125 })
|
|
20
|
-
.circle({ radius: 40, fill: '#00ff88' })
|
|
21
|
-
.start();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// ─────────────────────────────────────────────────────────
|
|
25
|
-
// Demo 2: Builder Chain
|
|
26
|
-
// ─────────────────────────────────────────────────────────
|
|
27
|
-
|
|
28
|
-
function initChainDemo() {
|
|
29
|
-
const canvas = document.getElementById('chain-canvas');
|
|
30
|
-
if (!canvas) return;
|
|
31
|
-
|
|
32
|
-
gcanvas({ canvas, bg: '#111' })
|
|
33
|
-
.scene('game')
|
|
34
|
-
.go({ x: 80, y: 125 })
|
|
35
|
-
.circle({ radius: 30, fill: '#ff6b6b' })
|
|
36
|
-
.end()
|
|
37
|
-
.go({ x: 200, y: 125 })
|
|
38
|
-
.star({ points: 5, radius: 35, fill: '#ffd93d' })
|
|
39
|
-
.end()
|
|
40
|
-
.go({ x: 320, y: 125 })
|
|
41
|
-
.rect({ width: 50, height: 50, fill: '#6bcb77' })
|
|
42
|
-
.start();
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// ─────────────────────────────────────────────────────────
|
|
46
|
-
// Demo 3: Shape Variety
|
|
47
|
-
// ─────────────────────────────────────────────────────────
|
|
48
|
-
|
|
49
|
-
function initShapesDemo() {
|
|
50
|
-
const canvas = document.getElementById('shapes-canvas');
|
|
51
|
-
if (!canvas) return;
|
|
52
|
-
|
|
53
|
-
gcanvas({ canvas, bg: '#111' })
|
|
54
|
-
.scene('shapes')
|
|
55
|
-
.go({ x: 40, y: 125 }).triangle({ size: 30, fill: '#ff6b6b' }).end()
|
|
56
|
-
.go({ x: 105, y: 125 }).hexagon({ radius: 18, fill: '#c44dff' }).end()
|
|
57
|
-
.go({ x: 170, y: 125 }).diamond({ width: 28, height: 36, fill: '#4ecdc4' }).end()
|
|
58
|
-
.go({ x: 235, y: 110 }).heart({ size: 26, fill: '#ff6b9d' }).end()
|
|
59
|
-
.go({ x: 300, y: 125 }).cross({ size: 26, thickness: 6, fill: '#ffd93d' }).end()
|
|
60
|
-
.go({ x: 365, y: 125 }).ring({ innerRadius: 10, outerRadius: 18, fill: '#a8e6cf' }).end()
|
|
61
|
-
.go({ x: 430, y: 125 }).star({ points: 6, radius: 18, fill: '#ff8c42' }).end()
|
|
62
|
-
.go({ x: 485, y: 125 }).cloud({ size: 25, fill: '#dfe6e9' })
|
|
63
|
-
.start();
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// ─────────────────────────────────────────────────────────
|
|
67
|
-
// Demo 4: Motion Presets
|
|
68
|
-
// ─────────────────────────────────────────────────────────
|
|
69
|
-
|
|
70
|
-
function initMotionDemo() {
|
|
71
|
-
const canvas = document.getElementById('motion-canvas');
|
|
72
|
-
if (!canvas) return;
|
|
73
|
-
|
|
74
|
-
gcanvas({ canvas, bg: '#111' })
|
|
75
|
-
.scene('motion')
|
|
76
|
-
// Pulsing circle
|
|
77
|
-
.go({ x: 100, y: 125 })
|
|
78
|
-
.circle({ radius: 30, fill: '#ff6b6b' })
|
|
79
|
-
.pulse({ min: 0.7, max: 1.3, duration: 1 })
|
|
80
|
-
.end()
|
|
81
|
-
// Oscillating star
|
|
82
|
-
.go({ x: 220, y: 125 })
|
|
83
|
-
.star({ points: 5, radius: 25, fill: '#ffd93d' })
|
|
84
|
-
.oscillate({ prop: 'y', min: -30, max: 30, duration: 2 })
|
|
85
|
-
.end()
|
|
86
|
-
// Orbiting shape
|
|
87
|
-
.go({ x: 300, y: 125 })
|
|
88
|
-
.hexagon({ radius: 20, fill: '#4ecdc4' })
|
|
89
|
-
.orbit({ radiusX: 40, radiusY: 40, duration: 3 })
|
|
90
|
-
.start();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// ─────────────────────────────────────────────────────────
|
|
94
|
-
// Demo 5: Sketch Mode (using gcanvas to target existing canvas)
|
|
95
|
-
// Note: sketch() auto-creates a canvas, so we recreate the pattern with gcanvas
|
|
96
|
-
// ─────────────────────────────────────────────────────────
|
|
97
|
-
|
|
98
|
-
function initSketchDemo() {
|
|
99
|
-
const canvas = document.getElementById('sketch-canvas');
|
|
100
|
-
if (!canvas) return;
|
|
101
|
-
|
|
102
|
-
const game = gcanvas({ canvas, bg: '#111' });
|
|
103
|
-
const scene = game.scene('default');
|
|
104
|
-
|
|
105
|
-
// Create radial pattern
|
|
106
|
-
const count = 12;
|
|
107
|
-
const radius = 80;
|
|
108
|
-
const cx = 200;
|
|
109
|
-
const cy = 125;
|
|
110
|
-
|
|
111
|
-
for (let i = 0; i < count; i++) {
|
|
112
|
-
const angle = (i / count) * Math.PI * 2;
|
|
113
|
-
const x = cx + Math.cos(angle) * radius;
|
|
114
|
-
const y = cy + Math.sin(angle) * radius;
|
|
115
|
-
|
|
116
|
-
scene.go({ x, y, name: `shape_${i}` })
|
|
117
|
-
.circle({ radius: 15, fill: `hsl(${i * 30}, 70%, 60%)` });
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
game.on('update', (dt, ctx) => {
|
|
121
|
-
for (let i = 0; i < count; i++) {
|
|
122
|
-
const shape = ctx.refs[`shape_${i}`];
|
|
123
|
-
if (shape) {
|
|
124
|
-
shape.rotation += dt * (i % 2 === 0 ? 1 : -1);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
game.start();
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// ─────────────────────────────────────────────────────────
|
|
133
|
-
// Demo 6: Events & Interactivity
|
|
134
|
-
// ─────────────────────────────────────────────────────────
|
|
135
|
-
|
|
136
|
-
function initEventsDemo() {
|
|
137
|
-
const canvas = document.getElementById('events-canvas');
|
|
138
|
-
if (!canvas) return;
|
|
139
|
-
|
|
140
|
-
const game = gcanvas({ canvas, bg: '#111' })
|
|
141
|
-
.state({ clicks: 0 });
|
|
142
|
-
|
|
143
|
-
game.scene('interactive')
|
|
144
|
-
.go({ x: 200, y: 100, name: 'clickTarget' })
|
|
145
|
-
.circle({ radius: 40, fill: '#ff6b6b' })
|
|
146
|
-
.on('click', (ctx) => {
|
|
147
|
-
// Access shared state via game.refs
|
|
148
|
-
const state = game.getState('clicks') || 0;
|
|
149
|
-
game.setState('clicks', state + 1);
|
|
150
|
-
|
|
151
|
-
// Update label text
|
|
152
|
-
const label = game.refs.label;
|
|
153
|
-
if (label && label._fluentShape) {
|
|
154
|
-
label._fluentShape.text = `Clicks: ${state + 1}`;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// Visual feedback - brief pulse
|
|
158
|
-
ctx.go.scaleX = 1.2;
|
|
159
|
-
ctx.go.scaleY = 1.2;
|
|
160
|
-
setTimeout(() => {
|
|
161
|
-
ctx.go.scaleX = 1;
|
|
162
|
-
ctx.go.scaleY = 1;
|
|
163
|
-
}, 100);
|
|
164
|
-
})
|
|
165
|
-
.end()
|
|
166
|
-
.go({ x: 200, y: 200, name: 'label' })
|
|
167
|
-
.text('Click the circle!', { fill: '#aaa', font: '14px monospace' });
|
|
168
|
-
|
|
169
|
-
game.start();
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// ─────────────────────────────────────────────────────────
|
|
173
|
-
// Initialize all demos on page load
|
|
174
|
-
// ─────────────────────────────────────────────────────────
|
|
175
|
-
|
|
176
|
-
window.addEventListener('load', () => {
|
|
177
|
-
initHelloDemo();
|
|
178
|
-
initChainDemo();
|
|
179
|
-
initShapesDemo();
|
|
180
|
-
initMotionDemo();
|
|
181
|
-
initSketchDemo();
|
|
182
|
-
initEventsDemo();
|
|
183
|
-
});
|