@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.
Files changed (349) hide show
  1. package/.github/workflows/release.yaml +70 -0
  2. package/.jshintrc +4 -0
  3. package/.vscode/settings.json +22 -0
  4. package/CLAUDE.md +310 -0
  5. package/blackhole.jpg +0 -0
  6. package/demo.png +0 -0
  7. package/demos/CNAME +1 -0
  8. package/demos/animations.html +31 -0
  9. package/demos/basic.html +38 -0
  10. package/demos/baskara.html +31 -0
  11. package/demos/bezier.html +35 -0
  12. package/demos/beziersignature.html +29 -0
  13. package/demos/blackhole.html +28 -0
  14. package/demos/blob.html +35 -0
  15. package/demos/demos.css +289 -0
  16. package/demos/easing.html +28 -0
  17. package/demos/events.html +195 -0
  18. package/demos/fluent.html +647 -0
  19. package/demos/fractals.html +36 -0
  20. package/demos/genart.html +26 -0
  21. package/demos/gendream.html +26 -0
  22. package/demos/group.html +36 -0
  23. package/demos/home.html +587 -0
  24. package/demos/index.html +364 -0
  25. package/demos/isometric.html +34 -0
  26. package/demos/js/animations.js +452 -0
  27. package/demos/js/basic.js +204 -0
  28. package/demos/js/baskara.js +751 -0
  29. package/demos/js/bezier.js +692 -0
  30. package/demos/js/beziersignature.js +241 -0
  31. package/demos/js/blackhole/accretiondisk.obj.js +379 -0
  32. package/demos/js/blackhole/blackhole.obj.js +318 -0
  33. package/demos/js/blackhole/index.js +409 -0
  34. package/demos/js/blackhole/particle.js +56 -0
  35. package/demos/js/blackhole/starfield.obj.js +218 -0
  36. package/demos/js/blob.js +2263 -0
  37. package/demos/js/easing.js +477 -0
  38. package/demos/js/fluent.js +183 -0
  39. package/demos/js/fractals.js +931 -0
  40. package/demos/js/fractalworker.js +93 -0
  41. package/demos/js/genart.js +268 -0
  42. package/demos/js/gendream.js +209 -0
  43. package/demos/js/group.js +140 -0
  44. package/demos/js/info-toggle.js +25 -0
  45. package/demos/js/isometric.js +863 -0
  46. package/demos/js/kerr.js +1556 -0
  47. package/demos/js/lavalamp.js +590 -0
  48. package/demos/js/layout.js +354 -0
  49. package/demos/js/mondrian.js +285 -0
  50. package/demos/js/opacity.js +275 -0
  51. package/demos/js/painter.js +484 -0
  52. package/demos/js/particles-showcase.js +514 -0
  53. package/demos/js/particles.js +299 -0
  54. package/demos/js/patterns.js +397 -0
  55. package/demos/js/penrose/artifact.js +69 -0
  56. package/demos/js/penrose/blackhole.js +121 -0
  57. package/demos/js/penrose/constants.js +73 -0
  58. package/demos/js/penrose/game.js +943 -0
  59. package/demos/js/penrose/lore.js +278 -0
  60. package/demos/js/penrose/penrosescene.js +892 -0
  61. package/demos/js/penrose/ship.js +216 -0
  62. package/demos/js/penrose/sounds.js +211 -0
  63. package/demos/js/penrose/voidparticle.js +55 -0
  64. package/demos/js/penrose/voidscene.js +258 -0
  65. package/demos/js/penrose/voidship.js +144 -0
  66. package/demos/js/penrose/wormhole.js +46 -0
  67. package/demos/js/pipeline.js +555 -0
  68. package/demos/js/scene.js +304 -0
  69. package/demos/js/scenes.js +320 -0
  70. package/demos/js/schrodinger.js +410 -0
  71. package/demos/js/schwarzschild.js +1023 -0
  72. package/demos/js/shapes.js +628 -0
  73. package/demos/js/space/alien.js +171 -0
  74. package/demos/js/space/boom.js +98 -0
  75. package/demos/js/space/boss.js +353 -0
  76. package/demos/js/space/buff.js +73 -0
  77. package/demos/js/space/bullet.js +102 -0
  78. package/demos/js/space/constants.js +85 -0
  79. package/demos/js/space/game.js +1884 -0
  80. package/demos/js/space/hud.js +112 -0
  81. package/demos/js/space/laserbeam.js +179 -0
  82. package/demos/js/space/lightning.js +277 -0
  83. package/demos/js/space/minion.js +192 -0
  84. package/demos/js/space/missile.js +212 -0
  85. package/demos/js/space/player.js +430 -0
  86. package/demos/js/space/powerup.js +90 -0
  87. package/demos/js/space/starfield.js +58 -0
  88. package/demos/js/space/starpower.js +90 -0
  89. package/demos/js/spacetime.js +559 -0
  90. package/demos/js/svgtween.js +204 -0
  91. package/demos/js/tde/accretiondisk.js +418 -0
  92. package/demos/js/tde/blackhole.js +219 -0
  93. package/demos/js/tde/blackholescene.js +209 -0
  94. package/demos/js/tde/config.js +59 -0
  95. package/demos/js/tde/index.js +695 -0
  96. package/demos/js/tde/jets.js +290 -0
  97. package/demos/js/tde/lensedstarfield.js +147 -0
  98. package/demos/js/tde/tdestar.js +317 -0
  99. package/demos/js/tde/tidalstream.js +356 -0
  100. package/demos/js/tde_old/blackhole.obj.js +354 -0
  101. package/demos/js/tde_old/debris.obj.js +791 -0
  102. package/demos/js/tde_old/flare.obj.js +239 -0
  103. package/demos/js/tde_old/index.js +448 -0
  104. package/demos/js/tde_old/star.obj.js +812 -0
  105. package/demos/js/tiles.js +312 -0
  106. package/demos/js/tweendemo.js +79 -0
  107. package/demos/js/visibility.js +102 -0
  108. package/demos/kerr.html +28 -0
  109. package/demos/lavalamp.html +27 -0
  110. package/demos/layouts.html +37 -0
  111. package/demos/logo.svg +4 -0
  112. package/demos/loop.html +84 -0
  113. package/demos/mondrian.html +32 -0
  114. package/demos/og_image.png +0 -0
  115. package/demos/opacity.html +36 -0
  116. package/demos/painter.html +39 -0
  117. package/demos/particles-showcase.html +28 -0
  118. package/demos/particles.html +24 -0
  119. package/demos/patterns.html +33 -0
  120. package/demos/penrose-game.html +31 -0
  121. package/demos/pipeline.html +737 -0
  122. package/demos/scene.html +33 -0
  123. package/demos/scenes.html +96 -0
  124. package/demos/schrodinger.html +27 -0
  125. package/demos/schwarzschild.html +27 -0
  126. package/demos/shapes.html +16 -0
  127. package/demos/space.html +85 -0
  128. package/demos/spacetime.html +27 -0
  129. package/demos/svgtween.html +29 -0
  130. package/demos/tde.html +28 -0
  131. package/demos/tiles.html +28 -0
  132. package/demos/transforms.html +400 -0
  133. package/demos/tween.html +45 -0
  134. package/demos/visibility.html +33 -0
  135. package/disk_example.png +0 -0
  136. package/docs/README.md +222 -0
  137. package/docs/concepts/architecture-overview.md +204 -0
  138. package/docs/concepts/lifecycle.md +255 -0
  139. package/docs/concepts/rendering-pipeline.md +279 -0
  140. package/docs/concepts/tde-zorder.md +106 -0
  141. package/docs/concepts/two-layer-architecture.md +229 -0
  142. package/docs/getting-started/first-game.md +354 -0
  143. package/docs/getting-started/hello-world.md +269 -0
  144. package/docs/getting-started/installation.md +157 -0
  145. package/docs/modules/collision/README.md +453 -0
  146. package/docs/modules/fluent/README.md +1075 -0
  147. package/docs/modules/game/README.md +303 -0
  148. package/docs/modules/isometric-camera.md +210 -0
  149. package/docs/modules/isometric.md +275 -0
  150. package/docs/modules/painter/README.md +328 -0
  151. package/docs/modules/particle/README.md +559 -0
  152. package/docs/modules/shapes/README.md +221 -0
  153. package/docs/modules/shapes/base/euclidian.md +123 -0
  154. package/docs/modules/shapes/base/geometry2d.md +204 -0
  155. package/docs/modules/shapes/base/renderable.md +215 -0
  156. package/docs/modules/shapes/base/shape.md +262 -0
  157. package/docs/modules/shapes/base/transformable.md +243 -0
  158. package/docs/modules/shapes/hierarchy.md +218 -0
  159. package/docs/modules/state/README.md +577 -0
  160. package/docs/modules/util/README.md +99 -0
  161. package/docs/modules/util/camera3d.md +412 -0
  162. package/docs/modules/util/scene3d.md +395 -0
  163. package/index.html +17 -0
  164. package/jsdoc.json +50 -0
  165. package/package.json +55 -0
  166. package/readme.md +599 -0
  167. package/scripts/build-demo.js +69 -0
  168. package/scripts/bundle4llm.js +276 -0
  169. package/scripts/clearconsole.js +48 -0
  170. package/src/collision/collision-system.js +332 -0
  171. package/src/collision/collision.js +303 -0
  172. package/src/collision/index.js +10 -0
  173. package/src/fluent/fluent-game.js +430 -0
  174. package/src/fluent/fluent-go.js +1060 -0
  175. package/src/fluent/fluent-layer.js +152 -0
  176. package/src/fluent/fluent-scene.js +291 -0
  177. package/src/fluent/index.js +98 -0
  178. package/src/fluent/sketch.js +380 -0
  179. package/src/game/game.js +467 -0
  180. package/src/game/index.js +49 -0
  181. package/src/game/objects/go.js +220 -0
  182. package/src/game/objects/imagego.js +30 -0
  183. package/src/game/objects/index.js +54 -0
  184. package/src/game/objects/isometric-scene.js +260 -0
  185. package/src/game/objects/layoutscene.js +549 -0
  186. package/src/game/objects/scene.js +175 -0
  187. package/src/game/objects/scene3d.js +118 -0
  188. package/src/game/objects/text.js +221 -0
  189. package/src/game/objects/wrapper.js +232 -0
  190. package/src/game/pipeline.js +243 -0
  191. package/src/game/ui/button.js +396 -0
  192. package/src/game/ui/cursor.js +93 -0
  193. package/src/game/ui/fps.js +91 -0
  194. package/src/game/ui/index.js +5 -0
  195. package/src/game/ui/togglebutton.js +93 -0
  196. package/src/game/ui/tooltip.js +249 -0
  197. package/src/index.js +25 -0
  198. package/src/io/events.js +20 -0
  199. package/src/io/index.js +86 -0
  200. package/src/io/input.js +70 -0
  201. package/src/io/keys.js +152 -0
  202. package/src/io/mouse.js +61 -0
  203. package/src/io/touch.js +39 -0
  204. package/src/logger/debugtab.js +138 -0
  205. package/src/logger/index.js +3 -0
  206. package/src/logger/loggable.js +47 -0
  207. package/src/logger/logger.js +113 -0
  208. package/src/math/complex.js +37 -0
  209. package/src/math/constants.js +1 -0
  210. package/src/math/fractal.js +1271 -0
  211. package/src/math/gr.js +201 -0
  212. package/src/math/heat.js +202 -0
  213. package/src/math/index.js +12 -0
  214. package/src/math/noise.js +433 -0
  215. package/src/math/orbital.js +191 -0
  216. package/src/math/patterns.js +1339 -0
  217. package/src/math/penrose.js +259 -0
  218. package/src/math/quantum.js +115 -0
  219. package/src/math/random.js +195 -0
  220. package/src/math/tensor.js +1009 -0
  221. package/src/mixins/anchor.js +131 -0
  222. package/src/mixins/draggable.js +72 -0
  223. package/src/mixins/index.js +2 -0
  224. package/src/motion/bezier.js +132 -0
  225. package/src/motion/bounce.js +58 -0
  226. package/src/motion/easing.js +349 -0
  227. package/src/motion/float.js +130 -0
  228. package/src/motion/follow.js +125 -0
  229. package/src/motion/hop.js +52 -0
  230. package/src/motion/index.js +82 -0
  231. package/src/motion/motion.js +1124 -0
  232. package/src/motion/orbit.js +49 -0
  233. package/src/motion/oscillate.js +39 -0
  234. package/src/motion/parabolic.js +141 -0
  235. package/src/motion/patrol.js +147 -0
  236. package/src/motion/pendulum.js +48 -0
  237. package/src/motion/pulse.js +88 -0
  238. package/src/motion/shake.js +83 -0
  239. package/src/motion/spiral.js +144 -0
  240. package/src/motion/spring.js +150 -0
  241. package/src/motion/swing.js +47 -0
  242. package/src/motion/tween.js +92 -0
  243. package/src/motion/tweenetik.js +139 -0
  244. package/src/motion/waypoint.js +210 -0
  245. package/src/painter/index.js +8 -0
  246. package/src/painter/painter.colors.js +331 -0
  247. package/src/painter/painter.effects.js +230 -0
  248. package/src/painter/painter.img.js +229 -0
  249. package/src/painter/painter.js +295 -0
  250. package/src/painter/painter.lines.js +189 -0
  251. package/src/painter/painter.opacity.js +41 -0
  252. package/src/painter/painter.shapes.js +277 -0
  253. package/src/painter/painter.text.js +273 -0
  254. package/src/particle/emitter.js +124 -0
  255. package/src/particle/index.js +11 -0
  256. package/src/particle/particle-system.js +322 -0
  257. package/src/particle/particle.js +71 -0
  258. package/src/particle/updaters.js +170 -0
  259. package/src/shapes/arc.js +43 -0
  260. package/src/shapes/arrow.js +33 -0
  261. package/src/shapes/bezier.js +42 -0
  262. package/src/shapes/circle.js +62 -0
  263. package/src/shapes/clouds.js +56 -0
  264. package/src/shapes/cone.js +219 -0
  265. package/src/shapes/cross.js +70 -0
  266. package/src/shapes/cube.js +244 -0
  267. package/src/shapes/cylinder.js +254 -0
  268. package/src/shapes/diamond.js +48 -0
  269. package/src/shapes/euclidian.js +111 -0
  270. package/src/shapes/figure.js +115 -0
  271. package/src/shapes/geometry.js +220 -0
  272. package/src/shapes/group.js +375 -0
  273. package/src/shapes/heart.js +42 -0
  274. package/src/shapes/hexagon.js +26 -0
  275. package/src/shapes/image.js +192 -0
  276. package/src/shapes/index.js +111 -0
  277. package/src/shapes/line.js +29 -0
  278. package/src/shapes/pattern.js +90 -0
  279. package/src/shapes/pin.js +44 -0
  280. package/src/shapes/poly.js +31 -0
  281. package/src/shapes/prism.js +226 -0
  282. package/src/shapes/rect.js +35 -0
  283. package/src/shapes/renderable.js +333 -0
  284. package/src/shapes/ring.js +26 -0
  285. package/src/shapes/roundrect.js +95 -0
  286. package/src/shapes/shape.js +117 -0
  287. package/src/shapes/slice.js +26 -0
  288. package/src/shapes/sphere.js +314 -0
  289. package/src/shapes/sphere3d.js +537 -0
  290. package/src/shapes/square.js +15 -0
  291. package/src/shapes/star.js +99 -0
  292. package/src/shapes/svg.js +408 -0
  293. package/src/shapes/text.js +553 -0
  294. package/src/shapes/traceable.js +83 -0
  295. package/src/shapes/transform.js +357 -0
  296. package/src/shapes/transformable.js +172 -0
  297. package/src/shapes/triangle.js +26 -0
  298. package/src/sound/index.js +17 -0
  299. package/src/sound/sound.js +473 -0
  300. package/src/sound/synth.analyzer.js +149 -0
  301. package/src/sound/synth.effects.js +207 -0
  302. package/src/sound/synth.envelope.js +59 -0
  303. package/src/sound/synth.js +229 -0
  304. package/src/sound/synth.musical.js +160 -0
  305. package/src/sound/synth.noise.js +85 -0
  306. package/src/sound/synth.oscillators.js +293 -0
  307. package/src/state/index.js +10 -0
  308. package/src/state/state-machine.js +371 -0
  309. package/src/util/camera3d.js +438 -0
  310. package/src/util/index.js +6 -0
  311. package/src/util/isometric-camera.js +235 -0
  312. package/src/util/layout.js +317 -0
  313. package/src/util/position.js +147 -0
  314. package/src/util/tasks.js +47 -0
  315. package/src/util/zindex.js +287 -0
  316. package/src/webgl/index.js +9 -0
  317. package/src/webgl/shaders/sphere-shaders.js +994 -0
  318. package/src/webgl/webgl-renderer.js +388 -0
  319. package/tde.png +0 -0
  320. package/test/math/orbital.test.js +61 -0
  321. package/test/math/tensor.test.js +114 -0
  322. package/test/particle/emitter.test.js +204 -0
  323. package/test/particle/particle-system.test.js +310 -0
  324. package/test/particle/particle.test.js +116 -0
  325. package/test/particle/updaters.test.js +386 -0
  326. package/test/setup.js +120 -0
  327. package/test/shapes/euclidian.test.js +44 -0
  328. package/test/shapes/geometry.test.js +86 -0
  329. package/test/shapes/group.test.js +86 -0
  330. package/test/shapes/rectangle.test.js +64 -0
  331. package/test/shapes/transform.test.js +379 -0
  332. package/test/util/camera3d.test.js +428 -0
  333. package/test/util/scene3d.test.js +352 -0
  334. package/types/collision.d.ts +249 -0
  335. package/types/common.d.ts +155 -0
  336. package/types/game.d.ts +497 -0
  337. package/types/index.d.ts +309 -0
  338. package/types/io.d.ts +188 -0
  339. package/types/logger.d.ts +127 -0
  340. package/types/math.d.ts +268 -0
  341. package/types/mixins.d.ts +92 -0
  342. package/types/motion.d.ts +678 -0
  343. package/types/painter.d.ts +378 -0
  344. package/types/shapes.d.ts +864 -0
  345. package/types/sound.d.ts +672 -0
  346. package/types/state.d.ts +251 -0
  347. package/types/util.d.ts +253 -0
  348. package/vite.config.js +50 -0
  349. package/vitest.config.js +13 -0
@@ -0,0 +1,312 @@
1
+ import {
2
+ Game,
3
+ Scene,
4
+ TileLayout,
5
+ HorizontalLayout,
6
+ Rectangle,
7
+ ShapeGOFactory,
8
+ Button,
9
+ FPSCounter,
10
+ Painter,
11
+ Tween,
12
+ Easing,
13
+ Position,
14
+ } from "../../src/index";
15
+
16
+ // Configuration
17
+ const CONFIG = {
18
+ tileSize: 50,
19
+ tileSpacing: 12,
20
+ tilePadding: 20,
21
+ initialTiles: 50,
22
+ maxColumns: 10,
23
+ uiHeight: 100, // Space reserved for UI at bottom
24
+ };
25
+
26
+ export class TileDemo extends Scene {
27
+ constructor(game, options = {}) {
28
+ super(game, options);
29
+ this.elapsedTime = this.lastChangeTime = 0;
30
+ }
31
+
32
+ isMobile() {
33
+ return this.game.width < 600;
34
+ }
35
+
36
+ getResponsiveColumns() {
37
+ const availableWidth = this.game.width - CONFIG.tilePadding * 2;
38
+ const tileWithSpacing = CONFIG.tileSize + CONFIG.tileSpacing;
39
+ const columns = Math.floor(availableWidth / tileWithSpacing);
40
+ return Math.max(2, Math.min(CONFIG.maxColumns, columns));
41
+ }
42
+
43
+ getViewportDimensions() {
44
+ const margin = this.isMobile() ? 20 : 40;
45
+ return {
46
+ width: this.game.width - margin * 2,
47
+ height: this.game.height - CONFIG.uiHeight - margin,
48
+ };
49
+ }
50
+
51
+ init() {
52
+ const game = this.game;
53
+ const viewport = this.getViewportDimensions();
54
+ const columns = this.getResponsiveColumns();
55
+
56
+ // 1) Create a scrollable tile grid anchored at center
57
+ this.grid = new TileLayout(game, {
58
+ anchor: Position.CENTER,
59
+ anchorOffsetY: -CONFIG.uiHeight / 2 + 20,
60
+ columns: columns,
61
+ spacing: CONFIG.tileSpacing,
62
+ padding: CONFIG.tilePadding,
63
+ autoSize: true,
64
+ debug: true,
65
+ // Enable scrolling
66
+ scrollable: true,
67
+ viewportWidth: viewport.width,
68
+ viewportHeight: viewport.height,
69
+ });
70
+
71
+ // Add initial tiles
72
+ for (let i = 0; i < CONFIG.initialTiles; i++) {
73
+ this.addTile();
74
+ }
75
+ this.add(this.grid);
76
+
77
+ // 2) Create a HorizontalLayout at bottom-center for UI buttons
78
+ this.createUI();
79
+ }
80
+
81
+ createUI() {
82
+ const game = this.game;
83
+ const isMobile = this.isMobile();
84
+ const buttonWidth = isMobile ? 70 : 90;
85
+
86
+ this.bottomUI = new HorizontalLayout(game, {
87
+ anchor: Position.BOTTOM_CENTER,
88
+ anchorOffsetY: -15,
89
+ spacing: isMobile ? 5 : 10,
90
+ padding: 10,
91
+ debug: false,
92
+ align: "center",
93
+ });
94
+ this.add(this.bottomUI);
95
+
96
+ // "Add Tile" button
97
+ this.bottomUI.add(new Button(game, {
98
+ text: isMobile ? "+" : "Add",
99
+ width: isMobile ? 40 : buttonWidth,
100
+ onClick: () => this.addTile(),
101
+ }));
102
+
103
+ // "Remove Tile" button
104
+ this.bottomUI.add(new Button(game, {
105
+ text: isMobile ? "-" : "Remove",
106
+ width: isMobile ? 40 : buttonWidth,
107
+ onClick: () => this.removeTile(),
108
+ }));
109
+
110
+ // "Add Column" button
111
+ this.bottomUI.add(new Button(game, {
112
+ text: isMobile ? "+Col" : "+ Column",
113
+ width: isMobile ? 50 : buttonWidth,
114
+ onClick: () => {
115
+ const maxColumns = this.getResponsiveColumns();
116
+ if (this.grid.columns < maxColumns) {
117
+ this.grid.columns++;
118
+ this.grid.markBoundsDirty();
119
+ }
120
+ },
121
+ }));
122
+
123
+ // "Remove Column" button
124
+ this.bottomUI.add(new Button(game, {
125
+ text: isMobile ? "-Col" : "- Column",
126
+ width: isMobile ? 50 : buttonWidth,
127
+ onClick: () => {
128
+ this.grid.columns = Math.max(1, this.grid.columns - 1);
129
+ this.grid.markBoundsDirty();
130
+ },
131
+ }));
132
+
133
+ // Add 10 tiles button (for quickly testing scroll)
134
+ this.bottomUI.add(new Button(game, {
135
+ text: isMobile ? "+10" : "Add 10",
136
+ width: isMobile ? 45 : buttonWidth,
137
+ onClick: () => {
138
+ for (let i = 0; i < 10; i++) this.addTile();
139
+ },
140
+ }));
141
+ }
142
+
143
+ addTile() {
144
+ const rect = new Rectangle({
145
+ width: CONFIG.tileSize,
146
+ height: CONFIG.tileSize,
147
+ color: Painter.colors.randomColorHSL(),
148
+ strokeColor: "white",
149
+ });
150
+ const tileGO = ShapeGOFactory.create(this.game, rect);
151
+ this.grid.add(tileGO);
152
+ }
153
+
154
+ removeTile() {
155
+ if (this.grid.children.length > 0) {
156
+ const last = this.grid.children[this.grid.children.length - 1];
157
+ this.grid.remove(last);
158
+ }
159
+ }
160
+
161
+ onResize() {
162
+ if (!this.grid) return;
163
+
164
+ // Update columns based on new width
165
+ const newColumns = this.getResponsiveColumns();
166
+ if (this.grid.columns !== newColumns) {
167
+ this.grid.columns = newColumns;
168
+ }
169
+
170
+ // Update viewport for scrolling
171
+ const viewport = this.getViewportDimensions();
172
+ this.grid._viewportWidth = viewport.width;
173
+ this.grid._viewportHeight = viewport.height;
174
+
175
+ this.grid.markBoundsDirty();
176
+ if (this.bottomUI) {
177
+ this.bottomUI.markBoundsDirty();
178
+ }
179
+ }
180
+
181
+ update(dt) {
182
+ super.update(dt);
183
+ this.elapsedTime += dt;
184
+
185
+ // Only process tiles every N seconds to reduce frequency
186
+ if (this.elapsedTime - this.lastChangeTime > 0.1) {
187
+ this.lastChangeTime = this.elapsedTime;
188
+
189
+ // Random number of tiles to change (between 1 and 10% of total tiles)
190
+ const tilesToChange = Math.max(
191
+ 1,
192
+ Math.floor(this.grid.children.length * (0.1 + Math.random() * 0.1))
193
+ );
194
+
195
+ // Filter out tiles that are already tweening
196
+ const availableTiles = this.grid.children.filter(
197
+ (tile) => !tile.isTweening
198
+ );
199
+
200
+ // Shuffle and pick random tiles
201
+ const shuffled = [...availableTiles].sort(() => 0.5 - Math.random());
202
+ const selectedTiles = shuffled.slice(
203
+ 0,
204
+ Math.min(tilesToChange, availableTiles.length)
205
+ );
206
+
207
+ // Start tweening on selected tiles
208
+ for (const tile of selectedTiles) {
209
+ tile.isTweening = true;
210
+
211
+ // Store RGB values directly instead of CSS string to avoid parsing issues
212
+ const rgb = tile.shape.color ?
213
+ Painter.colors.parseColorString(tile.shape.color) :
214
+ [255, 255, 255]; // Default to white if color is undefined
215
+
216
+ tile.startRGB = rgb;
217
+
218
+ // Generate vibrant random color in RGB directly
219
+ const hue = Math.floor(Math.random() * 360);
220
+ const saturation = 80 + Math.floor(Math.random() * 20); // 80-100%
221
+ const lightness = 50 + Math.floor(Math.random() * 30); // 50-80%
222
+ const targetRGB = Painter.colors.hslToRgb(hue, saturation, lightness);
223
+
224
+ tile.targetRGB = targetRGB;
225
+ tile.tweenElapsed = 0;
226
+ tile.tweenDuration = 0.5 + Math.random() * 0.5; // Random duration between 0.5-1.0 seconds
227
+ }
228
+ }
229
+
230
+ // Update all tweening tiles
231
+ for (const tile of this.grid.children) {
232
+ if (tile.isTweening) {
233
+ try {
234
+ // Update elapsed time
235
+ tile.tweenElapsed += dt;
236
+
237
+ // Calculate progress with proper easing
238
+ const progress = Math.min(tile.tweenElapsed / tile.tweenDuration, 1.0);
239
+ const easedProgress = Easing.easeInOutQuad(progress);
240
+
241
+ // Use the stored RGB values directly
242
+ if (tile.startRGB && tile.targetRGB) {
243
+ const newRGB = Tween.tweenColor(
244
+ tile.startRGB,
245
+ tile.targetRGB,
246
+ easedProgress
247
+ );
248
+
249
+ // Convert interpolated RGB values to CSS color string
250
+ tile.shape.color = Painter.colors.rgbArrayToCSS(newRGB);
251
+
252
+ // Check if tween is complete
253
+ if (progress >= 1) {
254
+ tile.isTweening = false;
255
+ tile.shape.color = Painter.colors.rgbArrayToCSS(tile.targetRGB);
256
+ }
257
+ } else {
258
+ // Color missing, reset the tweening state
259
+ console.warn("Missing color values for tweening");
260
+ tile.isTweening = false;
261
+
262
+ // Set a fallback color
263
+ const fallbackRGB = [
264
+ Math.floor(Math.random() * 255),
265
+ Math.floor(Math.random() * 255),
266
+ Math.floor(Math.random() * 255)
267
+ ];
268
+ tile.shape.color = Painter.colors.rgbArrayToCSS(fallbackRGB);
269
+ }
270
+ } catch (error) {
271
+ // Handle any errors in the color transition
272
+ console.warn("Error during color tweening:", error);
273
+ tile.isTweening = false;
274
+
275
+ // Set a fallback color
276
+ const fallbackRGB = [
277
+ Math.floor(Math.random() * 255),
278
+ Math.floor(Math.random() * 255),
279
+ Math.floor(Math.random() * 255)
280
+ ];
281
+ tile.shape.color = Painter.colors.rgbArrayToCSS(fallbackRGB);
282
+ }
283
+ }
284
+ }
285
+ }
286
+ }
287
+
288
+ //
289
+ export class MyGame extends Game {
290
+ constructor(canvas) {
291
+ super(canvas);
292
+ this.backgroundColor = "black";
293
+ this.enableFluidSize();
294
+ }
295
+
296
+ init() {
297
+ super.init();
298
+ this.tileDemo = new TileDemo(this);
299
+ this.pipeline.add(this.tileDemo);
300
+ this.pipeline.add(
301
+ new FPSCounter(this, {
302
+ anchor: "bottom-right",
303
+ })
304
+ );
305
+ }
306
+
307
+ onResize() {
308
+ if (this.tileDemo) {
309
+ this.tileDemo.onResize();
310
+ }
311
+ }
312
+ }
@@ -0,0 +1,79 @@
1
+ import {
2
+ Game,
3
+ Rectangle,
4
+ Group,
5
+ Scene,
6
+ ShapeGOFactory,
7
+ TextShape,
8
+ FPSCounter,
9
+ Tween,
10
+ Tweenetik,
11
+ Easing,
12
+ } from "../../src/index";
13
+ export class TweenDemo extends Scene {
14
+ constructor(game, options = {}) {
15
+ super(game, options);
16
+ const bg = new Rectangle({ width: 100, height: 100, color: "#0f0" });
17
+ const frame = new Rectangle({ width: 80, height: 80, color: "#000" });
18
+ this.label = new TextShape("1%", {
19
+ font: "18px monospace",
20
+ color: "#F0F",
21
+ align: "center",
22
+ baseline: "middle",
23
+ });
24
+ const group = new Group();
25
+ group.add(bg);
26
+ group.add(frame);
27
+ group.add(this.label);
28
+ group.scaleX = group.scaleY = 2; // add individual scale to this group to test if the outer group scales it too
29
+ //
30
+ const wrapper = new Group();
31
+ wrapper.add(group);
32
+ //
33
+ this.box = ShapeGOFactory.create(game, wrapper);
34
+ this.box.anchor = "center";
35
+ this.add(this.box);
36
+ this.growing = false;
37
+ this.tween();
38
+ }
39
+
40
+ tween() {
41
+ this.growing = !this.growing;
42
+ const scale = this.growing ? 2 : 1;
43
+ const easing = this.growing ? Easing.easeOutElastic : Easing.easeInOutBack;
44
+ // Tweenetik is a simple tweening library that works with any object
45
+ Tweenetik.to(
46
+ this.box, // an object or sprite
47
+ { scaleX: scale, scaleY: scale }, // the properties & end-values
48
+ 2.0, // duration in seconds
49
+ easing, // easing function
50
+ {
51
+ delay: 0.3,
52
+ onComplete: () => this.tween(), // restart the tween
53
+ onUpdate: () => this.updateText(),
54
+ }
55
+ );
56
+ }
57
+
58
+ updateText() {
59
+ this.label.text = `${Math.round(this.box.scaleX * 100)}%`;
60
+ }
61
+ }
62
+ //
63
+ export class MyGame extends Game {
64
+ constructor(canvas) {
65
+ super(canvas);
66
+ this.backgroundColor = "black";
67
+ this.enableFluidSize();
68
+ }
69
+
70
+ init() {
71
+ super.init();
72
+ this.pipeline.add(new TweenDemo(this, {debug: true, anchor: "center"}));
73
+ this.pipeline.add(
74
+ new FPSCounter(this, {
75
+ anchor: "bottom-right",
76
+ })
77
+ );
78
+ }
79
+ }
@@ -0,0 +1,102 @@
1
+ import {
2
+ Game,
3
+ Scene,
4
+ HorizontalLayout,
5
+ Rectangle,
6
+ ShapeGOFactory,
7
+ Button,
8
+ FPSCounter,
9
+ Square,
10
+ Position,
11
+ } from "../../src/index";
12
+
13
+ export class VisibilityDemo extends Scene {
14
+ constructor(game, options = {}) {
15
+ super(game, options);
16
+ this.MARGIN = 20;
17
+ // 1) A horizontal layout of squares at screen center
18
+ this.squaresLayout = new HorizontalLayout(game, {
19
+ spacing: 1,
20
+ padding: 4,
21
+ });
22
+ this.add(this.squaresLayout);
23
+ // Create a few colored squares and add them to the layout
24
+ const colors = ["#0f0", "#0f0", "#0f0"];
25
+ for (let i = 0; i < colors.length; i++) {
26
+ const rect = new Square(100, {
27
+ color: colors[i],
28
+ });
29
+ const squareGO = ShapeGOFactory.create(game, rect);
30
+ this.squaresLayout.add(squareGO);
31
+ }
32
+ // 2) A UI scene that holds the buttons
33
+ this.uiScene = new Scene(game, {
34
+ name: "UI Scene",
35
+ width: 120,
36
+ height: 40,
37
+ anchor: Position.BOTTOM_CENTER,
38
+ anchorMargin: 20,
39
+ });
40
+ this.uiScene.width = 150;
41
+ this.uiScene.height = 50;
42
+ this.add(this.uiScene);
43
+ // A button that toggles visibility of a random square
44
+ let currentSquare = null;
45
+ const pickOne = () => {
46
+ if (currentSquare) {
47
+ currentSquare.visible = !currentSquare.visible;
48
+ }
49
+ const index = Math.floor(
50
+ Math.random() * this.squaresLayout.children.length
51
+ );
52
+ const square = this.squaresLayout.children[index];
53
+ if (currentSquare == square) {
54
+ currentSquare = null;
55
+ return pickOne();
56
+ }
57
+ currentSquare = square;
58
+ currentSquare.visible = !currentSquare.visible;
59
+ };
60
+ const toggleBtn = new Button(game, {
61
+ text: "Toggle Random",
62
+ width: 120,
63
+ onClick: () => {
64
+ pickOne();
65
+ },
66
+ });
67
+ this.uiScene.add(toggleBtn);
68
+ }
69
+
70
+ update(dt) {
71
+ // Update scene dimensions based on margin
72
+ this.width = this.game.width - this.MARGIN * 2;
73
+ this.height = this.game.height - this.MARGIN * 2;
74
+ // Center the scene in the game
75
+ this.x = this.game.width / 2;
76
+ this.y = this.game.height / 2;
77
+ super.update(dt);
78
+ }
79
+ }
80
+
81
+ //
82
+ export class MyGame extends Game {
83
+ constructor(canvas) {
84
+ super(canvas);
85
+ this.backgroundColor = "black";
86
+ this.enableFluidSize();
87
+ }
88
+
89
+ init() {
90
+ super.init();
91
+ this.scene = new VisibilityDemo(this, {
92
+ width: this.width,
93
+ height: this.height,
94
+ });
95
+ this.pipeline.add(this.scene);
96
+ this.pipeline.add(
97
+ new FPSCounter(this, {
98
+ anchor: Position.BOTTOM_RIGHT,
99
+ })
100
+ );
101
+ }
102
+ }
@@ -0,0 +1,28 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+
4
+ <head>
5
+ <meta charset="UTF-8" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>Math & Physics - Kerr Metric (Rotating Black Hole)</title>
8
+ <link rel="stylesheet" href="demos.css" />
9
+ <script src="./js/info-toggle.js"></script>
10
+ </head>
11
+
12
+ <body>
13
+ <div id="info">
14
+ <strong>Kerr Metric</strong> — Rotating black hole with frame dragging.<br/>
15
+ <span style="color:#CCC">
16
+ <li><code>Spin</code> — Parameter a controls rotation (0 to M).</li>
17
+ <li><code>g_t&phi;</code> — Off-diagonal term = frame dragging!</li>
18
+ <li><code>Ergosphere</code> — Orange region where nothing stays still.</li>
19
+ <li><code>Two ISCOs</code> — Prograde vs retrograde orbits differ.</li>
20
+ <li><code>Click</code> — Shuffle mass and spin parameters.</li>
21
+ <li><code>Drag</code> — Rotate the 3D view.</li>
22
+ </span>
23
+ </div>
24
+ <canvas id="game"></canvas>
25
+ <script type="module" src="./js/kerr.js"></script>
26
+ </body>
27
+
28
+ </html>
@@ -0,0 +1,27 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+
4
+ <head>
5
+ <meta charset="UTF-8" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>Generative Art - Lava Lamp</title>
8
+ <link rel="stylesheet" href="demos.css" />
9
+ <script src="./js/info-toggle.js"></script>
10
+ </head>
11
+
12
+ <body>
13
+ <div id="info">
14
+ <strong>Lava Lamp</strong> — Metaball lava lamp with heat dynamics.<br/>
15
+ <span style="color:#CCC">
16
+ <li><code>ON/OFF</code> — Toggle power. Watch the wax cool and rise!</li>
17
+ <li><code>Heat zones</code> — Smooth thermal transitions between hot/cold.</li>
18
+ <li><code>Buoyancy</code> — Hot blobs rise, cold blobs sink.</li>
19
+ <li><code>Heat transfer</code> — Nearby blobs exchange temperature.</li>
20
+ <li><code>Metaballs</code> — Blobs merge and split organically.</li>
21
+ </span>
22
+ </div>
23
+ <canvas id="game"></canvas>
24
+ <script type="module" src="./js/lavalamp.js"></script>
25
+ </body>
26
+
27
+ </html>
@@ -0,0 +1,37 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+
4
+ <head>
5
+ <meta charset="UTF-8" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>Layout Demo</title>
8
+ <link rel="stylesheet" href="demos.css" />
9
+ <script src="./js/info-toggle.js"></script>
10
+ </head>
11
+
12
+ <body>
13
+ <div id="info" class="light">
14
+ <strong>Layout Demo</strong><br>
15
+ <span>Demonstrates dynamic switching between <code>HorizontalLayout</code> and
16
+ <code>VerticalLayout</code>.<br>
17
+ Use the right side buttons to switch layout direction.<br>
18
+ Use the bottom buttons to add or remove random rectangles from the layout group.<br>
19
+ Layout auto-sizes and aligns children with spacing and padding.
20
+ </span>
21
+ </div>
22
+ <canvas id="game"></canvas>
23
+
24
+ <script type="module">
25
+ import { LayoutDemo } from "./js/layout.js";
26
+ window.addEventListener("load", () => {
27
+ const canvas = document.getElementById("game");
28
+ const game = new LayoutDemo(canvas);
29
+ //game.setFPS(1)
30
+ //game.enableLogging(true);
31
+ game.start();
32
+ //setTimeout(game.stop.bind(game), 3000);
33
+ });
34
+ </script>
35
+ </body>
36
+
37
+ </html>
package/demos/logo.svg ADDED
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="32.9 174.743 71.888 63.576" width="71.888px" height="63.576px">
3
+ <path d="M 57.971 224.292 L 57.971 203.374 L 57.971 194.861 L 75.109 194.861 L 75.109 188.769 L 63.16 188.769 L 63.16 174.743 L 57.971 174.743 L 57.971 189.041 L 57.971 194.861 L 32.9 194.861 L 32.9 203.773 L 50.377 203.773 L 50.377 224.292 L 57.971 224.292 Z M 79.717 238.319 L 79.717 224.02 L 79.717 218.2 L 104.788 218.2 L 104.788 209.287 L 87.31 209.287 L 87.31 188.769 L 79.717 188.769 L 79.717 209.686 L 79.717 218.2 L 62.579 218.2 L 62.579 224.293 L 74.526 224.293 L 74.526 238.319 L 79.717 238.319 Z" style="fill: rgb(255, 255, 255); fill-rule: evenodd; stroke-width: 1;" id="path8" transform="matrix(0.9999999999999999, 0, 0, 0.9999999999999999, 0, 0)"/>
4
+ </svg>
@@ -0,0 +1,84 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+
4
+ <head>
5
+ <meta charset="UTF-8" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>Game Loop Demo</title>
8
+ <link rel="stylesheet" href="demos.css" />
9
+ <script src="./js/info-toggle.js"></script>
10
+ </head>
11
+
12
+ <body>
13
+ <div id="info">
14
+ <strong>Game Loop Demo</strong> — Demonstrates the <code>update → render</code> cycle using a bouncing ball.
15
+ <br>
16
+ A <strong>Game</strong> runs the loop and delegates updates and rendering to its <strong>Pipeline</strong>. <br>
17
+ A <strong>GameObject</strong> implements <code>update(dt)</code> and <code>render()</code> to animate and draw
18
+ itself. <br>
19
+ This demo shows a ball that moves and bounces off canvas edges on each frame.
20
+ </div>
21
+
22
+ <canvas id="game"></canvas>
23
+
24
+ <script type="module">
25
+ import { Game, Scene, GameObject, FPSCounter, Painter, Circle } from "../src/index";
26
+ class BouncingBall extends GameObject {
27
+ constructor(game) {
28
+ super(game);
29
+ this.radius = 20;
30
+ this.circle = new Circle(this.radius, {
31
+ color: "#0f0",
32
+ debug: false
33
+ });
34
+ this.x = game.width / 2;
35
+ this.y = game.height / 2;
36
+ this.vx = 150;
37
+ this.vy = 100;
38
+ }
39
+
40
+ update(dt) {
41
+ this.x += this.vx * dt;
42
+ this.y += this.vy * dt;
43
+ const w = this.game.width;
44
+ const h = this.game.height;
45
+ if (this.x - this.radius < 0 || this.x + this.radius > w) this.vx *= -1;
46
+ if (this.y - this.radius < 0 || this.y + this.radius > h) this.vy *= -1;
47
+ // Clamp and update shape position
48
+ this.x = Math.max(this.radius, Math.min(w - this.radius, this.x));
49
+ this.y = Math.max(this.radius, Math.min(h - this.radius, this.y));
50
+ super.update(dt);
51
+ }
52
+
53
+ draw() {
54
+ super.draw();
55
+ this.circle.render();
56
+ }
57
+ }
58
+
59
+ class LoopGame extends Game {
60
+ constructor(canvas) {
61
+ super(canvas);
62
+ this.enableFluidSize();
63
+ this.backgroundColor = "black";
64
+ }
65
+
66
+ init() {
67
+ super.init();
68
+ this.pipeline.add(new BouncingBall(this));
69
+ this.pipeline.add(new FPSCounter(this, { anchor: "bottom-left" }));
70
+ }
71
+ }
72
+
73
+ window.addEventListener("load", () => {
74
+ const canvas = document.getElementById("game");
75
+ const game = new LoopGame(canvas);
76
+ //game.enableLogging();
77
+ game.enablePauseOnBlur(true);
78
+ game.setFPS(60);
79
+ game.start();
80
+ });
81
+ </script>
82
+ </body>
83
+
84
+ </html>