@guinetik/gcanvas 1.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.
- package/.github/workflows/release.yaml +70 -0
- package/.jshintrc +4 -0
- package/.vscode/settings.json +22 -0
- package/CLAUDE.md +310 -0
- package/blackhole.jpg +0 -0
- package/demo.png +0 -0
- package/demos/CNAME +1 -0
- package/demos/animations.html +31 -0
- package/demos/basic.html +38 -0
- package/demos/baskara.html +31 -0
- package/demos/bezier.html +35 -0
- package/demos/beziersignature.html +29 -0
- package/demos/blackhole.html +28 -0
- package/demos/blob.html +35 -0
- package/demos/demos.css +289 -0
- package/demos/easing.html +28 -0
- package/demos/events.html +195 -0
- package/demos/fluent.html +647 -0
- package/demos/fractals.html +36 -0
- package/demos/genart.html +26 -0
- package/demos/gendream.html +26 -0
- package/demos/group.html +36 -0
- package/demos/home.html +587 -0
- package/demos/index.html +364 -0
- package/demos/isometric.html +34 -0
- package/demos/js/animations.js +452 -0
- package/demos/js/basic.js +204 -0
- package/demos/js/baskara.js +751 -0
- package/demos/js/bezier.js +692 -0
- package/demos/js/beziersignature.js +241 -0
- package/demos/js/blackhole/accretiondisk.obj.js +379 -0
- package/demos/js/blackhole/blackhole.obj.js +318 -0
- package/demos/js/blackhole/index.js +409 -0
- package/demos/js/blackhole/particle.js +56 -0
- package/demos/js/blackhole/starfield.obj.js +218 -0
- package/demos/js/blob.js +2263 -0
- package/demos/js/easing.js +477 -0
- package/demos/js/fluent.js +183 -0
- package/demos/js/fractals.js +931 -0
- package/demos/js/fractalworker.js +93 -0
- package/demos/js/genart.js +268 -0
- package/demos/js/gendream.js +209 -0
- package/demos/js/group.js +140 -0
- package/demos/js/info-toggle.js +25 -0
- package/demos/js/isometric.js +863 -0
- package/demos/js/kerr.js +1556 -0
- package/demos/js/lavalamp.js +590 -0
- package/demos/js/layout.js +354 -0
- package/demos/js/mondrian.js +285 -0
- package/demos/js/opacity.js +275 -0
- package/demos/js/painter.js +484 -0
- package/demos/js/particles-showcase.js +514 -0
- package/demos/js/particles.js +299 -0
- package/demos/js/patterns.js +397 -0
- package/demos/js/penrose/artifact.js +69 -0
- package/demos/js/penrose/blackhole.js +121 -0
- package/demos/js/penrose/constants.js +73 -0
- package/demos/js/penrose/game.js +943 -0
- package/demos/js/penrose/lore.js +278 -0
- package/demos/js/penrose/penrosescene.js +892 -0
- package/demos/js/penrose/ship.js +216 -0
- package/demos/js/penrose/sounds.js +211 -0
- package/demos/js/penrose/voidparticle.js +55 -0
- package/demos/js/penrose/voidscene.js +258 -0
- package/demos/js/penrose/voidship.js +144 -0
- package/demos/js/penrose/wormhole.js +46 -0
- package/demos/js/pipeline.js +555 -0
- package/demos/js/scene.js +304 -0
- package/demos/js/scenes.js +320 -0
- package/demos/js/schrodinger.js +410 -0
- package/demos/js/schwarzschild.js +1023 -0
- package/demos/js/shapes.js +628 -0
- package/demos/js/space/alien.js +171 -0
- package/demos/js/space/boom.js +98 -0
- package/demos/js/space/boss.js +353 -0
- package/demos/js/space/buff.js +73 -0
- package/demos/js/space/bullet.js +102 -0
- package/demos/js/space/constants.js +85 -0
- package/demos/js/space/game.js +1884 -0
- package/demos/js/space/hud.js +112 -0
- package/demos/js/space/laserbeam.js +179 -0
- package/demos/js/space/lightning.js +277 -0
- package/demos/js/space/minion.js +192 -0
- package/demos/js/space/missile.js +212 -0
- package/demos/js/space/player.js +430 -0
- package/demos/js/space/powerup.js +90 -0
- package/demos/js/space/starfield.js +58 -0
- package/demos/js/space/starpower.js +90 -0
- package/demos/js/spacetime.js +559 -0
- package/demos/js/svgtween.js +204 -0
- package/demos/js/tde/accretiondisk.js +418 -0
- package/demos/js/tde/blackhole.js +219 -0
- package/demos/js/tde/blackholescene.js +209 -0
- package/demos/js/tde/config.js +59 -0
- package/demos/js/tde/index.js +695 -0
- package/demos/js/tde/jets.js +290 -0
- package/demos/js/tde/lensedstarfield.js +147 -0
- package/demos/js/tde/tdestar.js +317 -0
- package/demos/js/tde/tidalstream.js +356 -0
- package/demos/js/tde_old/blackhole.obj.js +354 -0
- package/demos/js/tde_old/debris.obj.js +791 -0
- package/demos/js/tde_old/flare.obj.js +239 -0
- package/demos/js/tde_old/index.js +448 -0
- package/demos/js/tde_old/star.obj.js +812 -0
- package/demos/js/tiles.js +312 -0
- package/demos/js/tweendemo.js +79 -0
- package/demos/js/visibility.js +102 -0
- package/demos/kerr.html +28 -0
- package/demos/lavalamp.html +27 -0
- package/demos/layouts.html +37 -0
- package/demos/logo.svg +4 -0
- package/demos/loop.html +84 -0
- package/demos/mondrian.html +32 -0
- package/demos/og_image.png +0 -0
- package/demos/opacity.html +36 -0
- package/demos/painter.html +39 -0
- package/demos/particles-showcase.html +28 -0
- package/demos/particles.html +24 -0
- package/demos/patterns.html +33 -0
- package/demos/penrose-game.html +31 -0
- package/demos/pipeline.html +737 -0
- package/demos/scene.html +33 -0
- package/demos/scenes.html +96 -0
- package/demos/schrodinger.html +27 -0
- package/demos/schwarzschild.html +27 -0
- package/demos/shapes.html +16 -0
- package/demos/space.html +85 -0
- package/demos/spacetime.html +27 -0
- package/demos/svgtween.html +29 -0
- package/demos/tde.html +28 -0
- package/demos/tiles.html +28 -0
- package/demos/transforms.html +400 -0
- package/demos/tween.html +45 -0
- package/demos/visibility.html +33 -0
- package/disk_example.png +0 -0
- package/docs/README.md +222 -0
- package/docs/concepts/architecture-overview.md +204 -0
- package/docs/concepts/lifecycle.md +255 -0
- package/docs/concepts/rendering-pipeline.md +279 -0
- package/docs/concepts/tde-zorder.md +106 -0
- package/docs/concepts/two-layer-architecture.md +229 -0
- package/docs/getting-started/first-game.md +354 -0
- package/docs/getting-started/hello-world.md +269 -0
- package/docs/getting-started/installation.md +157 -0
- package/docs/modules/collision/README.md +453 -0
- package/docs/modules/fluent/README.md +1075 -0
- package/docs/modules/game/README.md +303 -0
- package/docs/modules/isometric-camera.md +210 -0
- package/docs/modules/isometric.md +275 -0
- package/docs/modules/painter/README.md +328 -0
- package/docs/modules/particle/README.md +559 -0
- package/docs/modules/shapes/README.md +221 -0
- package/docs/modules/shapes/base/euclidian.md +123 -0
- package/docs/modules/shapes/base/geometry2d.md +204 -0
- package/docs/modules/shapes/base/renderable.md +215 -0
- package/docs/modules/shapes/base/shape.md +262 -0
- package/docs/modules/shapes/base/transformable.md +243 -0
- package/docs/modules/shapes/hierarchy.md +218 -0
- package/docs/modules/state/README.md +577 -0
- package/docs/modules/util/README.md +99 -0
- package/docs/modules/util/camera3d.md +412 -0
- package/docs/modules/util/scene3d.md +395 -0
- package/index.html +17 -0
- package/jsdoc.json +50 -0
- package/package.json +55 -0
- package/readme.md +599 -0
- package/scripts/build-demo.js +69 -0
- package/scripts/bundle4llm.js +276 -0
- package/scripts/clearconsole.js +48 -0
- package/src/collision/collision-system.js +332 -0
- package/src/collision/collision.js +303 -0
- package/src/collision/index.js +10 -0
- package/src/fluent/fluent-game.js +430 -0
- package/src/fluent/fluent-go.js +1060 -0
- package/src/fluent/fluent-layer.js +152 -0
- package/src/fluent/fluent-scene.js +291 -0
- package/src/fluent/index.js +98 -0
- package/src/fluent/sketch.js +380 -0
- package/src/game/game.js +467 -0
- package/src/game/index.js +49 -0
- package/src/game/objects/go.js +220 -0
- package/src/game/objects/imagego.js +30 -0
- package/src/game/objects/index.js +54 -0
- package/src/game/objects/isometric-scene.js +260 -0
- package/src/game/objects/layoutscene.js +549 -0
- package/src/game/objects/scene.js +175 -0
- package/src/game/objects/scene3d.js +118 -0
- package/src/game/objects/text.js +221 -0
- package/src/game/objects/wrapper.js +232 -0
- package/src/game/pipeline.js +243 -0
- package/src/game/ui/button.js +396 -0
- package/src/game/ui/cursor.js +93 -0
- package/src/game/ui/fps.js +91 -0
- package/src/game/ui/index.js +5 -0
- package/src/game/ui/togglebutton.js +93 -0
- package/src/game/ui/tooltip.js +249 -0
- package/src/index.js +25 -0
- package/src/io/events.js +20 -0
- package/src/io/index.js +86 -0
- package/src/io/input.js +70 -0
- package/src/io/keys.js +152 -0
- package/src/io/mouse.js +61 -0
- package/src/io/touch.js +39 -0
- package/src/logger/debugtab.js +138 -0
- package/src/logger/index.js +3 -0
- package/src/logger/loggable.js +47 -0
- package/src/logger/logger.js +113 -0
- package/src/math/complex.js +37 -0
- package/src/math/constants.js +1 -0
- package/src/math/fractal.js +1271 -0
- package/src/math/gr.js +201 -0
- package/src/math/heat.js +202 -0
- package/src/math/index.js +12 -0
- package/src/math/noise.js +433 -0
- package/src/math/orbital.js +191 -0
- package/src/math/patterns.js +1339 -0
- package/src/math/penrose.js +259 -0
- package/src/math/quantum.js +115 -0
- package/src/math/random.js +195 -0
- package/src/math/tensor.js +1009 -0
- package/src/mixins/anchor.js +131 -0
- package/src/mixins/draggable.js +72 -0
- package/src/mixins/index.js +2 -0
- package/src/motion/bezier.js +132 -0
- package/src/motion/bounce.js +58 -0
- package/src/motion/easing.js +349 -0
- package/src/motion/float.js +130 -0
- package/src/motion/follow.js +125 -0
- package/src/motion/hop.js +52 -0
- package/src/motion/index.js +82 -0
- package/src/motion/motion.js +1124 -0
- package/src/motion/orbit.js +49 -0
- package/src/motion/oscillate.js +39 -0
- package/src/motion/parabolic.js +141 -0
- package/src/motion/patrol.js +147 -0
- package/src/motion/pendulum.js +48 -0
- package/src/motion/pulse.js +88 -0
- package/src/motion/shake.js +83 -0
- package/src/motion/spiral.js +144 -0
- package/src/motion/spring.js +150 -0
- package/src/motion/swing.js +47 -0
- package/src/motion/tween.js +92 -0
- package/src/motion/tweenetik.js +139 -0
- package/src/motion/waypoint.js +210 -0
- package/src/painter/index.js +8 -0
- package/src/painter/painter.colors.js +331 -0
- package/src/painter/painter.effects.js +230 -0
- package/src/painter/painter.img.js +229 -0
- package/src/painter/painter.js +295 -0
- package/src/painter/painter.lines.js +189 -0
- package/src/painter/painter.opacity.js +41 -0
- package/src/painter/painter.shapes.js +277 -0
- package/src/painter/painter.text.js +273 -0
- package/src/particle/emitter.js +124 -0
- package/src/particle/index.js +11 -0
- package/src/particle/particle-system.js +322 -0
- package/src/particle/particle.js +71 -0
- package/src/particle/updaters.js +170 -0
- package/src/shapes/arc.js +43 -0
- package/src/shapes/arrow.js +33 -0
- package/src/shapes/bezier.js +42 -0
- package/src/shapes/circle.js +62 -0
- package/src/shapes/clouds.js +56 -0
- package/src/shapes/cone.js +219 -0
- package/src/shapes/cross.js +70 -0
- package/src/shapes/cube.js +244 -0
- package/src/shapes/cylinder.js +254 -0
- package/src/shapes/diamond.js +48 -0
- package/src/shapes/euclidian.js +111 -0
- package/src/shapes/figure.js +115 -0
- package/src/shapes/geometry.js +220 -0
- package/src/shapes/group.js +375 -0
- package/src/shapes/heart.js +42 -0
- package/src/shapes/hexagon.js +26 -0
- package/src/shapes/image.js +192 -0
- package/src/shapes/index.js +111 -0
- package/src/shapes/line.js +29 -0
- package/src/shapes/pattern.js +90 -0
- package/src/shapes/pin.js +44 -0
- package/src/shapes/poly.js +31 -0
- package/src/shapes/prism.js +226 -0
- package/src/shapes/rect.js +35 -0
- package/src/shapes/renderable.js +333 -0
- package/src/shapes/ring.js +26 -0
- package/src/shapes/roundrect.js +95 -0
- package/src/shapes/shape.js +117 -0
- package/src/shapes/slice.js +26 -0
- package/src/shapes/sphere.js +314 -0
- package/src/shapes/sphere3d.js +537 -0
- package/src/shapes/square.js +15 -0
- package/src/shapes/star.js +99 -0
- package/src/shapes/svg.js +408 -0
- package/src/shapes/text.js +553 -0
- package/src/shapes/traceable.js +83 -0
- package/src/shapes/transform.js +357 -0
- package/src/shapes/transformable.js +172 -0
- package/src/shapes/triangle.js +26 -0
- package/src/sound/index.js +17 -0
- package/src/sound/sound.js +473 -0
- package/src/sound/synth.analyzer.js +149 -0
- package/src/sound/synth.effects.js +207 -0
- package/src/sound/synth.envelope.js +59 -0
- package/src/sound/synth.js +229 -0
- package/src/sound/synth.musical.js +160 -0
- package/src/sound/synth.noise.js +85 -0
- package/src/sound/synth.oscillators.js +293 -0
- package/src/state/index.js +10 -0
- package/src/state/state-machine.js +371 -0
- package/src/util/camera3d.js +438 -0
- package/src/util/index.js +6 -0
- package/src/util/isometric-camera.js +235 -0
- package/src/util/layout.js +317 -0
- package/src/util/position.js +147 -0
- package/src/util/tasks.js +47 -0
- package/src/util/zindex.js +287 -0
- package/src/webgl/index.js +9 -0
- package/src/webgl/shaders/sphere-shaders.js +994 -0
- package/src/webgl/webgl-renderer.js +388 -0
- package/tde.png +0 -0
- package/test/math/orbital.test.js +61 -0
- package/test/math/tensor.test.js +114 -0
- package/test/particle/emitter.test.js +204 -0
- package/test/particle/particle-system.test.js +310 -0
- package/test/particle/particle.test.js +116 -0
- package/test/particle/updaters.test.js +386 -0
- package/test/setup.js +120 -0
- package/test/shapes/euclidian.test.js +44 -0
- package/test/shapes/geometry.test.js +86 -0
- package/test/shapes/group.test.js +86 -0
- package/test/shapes/rectangle.test.js +64 -0
- package/test/shapes/transform.test.js +379 -0
- package/test/util/camera3d.test.js +428 -0
- package/test/util/scene3d.test.js +352 -0
- package/types/collision.d.ts +249 -0
- package/types/common.d.ts +155 -0
- package/types/game.d.ts +497 -0
- package/types/index.d.ts +309 -0
- package/types/io.d.ts +188 -0
- package/types/logger.d.ts +127 -0
- package/types/math.d.ts +268 -0
- package/types/mixins.d.ts +92 -0
- package/types/motion.d.ts +678 -0
- package/types/painter.d.ts +378 -0
- package/types/shapes.d.ts +864 -0
- package/types/sound.d.ts +672 -0
- package/types/state.d.ts +251 -0
- package/types/util.d.ts +253 -0
- package/vite.config.js +50 -0
- package/vitest.config.js +13 -0
|
@@ -0,0 +1,477 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
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
|
+
});
|