@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,892 @@
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 "/gcanvas.es.min.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
+ }