@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.
Files changed (217) hide show
  1. package/dist/gcanvas.es.js +25656 -0
  2. package/dist/gcanvas.es.min.js +1 -0
  3. package/dist/gcanvas.umd.js +1 -0
  4. package/dist/gcanvas.umd.min.js +1 -0
  5. package/package.json +23 -6
  6. package/src/game/objects/index.js +1 -0
  7. package/src/game/objects/spritesheet.js +260 -0
  8. package/src/game/ui/theme.js +6 -0
  9. package/src/io/keys.js +9 -1
  10. package/src/math/boolean.js +481 -0
  11. package/src/math/index.js +1 -0
  12. package/.github/workflows/release.yaml +0 -70
  13. package/.jshintrc +0 -4
  14. package/.vscode/settings.json +0 -22
  15. package/CLAUDE.md +0 -310
  16. package/blackhole.jpg +0 -0
  17. package/demo.png +0 -0
  18. package/demos/CNAME +0 -1
  19. package/demos/animations.html +0 -31
  20. package/demos/basic.html +0 -38
  21. package/demos/baskara.html +0 -31
  22. package/demos/bezier.html +0 -35
  23. package/demos/beziersignature.html +0 -29
  24. package/demos/blackhole.html +0 -28
  25. package/demos/blob.html +0 -35
  26. package/demos/coordinates.html +0 -698
  27. package/demos/cube3d.html +0 -23
  28. package/demos/demos.css +0 -303
  29. package/demos/dino.html +0 -42
  30. package/demos/easing.html +0 -28
  31. package/demos/events.html +0 -195
  32. package/demos/fluent.html +0 -647
  33. package/demos/fluid-simple.html +0 -22
  34. package/demos/fluid.html +0 -37
  35. package/demos/fractals.html +0 -36
  36. package/demos/gameobjects.html +0 -626
  37. package/demos/genart.html +0 -26
  38. package/demos/gendream.html +0 -26
  39. package/demos/group.html +0 -36
  40. package/demos/home.html +0 -587
  41. package/demos/index.html +0 -376
  42. package/demos/isometric.html +0 -34
  43. package/demos/js/animations.js +0 -452
  44. package/demos/js/basic.js +0 -204
  45. package/demos/js/baskara.js +0 -751
  46. package/demos/js/bezier.js +0 -692
  47. package/demos/js/beziersignature.js +0 -241
  48. package/demos/js/blackhole/accretiondisk.obj.js +0 -379
  49. package/demos/js/blackhole/blackhole.obj.js +0 -318
  50. package/demos/js/blackhole/index.js +0 -409
  51. package/demos/js/blackhole/particle.js +0 -56
  52. package/demos/js/blackhole/starfield.obj.js +0 -218
  53. package/demos/js/blob.js +0 -2276
  54. package/demos/js/coordinates.js +0 -840
  55. package/demos/js/cube3d.js +0 -789
  56. package/demos/js/dino.js +0 -1420
  57. package/demos/js/easing.js +0 -477
  58. package/demos/js/fluent.js +0 -183
  59. package/demos/js/fluid-simple.js +0 -253
  60. package/demos/js/fluid.js +0 -527
  61. package/demos/js/fractals.js +0 -931
  62. package/demos/js/fractalworker.js +0 -93
  63. package/demos/js/gameobjects.js +0 -176
  64. package/demos/js/genart.js +0 -268
  65. package/demos/js/gendream.js +0 -209
  66. package/demos/js/group.js +0 -140
  67. package/demos/js/info-toggle.js +0 -25
  68. package/demos/js/isometric.js +0 -863
  69. package/demos/js/kerr.js +0 -1556
  70. package/demos/js/lavalamp.js +0 -590
  71. package/demos/js/layout.js +0 -354
  72. package/demos/js/mondrian.js +0 -285
  73. package/demos/js/opacity.js +0 -275
  74. package/demos/js/painter.js +0 -484
  75. package/demos/js/particles-showcase.js +0 -514
  76. package/demos/js/particles.js +0 -299
  77. package/demos/js/patterns.js +0 -397
  78. package/demos/js/penrose/artifact.js +0 -69
  79. package/demos/js/penrose/blackhole.js +0 -121
  80. package/demos/js/penrose/constants.js +0 -73
  81. package/demos/js/penrose/game.js +0 -943
  82. package/demos/js/penrose/lore.js +0 -278
  83. package/demos/js/penrose/penrosescene.js +0 -892
  84. package/demos/js/penrose/ship.js +0 -216
  85. package/demos/js/penrose/sounds.js +0 -211
  86. package/demos/js/penrose/voidparticle.js +0 -55
  87. package/demos/js/penrose/voidscene.js +0 -258
  88. package/demos/js/penrose/voidship.js +0 -144
  89. package/demos/js/penrose/wormhole.js +0 -46
  90. package/demos/js/pipeline.js +0 -555
  91. package/demos/js/plane3d.js +0 -256
  92. package/demos/js/platformer.js +0 -1579
  93. package/demos/js/scene.js +0 -304
  94. package/demos/js/scenes.js +0 -320
  95. package/demos/js/schrodinger.js +0 -410
  96. package/demos/js/schwarzschild.js +0 -1023
  97. package/demos/js/shapes.js +0 -628
  98. package/demos/js/space/alien.js +0 -171
  99. package/demos/js/space/boom.js +0 -98
  100. package/demos/js/space/boss.js +0 -353
  101. package/demos/js/space/buff.js +0 -73
  102. package/demos/js/space/bullet.js +0 -102
  103. package/demos/js/space/constants.js +0 -85
  104. package/demos/js/space/game.js +0 -1884
  105. package/demos/js/space/hud.js +0 -112
  106. package/demos/js/space/laserbeam.js +0 -179
  107. package/demos/js/space/lightning.js +0 -277
  108. package/demos/js/space/minion.js +0 -192
  109. package/demos/js/space/missile.js +0 -212
  110. package/demos/js/space/player.js +0 -430
  111. package/demos/js/space/powerup.js +0 -90
  112. package/demos/js/space/starfield.js +0 -58
  113. package/demos/js/space/starpower.js +0 -90
  114. package/demos/js/spacetime.js +0 -559
  115. package/demos/js/sphere3d.js +0 -229
  116. package/demos/js/sprite.js +0 -473
  117. package/demos/js/svgtween.js +0 -204
  118. package/demos/js/tde/accretiondisk.js +0 -471
  119. package/demos/js/tde/blackhole.js +0 -219
  120. package/demos/js/tde/blackholescene.js +0 -209
  121. package/demos/js/tde/config.js +0 -59
  122. package/demos/js/tde/index.js +0 -820
  123. package/demos/js/tde/jets.js +0 -290
  124. package/demos/js/tde/lensedstarfield.js +0 -154
  125. package/demos/js/tde/tdestar.js +0 -297
  126. package/demos/js/tde/tidalstream.js +0 -372
  127. package/demos/js/tde_old/blackhole.obj.js +0 -354
  128. package/demos/js/tde_old/debris.obj.js +0 -791
  129. package/demos/js/tde_old/flare.obj.js +0 -239
  130. package/demos/js/tde_old/index.js +0 -448
  131. package/demos/js/tde_old/star.obj.js +0 -812
  132. package/demos/js/tiles.js +0 -312
  133. package/demos/js/tweendemo.js +0 -79
  134. package/demos/js/visibility.js +0 -102
  135. package/demos/kerr.html +0 -28
  136. package/demos/lavalamp.html +0 -27
  137. package/demos/layouts.html +0 -37
  138. package/demos/logo.svg +0 -4
  139. package/demos/loop.html +0 -84
  140. package/demos/mondrian.html +0 -32
  141. package/demos/og_image.png +0 -0
  142. package/demos/opacity.html +0 -36
  143. package/demos/painter.html +0 -39
  144. package/demos/particles-showcase.html +0 -28
  145. package/demos/particles.html +0 -24
  146. package/demos/patterns.html +0 -33
  147. package/demos/penrose-game.html +0 -31
  148. package/demos/pipeline.html +0 -737
  149. package/demos/plane3d.html +0 -24
  150. package/demos/platformer.html +0 -43
  151. package/demos/scene.html +0 -33
  152. package/demos/scenes.html +0 -96
  153. package/demos/schrodinger.html +0 -27
  154. package/demos/schwarzschild.html +0 -27
  155. package/demos/shapes.html +0 -16
  156. package/demos/space.html +0 -85
  157. package/demos/spacetime.html +0 -27
  158. package/demos/sphere3d.html +0 -24
  159. package/demos/sprite.html +0 -18
  160. package/demos/svgtween.html +0 -29
  161. package/demos/tde.html +0 -28
  162. package/demos/tiles.html +0 -28
  163. package/demos/transforms.html +0 -400
  164. package/demos/tween.html +0 -45
  165. package/demos/visibility.html +0 -33
  166. package/docs/README.md +0 -230
  167. package/docs/api/FluidSystem.md +0 -173
  168. package/docs/concepts/architecture-overview.md +0 -204
  169. package/docs/concepts/coordinate-system.md +0 -384
  170. package/docs/concepts/lifecycle.md +0 -255
  171. package/docs/concepts/rendering-pipeline.md +0 -279
  172. package/docs/concepts/shapes-vs-gameobjects.md +0 -187
  173. package/docs/concepts/tde-zorder.md +0 -106
  174. package/docs/concepts/two-layer-architecture.md +0 -229
  175. package/docs/fluid-dynamics.md +0 -99
  176. package/docs/getting-started/first-game.md +0 -354
  177. package/docs/getting-started/hello-world.md +0 -269
  178. package/docs/getting-started/installation.md +0 -175
  179. package/docs/modules/collision/README.md +0 -453
  180. package/docs/modules/fluent/README.md +0 -1075
  181. package/docs/modules/game/README.md +0 -303
  182. package/docs/modules/isometric-camera.md +0 -210
  183. package/docs/modules/isometric.md +0 -275
  184. package/docs/modules/painter/README.md +0 -328
  185. package/docs/modules/particle/README.md +0 -559
  186. package/docs/modules/shapes/README.md +0 -221
  187. package/docs/modules/shapes/base/euclidian.md +0 -123
  188. package/docs/modules/shapes/base/geometry2d.md +0 -204
  189. package/docs/modules/shapes/base/renderable.md +0 -215
  190. package/docs/modules/shapes/base/shape.md +0 -262
  191. package/docs/modules/shapes/base/transformable.md +0 -243
  192. package/docs/modules/shapes/hierarchy.md +0 -218
  193. package/docs/modules/state/README.md +0 -577
  194. package/docs/modules/util/README.md +0 -99
  195. package/docs/modules/util/camera3d.md +0 -412
  196. package/docs/modules/util/scene3d.md +0 -395
  197. package/index.html +0 -17
  198. package/jsdoc.json +0 -50
  199. package/scripts/build-demo.js +0 -69
  200. package/scripts/bundle4llm.js +0 -276
  201. package/scripts/clearconsole.js +0 -48
  202. package/test/math/orbital.test.js +0 -61
  203. package/test/math/tensor.test.js +0 -114
  204. package/test/particle/emitter.test.js +0 -204
  205. package/test/particle/particle-system.test.js +0 -310
  206. package/test/particle/particle.test.js +0 -116
  207. package/test/particle/updaters.test.js +0 -386
  208. package/test/setup.js +0 -120
  209. package/test/shapes/euclidian.test.js +0 -44
  210. package/test/shapes/geometry.test.js +0 -86
  211. package/test/shapes/group.test.js +0 -86
  212. package/test/shapes/rectangle.test.js +0 -64
  213. package/test/shapes/transform.test.js +0 -379
  214. package/test/util/camera3d.test.js +0 -428
  215. package/test/util/scene3d.test.js +0 -352
  216. package/vite.config.js +0 -50
  217. package/vitest.config.js +0 -13
package/demos/js/tiles.js DELETED
@@ -1,312 +0,0 @@
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
- }
@@ -1,79 +0,0 @@
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
- }
@@ -1,102 +0,0 @@
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
- }
package/demos/kerr.html DELETED
@@ -1,28 +0,0 @@
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>
@@ -1,27 +0,0 @@
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>
@@ -1,37 +0,0 @@
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 DELETED
@@ -1,4 +0,0 @@
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>
package/demos/loop.html DELETED
@@ -1,84 +0,0 @@
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>