@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
@@ -1,892 +0,0 @@
1
- /**
2
- * PenroseScene - The Penrose Diagram Map
3
- *
4
- * Renders the conformal spacetime diagram where the game takes place.
5
- * Handles coordinate transformation, diagram structure, and all
6
- * spacetime objects (black holes, wormholes, artifacts).
7
- *
8
- * @extends Scene
9
- */
10
-
11
- import { Painter, Scene } from "../../../src/index.js";
12
- import { CONFIG } from "./constants.js";
13
-
14
- export class PenroseScene extends Scene {
15
- constructor(game) {
16
- super(game);
17
-
18
- // Camera state (controlled by game)
19
- this.viewCenter = { u: 0, v: 0 };
20
- this.viewScale = CONFIG.baseViewScale;
21
- this.cameraRotation = 0;
22
-
23
- // Background stars
24
- this.stars = [];
25
- this.initStars();
26
-
27
- // References set by game
28
- this.ship = null;
29
- this.blackHoles = [];
30
- this.wormholes = [];
31
- this.artifacts = [];
32
- this.lorePrisms = [];
33
-
34
- // Rendering state from game
35
- this.harvestingBlackHole = null;
36
- this.kerrCollectedTimer = 0;
37
- this.scoreMultiplier = 1;
38
- this.timeSurvived = 0;
39
- this.isIntro = false;
40
- this.introPhase = 0;
41
- this.isBoosting = false;
42
- }
43
-
44
- initStars() {
45
- for (let i = 0; i < CONFIG.starCount; i++) {
46
- this.stars.push({
47
- u: (Math.random() - 0.5) * 4,
48
- v: (Math.random() - 0.5) * 4,
49
- size: 0.5 + Math.random() * 2,
50
- alpha: 0.2 + Math.random() * 0.5,
51
- });
52
- }
53
- }
54
-
55
- /**
56
- * Regenerate stars around current ship position
57
- */
58
- regenerateStars() {
59
- if (!this.ship) return;
60
-
61
- this.stars = [];
62
- for (let i = 0; i < CONFIG.starCount; i++) {
63
- this.stars.push({
64
- u: this.ship.u + (Math.random() - 0.5) * 2,
65
- v: this.ship.v + (Math.random() - 0.3) * 2,
66
- size: 0.5 + Math.random() * 2,
67
- alpha: 0.3 + Math.random() * 0.5,
68
- });
69
- }
70
- }
71
-
72
- // ============================================================================
73
- // COORDINATE CONVERSION
74
- // ============================================================================
75
-
76
- /**
77
- * Convert Penrose coordinates to screen coordinates
78
- */
79
- penroseToScreen(u, v) {
80
- const relU = u - this.viewCenter.u;
81
- const relV = v - this.viewCenter.v;
82
- const scale = Math.min(this.game.width, this.game.height) / this.viewScale;
83
-
84
- return {
85
- x: this.game.width / 2 + relU * scale,
86
- y: this.game.height / 2 - relV * scale,
87
- };
88
- }
89
-
90
- /**
91
- * Convert screen coordinates to Penrose coordinates
92
- */
93
- screenToPenrose(x, y) {
94
- const scale = Math.min(this.game.width, this.game.height) / this.viewScale;
95
- return {
96
- u: this.viewCenter.u + (x - this.game.width / 2) / scale,
97
- v: this.viewCenter.v - (y - this.game.height / 2) / scale,
98
- };
99
- }
100
-
101
- // ============================================================================
102
- // RENDERING
103
- // ============================================================================
104
-
105
- render() {
106
- const ctx = Painter.ctx;
107
-
108
- // Apply camera rotation during gameplay
109
- const shouldRotate = !this.isIntro && Math.abs(this.cameraRotation) > 0.001;
110
- if (shouldRotate) {
111
- ctx.save();
112
- ctx.translate(this.game.width / 2, this.game.height / 2);
113
- ctx.rotate(this.cameraRotation);
114
- ctx.translate(-this.game.width / 2, -this.game.height / 2);
115
- }
116
-
117
- // Draw layers
118
- this.drawStars(ctx);
119
- this.drawDiagram(ctx);
120
- this.drawNullGrid(ctx);
121
-
122
- for (const bh of this.blackHoles) {
123
- this.drawBlackHole(ctx, bh);
124
- }
125
-
126
- for (const wh of this.wormholes) {
127
- this.drawWormhole(ctx, wh);
128
- }
129
-
130
- for (const art of this.artifacts) {
131
- this.drawArtifact(ctx, art);
132
- }
133
-
134
- for (const prism of this.lorePrisms) {
135
- this.drawLorePrism(ctx, prism);
136
- }
137
-
138
- if (!this.isIntro || this.introPhase === 1) {
139
- this.drawLightCone(ctx);
140
- }
141
-
142
- this.drawWorldline(ctx);
143
- this.drawShip(ctx);
144
-
145
- if (shouldRotate) {
146
- ctx.restore();
147
- }
148
-
149
- // Children (if any)
150
- super.render();
151
- }
152
-
153
- // ============================================================================
154
- // DRAW METHODS
155
- // ============================================================================
156
-
157
- drawStars(ctx) {
158
- ctx.fillStyle = "#fff";
159
- for (const star of this.stars) {
160
- const pos = this.penroseToScreen(star.u, star.v);
161
- ctx.globalAlpha = star.alpha * 0.5;
162
- ctx.beginPath();
163
- ctx.arc(pos.x, pos.y, star.size, 0, Math.PI * 2);
164
- ctx.fill();
165
- }
166
- ctx.globalAlpha = 1;
167
- }
168
-
169
- drawDiagram(ctx) {
170
- // Diamond corners
171
- const corners = [
172
- { u: 0, v: 1 }, // i+ (top)
173
- { u: 1, v: 0 }, // i0 right
174
- { u: 0, v: -1 }, // i- (bottom)
175
- { u: -1, v: 0 }, // i0 left
176
- ];
177
-
178
- // Draw diamond outline
179
- ctx.strokeStyle = "rgba(100, 100, 150, 0.5)";
180
- ctx.lineWidth = 2;
181
- ctx.beginPath();
182
-
183
- for (let i = 0; i < corners.length; i++) {
184
- const pos = this.penroseToScreen(corners[i].u, corners[i].v);
185
- if (i === 0) {
186
- ctx.moveTo(pos.x, pos.y);
187
- } else {
188
- ctx.lineTo(pos.x, pos.y);
189
- }
190
- }
191
- ctx.closePath();
192
- ctx.stroke();
193
-
194
- // Draw labels in intro
195
- if (this.isIntro) {
196
- this.drawDiagramLabels(ctx);
197
- }
198
- }
199
-
200
- drawDiagramLabels(ctx) {
201
- ctx.textAlign = "center";
202
-
203
- // i+ (Future Infinity)
204
- const topPos = this.penroseToScreen(0, 0.85);
205
- ctx.fillStyle = "#8ff";
206
- ctx.font = "bold 14px monospace";
207
- ctx.fillText("i+", topPos.x, topPos.y);
208
- ctx.font = "11px monospace";
209
- ctx.fillStyle = "#8aa";
210
- ctx.fillText("Future Infinity", topPos.x, topPos.y + 14);
211
- ctx.fillText("(where time ends)", topPos.x, topPos.y + 26);
212
-
213
- // i- (Past Infinity)
214
- const bottomPos = this.penroseToScreen(0, -0.85);
215
- ctx.fillStyle = "#f8f";
216
- ctx.font = "bold 14px monospace";
217
- ctx.fillText("i-", bottomPos.x, bottomPos.y);
218
- ctx.font = "11px monospace";
219
- ctx.fillStyle = "#a8a";
220
- ctx.fillText("Past Infinity", bottomPos.x, bottomPos.y + 14);
221
- ctx.fillText("(where time began)", bottomPos.x, bottomPos.y + 26);
222
-
223
- // i0 right (Spatial Infinity)
224
- const rightPos = this.penroseToScreen(0.85, 0);
225
- ctx.fillStyle = "#8f8";
226
- ctx.font = "bold 14px monospace";
227
- ctx.fillText("i0", rightPos.x + 15, rightPos.y);
228
- ctx.font = "10px monospace";
229
- ctx.fillStyle = "#8a8";
230
- ctx.textAlign = "left";
231
- ctx.fillText("Spatial", rightPos.x + 5, rightPos.y + 14);
232
- ctx.fillText("Infinity", rightPos.x + 5, rightPos.y + 26);
233
-
234
- // i0 left
235
- const leftPos = this.penroseToScreen(-0.85, 0);
236
- ctx.fillStyle = "#8f8";
237
- ctx.font = "bold 14px monospace";
238
- ctx.textAlign = "right";
239
- ctx.fillText("i0", leftPos.x - 15, leftPos.y);
240
- ctx.font = "10px monospace";
241
- ctx.fillStyle = "#8a8";
242
- ctx.fillText("Spatial", leftPos.x - 5, leftPos.y + 14);
243
- ctx.fillText("Infinity", leftPos.x - 5, leftPos.y + 26);
244
-
245
- // Null infinity labels
246
- ctx.textAlign = "center";
247
- ctx.font = "bold 12px monospace";
248
-
249
- ctx.fillStyle = "#ff8";
250
- const jPlusRight = this.penroseToScreen(0.55, 0.45);
251
- ctx.fillText("J+", jPlusRight.x, jPlusRight.y);
252
- ctx.font = "9px monospace";
253
- ctx.fillStyle = "#aa8";
254
- ctx.fillText("light escapes", jPlusRight.x, jPlusRight.y + 11);
255
-
256
- ctx.font = "bold 12px monospace";
257
- ctx.fillStyle = "#ff8";
258
- const jPlusLeft = this.penroseToScreen(-0.55, 0.45);
259
- ctx.fillText("J+", jPlusLeft.x, jPlusLeft.y);
260
-
261
- ctx.fillStyle = "#fa8";
262
- const jMinusRight = this.penroseToScreen(0.55, -0.45);
263
- ctx.fillText("J-", jMinusRight.x, jMinusRight.y);
264
- ctx.font = "9px monospace";
265
- ctx.fillStyle = "#a88";
266
- ctx.fillText("light arrives", jMinusRight.x, jMinusRight.y + 11);
267
-
268
- ctx.font = "bold 12px monospace";
269
- ctx.fillStyle = "#fa8";
270
- const jMinusLeft = this.penroseToScreen(-0.55, -0.45);
271
- ctx.fillText("J-", jMinusLeft.x, jMinusLeft.y);
272
- }
273
-
274
- drawNullGrid(ctx) {
275
- const spacing = CONFIG.gridSpacing;
276
- ctx.strokeStyle = "rgba(100, 120, 160, 0.3)";
277
- ctx.lineWidth = 1;
278
-
279
- // Lines where u + v = c
280
- for (let c = -1; c <= 1; c += spacing) {
281
- const pts = this.getLineInDiamond(c, true);
282
- if (pts) {
283
- const p1 = this.penroseToScreen(pts.u1, pts.v1);
284
- const p2 = this.penroseToScreen(pts.u2, pts.v2);
285
- ctx.beginPath();
286
- ctx.moveTo(p1.x, p1.y);
287
- ctx.lineTo(p2.x, p2.y);
288
- ctx.stroke();
289
- }
290
- }
291
-
292
- // Lines where u - v = c
293
- for (let c = -1; c <= 1; c += spacing) {
294
- const pts = this.getLineInDiamond(c, false);
295
- if (pts) {
296
- const p1 = this.penroseToScreen(pts.u1, pts.v1);
297
- const p2 = this.penroseToScreen(pts.u2, pts.v2);
298
- ctx.beginPath();
299
- ctx.moveTo(p1.x, p1.y);
300
- ctx.lineTo(p2.x, p2.y);
301
- ctx.stroke();
302
- }
303
- }
304
- }
305
-
306
- /**
307
- * Get endpoints of a 45deg line inside the diamond |u|+|v|<=1
308
- */
309
- getLineInDiamond(c, isPlusLine) {
310
- if (Math.abs(c) > 1) return null;
311
-
312
- let u1, v1, u2, v2;
313
-
314
- if (isPlusLine) {
315
- // u + v = c
316
- u1 = (1 + c) / 2;
317
- v1 = (c - 1) / 2;
318
- u2 = (c - 1) / 2;
319
- v2 = (1 + c) / 2;
320
- } else {
321
- // u - v = c
322
- u1 = (c - 1) / 2;
323
- v1 = -1 - u1;
324
- u2 = (1 + c) / 2;
325
- v2 = (1 - c) / 2;
326
- }
327
-
328
- return { u1, v1, u2, v2 };
329
- }
330
-
331
- drawBlackHole(ctx, bh) {
332
- const pos = this.penroseToScreen(bh.u, bh.v);
333
- const scale = Math.min(this.game.width, this.game.height) / this.viewScale;
334
- const screenRadius = bh.horizonRadius * scale;
335
- const ergoRadius = bh.ergosphereRadius * scale;
336
-
337
- const pulse = 0.8 + Math.sin(bh.pulsePhase) * 0.2;
338
- const rotationAngle = this.timeSurvived * 2 + bh.pulsePhase;
339
-
340
- // Ergosphere (harvesting zone)
341
- if (!bh.harvested) {
342
- const ergoGradient = ctx.createRadialGradient(
343
- pos.x, pos.y, screenRadius,
344
- pos.x, pos.y, ergoRadius
345
- );
346
- const ergoAlpha = bh.isBeingHarvested ? 0.4 : 0.15;
347
- ergoGradient.addColorStop(0, `rgba(0, 255, 200, ${ergoAlpha})`);
348
- ergoGradient.addColorStop(1, "rgba(0, 255, 200, 0)");
349
-
350
- ctx.fillStyle = ergoGradient;
351
- ctx.beginPath();
352
- ctx.arc(pos.x, pos.y, ergoRadius, 0, Math.PI * 2);
353
- ctx.fill();
354
-
355
- // Rotating ergosphere boundary
356
- ctx.save();
357
- ctx.translate(pos.x, pos.y);
358
- ctx.rotate(rotationAngle);
359
- ctx.strokeStyle = bh.isBeingHarvested
360
- ? `rgba(50, 255, 150, ${0.8 * pulse})`
361
- : "rgba(0, 200, 150, 0.3)";
362
- ctx.lineWidth = bh.isBeingHarvested ? 2 : 1;
363
- ctx.setLineDash([8, 8]);
364
- ctx.beginPath();
365
- ctx.arc(0, 0, ergoRadius, 0, Math.PI * 2);
366
- ctx.stroke();
367
- ctx.setLineDash([]);
368
- ctx.restore();
369
- }
370
-
371
- // Rotating accretion swirl
372
- ctx.save();
373
- ctx.translate(pos.x, pos.y);
374
- ctx.rotate(rotationAngle);
375
-
376
- for (let i = 0; i < 3; i++) {
377
- const armAngle = (i * Math.PI * 2) / 3;
378
- ctx.strokeStyle = `rgba(255, 100, 50, ${0.3 * pulse})`;
379
- ctx.lineWidth = 2;
380
- ctx.beginPath();
381
- for (let r = screenRadius * 0.6; r < screenRadius * 1.1; r += 2) {
382
- const angle = armAngle + (r - screenRadius * 0.6) * 0.15;
383
- const x = Math.cos(angle) * r;
384
- const y = Math.sin(angle) * r;
385
- if (r === screenRadius * 0.6) {
386
- ctx.moveTo(x, y);
387
- } else {
388
- ctx.lineTo(x, y);
389
- }
390
- }
391
- ctx.stroke();
392
- }
393
- ctx.restore();
394
-
395
- // Outer glow
396
- const gradient = ctx.createRadialGradient(
397
- pos.x, pos.y, screenRadius * 0.3,
398
- pos.x, pos.y, screenRadius * 1.2
399
- );
400
- gradient.addColorStop(0, "rgba(255, 50, 0, 0.8)");
401
- gradient.addColorStop(0.5, `rgba(255, 100, 50, ${0.4 * pulse})`);
402
- gradient.addColorStop(1, "rgba(255, 50, 0, 0)");
403
-
404
- ctx.fillStyle = gradient;
405
- ctx.beginPath();
406
- ctx.arc(pos.x, pos.y, screenRadius * 1.2, 0, Math.PI * 2);
407
- ctx.fill();
408
-
409
- // Event horizon boundary
410
- ctx.strokeStyle = `rgba(255, 150, 100, ${0.8 * pulse})`;
411
- ctx.lineWidth = 2;
412
- ctx.beginPath();
413
- ctx.arc(pos.x, pos.y, screenRadius, 0, Math.PI * 2);
414
- ctx.stroke();
415
-
416
- // Singularity center
417
- ctx.save();
418
- ctx.translate(pos.x, pos.y);
419
- ctx.rotate(-rotationAngle * 1.5);
420
-
421
- const singularityGradient = ctx.createRadialGradient(0, 0, 0, 0, 0, screenRadius * 0.5);
422
- singularityGradient.addColorStop(0, "#000");
423
- singularityGradient.addColorStop(0.7, "#000");
424
- singularityGradient.addColorStop(1, "rgba(128, 0, 128, 0.5)");
425
-
426
- ctx.fillStyle = singularityGradient;
427
- ctx.beginPath();
428
- ctx.arc(0, 0, screenRadius * 0.5, 0, Math.PI * 2);
429
- ctx.fill();
430
-
431
- ctx.strokeStyle = `rgba(200, 50, 200, ${0.5 * pulse})`;
432
- ctx.lineWidth = 1;
433
- ctx.beginPath();
434
- ctx.arc(0, 0, screenRadius * 0.35, 0, Math.PI * 1.5);
435
- ctx.stroke();
436
-
437
- ctx.restore();
438
- }
439
-
440
- drawWormhole(ctx, wh) {
441
- const pos = this.penroseToScreen(wh.u, wh.v);
442
- const scale = Math.min(this.game.width, this.game.height) / this.viewScale;
443
- const screenRadius = wh.radius * scale;
444
-
445
- const fadeIn = Math.min(1, wh.spawnTime / 0.5);
446
- const pulse = 0.7 + Math.sin(wh.pulsePhase) * 0.3;
447
-
448
- ctx.save();
449
- ctx.globalAlpha = fadeIn;
450
- ctx.translate(pos.x, pos.y);
451
-
452
- // Outer swirling rings
453
- for (let ring = 3; ring >= 0; ring--) {
454
- const ringRadius = screenRadius * (1 + ring * 0.3);
455
- const ringRotation = wh.rotationPhase * (ring % 2 === 0 ? 1 : -1) * (1 + ring * 0.2);
456
-
457
- ctx.save();
458
- ctx.rotate(ringRotation);
459
-
460
- const gradient = ctx.createRadialGradient(0, 0, ringRadius * 0.3, 0, 0, ringRadius);
461
-
462
- if (ring === 0) {
463
- gradient.addColorStop(0, `rgba(100, 255, 255, ${0.9 * pulse})`);
464
- gradient.addColorStop(0.5, `rgba(50, 200, 255, ${0.6 * pulse})`);
465
- gradient.addColorStop(1, "rgba(100, 50, 255, 0)");
466
- } else {
467
- const alpha = (0.3 / ring) * pulse;
468
- gradient.addColorStop(0, `rgba(150, 100, 255, ${alpha})`);
469
- gradient.addColorStop(0.5, `rgba(100, 150, 255, ${alpha * 0.5})`);
470
- gradient.addColorStop(1, "rgba(50, 50, 200, 0)");
471
- }
472
-
473
- ctx.fillStyle = gradient;
474
- ctx.beginPath();
475
- ctx.arc(0, 0, ringRadius, 0, Math.PI * 2);
476
- ctx.fill();
477
-
478
- // Spiral arms
479
- if (ring > 0) {
480
- ctx.strokeStyle = `rgba(150, 100, 255, ${0.4 * pulse / ring})`;
481
- ctx.lineWidth = 2;
482
- for (let arm = 0; arm < 4; arm++) {
483
- const armAngle = (arm * Math.PI * 2) / 4;
484
- ctx.beginPath();
485
- for (let r = ringRadius * 0.4; r < ringRadius; r += 3) {
486
- const angle = armAngle + (r - ringRadius * 0.4) * 0.08;
487
- const x = Math.cos(angle) * r;
488
- const y = Math.sin(angle) * r;
489
- if (r === ringRadius * 0.4) {
490
- ctx.moveTo(x, y);
491
- } else {
492
- ctx.lineTo(x, y);
493
- }
494
- }
495
- ctx.stroke();
496
- }
497
- }
498
-
499
- ctx.restore();
500
- }
501
-
502
- // Center portal
503
- const centerGradient = ctx.createRadialGradient(0, 0, 0, 0, 0, screenRadius * 0.5);
504
- centerGradient.addColorStop(0, "#000");
505
- centerGradient.addColorStop(0.6, "#001");
506
- centerGradient.addColorStop(0.9, `rgba(100, 200, 255, ${0.8 * pulse})`);
507
- centerGradient.addColorStop(1, "rgba(150, 100, 255, 0)");
508
-
509
- ctx.fillStyle = centerGradient;
510
- ctx.beginPath();
511
- ctx.arc(0, 0, screenRadius * 0.5, 0, Math.PI * 2);
512
- ctx.fill();
513
-
514
- ctx.strokeStyle = `rgba(150, 200, 255, ${0.9 * pulse})`;
515
- ctx.lineWidth = 3;
516
- ctx.beginPath();
517
- ctx.arc(0, 0, screenRadius * 0.45, 0, Math.PI * 2);
518
- ctx.stroke();
519
-
520
- // Inner glow particles
521
- for (let i = 0; i < 6; i++) {
522
- const particleAngle = wh.rotationPhase * 2 + (i * Math.PI * 2) / 6;
523
- const particleR = screenRadius * 0.3 * (0.5 + Math.sin(wh.pulsePhase + i) * 0.5);
524
- const px = Math.cos(particleAngle) * particleR;
525
- const py = Math.sin(particleAngle) * particleR;
526
-
527
- ctx.fillStyle = `rgba(200, 255, 255, ${0.8 * pulse})`;
528
- ctx.beginPath();
529
- ctx.arc(px, py, 3, 0, Math.PI * 2);
530
- ctx.fill();
531
- }
532
-
533
- ctx.restore();
534
-
535
- // Label
536
- if (fadeIn >= 1) {
537
- this.drawOutlinedText(
538
- ctx,
539
- "WORMHOLE",
540
- pos.x,
541
- pos.y - screenRadius - 15,
542
- `rgba(150, 200, 255, ${0.8 * pulse})`,
543
- "#000",
544
- "bold 12px monospace"
545
- );
546
- }
547
- }
548
-
549
- drawArtifact(ctx, art) {
550
- const pos = this.penroseToScreen(art.u, art.v);
551
- const scale = Math.min(this.game.width, this.game.height) / this.viewScale;
552
- const screenRadius = art.radius * scale;
553
-
554
- const fadeIn = Math.min(1, art.spawnTime / 0.5);
555
- const pulse = 0.7 + Math.sin(art.pulsePhase) * 0.3;
556
-
557
- ctx.save();
558
- ctx.globalAlpha = fadeIn;
559
-
560
- // Outer glow
561
- const gradient = ctx.createRadialGradient(
562
- pos.x, pos.y, screenRadius * 0.3,
563
- pos.x, pos.y, screenRadius * 2
564
- );
565
- gradient.addColorStop(0, `rgba(200, 100, 255, ${0.6 * pulse})`);
566
- gradient.addColorStop(0.5, `rgba(150, 50, 200, ${0.3 * pulse})`);
567
- gradient.addColorStop(1, "rgba(100, 0, 150, 0)");
568
-
569
- ctx.fillStyle = gradient;
570
- ctx.beginPath();
571
- ctx.arc(pos.x, pos.y, screenRadius * 2, 0, Math.PI * 2);
572
- ctx.fill();
573
-
574
- // Draw the cube
575
- ctx.save();
576
- ctx.translate(pos.x, pos.y + art.hoverOffset);
577
- art.cube.x = 0;
578
- art.cube.y = 0;
579
- art.cube.draw();
580
- ctx.restore();
581
-
582
- // Sparkles
583
- for (let i = 0; i < 6; i++) {
584
- const angle = art.rotationPhase + (i * Math.PI * 2) / 6;
585
- const sparkleR = screenRadius * 1.2;
586
- const sx = pos.x + Math.cos(angle) * sparkleR;
587
- const sy = pos.y + Math.sin(angle) * sparkleR + art.hoverOffset;
588
-
589
- ctx.fillStyle = `rgba(255, 200, 255, ${0.8 * pulse})`;
590
- ctx.beginPath();
591
- ctx.arc(sx, sy, 3, 0, Math.PI * 2);
592
- ctx.fill();
593
- }
594
-
595
- ctx.restore();
596
- }
597
-
598
- drawLorePrism(ctx, prism) {
599
- const pos = this.penroseToScreen(prism.u, prism.v);
600
- const scale = Math.min(this.game.width, this.game.height) / this.viewScale;
601
- const screenRadius = prism.radius * scale;
602
-
603
- const fadeIn = Math.min(1, prism.spawnTime / 0.5);
604
- const pulse = 0.7 + Math.sin(prism.pulsePhase) * 0.3;
605
-
606
- ctx.save();
607
- ctx.globalAlpha = fadeIn;
608
-
609
- // Outer glow - cyan/blue to match prism colors
610
- const gradient = ctx.createRadialGradient(
611
- pos.x, pos.y, screenRadius * 0.2,
612
- pos.x, pos.y, screenRadius * 2.5
613
- );
614
- gradient.addColorStop(0, `rgba(100, 220, 255, ${0.5 * pulse})`);
615
- gradient.addColorStop(0.4, `rgba(50, 180, 220, ${0.3 * pulse})`);
616
- gradient.addColorStop(1, "rgba(30, 100, 150, 0)");
617
-
618
- ctx.fillStyle = gradient;
619
- ctx.beginPath();
620
- ctx.arc(pos.x, pos.y, screenRadius * 2.5, 0, Math.PI * 2);
621
- ctx.fill();
622
-
623
- // Draw the prism shape
624
- ctx.save();
625
- ctx.translate(pos.x, pos.y + prism.hoverOffset);
626
- prism.prism.x = 0;
627
- prism.prism.y = 0;
628
- prism.prism.draw();
629
- ctx.restore();
630
-
631
- // Sparkle particles orbiting
632
- for (let i = 0; i < 4; i++) {
633
- const angle = prism.rotationPhase * 1.5 + (i * Math.PI * 2) / 4;
634
- const sparkleR = screenRadius * 1.4;
635
- const sx = pos.x + Math.cos(angle) * sparkleR;
636
- const sy = pos.y + Math.sin(angle) * sparkleR + prism.hoverOffset;
637
-
638
- ctx.fillStyle = `rgba(150, 230, 255, ${0.8 * pulse})`;
639
- ctx.beginPath();
640
- ctx.arc(sx, sy, 2.5, 0, Math.PI * 2);
641
- ctx.fill();
642
- }
643
-
644
- ctx.restore();
645
- }
646
-
647
- drawLightCone(ctx) {
648
- if (!this.ship) return;
649
- if (!this.ship.alive && this.ship.deathFade > 0.5) return;
650
-
651
- const shipPos = this.penroseToScreen(this.ship.u, this.ship.v);
652
- const scale = Math.min(this.game.width, this.game.height) / this.viewScale;
653
- const coneLength = CONFIG.coneLength * scale;
654
-
655
- const isHarvesting = this.harvestingBlackHole !== null;
656
- const harvestProgress = isHarvesting
657
- ? this.harvestingBlackHole.harvestProgress / CONFIG.kerrHarvestTime
658
- : 0;
659
-
660
- // Cone colors
661
- let fillColor, strokeColor;
662
- if (isHarvesting) {
663
- strokeColor = "rgba(50, 255, 100, 0.9)";
664
- fillColor = "rgba(50, 255, 100, 0.1)";
665
- } else {
666
- strokeColor = "rgba(255, 220, 100, 0.5)";
667
- fillColor = "rgba(255, 220, 100, 0.15)";
668
- }
669
-
670
- // Light cone points in ship's heading direction
671
- const coneRotation = this.ship.heading;
672
-
673
- ctx.save();
674
- ctx.translate(shipPos.x, shipPos.y);
675
- ctx.rotate(coneRotation);
676
-
677
- ctx.strokeStyle = strokeColor;
678
- ctx.lineWidth = isHarvesting ? 3 : 2;
679
- ctx.beginPath();
680
- ctx.moveTo(0, 0);
681
- ctx.lineTo(coneLength, -coneLength);
682
- ctx.lineTo(-coneLength, -coneLength);
683
- ctx.closePath();
684
- ctx.stroke();
685
-
686
- ctx.fillStyle = fillColor;
687
- ctx.fill();
688
-
689
- ctx.restore();
690
-
691
- // Harvest progress fill
692
- if (isHarvesting && harvestProgress > 0) {
693
- const fillHeight = coneLength * harvestProgress;
694
- const fillWidth = fillHeight;
695
-
696
- ctx.save();
697
- ctx.translate(shipPos.x, shipPos.y);
698
- ctx.rotate(coneRotation);
699
-
700
- ctx.fillStyle = "rgba(50, 255, 100, 0.4)";
701
- ctx.beginPath();
702
- ctx.moveTo(0, 0);
703
- ctx.lineTo(fillWidth, -fillHeight);
704
- ctx.lineTo(-fillWidth, -fillHeight);
705
- ctx.closePath();
706
- ctx.fill();
707
-
708
- const pulse = 0.5 + Math.sin(Date.now() / 100) * 0.3;
709
- ctx.strokeStyle = `rgba(100, 255, 150, ${pulse})`;
710
- ctx.lineWidth = 4;
711
- ctx.stroke();
712
-
713
- ctx.restore();
714
-
715
- // Progress text
716
- const tipX = shipPos.x + Math.sin(coneRotation) * (coneLength + 15);
717
- const tipY = shipPos.y - Math.cos(coneRotation) * (coneLength + 15);
718
- this.drawOutlinedText(
719
- ctx,
720
- `${(harvestProgress * 100).toFixed(0)}%`,
721
- tipX,
722
- tipY,
723
- "#5f5",
724
- "#000",
725
- "bold 16px monospace"
726
- );
727
-
728
- // Collecting message
729
- const textPulse = 0.7 + Math.sin(Date.now() / 200) * 0.3;
730
- this.drawOutlinedText(
731
- ctx,
732
- "COLLECTING KERR ENERGY",
733
- shipPos.x,
734
- shipPos.y + 50,
735
- `rgba(80, 255, 120, ${textPulse})`,
736
- "#000",
737
- "bold 14px monospace"
738
- );
739
- }
740
-
741
- // Kerr collected message
742
- if (this.kerrCollectedTimer > 0 && this.ship.alive) {
743
- const alpha = Math.min(1, this.kerrCollectedTimer);
744
- const textScale = 1 + (2 - this.kerrCollectedTimer) * 0.1;
745
- ctx.save();
746
- ctx.translate(shipPos.x, shipPos.y + 50);
747
- ctx.scale(textScale, textScale);
748
- this.drawOutlinedText(
749
- ctx,
750
- "KERR ENERGY COLLECTED!",
751
- 0,
752
- 0,
753
- `rgba(100, 255, 255, ${alpha})`,
754
- `rgba(0, 0, 0, ${alpha})`,
755
- "bold 16px monospace"
756
- );
757
- this.drawOutlinedText(
758
- ctx,
759
- `x${this.scoreMultiplier} MULTIPLIER!`,
760
- 0,
761
- 20,
762
- `rgba(255, 200, 50, ${alpha})`,
763
- `rgba(0, 0, 0, ${alpha})`,
764
- "bold 14px monospace"
765
- );
766
- ctx.restore();
767
- }
768
-
769
- // Frame drag indicator
770
- if (this.ship.inErgosphere && !isHarvesting && this.ship.alive) {
771
- const tipX = shipPos.x + Math.sin(coneRotation) * (coneLength + 15);
772
- const tipY = shipPos.y - Math.cos(coneRotation) * (coneLength + 15);
773
- this.drawOutlinedText(ctx, "FRAME DRAG", tipX, tipY, "#5ff", "#000", "bold 14px monospace");
774
- }
775
-
776
- // Spatial infinity indicator
777
- if (this.ship.hitSpatialInfinity && this.ship.alive) {
778
- this.drawOutlinedText(
779
- ctx,
780
- "SPATIAL INFINITY",
781
- shipPos.x,
782
- shipPos.y + 70,
783
- "#f88",
784
- "#000",
785
- "bold 12px monospace"
786
- );
787
- }
788
-
789
- // Dying cone
790
- if (!this.ship.alive && this.ship.deathBlackHole) {
791
- const bh = this.ship.deathBlackHole;
792
- const bhPos = this.penroseToScreen(bh.u, bh.v);
793
- const t = Math.min(this.ship.deathProgress, 1);
794
-
795
- ctx.fillStyle = `rgba(255, 50, 50, ${0.3 * t})`;
796
- ctx.strokeStyle = `rgba(255, 50, 50, ${0.8 * t})`;
797
-
798
- ctx.beginPath();
799
- ctx.moveTo(shipPos.x, shipPos.y);
800
- ctx.lineTo(bhPos.x, bhPos.y);
801
- ctx.lineTo(shipPos.x + (bhPos.x - shipPos.x) * 0.3, shipPos.y - coneLength * 0.5);
802
- ctx.closePath();
803
- ctx.fill();
804
- ctx.stroke();
805
- }
806
- }
807
-
808
- drawWorldline(ctx) {
809
- if (!this.ship || this.ship.worldline.length < 2) return;
810
-
811
- ctx.strokeStyle = "#0f0";
812
- ctx.lineWidth = 2;
813
- ctx.beginPath();
814
-
815
- for (let i = 0; i < this.ship.worldline.length; i++) {
816
- const pt = this.ship.worldline[i];
817
- const pos = this.penroseToScreen(pt.u, pt.v);
818
- const alpha = i / this.ship.worldline.length;
819
- ctx.strokeStyle = `rgba(0, 255, 0, ${alpha * 0.8})`;
820
-
821
- if (i === 0) {
822
- ctx.moveTo(pos.x, pos.y);
823
- } else {
824
- ctx.lineTo(pos.x, pos.y);
825
- }
826
- }
827
-
828
- ctx.stroke();
829
- }
830
-
831
- drawShip(ctx) {
832
- if (!this.ship) return;
833
- if (this.isIntro && this.introPhase === 0) return;
834
- if (!this.ship.alive && this.ship.deathFade >= 1) return;
835
-
836
- const pos = this.penroseToScreen(this.ship.u, this.ship.v);
837
-
838
- this.ship.shipGroup.x = pos.x;
839
- this.ship.shipGroup.y = pos.y;
840
-
841
- // Ship tilts to show heading direction
842
- const tiltDegrees = this.ship.heading * (180 / Math.PI) * 0.5; // Subtle tilt
843
- this.ship.shipGroup.rotation = tiltDegrees;
844
-
845
- if (!this.ship.alive) {
846
- ctx.save();
847
- const redshiftAmount = Math.min(this.ship.deathProgress * 2, 1);
848
- const hueShift = -120 * redshiftAmount;
849
- const saturate = 1 + redshiftAmount * 0.5;
850
- const brightness = 1 - redshiftAmount * 0.3;
851
-
852
- ctx.filter = `hue-rotate(${hueShift}deg) saturate(${saturate}) brightness(${brightness})`;
853
- this.ship.shipGroup.opacity = 1 - this.ship.deathFade;
854
- this.ship.shipGroup.render();
855
- ctx.restore();
856
- } else if (this.isBoosting) {
857
- ctx.save();
858
- const pulse = 0.8 + Math.sin(Date.now() / 50) * 0.2;
859
- ctx.filter = `hue-rotate(60deg) saturate(1.8) brightness(${1.4 + pulse * 0.3})`;
860
- this.ship.shipGroup.opacity = 1;
861
- this.ship.shipGroup.render();
862
- ctx.restore();
863
- } else if (this.ship.inErgosphere) {
864
- ctx.save();
865
- const pulse = 0.8 + Math.sin(Date.now() / 100) * 0.2;
866
- ctx.filter = `hue-rotate(160deg) saturate(${1.2 * pulse}) brightness(1.1)`;
867
- this.ship.shipGroup.opacity = 1;
868
- this.ship.shipGroup.render();
869
- ctx.restore();
870
- } else {
871
- this.ship.shipGroup.opacity = 1;
872
- this.ship.shipGroup.render();
873
- }
874
- }
875
-
876
- // ============================================================================
877
- // HELPERS
878
- // ============================================================================
879
-
880
- drawOutlinedText(ctx, text, x, y, fillColor, strokeColor, font) {
881
- ctx.save();
882
- ctx.font = font;
883
- ctx.textAlign = "center";
884
- ctx.textBaseline = "middle";
885
- ctx.lineWidth = 4;
886
- ctx.strokeStyle = strokeColor;
887
- ctx.fillStyle = fillColor;
888
- ctx.strokeText(text, x, y);
889
- ctx.fillText(text, x, y);
890
- ctx.restore();
891
- }
892
- }