@guinetik/gcanvas 1.0.0 → 1.0.1

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 (68) hide show
  1. package/demos/fluid-simple.html +22 -0
  2. package/demos/fluid.html +37 -0
  3. package/demos/index.html +2 -0
  4. package/demos/js/blob.js +18 -5
  5. package/demos/js/fluid-simple.js +253 -0
  6. package/demos/js/fluid.js +527 -0
  7. package/demos/js/tde/accretiondisk.js +64 -11
  8. package/demos/js/tde/blackholescene.js +2 -2
  9. package/demos/js/tde/config.js +2 -2
  10. package/demos/js/tde/index.js +152 -27
  11. package/demos/js/tde/lensedstarfield.js +32 -25
  12. package/demos/js/tde/tdestar.js +78 -98
  13. package/demos/js/tde/tidalstream.js +23 -7
  14. package/docs/README.md +230 -222
  15. package/docs/api/FluidSystem.md +173 -0
  16. package/docs/concepts/architecture-overview.md +204 -204
  17. package/docs/concepts/rendering-pipeline.md +279 -279
  18. package/docs/concepts/two-layer-architecture.md +229 -229
  19. package/docs/fluid-dynamics.md +97 -0
  20. package/docs/getting-started/first-game.md +354 -354
  21. package/docs/getting-started/installation.md +175 -157
  22. package/docs/modules/collision/README.md +2 -2
  23. package/docs/modules/fluent/README.md +6 -6
  24. package/docs/modules/game/README.md +303 -303
  25. package/docs/modules/isometric-camera.md +2 -2
  26. package/docs/modules/isometric.md +1 -1
  27. package/docs/modules/painter/README.md +328 -328
  28. package/docs/modules/particle/README.md +3 -3
  29. package/docs/modules/shapes/README.md +221 -221
  30. package/docs/modules/shapes/base/euclidian.md +123 -123
  31. package/docs/modules/shapes/base/shape.md +262 -262
  32. package/docs/modules/shapes/base/transformable.md +243 -243
  33. package/docs/modules/state/README.md +2 -2
  34. package/docs/modules/util/README.md +1 -1
  35. package/docs/modules/util/camera3d.md +3 -3
  36. package/docs/modules/util/scene3d.md +1 -1
  37. package/package.json +3 -1
  38. package/readme.md +19 -5
  39. package/src/collision/collision.js +75 -0
  40. package/src/game/index.js +2 -1
  41. package/src/game/pipeline.js +3 -3
  42. package/src/game/systems/FluidSystem.js +835 -0
  43. package/src/game/systems/index.js +11 -0
  44. package/src/game/ui/button.js +39 -18
  45. package/src/game/ui/cursor.js +14 -0
  46. package/src/game/ui/fps.js +12 -4
  47. package/src/game/ui/index.js +2 -0
  48. package/src/game/ui/stepper.js +549 -0
  49. package/src/game/ui/theme.js +121 -0
  50. package/src/game/ui/togglebutton.js +9 -3
  51. package/src/game/ui/tooltip.js +11 -4
  52. package/src/math/fluid.js +507 -0
  53. package/src/math/index.js +2 -0
  54. package/src/mixins/anchor.js +17 -7
  55. package/src/motion/tweenetik.js +16 -0
  56. package/src/shapes/index.js +1 -0
  57. package/src/util/camera3d.js +218 -12
  58. package/types/fluent.d.ts +361 -0
  59. package/types/game.d.ts +303 -0
  60. package/types/index.d.ts +144 -5
  61. package/types/math.d.ts +361 -0
  62. package/types/motion.d.ts +271 -0
  63. package/types/particle.d.ts +373 -0
  64. package/types/shapes.d.ts +107 -9
  65. package/types/util.d.ts +353 -0
  66. package/types/webgl.d.ts +109 -0
  67. package/disk_example.png +0 -0
  68. package/tde.png +0 -0
package/types/game.d.ts CHANGED
@@ -495,3 +495,306 @@ export class Cursor extends GameObject {
495
495
  export class FPSCounter extends GameObject {
496
496
  constructor(game: Game, options?: GameObjectOptions);
497
497
  }
498
+
499
+ // ==========================================================================
500
+ // Advanced UI Components
501
+ // ==========================================================================
502
+
503
+ /** Options for Tooltip */
504
+ export interface TooltipOptions extends GameObjectOptions {
505
+ /** Tooltip text */
506
+ text?: string;
507
+ /** Background color */
508
+ backgroundColor?: string;
509
+ /** Text color */
510
+ textColor?: string;
511
+ /** CSS font string */
512
+ font?: string;
513
+ /** Padding around text */
514
+ padding?: number;
515
+ /** Corner radius */
516
+ cornerRadius?: number;
517
+ /** Show delay in milliseconds */
518
+ delay?: number;
519
+ }
520
+
521
+ /**
522
+ * Tooltip component that shows on hover.
523
+ */
524
+ export class Tooltip extends GameObject {
525
+ /** Tooltip text */
526
+ text: string;
527
+ /** Whether tooltip is visible */
528
+ isVisible: boolean;
529
+
530
+ constructor(game: Game, options?: TooltipOptions);
531
+
532
+ /**
533
+ * Show tooltip at position.
534
+ * @param x - X position
535
+ * @param y - Y position
536
+ */
537
+ show(x: number, y: number): void;
538
+
539
+ /** Hide tooltip */
540
+ hide(): void;
541
+ }
542
+
543
+ /** Options for Stepper */
544
+ export interface StepperOptions extends GameObjectOptions {
545
+ /** Minimum value */
546
+ min?: number;
547
+ /** Maximum value */
548
+ max?: number;
549
+ /** Current value */
550
+ value?: number;
551
+ /** Step increment */
552
+ step?: number;
553
+ /** Label text */
554
+ label?: string;
555
+ /** CSS font string */
556
+ font?: string;
557
+ /** Width of the stepper */
558
+ width?: number;
559
+ /** Height of the stepper */
560
+ height?: number;
561
+ }
562
+
563
+ /**
564
+ * Numeric stepper component with +/- buttons.
565
+ *
566
+ * @example
567
+ * const stepper = new Stepper(game, {
568
+ * x: 100, y: 100,
569
+ * min: 0, max: 100,
570
+ * value: 50,
571
+ * step: 5,
572
+ * label: 'Speed'
573
+ * });
574
+ * stepper.on('change', (value) => console.log('New value:', value));
575
+ */
576
+ export class Stepper extends GameObject {
577
+ /** Current value */
578
+ value: number;
579
+ /** Minimum value */
580
+ min: number;
581
+ /** Maximum value */
582
+ max: number;
583
+ /** Step increment */
584
+ step: number;
585
+
586
+ constructor(game: Game, options?: StepperOptions);
587
+
588
+ /** Increment value by step */
589
+ increment(): void;
590
+ /** Decrement value by step */
591
+ decrement(): void;
592
+ /** Set value directly */
593
+ setValue(value: number): void;
594
+ }
595
+
596
+ /**
597
+ * UI theme constants for consistent styling.
598
+ * Terminal × Vercel aesthetic.
599
+ */
600
+ export namespace UI_THEME {
601
+ /** Primary accent color (terminal green) */
602
+ const PRIMARY: string;
603
+ /** Background color (dark) */
604
+ const BACKGROUND: string;
605
+ /** Surface color (slightly lighter) */
606
+ const SURFACE: string;
607
+ /** Text color */
608
+ const TEXT: string;
609
+ /** Muted text color */
610
+ const TEXT_MUTED: string;
611
+ /** Border color */
612
+ const BORDER: string;
613
+ /** Success color */
614
+ const SUCCESS: string;
615
+ /** Warning color */
616
+ const WARNING: string;
617
+ /** Error color */
618
+ const ERROR: string;
619
+ /** Font family */
620
+ const FONT: string;
621
+ /** Default corner radius */
622
+ const RADIUS: number;
623
+ }
624
+
625
+ // ==========================================================================
626
+ // Scene3D
627
+ // ==========================================================================
628
+
629
+ /** Options for Scene3D */
630
+ export interface Scene3DOptions extends SceneOptions {
631
+ /** Camera3D instance for projection */
632
+ camera?: any; // Camera3D from util
633
+ /** Enable depth sorting */
634
+ depthSort?: boolean;
635
+ }
636
+
637
+ /**
638
+ * 3D scene with Camera3D projection support.
639
+ * Children with x, y, z positions are projected through the camera.
640
+ *
641
+ * @example
642
+ * const camera = new Camera3D({ rotationX: 0.3, perspective: 800 });
643
+ * const scene3d = new Scene3D(game, { camera });
644
+ * scene3d.add(myObject);
645
+ */
646
+ export class Scene3D extends Scene {
647
+ /** Camera3D instance */
648
+ camera: any;
649
+ /** Whether to depth sort children */
650
+ depthSort: boolean;
651
+
652
+ constructor(game: Game, options?: Scene3DOptions);
653
+
654
+ /**
655
+ * Project a 3D point through the camera.
656
+ * @param x - X coordinate
657
+ * @param y - Y coordinate
658
+ * @param z - Z coordinate
659
+ */
660
+ project(x: number, y: number, z: number): { x: number; y: number; z: number; scale: number };
661
+ }
662
+
663
+ // ==========================================================================
664
+ // IsometricScene
665
+ // ==========================================================================
666
+
667
+ /** Options for IsometricScene */
668
+ export interface IsometricSceneOptions extends SceneOptions {
669
+ /** Isometric camera instance */
670
+ camera?: any; // IsometricCamera from util
671
+ /** Tile width */
672
+ tileWidth?: number;
673
+ /** Tile height */
674
+ tileHeight?: number;
675
+ /** Grid columns */
676
+ cols?: number;
677
+ /** Grid rows */
678
+ rows?: number;
679
+ }
680
+
681
+ /**
682
+ * Isometric scene with 2.5D grid projection.
683
+ * Converts grid coordinates to isometric screen positions.
684
+ *
685
+ * @example
686
+ * const isoScene = new IsometricScene(game, {
687
+ * tileWidth: 64,
688
+ * tileHeight: 32,
689
+ * cols: 10,
690
+ * rows: 10
691
+ * });
692
+ */
693
+ export class IsometricScene extends Scene {
694
+ /** Tile width */
695
+ tileWidth: number;
696
+ /** Tile height */
697
+ tileHeight: number;
698
+ /** Grid columns */
699
+ cols: number;
700
+ /** Grid rows */
701
+ rows: number;
702
+ /** Isometric camera */
703
+ camera: any;
704
+
705
+ constructor(game: Game, options?: IsometricSceneOptions);
706
+
707
+ /**
708
+ * Convert grid coordinates to screen position.
709
+ * @param gridX - Grid X coordinate
710
+ * @param gridY - Grid Y coordinate
711
+ * @param height - Optional height offset
712
+ */
713
+ gridToScreen(gridX: number, gridY: number, height?: number): { x: number; y: number };
714
+
715
+ /**
716
+ * Convert screen position to grid coordinates.
717
+ * @param screenX - Screen X coordinate
718
+ * @param screenY - Screen Y coordinate
719
+ */
720
+ screenToGrid(screenX: number, screenY: number): { x: number; y: number };
721
+ }
722
+
723
+ // ==========================================================================
724
+ // FluidSystem
725
+ // ==========================================================================
726
+
727
+ /** Options for FluidSystem */
728
+ export interface FluidSystemOptions extends GameObjectOptions {
729
+ /** Maximum number of particles */
730
+ maxParticles?: number;
731
+ /** Particle radius */
732
+ particleRadius?: number;
733
+ /** Gravity strength */
734
+ gravity?: number;
735
+ /** Fluid viscosity */
736
+ viscosity?: number;
737
+ /** Pressure multiplier */
738
+ pressure?: number;
739
+ /** Surface tension */
740
+ surfaceTension?: number;
741
+ /** Boundary bounds */
742
+ bounds?: { x: number; y: number; width: number; height: number };
743
+ /** Particle color */
744
+ color?: string | ((particle: any) => string);
745
+ /** Canvas blend mode */
746
+ blendMode?: GlobalCompositeOperation;
747
+ }
748
+
749
+ /**
750
+ * Fluid simulation system using SPH (Smoothed Particle Hydrodynamics).
751
+ *
752
+ * @example
753
+ * const fluid = new FluidSystem(game, {
754
+ * maxParticles: 500,
755
+ * gravity: 200,
756
+ * viscosity: 0.1,
757
+ * bounds: { x: 0, y: 0, width: 800, height: 600 }
758
+ * });
759
+ * game.pipeline.add(fluid);
760
+ */
761
+ export class FluidSystem extends GameObject {
762
+ /** All fluid particles */
763
+ particles: any[];
764
+ /** Maximum particles */
765
+ maxParticles: number;
766
+ /** Particle radius */
767
+ particleRadius: number;
768
+ /** Gravity strength */
769
+ gravity: number;
770
+ /** Fluid viscosity */
771
+ viscosity: number;
772
+ /** Pressure multiplier */
773
+ pressure: number;
774
+
775
+ /** Current particle count */
776
+ readonly particleCount: number;
777
+
778
+ constructor(game: Game, options?: FluidSystemOptions);
779
+
780
+ /**
781
+ * Spawn particles at position.
782
+ * @param x - X position
783
+ * @param y - Y position
784
+ * @param count - Number of particles
785
+ * @param spread - Position spread
786
+ */
787
+ spawn(x: number, y: number, count: number, spread?: number): void;
788
+
789
+ /**
790
+ * Apply force to particles in radius.
791
+ * @param x - Force center X
792
+ * @param y - Force center Y
793
+ * @param radius - Effect radius
794
+ * @param force - Force strength
795
+ */
796
+ applyForce(x: number, y: number, radius: number, force: number): void;
797
+
798
+ /** Clear all particles */
799
+ clear(): void;
800
+ }
package/types/index.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * GCanvas - TypeScript Definitions
3
3
  * A minimalist 2D canvas rendering library with shapes, game engine, and animations.
4
4
  *
5
- * @version 0.0.3-alpha
5
+ * @version 1.0.1
6
6
  * @see https://github.com/guinetik/gcanvas
7
7
  * @license ISC
8
8
  */
@@ -100,6 +100,7 @@ export {
100
100
  PatternRectangleOptions,
101
101
  ImageShape,
102
102
  ImageShapeOptions,
103
+ BitmapSource,
103
104
 
104
105
  // 2.5D shapes
105
106
  Cube,
@@ -108,6 +109,8 @@ export {
108
109
  Cone,
109
110
  Prism,
110
111
  Sphere,
112
+ Sphere3D,
113
+ Sphere3DOptions,
111
114
 
112
115
  // Text shapes
113
116
  TextShape,
@@ -174,7 +177,22 @@ export {
174
177
  ToggleButton,
175
178
  Cursor,
176
179
  CursorOptions,
177
- FPSCounter
180
+ FPSCounter,
181
+ Tooltip,
182
+ TooltipOptions,
183
+ Stepper,
184
+ StepperOptions,
185
+ UI_THEME,
186
+
187
+ // 3D and Isometric scenes
188
+ Scene3D,
189
+ Scene3DOptions,
190
+ IsometricScene,
191
+ IsometricSceneOptions,
192
+
193
+ // Fluid simulation
194
+ FluidSystem,
195
+ FluidSystemOptions
178
196
  } from './game';
179
197
 
180
198
  // ==========================================================================
@@ -188,7 +206,25 @@ export {
188
206
  TweenetikOptions,
189
207
  Motion,
190
208
  SpringParams,
191
- PositionTarget
209
+ PositionTarget,
210
+
211
+ // Standalone motion functions (V1 API)
212
+ bezierV1,
213
+ bounceV1,
214
+ floatV1,
215
+ followPath,
216
+ orbitV1,
217
+ oscillateV1,
218
+ parabolicV1,
219
+ patrolV1,
220
+ pendulumV1,
221
+ pulseV1,
222
+ hopV1,
223
+ shakeV1,
224
+ spiralV1,
225
+ springV1,
226
+ swingV1,
227
+ waypointV1
192
228
  } from './motion';
193
229
 
194
230
  // ==========================================================================
@@ -201,7 +237,41 @@ export {
201
237
  Fractals,
202
238
  Patterns,
203
239
  Noise,
204
- generatePenroseTilingPixels
240
+ generatePenroseTilingPixels,
241
+
242
+ // Tensor for GR calculations
243
+ Tensor,
244
+ TensorOptions,
245
+
246
+ // Physics modules (General Relativity)
247
+ gravitationalLensingAngle,
248
+ timeDilationFactor,
249
+ gravitationalRedshift,
250
+
251
+ // Orbital Mechanics
252
+ OrbitalState,
253
+ OrbitalElements,
254
+ orbitalVelocity,
255
+ orbitalPeriod,
256
+ elementsToState,
257
+ propagateOrbit,
258
+
259
+ // Quantum Mechanics
260
+ gaussianWavePacket,
261
+ probabilityDensity,
262
+ particleInBox,
263
+ harmonicOscillator,
264
+
265
+ // Heat Transfer
266
+ heatTransfer,
267
+ buoyancyForce,
268
+ temperatureDecay,
269
+
270
+ // Fluid Dynamics
271
+ viscosityDrag,
272
+ surfaceTension,
273
+ reynoldsNumber,
274
+ pressureGradient
205
275
  } from './math';
206
276
 
207
277
  // ==========================================================================
@@ -226,7 +296,19 @@ export {
226
296
  horizontalLayout,
227
297
  verticalLayout,
228
298
  tileLayout,
229
- gridLayout
299
+ gridLayout,
300
+
301
+ // Camera3D
302
+ Camera3D,
303
+ Camera3DOptions,
304
+ ProjectedPoint,
305
+ MouseControlOptions,
306
+ FollowOptions,
307
+ MoveToOptions,
308
+
309
+ // IsometricCamera
310
+ IsometricCamera,
311
+ IsometricCameraOptions
230
312
  } from './util';
231
313
 
232
314
  // ==========================================================================
@@ -307,3 +389,60 @@ export {
307
389
  PhaseConfig,
308
390
  SequenceOptions
309
391
  } from './state';
392
+
393
+ // ==========================================================================
394
+ // Fluent API Module
395
+ // ==========================================================================
396
+
397
+ export {
398
+ // Entry points
399
+ gcanvas,
400
+ sketch,
401
+
402
+ // Builder classes
403
+ FluentGame,
404
+ FluentGameOptions,
405
+ FluentScene,
406
+ FluentSceneOptions,
407
+ FluentGO,
408
+ FluentLayer,
409
+
410
+ // Sketch API
411
+ SketchAPI,
412
+ SketchContext,
413
+
414
+ // Context
415
+ FluentContext,
416
+ TransitionOptions
417
+ } from './fluent';
418
+
419
+ // ==========================================================================
420
+ // Particle System Module
421
+ // ==========================================================================
422
+
423
+ export {
424
+ // Core classes
425
+ Particle,
426
+ ParticleEmitter,
427
+ ParticleSystem,
428
+
429
+ // Types
430
+ ParticleColor,
431
+ ParticleShape,
432
+ ParticleEmitterOptions,
433
+ ParticleSystemOptions,
434
+ ParticleUpdater,
435
+
436
+ // Updaters namespace
437
+ Updaters
438
+ } from './particle';
439
+
440
+ // ==========================================================================
441
+ // WebGL Module (Optional)
442
+ // ==========================================================================
443
+
444
+ export {
445
+ WebGLRenderer,
446
+ WebGLRendererOptions,
447
+ SPHERE_SHADERS
448
+ } from './webgl';