@guinetik/gcanvas 1.0.4 → 1.0.5

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 (193) hide show
  1. package/dist/CNAME +1 -0
  2. package/dist/animations.html +31 -0
  3. package/dist/basic.html +38 -0
  4. package/dist/baskara.html +31 -0
  5. package/dist/bezier.html +35 -0
  6. package/dist/beziersignature.html +29 -0
  7. package/dist/blackhole.html +28 -0
  8. package/dist/blob.html +35 -0
  9. package/dist/coordinates.html +698 -0
  10. package/dist/cube3d.html +23 -0
  11. package/dist/demos.css +303 -0
  12. package/dist/dino.html +42 -0
  13. package/dist/easing.html +28 -0
  14. package/dist/events.html +195 -0
  15. package/dist/fluent.html +647 -0
  16. package/dist/fluid-simple.html +22 -0
  17. package/dist/fluid.html +37 -0
  18. package/dist/fractals.html +36 -0
  19. package/dist/gameobjects.html +626 -0
  20. package/dist/gcanvas.es.js +517 -0
  21. package/dist/gcanvas.es.min.js +1 -1
  22. package/dist/gcanvas.umd.js +1 -1
  23. package/dist/gcanvas.umd.min.js +1 -1
  24. package/dist/genart.html +26 -0
  25. package/dist/gendream.html +26 -0
  26. package/dist/group.html +36 -0
  27. package/dist/home.html +587 -0
  28. package/dist/hyperbolic001.html +23 -0
  29. package/dist/hyperbolic002.html +23 -0
  30. package/dist/hyperbolic003.html +23 -0
  31. package/dist/hyperbolic004.html +23 -0
  32. package/dist/hyperbolic005.html +22 -0
  33. package/dist/index.html +398 -0
  34. package/dist/isometric.html +34 -0
  35. package/dist/js/animations.js +452 -0
  36. package/dist/js/basic.js +204 -0
  37. package/dist/js/baskara.js +751 -0
  38. package/dist/js/bezier.js +692 -0
  39. package/dist/js/beziersignature.js +241 -0
  40. package/dist/js/blackhole/accretiondisk.obj.js +379 -0
  41. package/dist/js/blackhole/blackhole.obj.js +318 -0
  42. package/dist/js/blackhole/index.js +409 -0
  43. package/dist/js/blackhole/particle.js +56 -0
  44. package/dist/js/blackhole/starfield.obj.js +218 -0
  45. package/dist/js/blob.js +2276 -0
  46. package/dist/js/coordinates.js +840 -0
  47. package/dist/js/cube3d.js +789 -0
  48. package/dist/js/dino.js +1420 -0
  49. package/dist/js/easing.js +477 -0
  50. package/dist/js/fluent.js +183 -0
  51. package/dist/js/fluid-simple.js +253 -0
  52. package/dist/js/fluid.js +527 -0
  53. package/dist/js/fractals.js +932 -0
  54. package/dist/js/fractalworker.js +93 -0
  55. package/dist/js/gameobjects.js +176 -0
  56. package/dist/js/genart.js +268 -0
  57. package/dist/js/gendream.js +209 -0
  58. package/dist/js/group.js +140 -0
  59. package/dist/js/hyperbolic001.js +310 -0
  60. package/dist/js/hyperbolic002.js +388 -0
  61. package/dist/js/hyperbolic003.js +319 -0
  62. package/dist/js/hyperbolic004.js +345 -0
  63. package/dist/js/hyperbolic005.js +340 -0
  64. package/dist/js/info-toggle.js +25 -0
  65. package/dist/js/isometric.js +863 -0
  66. package/dist/js/kerr.js +1547 -0
  67. package/dist/js/lavalamp.js +590 -0
  68. package/dist/js/layout.js +354 -0
  69. package/dist/js/mondrian.js +285 -0
  70. package/dist/js/opacity.js +275 -0
  71. package/dist/js/painter.js +484 -0
  72. package/dist/js/particles-showcase.js +514 -0
  73. package/dist/js/particles.js +299 -0
  74. package/dist/js/patterns.js +397 -0
  75. package/dist/js/penrose/artifact.js +69 -0
  76. package/dist/js/penrose/blackhole.js +121 -0
  77. package/dist/js/penrose/constants.js +73 -0
  78. package/dist/js/penrose/game.js +943 -0
  79. package/dist/js/penrose/lore.js +278 -0
  80. package/dist/js/penrose/penrosescene.js +892 -0
  81. package/dist/js/penrose/ship.js +216 -0
  82. package/dist/js/penrose/sounds.js +211 -0
  83. package/dist/js/penrose/voidparticle.js +55 -0
  84. package/dist/js/penrose/voidscene.js +258 -0
  85. package/dist/js/penrose/voidship.js +144 -0
  86. package/dist/js/penrose/wormhole.js +46 -0
  87. package/dist/js/pipeline.js +555 -0
  88. package/dist/js/plane3d.js +256 -0
  89. package/dist/js/platformer.js +1579 -0
  90. package/dist/js/scene.js +304 -0
  91. package/dist/js/scenes.js +320 -0
  92. package/dist/js/schrodinger.js +410 -0
  93. package/dist/js/schwarzschild.js +1015 -0
  94. package/dist/js/shapes.js +628 -0
  95. package/dist/js/space/alien.js +171 -0
  96. package/dist/js/space/boom.js +98 -0
  97. package/dist/js/space/boss.js +353 -0
  98. package/dist/js/space/buff.js +73 -0
  99. package/dist/js/space/bullet.js +102 -0
  100. package/dist/js/space/constants.js +85 -0
  101. package/dist/js/space/game.js +1884 -0
  102. package/dist/js/space/hud.js +112 -0
  103. package/dist/js/space/laserbeam.js +179 -0
  104. package/dist/js/space/lightning.js +277 -0
  105. package/dist/js/space/minion.js +192 -0
  106. package/dist/js/space/missile.js +212 -0
  107. package/dist/js/space/player.js +430 -0
  108. package/dist/js/space/powerup.js +90 -0
  109. package/dist/js/space/starfield.js +58 -0
  110. package/dist/js/space/starpower.js +90 -0
  111. package/dist/js/spacetime.js +559 -0
  112. package/dist/js/sphere3d.js +229 -0
  113. package/dist/js/sprite.js +473 -0
  114. package/dist/js/starfaux/config.js +118 -0
  115. package/dist/js/starfaux/enemy.js +353 -0
  116. package/dist/js/starfaux/hud.js +78 -0
  117. package/dist/js/starfaux/index.js +482 -0
  118. package/dist/js/starfaux/laser.js +182 -0
  119. package/dist/js/starfaux/player.js +468 -0
  120. package/dist/js/starfaux/terrain.js +560 -0
  121. package/dist/js/study001.js +275 -0
  122. package/dist/js/study002.js +366 -0
  123. package/dist/js/study003.js +331 -0
  124. package/dist/js/study004.js +389 -0
  125. package/dist/js/study005.js +209 -0
  126. package/dist/js/study006.js +194 -0
  127. package/dist/js/study007.js +192 -0
  128. package/dist/js/study008.js +413 -0
  129. package/dist/js/svgtween.js +204 -0
  130. package/dist/js/tde/accretiondisk.js +471 -0
  131. package/dist/js/tde/blackhole.js +219 -0
  132. package/dist/js/tde/blackholescene.js +209 -0
  133. package/dist/js/tde/config.js +59 -0
  134. package/dist/js/tde/index.js +820 -0
  135. package/dist/js/tde/jets.js +290 -0
  136. package/dist/js/tde/lensedstarfield.js +154 -0
  137. package/dist/js/tde/tdestar.js +297 -0
  138. package/dist/js/tde/tidalstream.js +372 -0
  139. package/dist/js/tde_old/blackhole.obj.js +354 -0
  140. package/dist/js/tde_old/debris.obj.js +791 -0
  141. package/dist/js/tde_old/flare.obj.js +239 -0
  142. package/dist/js/tde_old/index.js +448 -0
  143. package/dist/js/tde_old/star.obj.js +812 -0
  144. package/dist/js/tetris/config.js +157 -0
  145. package/dist/js/tetris/grid.js +286 -0
  146. package/dist/js/tetris/index.js +1195 -0
  147. package/dist/js/tetris/renderer.js +634 -0
  148. package/dist/js/tetris/tetrominos.js +280 -0
  149. package/dist/js/tiles.js +312 -0
  150. package/dist/js/tweendemo.js +79 -0
  151. package/dist/js/visibility.js +102 -0
  152. package/dist/kerr.html +28 -0
  153. package/dist/lavalamp.html +27 -0
  154. package/dist/layouts.html +37 -0
  155. package/dist/logo.svg +4 -0
  156. package/dist/loop.html +84 -0
  157. package/dist/mondrian.html +32 -0
  158. package/dist/og_image.png +0 -0
  159. package/dist/opacity.html +36 -0
  160. package/dist/painter.html +39 -0
  161. package/dist/particles-showcase.html +28 -0
  162. package/dist/particles.html +24 -0
  163. package/dist/patterns.html +33 -0
  164. package/dist/penrose-game.html +31 -0
  165. package/dist/pipeline.html +737 -0
  166. package/dist/plane3d.html +24 -0
  167. package/dist/platformer.html +43 -0
  168. package/dist/scene.html +33 -0
  169. package/dist/scenes.html +96 -0
  170. package/dist/schrodinger.html +27 -0
  171. package/dist/schwarzschild.html +27 -0
  172. package/dist/shapes.html +16 -0
  173. package/dist/space.html +85 -0
  174. package/dist/spacetime.html +27 -0
  175. package/dist/sphere3d.html +24 -0
  176. package/dist/sprite.html +18 -0
  177. package/dist/starfaux.html +22 -0
  178. package/dist/study001.html +23 -0
  179. package/dist/study002.html +23 -0
  180. package/dist/study003.html +23 -0
  181. package/dist/study004.html +23 -0
  182. package/dist/study005.html +22 -0
  183. package/dist/study006.html +24 -0
  184. package/dist/study007.html +24 -0
  185. package/dist/study008.html +22 -0
  186. package/dist/svgtween.html +29 -0
  187. package/dist/tde.html +28 -0
  188. package/dist/tetris3d.html +25 -0
  189. package/dist/tiles.html +28 -0
  190. package/dist/transforms.html +400 -0
  191. package/dist/tween.html +45 -0
  192. package/dist/visibility.html +33 -0
  193. package/package.json +1 -1
@@ -0,0 +1,229 @@
1
+ import {
2
+ Game,
3
+ Sphere3D,
4
+ FPSCounter,
5
+ } from "/gcanvas.es.min.js";
6
+ import { Camera3D } from "/gcanvas.es.min.js";
7
+
8
+ /**
9
+ * Configuration for the Sphere3D showcase demo
10
+ * Sizes are calculated dynamically based on screen size
11
+ */
12
+ const CONFIG = {
13
+ // Base sizes (will be scaled)
14
+ baseRadius: 0.08, // fraction of min(width, height)
15
+ baseSpacing: 0.22, // fraction of width
16
+
17
+ camera: {
18
+ perspective: 800,
19
+ rotationX: 0.2,
20
+ rotationY: -0.3,
21
+ inertia: true,
22
+ friction: 0.95,
23
+ },
24
+
25
+ selfRotation: {
26
+ speed: 1.5, // radians per second
27
+ },
28
+
29
+ solidSphere: {
30
+ color: "#FF6B35",
31
+ segments: 24,
32
+ },
33
+
34
+ gasGiant: {
35
+ baseColor: [0.9, 0.7, 0.5],
36
+ seed: 42.0,
37
+ stormIntensity: 0.6,
38
+ rotationSpeed: 0.8,
39
+ },
40
+
41
+ star: {
42
+ color: [1.0, 0.9, 0.5],
43
+ temperature: 5778,
44
+ activityLevel: 0.5,
45
+ rotationSpeed: 1.2,
46
+ },
47
+ };
48
+
49
+ /**
50
+ * SphereData - Holds sphere and its world position
51
+ */
52
+ class SphereData {
53
+ constructor(sphere, worldX, worldY, worldZ, label) {
54
+ this.sphere = sphere;
55
+ this.worldX = worldX;
56
+ this.worldY = worldY;
57
+ this.worldZ = worldZ;
58
+ this.label = label;
59
+ }
60
+ }
61
+
62
+ /**
63
+ * Sphere3DDemo - Showcases different Sphere3D rendering modes
64
+ */
65
+ class Sphere3DDemo extends Game {
66
+ constructor(canvas) {
67
+ super(canvas);
68
+ this.backgroundColor = "#000000";
69
+ this.enableFluidSize();
70
+ }
71
+
72
+ init() {
73
+ super.init();
74
+
75
+ // Create camera with mouse controls
76
+ this.camera = new Camera3D({
77
+ perspective: CONFIG.camera.perspective,
78
+ rotationX: CONFIG.camera.rotationX,
79
+ rotationY: CONFIG.camera.rotationY,
80
+ inertia: CONFIG.camera.inertia,
81
+ friction: CONFIG.camera.friction,
82
+ });
83
+ this.camera.enableMouseControl(this.canvas);
84
+
85
+ // Calculate initial sizes based on screen
86
+ this._updateSizes();
87
+
88
+ // Sphere 1: Solid Color (Canvas 2D rendering)
89
+ const solidSphere = new Sphere3D(this.sphereRadius, {
90
+ color: CONFIG.solidSphere.color,
91
+ camera: this.camera,
92
+ segments: CONFIG.solidSphere.segments,
93
+ });
94
+ this.solidData = new SphereData(solidSphere, -this.spacing, 0, 0, "Solid Color");
95
+
96
+ // Sphere 2: Gas Giant (WebGL shader)
97
+ const gasGiantSphere = new Sphere3D(this.sphereRadius, {
98
+ camera: this.camera,
99
+ useShader: true,
100
+ shaderType: "gasGiant",
101
+ shaderUniforms: {
102
+ uBaseColor: CONFIG.gasGiant.baseColor,
103
+ uSeed: CONFIG.gasGiant.seed,
104
+ uStormIntensity: CONFIG.gasGiant.stormIntensity,
105
+ uRotationSpeed: CONFIG.gasGiant.rotationSpeed,
106
+ },
107
+ });
108
+ this.gasGiantData = new SphereData(gasGiantSphere, 0, 0, 0, "Gas Giant");
109
+
110
+ // Sphere 3: Star (WebGL shader with glow)
111
+ const starSphere = new Sphere3D(this.sphereRadius, {
112
+ camera: this.camera,
113
+ useShader: true,
114
+ shaderType: "star",
115
+ shaderUniforms: {
116
+ uStarColor: CONFIG.star.color,
117
+ uTemperature: CONFIG.star.temperature,
118
+ uActivityLevel: CONFIG.star.activityLevel,
119
+ uRotationSpeed: CONFIG.star.rotationSpeed,
120
+ },
121
+ });
122
+ this.starData = new SphereData(starSphere, this.spacing, 0, 0, "Star");
123
+
124
+ // Store all sphere data for rendering
125
+ this.sphereDataList = [this.solidData, this.gasGiantData, this.starData];
126
+
127
+ // Add FPS counter
128
+ this.pipeline.add(
129
+ new FPSCounter(this, {
130
+ anchor: "bottom-right",
131
+ })
132
+ );
133
+ }
134
+
135
+ /**
136
+ * Calculate sizes based on current screen dimensions
137
+ */
138
+ _updateSizes() {
139
+ const minDim = Math.min(this.width, this.height);
140
+ this.sphereRadius = minDim * CONFIG.baseRadius;
141
+ this.spacing = this.width * CONFIG.baseSpacing;
142
+ }
143
+
144
+ /**
145
+ * Handle window resize
146
+ */
147
+ onResize() {
148
+ this._updateSizes();
149
+
150
+ // Update sphere radii
151
+ if (this.sphereDataList) {
152
+ for (const data of this.sphereDataList) {
153
+ data.sphere.radius = this.sphereRadius;
154
+ data.sphere._generateGeometry();
155
+ }
156
+
157
+ // Update world positions
158
+ this.solidData.worldX = -this.spacing;
159
+ this.gasGiantData.worldX = 0;
160
+ this.starData.worldX = this.spacing;
161
+ }
162
+ }
163
+
164
+ update(dt) {
165
+ super.update(dt);
166
+
167
+ // Update camera (for inertia)
168
+ this.camera.update(dt);
169
+
170
+ // Update self-rotation for Canvas 2D sphere
171
+ this.solidData.sphere.selfRotationY += CONFIG.selfRotation.speed * dt;
172
+ }
173
+
174
+ render() {
175
+ super.render();
176
+
177
+ const ctx = this.ctx;
178
+ const centerX = this.width / 2;
179
+ const centerY = this.height / 2;
180
+
181
+ // Project and sort by depth (back to front)
182
+ const projected = this.sphereDataList.map(data => {
183
+ const proj = this.camera.project(data.worldX, data.worldY, data.worldZ);
184
+ return { data, proj };
185
+ });
186
+ projected.sort((a, b) => b.proj.z - a.proj.z);
187
+
188
+ // Render each sphere at its projected position
189
+ for (const { data, proj } of projected) {
190
+ ctx.save();
191
+ // Translate to screen center + projected position
192
+ ctx.translate(centerX + proj.x, centerY + proj.y);
193
+ // Scale by perspective
194
+ ctx.scale(proj.scale, proj.scale);
195
+ // Render sphere at origin (it will draw centered)
196
+ data.sphere.draw();
197
+ ctx.restore();
198
+ }
199
+
200
+ // Render labels (always on top)
201
+ this.renderLabels(projected, centerX, centerY);
202
+ }
203
+
204
+ /**
205
+ * Render sphere labels at projected positions
206
+ */
207
+ renderLabels(projected, centerX, centerY) {
208
+ const ctx = this.ctx;
209
+
210
+ for (const { data, proj } of projected) {
211
+ // Calculate label position below the sphere
212
+ const screenX = centerX + proj.x;
213
+ const screenY = centerY + proj.y + this.sphereRadius * proj.scale + 20;
214
+
215
+ ctx.font = "14px monospace";
216
+ ctx.fillStyle = "#ffffff";
217
+ ctx.textAlign = "center";
218
+ ctx.textBaseline = "top";
219
+ ctx.fillText(data.label, screenX, screenY);
220
+ }
221
+ }
222
+ }
223
+
224
+ // Start the demo
225
+ window.addEventListener("load", () => {
226
+ const canvas = document.getElementById("game");
227
+ const demo = new Sphere3DDemo(canvas);
228
+ demo.start();
229
+ });
@@ -0,0 +1,473 @@
1
+ import {
2
+ Circle,
3
+ FPSCounter,
4
+ Game,
5
+ Group,
6
+ Heart,
7
+ Keys,
8
+ Position,
9
+ Rectangle,
10
+ Scene,
11
+ ShapeGOFactory,
12
+ Sprite,
13
+ Square,
14
+ Star,
15
+ Text,
16
+ TileLayout,
17
+ Triangle,
18
+ } from "/gcanvas.es.min.js";
19
+
20
+ const CONFIG = {
21
+ headerHeight: 80,
22
+ margin: 40,
23
+ bottomMargin: 70,
24
+ cellSize: 140,
25
+ maxColumns: 4,
26
+ };
27
+
28
+ /**
29
+ * Sprite Demo - Shows various Sprite animation examples using TileLayout
30
+ */
31
+ class SpriteDemo extends Game {
32
+ constructor(canvas) {
33
+ super(canvas);
34
+ this.backgroundColor = "#000000";
35
+ this.enableFluidSize();
36
+ }
37
+
38
+ getViewportDimensions() {
39
+ const availableHeight = this.canvas.height - CONFIG.headerHeight - CONFIG.bottomMargin - CONFIG.margin;
40
+ const availableWidth = this.canvas.width - CONFIG.margin * 2;
41
+ return {
42
+ width: Math.max(200, availableWidth),
43
+ height: Math.max(200, availableHeight),
44
+ };
45
+ }
46
+
47
+ init() {
48
+ super.init();
49
+
50
+ // Define sprite examples
51
+ this.spriteEntries = [
52
+ {
53
+ name: "Pulsing",
54
+ create: () => this.createPulsingSprite(),
55
+ },
56
+ {
57
+ name: "Shape Shifter",
58
+ create: () => this.createShapeShifter(),
59
+ },
60
+ {
61
+ name: "Color Cycle",
62
+ create: () => this.createColorCycle(),
63
+ },
64
+ {
65
+ name: "Bouncing Ball",
66
+ create: () => this.createBouncingBall(),
67
+ },
68
+ {
69
+ name: "Controlled",
70
+ create: () => this.createControlledSprite(),
71
+ },
72
+ {
73
+ name: "Star Spin",
74
+ create: () => this.createStarSpin(),
75
+ },
76
+ {
77
+ name: "Pixel Walker",
78
+ create: () => this.createPixelWalker(),
79
+ },
80
+ {
81
+ name: "Heartbeat",
82
+ create: () => this.createHeartbeat(),
83
+ },
84
+ ];
85
+
86
+ // Create gallery using TileLayout
87
+ this.createGallery();
88
+
89
+ // Title - positioned above the grid
90
+ this.pipeline.add(new Text(this, "Sprite Timeline Demo", {
91
+ font: "bold 24px monospace",
92
+ color: "#00ff00",
93
+ anchor: Position.CENTER,
94
+ anchorOffsetY: -220,
95
+ }));
96
+
97
+ // Subtitle
98
+ this.pipeline.add(new Text(this, "Space: Play/Pause | R: Rewind | S: Stop | Arrows: Step Frame", {
99
+ font: "14px monospace",
100
+ color: "#666666",
101
+ anchor: Position.CENTER,
102
+ anchorOffsetY: -190,
103
+ }));
104
+
105
+ // Status text
106
+ this.statusText = new Text(this, "", {
107
+ font: "14px monospace",
108
+ color: "#00cc00",
109
+ anchor: Position.BOTTOM_CENTER,
110
+ anchorOffsetY: -30,
111
+ });
112
+ this.pipeline.add(this.statusText);
113
+
114
+ // FPS counter
115
+ this.pipeline.add(new FPSCounter(this, {
116
+ color: "#666666",
117
+ anchor: Position.BOTTOM_RIGHT,
118
+ anchorOffsetX: -10,
119
+ anchorOffsetY: -10,
120
+ }));
121
+
122
+ // Setup keyboard controls
123
+ this.setupControls();
124
+ }
125
+
126
+ createGallery() {
127
+ const cellSize = CONFIG.cellSize;
128
+ const initialColumns = Math.min(
129
+ CONFIG.maxColumns,
130
+ Math.max(1, Math.floor((this.canvas.width - CONFIG.margin) / cellSize))
131
+ );
132
+ const viewport = this.getViewportDimensions();
133
+
134
+ this.gallery = new TileLayout(this, {
135
+ debug: false,
136
+ columns: initialColumns,
137
+ spacing: 15,
138
+ scrollable: true,
139
+ viewportWidth: viewport.width,
140
+ viewportHeight: viewport.height,
141
+ anchor: Position.CENTER,
142
+ anchorOffsetY: CONFIG.headerHeight / 2,
143
+ autoSize: true,
144
+ });
145
+
146
+ this.spriteEntries.forEach((entry) => {
147
+ // Use Scene (GameObject container) - NOT Group (Shape container)
148
+ // This ensures Sprite.update() is called automatically via pipeline
149
+ const cell = new Scene(this, {
150
+ width: cellSize,
151
+ height: cellSize,
152
+ });
153
+
154
+ // Background - wrap Shape as GameObject for Scene
155
+ const bg = ShapeGOFactory.create(this, new Rectangle({
156
+ width: cellSize - 10,
157
+ height: cellSize - 10,
158
+ color: "#0a0a0a",
159
+ stroke: "#00ff00",
160
+ lineWidth: 1,
161
+ }));
162
+ cell.add(bg);
163
+
164
+ // Create sprite - already a GameObject, add directly to Scene
165
+ const sprite = entry.create();
166
+ entry.sprite = sprite;
167
+ cell.add(sprite);
168
+
169
+ // Label - use Text (GameObject) instead of TextShape (Shape)
170
+ const label = new Text(this, entry.name, {
171
+ y: (cellSize - 10) / 2 - 12,
172
+ font: "12px monospace",
173
+ color: "#00ff00",
174
+ align: "center",
175
+ baseline: "bottom",
176
+ });
177
+ cell.add(label);
178
+
179
+ cell.entry = entry;
180
+ this.gallery.add(cell);
181
+ });
182
+
183
+ this.pipeline.add(this.gallery);
184
+ }
185
+
186
+ createPulsingSprite() {
187
+ const sprite = new Sprite(this, {
188
+ frameRate: 8,
189
+ loop: true,
190
+ autoPlay: true,
191
+ });
192
+
193
+ const sizes = [20, 25, 30, 35, 30, 25];
194
+ const colors = ["#ff6b6b", "#ee5a6f", "#f06595", "#cc5de8", "#845ef7", "#5c7cfa"];
195
+
196
+ sizes.forEach((size, i) => {
197
+ sprite.addFrame(new Circle(size, { color: colors[i], stroke: "white", lineWidth: 2 }));
198
+ });
199
+
200
+ return sprite;
201
+ }
202
+
203
+ createShapeShifter() {
204
+ const sprite = new Sprite(this, {
205
+ frameRate: 4,
206
+ loop: true,
207
+ autoPlay: true,
208
+ });
209
+
210
+ sprite.addFrame(new Circle(25, { color: "#51cf66", stroke: "white", lineWidth: 2 }));
211
+ sprite.addFrame(new Square(45, { color: "#51cf66", stroke: "white", lineWidth: 2 }));
212
+ sprite.addFrame(new Triangle(50, { color: "#51cf66", stroke: "white", lineWidth: 2 }));
213
+ sprite.addFrame(new Star({ outerRadius: 30, innerRadius: 15, points: 5, color: "#51cf66", stroke: "white", lineWidth: 2 }));
214
+
215
+ return sprite;
216
+ }
217
+
218
+ createColorCycle() {
219
+ const sprite = new Sprite(this, {
220
+ frameRate: 4,
221
+ loop: true,
222
+ autoPlay: true,
223
+ });
224
+
225
+ const colors = ["#ff6b6b", "#ffd43b", "#51cf66", "#339af0", "#cc5de8", "#f783ac"];
226
+ colors.forEach(color => {
227
+ sprite.addFrame(new Square(50, { color, stroke: "white", lineWidth: 2 }));
228
+ });
229
+
230
+ return sprite;
231
+ }
232
+
233
+ createBouncingBall() {
234
+ const sprite = new Sprite(this, {
235
+ frameRate: 12,
236
+ loop: true,
237
+ autoPlay: true,
238
+ });
239
+
240
+ const frames = [
241
+ { scaleX: 1.0, scaleY: 1.0 },
242
+ { scaleX: 0.95, scaleY: 1.1 },
243
+ { scaleX: 0.9, scaleY: 1.2 },
244
+ { scaleX: 1.3, scaleY: 0.7 },
245
+ { scaleX: 1.1, scaleY: 0.85 },
246
+ { scaleX: 1.0, scaleY: 1.0 },
247
+ ];
248
+
249
+ frames.forEach(frame => {
250
+ const circle = new Circle(25, { color: "#ff6347", stroke: "white", lineWidth: 2 });
251
+ circle.scaleX = frame.scaleX;
252
+ circle.scaleY = frame.scaleY;
253
+ sprite.addFrame(circle);
254
+ });
255
+
256
+ return sprite;
257
+ }
258
+
259
+ createControlledSprite() {
260
+ const sprite = new Sprite(this, {
261
+ frameRate: 8,
262
+ loop: true,
263
+ autoPlay: false,
264
+ });
265
+
266
+ const widths = [20, 30, 40, 50, 60, 50, 40, 30];
267
+ const heights = [60, 50, 40, 30, 20, 30, 40, 50];
268
+
269
+ widths.forEach((width, i) => {
270
+ sprite.addFrame(new Rectangle({
271
+ width,
272
+ height: heights[i],
273
+ color: "#ff922b",
274
+ stroke: "white",
275
+ lineWidth: 2,
276
+ }));
277
+ });
278
+
279
+ // Store reference for keyboard controls
280
+ this.controlledSprite = sprite;
281
+
282
+ return sprite;
283
+ }
284
+
285
+ createStarSpin() {
286
+ const sprite = new Sprite(this, {
287
+ frameRate: 10,
288
+ loop: true,
289
+ autoPlay: true,
290
+ });
291
+
292
+ // Create star frames with different point counts for morphing effect
293
+ const configs = [
294
+ { points: 5, outer: 28, ratio: 0.4 },
295
+ { points: 6, outer: 26, ratio: 0.5 },
296
+ { points: 7, outer: 24, ratio: 0.55 },
297
+ { points: 8, outer: 26, ratio: 0.5 },
298
+ { points: 6, outer: 28, ratio: 0.45 },
299
+ { points: 5, outer: 30, ratio: 0.35 },
300
+ ];
301
+
302
+ configs.forEach(cfg => {
303
+ sprite.addFrame(new Star(cfg.outer, cfg.points, cfg.ratio, {
304
+ color: "#00ff00",
305
+ stroke: "#00cc00",
306
+ lineWidth: 2,
307
+ }));
308
+ });
309
+
310
+ return sprite;
311
+ }
312
+
313
+ createPixelWalker() {
314
+ const sprite = new Sprite(this, {
315
+ frameRate: 8,
316
+ loop: true,
317
+ autoPlay: true,
318
+ });
319
+
320
+ const px = 4;
321
+ const color = "#00ff00";
322
+
323
+ // Frame 1: Standing / left leg forward
324
+ const frame1 = new Group();
325
+ // Head
326
+ frame1.add(new Rectangle({ x: 0, y: -20, width: px * 3, height: px * 3, color }));
327
+ // Body
328
+ frame1.add(new Rectangle({ x: 0, y: -8, width: px * 2, height: px * 4, color }));
329
+ // Left leg forward
330
+ frame1.add(new Rectangle({ x: -px, y: 4, width: px, height: px * 3, color }));
331
+ // Right leg back
332
+ frame1.add(new Rectangle({ x: px, y: 2, width: px, height: px * 2, color }));
333
+ // Arms
334
+ frame1.add(new Rectangle({ x: -px * 2, y: -6, width: px, height: px * 2, color }));
335
+ frame1.add(new Rectangle({ x: px * 2, y: -10, width: px, height: px * 2, color }));
336
+
337
+ // Frame 2: Standing straight
338
+ const frame2 = new Group();
339
+ frame2.add(new Rectangle({ x: 0, y: -20, width: px * 3, height: px * 3, color }));
340
+ frame2.add(new Rectangle({ x: 0, y: -8, width: px * 2, height: px * 4, color }));
341
+ frame2.add(new Rectangle({ x: -px, y: 4, width: px, height: px * 3, color }));
342
+ frame2.add(new Rectangle({ x: px, y: 4, width: px, height: px * 3, color }));
343
+ frame2.add(new Rectangle({ x: -px * 2, y: -8, width: px, height: px * 2, color }));
344
+ frame2.add(new Rectangle({ x: px * 2, y: -8, width: px, height: px * 2, color }));
345
+
346
+ // Frame 3: Right leg forward
347
+ const frame3 = new Group();
348
+ frame3.add(new Rectangle({ x: 0, y: -20, width: px * 3, height: px * 3, color }));
349
+ frame3.add(new Rectangle({ x: 0, y: -8, width: px * 2, height: px * 4, color }));
350
+ frame3.add(new Rectangle({ x: -px, y: 2, width: px, height: px * 2, color }));
351
+ frame3.add(new Rectangle({ x: px, y: 4, width: px, height: px * 3, color }));
352
+ frame3.add(new Rectangle({ x: -px * 2, y: -10, width: px, height: px * 2, color }));
353
+ frame3.add(new Rectangle({ x: px * 2, y: -6, width: px, height: px * 2, color }));
354
+
355
+ sprite.addFrame(frame1);
356
+ sprite.addFrame(frame2);
357
+ sprite.addFrame(frame3);
358
+ sprite.addFrame(frame2);
359
+
360
+ return sprite;
361
+ }
362
+
363
+ createHeartbeat() {
364
+ const sprite = new Sprite(this, {
365
+ frameRate: 6,
366
+ loop: true,
367
+ autoPlay: true,
368
+ });
369
+
370
+ // Heartbeat animation - scale and color pulse
371
+ const sizes = [
372
+ { w: 35, h: 35, color: "#ff0040" },
373
+ { w: 40, h: 40, color: "#ff0050" },
374
+ { w: 50, h: 50, color: "#ff0066" },
375
+ { w: 45, h: 45, color: "#ff0055" },
376
+ { w: 38, h: 38, color: "#ff0045" },
377
+ { w: 35, h: 35, color: "#ff0040" },
378
+ { w: 35, h: 35, color: "#cc0030" },
379
+ { w: 35, h: 35, color: "#aa0025" },
380
+ ];
381
+
382
+ sizes.forEach(cfg => {
383
+ sprite.addFrame(new Heart({
384
+ y: -25,
385
+ width: cfg.w,
386
+ height: cfg.h,
387
+ color: cfg.color,
388
+ stroke: "#00ff00",
389
+ lineWidth: 1,
390
+ }));
391
+ });
392
+
393
+ return sprite;
394
+ }
395
+
396
+ setupControls() {
397
+ this.events.on(Keys.SPACE, () => {
398
+ if (this.controlledSprite) {
399
+ if (this.controlledSprite.isPlaying) {
400
+ this.controlledSprite.pause();
401
+ } else {
402
+ this.controlledSprite.play();
403
+ }
404
+ }
405
+ });
406
+
407
+ this.events.on(Keys.LEFT, () => {
408
+ if (this.controlledSprite) {
409
+ this.controlledSprite.gotoAndStop(
410
+ Math.max(0, this.controlledSprite.currentFrame - 1)
411
+ );
412
+ }
413
+ });
414
+
415
+ this.events.on(Keys.RIGHT, () => {
416
+ if (this.controlledSprite) {
417
+ this.controlledSprite.gotoAndStop(
418
+ Math.min(this.controlledSprite.totalFrames - 1, this.controlledSprite.currentFrame + 1)
419
+ );
420
+ }
421
+ });
422
+
423
+ // R and S aren't in Keys mapping, use raw keydown
424
+ this.events.on("keydown", (e) => {
425
+ if (!this.controlledSprite) return;
426
+ if (e.code === "KeyR") {
427
+ this.controlledSprite.rewind();
428
+ } else if (e.code === "KeyS") {
429
+ this.controlledSprite.stop();
430
+ }
431
+ });
432
+ }
433
+
434
+ onResize() {
435
+ if (this.gallery) {
436
+ const availableWidth = this.canvas.width - CONFIG.margin;
437
+ const columns = Math.min(
438
+ CONFIG.maxColumns,
439
+ Math.max(1, Math.floor(availableWidth / CONFIG.cellSize))
440
+ );
441
+
442
+ if (this.gallery.columns !== columns) {
443
+ this.gallery.columns = columns;
444
+ this.gallery.markBoundsDirty();
445
+ }
446
+
447
+ const viewport = this.getViewportDimensions();
448
+ this.gallery._viewportWidth = viewport.width;
449
+ this.gallery._viewportHeight = viewport.height;
450
+ this.gallery.anchorOffsetY = CONFIG.headerHeight / 2;
451
+ this.gallery.markBoundsDirty();
452
+ }
453
+ }
454
+
455
+ update(dt) {
456
+ super.update(dt);
457
+
458
+ // No manual sprite updates needed - Scene automatically propagates
459
+ // update() to all child GameObjects including Sprites
460
+
461
+ if (this.statusText && this.controlledSprite) {
462
+ const cs = this.controlledSprite;
463
+ this.statusText.text = `Controlled: Frame ${cs.currentFrame + 1}/${cs.totalFrames} | ${cs.isPlaying ? "Playing" : "Paused"}`;
464
+ }
465
+ }
466
+ }
467
+
468
+ // Initialize
469
+ window.addEventListener("load", () => {
470
+ const canvas = document.getElementById("game");
471
+ const game = new SpriteDemo(canvas);
472
+ game.start();
473
+ });