@guinetik/gcanvas 1.0.0 → 1.0.2

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 (102) hide show
  1. package/demos/coordinates.html +698 -0
  2. package/demos/cube3d.html +23 -0
  3. package/demos/demos.css +17 -3
  4. package/demos/dino.html +42 -0
  5. package/demos/fluid-simple.html +22 -0
  6. package/demos/fluid.html +37 -0
  7. package/demos/gameobjects.html +626 -0
  8. package/demos/index.html +19 -7
  9. package/demos/js/blob.js +18 -5
  10. package/demos/js/coordinates.js +840 -0
  11. package/demos/js/cube3d.js +789 -0
  12. package/demos/js/dino.js +1420 -0
  13. package/demos/js/fluid-simple.js +253 -0
  14. package/demos/js/fluid.js +527 -0
  15. package/demos/js/gameobjects.js +176 -0
  16. package/demos/js/plane3d.js +256 -0
  17. package/demos/js/platformer.js +1579 -0
  18. package/demos/js/sphere3d.js +229 -0
  19. package/demos/js/sprite.js +473 -0
  20. package/demos/js/tde/accretiondisk.js +65 -12
  21. package/demos/js/tde/blackholescene.js +2 -2
  22. package/demos/js/tde/config.js +2 -2
  23. package/demos/js/tde/index.js +152 -27
  24. package/demos/js/tde/lensedstarfield.js +32 -25
  25. package/demos/js/tde/tdestar.js +78 -98
  26. package/demos/js/tde/tidalstream.js +24 -8
  27. package/demos/plane3d.html +24 -0
  28. package/demos/platformer.html +43 -0
  29. package/demos/sphere3d.html +24 -0
  30. package/demos/sprite.html +18 -0
  31. package/docs/README.md +230 -222
  32. package/docs/api/FluidSystem.md +173 -0
  33. package/docs/concepts/architecture-overview.md +204 -204
  34. package/docs/concepts/coordinate-system.md +384 -0
  35. package/docs/concepts/rendering-pipeline.md +279 -279
  36. package/docs/concepts/shapes-vs-gameobjects.md +187 -0
  37. package/docs/concepts/two-layer-architecture.md +229 -229
  38. package/docs/fluid-dynamics.md +99 -0
  39. package/docs/getting-started/first-game.md +354 -354
  40. package/docs/getting-started/installation.md +175 -157
  41. package/docs/modules/collision/README.md +2 -2
  42. package/docs/modules/fluent/README.md +6 -6
  43. package/docs/modules/game/README.md +303 -303
  44. package/docs/modules/isometric-camera.md +2 -2
  45. package/docs/modules/isometric.md +1 -1
  46. package/docs/modules/painter/README.md +328 -328
  47. package/docs/modules/particle/README.md +3 -3
  48. package/docs/modules/shapes/README.md +221 -221
  49. package/docs/modules/shapes/base/euclidian.md +123 -123
  50. package/docs/modules/shapes/base/shape.md +262 -262
  51. package/docs/modules/shapes/base/transformable.md +243 -243
  52. package/docs/modules/state/README.md +2 -2
  53. package/docs/modules/util/README.md +1 -1
  54. package/docs/modules/util/camera3d.md +3 -3
  55. package/docs/modules/util/scene3d.md +1 -1
  56. package/package.json +3 -1
  57. package/readme.md +19 -5
  58. package/src/collision/collision.js +75 -0
  59. package/src/game/game.js +11 -5
  60. package/src/game/index.js +2 -1
  61. package/src/game/objects/index.js +3 -0
  62. package/src/game/objects/platformer-scene.js +411 -0
  63. package/src/game/objects/scene.js +14 -0
  64. package/src/game/objects/sprite.js +529 -0
  65. package/src/game/pipeline.js +20 -16
  66. package/src/game/systems/FluidSystem.js +835 -0
  67. package/src/game/systems/index.js +11 -0
  68. package/src/game/ui/button.js +39 -18
  69. package/src/game/ui/cursor.js +14 -0
  70. package/src/game/ui/fps.js +12 -4
  71. package/src/game/ui/index.js +2 -0
  72. package/src/game/ui/stepper.js +549 -0
  73. package/src/game/ui/theme.js +123 -0
  74. package/src/game/ui/togglebutton.js +9 -3
  75. package/src/game/ui/tooltip.js +11 -4
  76. package/src/io/input.js +75 -45
  77. package/src/io/mouse.js +44 -19
  78. package/src/io/touch.js +35 -12
  79. package/src/math/fluid.js +507 -0
  80. package/src/math/index.js +2 -0
  81. package/src/mixins/anchor.js +17 -7
  82. package/src/motion/tweenetik.js +16 -0
  83. package/src/shapes/cube3d.js +599 -0
  84. package/src/shapes/index.js +3 -0
  85. package/src/shapes/plane3d.js +687 -0
  86. package/src/shapes/sphere3d.js +75 -6
  87. package/src/util/camera2d.js +315 -0
  88. package/src/util/camera3d.js +218 -12
  89. package/src/util/index.js +1 -0
  90. package/src/webgl/shaders/plane-shaders.js +332 -0
  91. package/src/webgl/shaders/sphere-shaders.js +4 -2
  92. package/types/fluent.d.ts +361 -0
  93. package/types/game.d.ts +303 -0
  94. package/types/index.d.ts +144 -5
  95. package/types/math.d.ts +361 -0
  96. package/types/motion.d.ts +271 -0
  97. package/types/particle.d.ts +373 -0
  98. package/types/shapes.d.ts +107 -9
  99. package/types/util.d.ts +353 -0
  100. package/types/webgl.d.ts +109 -0
  101. package/disk_example.png +0 -0
  102. package/tde.png +0 -0
@@ -1,204 +1,204 @@
1
- # Architecture Overview
2
-
3
- > High-level system architecture, module relationships, and design philosophy.
4
-
5
- ## Overview
6
-
7
- GCanvas is a modular 2D rendering and game framework built on top of the HTML5 Canvas API. It follows a layered architecture where each module has a clear responsibility and minimal coupling to other modules.
8
-
9
- The library is designed around three core principles:
10
-
11
- 1. **Modularity** - Use only what you need
12
- 2. **Composability** - Combine simple parts to build complex systems
13
- 3. **Zero Dependencies** - Pure JavaScript, works everywhere
14
-
15
- ## Module Architecture
16
-
17
- ```
18
- ┌─────────────────────────────────────────────────────────────────┐
19
- │ GCanvas │
20
- │ (index.js) │
21
- ├─────────────────────────────────────────────────────────────────┤
22
- │ │
23
- │ ┌──────────────────────────────────────────────────────────┐ │
24
- │ │ Core Modules │ │
25
- │ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────────┐ │ │
26
- │ │ │ shapes/ │ │ game/ │ │ painter/ │ │ │
27
- │ │ │ 40+ shapes │ │ Game loop │ │ Canvas API │ │ │
28
- │ │ │ hierarchy │ │ Pipeline │ │ abstraction │ │ │
29
- │ │ │ Group │ │ GameObject │ │ │ │ │
30
- │ │ └─────────────┘ └─────────────┘ └─────────────────┘ │ │
31
- │ └──────────────────────────────────────────────────────────┘ │
32
- │ │
33
- │ ┌──────────────────────────────────────────────────────────┐ │
34
- │ │ Support Modules │ │
35
- │ │ ┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐ │ │
36
- │ │ │ motion │ │ io │ │ math │ │ util │ │ mixins │ │ │
37
- │ │ │ Tween │ │ Events │ │ Random │ │ Layout │ │Draggable│ │ │
38
- │ │ │ Easing │ │ Mouse │ │ Noise │ │Position│ │ Anchor │ │ │
39
- │ │ │ Motion │ │ Keys │ │Fractals│ │ZIndex │ │ │ │ │
40
- │ │ │Tweenetik│ │ Touch │ │Patterns│ │ Tasks │ │ │ │ │
41
- │ │ └────────┘ └────────┘ └────────┘ └────────┘ └────────┘ │ │
42
- │ └──────────────────────────────────────────────────────────┘ │
43
- │ │
44
- │ ┌──────────────────────────────────────────────────────────┐ │
45
- │ │ Utility Modules │ │
46
- │ │ ┌────────┐ │ │
47
- │ │ │ logger │ │ │
48
- │ │ │ Logger │ │ │
49
- │ │ │Loggable│ │ │
50
- │ │ │DebugTab│ │ │
51
- │ │ └────────┘ │ │
52
- │ └──────────────────────────────────────────────────────────┘ │
53
- │ │
54
- └─────────────────────────────────────────────────────────────────┘
55
- ```
56
-
57
- ## Module Responsibilities
58
-
59
- ### Core Modules
60
-
61
- | Module | Responsibility | Key Classes |
62
- |--------|---------------|-------------|
63
- | **shapes** | Visual primitives and rendering | `Shape`, `Circle`, `Rectangle`, `Group`, `Transformable` |
64
- | **game** | Game loop, lifecycle, object management | `Game`, `Pipeline`, `GameObject`, `Scene` |
65
- | **painter** | Canvas context abstraction | `Painter`, `PainterShapes`, `PainterText` |
66
-
67
- ### Support Modules
68
-
69
- | Module | Responsibility | Key Classes |
70
- |--------|---------------|-------------|
71
- | **motion** | Animation and tweening | `Motion`, `Tweenetik`, `Easing`, `Tween` |
72
- | **io** | Input handling | `EventEmitter`, `Mouse`, `Keys`, `Touch`, `Input` |
73
- | **math** | Mathematical utilities | `Random`, `Noise`, `Complex`, `Fractals`, `Patterns` |
74
- | **util** | Layout and positioning | `Layout`, `Position`, `ZOrderedCollection` |
75
- | **mixins** | Composable behaviors | `applyDraggable()`, `applyAnchor()` |
76
-
77
- ### Utility Modules
78
-
79
- | Module | Responsibility | Key Classes |
80
- |--------|---------------|-------------|
81
- | **logger** | Debug and logging | `Logger`, `Loggable`, `DebugTab` |
82
-
83
- ## Data Flow
84
-
85
- ```
86
- User Input Game Loop
87
- │ │
88
- ▼ ▼
89
- ┌────────┐ events ┌────────┐
90
- │ IO │ ──────────────────►│ Game │
91
- └────────┘ └────────┘
92
-
93
- ┌──────────────┼──────────────┐
94
- ▼ ▼ ▼
95
- ┌──────────┐ ┌──────────┐ ┌──────────┐
96
- │ Pipeline │ │ Tweenetik│ │ Painter │
97
- │ update() │ │ update() │ │ clear() │
98
- └──────────┘ └──────────┘ └──────────┘
99
-
100
-
101
- ┌──────────┐
102
- │GameObject│
103
- │ update() │
104
- │ render() │
105
- └──────────┘
106
-
107
-
108
- ┌──────────┐
109
- │ Shape │
110
- │ draw() │
111
- └──────────┘
112
-
113
-
114
- ┌──────────┐
115
- │ Painter │
116
- │ Canvas │
117
- └──────────┘
118
- ```
119
-
120
- ## Design Patterns
121
-
122
- ### 1. Inheritance Chain (Shapes)
123
-
124
- Shapes use a linear inheritance hierarchy where each class adds specific functionality:
125
-
126
- ```
127
- Euclidian → Geometry2d → Traceable → Renderable → Transformable → Shape
128
- ```
129
-
130
- See: [Rendering Pipeline](./rendering-pipeline.md)
131
-
132
- ### 2. Static Singleton (Painter)
133
-
134
- `Painter` is a static utility class initialized once with the canvas context:
135
-
136
- ```js
137
- Painter.init(ctx);
138
- Painter.shapes.circle(100, 100, 50);
139
- ```
140
-
141
- ### 3. Component Pattern (GameObject + Shape)
142
-
143
- GameObjects compose shapes rather than inheriting from them:
144
-
145
- ```js
146
- class Player extends GameObject {
147
- constructor(game) {
148
- super(game);
149
- this.shape = new Circle(40, { color: 'blue' });
150
- }
151
- }
152
- ```
153
-
154
- ### 4. Mixin Pattern (Behaviors)
155
-
156
- Optional behaviors are applied via mixin functions:
157
-
158
- ```js
159
- applyDraggable(gameObject, gameObject.shape);
160
- applyAnchor(gameObject, { anchor: 'top-right' });
161
- ```
162
-
163
- ### 5. Observer Pattern (Events)
164
-
165
- The `EventEmitter` provides pub-sub event handling:
166
-
167
- ```js
168
- game.events.on('click', (e) => { ... });
169
- game.events.emit('custom-event', data);
170
- ```
171
-
172
- ## Entry Point
173
-
174
- The main entry point (`src/index.js`) re-exports all modules:
175
-
176
- ```js
177
- export * from "./util";
178
- export * from "./math";
179
- export * from "./logger";
180
- export * from "./painter";
181
- export * from "./shapes";
182
- export * from "./io";
183
- export * from "./game";
184
- export * from "./motion";
185
- export * from "./mixins";
186
- ```
187
-
188
- This allows importing any component from the main package:
189
-
190
- ```js
191
- import { Game, Circle, Painter, Motion } from 'gcanvas';
192
- ```
193
-
194
- ## Related
195
-
196
- - [Two-Layer Architecture](./two-layer-architecture.md) - Shape vs Game layer
197
- - [Rendering Pipeline](./rendering-pipeline.md) - Shape inheritance chain
198
- - [Game Lifecycle](./lifecycle.md) - Update/render cycle
199
-
200
- ## See Also
201
-
202
- - [Shapes Module](../modules/shapes/README.md)
203
- - [Game Module](../modules/game/README.md)
204
- - [Painter Module](../modules/painter/README.md)
1
+ # Architecture Overview
2
+
3
+ > High-level system architecture, module relationships, and design philosophy.
4
+
5
+ ## Overview
6
+
7
+ GCanvas is a modular 2D rendering and game framework built on top of the HTML5 Canvas API. It follows a layered architecture where each module has a clear responsibility and minimal coupling to other modules.
8
+
9
+ The library is designed around three core principles:
10
+
11
+ 1. **Modularity** - Use only what you need
12
+ 2. **Composability** - Combine simple parts to build complex systems
13
+ 3. **Zero Dependencies** - Pure JavaScript, works everywhere
14
+
15
+ ## Module Architecture
16
+
17
+ ```
18
+ ┌─────────────────────────────────────────────────────────────────┐
19
+ │ GCanvas │
20
+ │ (index.js) │
21
+ ├─────────────────────────────────────────────────────────────────┤
22
+ │ │
23
+ │ ┌──────────────────────────────────────────────────────────┐ │
24
+ │ │ Core Modules │ │
25
+ │ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────────┐ │ │
26
+ │ │ │ shapes/ │ │ game/ │ │ painter/ │ │ │
27
+ │ │ │ 40+ shapes │ │ Game loop │ │ Canvas API │ │ │
28
+ │ │ │ hierarchy │ │ Pipeline │ │ abstraction │ │ │
29
+ │ │ │ Group │ │ GameObject │ │ │ │ │
30
+ │ │ └─────────────┘ └─────────────┘ └─────────────────┘ │ │
31
+ │ └──────────────────────────────────────────────────────────┘ │
32
+ │ │
33
+ │ ┌──────────────────────────────────────────────────────────┐ │
34
+ │ │ Support Modules │ │
35
+ │ │ ┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐ │ │
36
+ │ │ │ motion │ │ io │ │ math │ │ util │ │ mixins │ │ │
37
+ │ │ │ Tween │ │ Events │ │ Random │ │ Layout │ │Draggable│ │ │
38
+ │ │ │ Easing │ │ Mouse │ │ Noise │ │Position│ │ Anchor │ │ │
39
+ │ │ │ Motion │ │ Keys │ │Fractals│ │ZIndex │ │ │ │ │
40
+ │ │ │Tweenetik│ │ Touch │ │Patterns│ │ Tasks │ │ │ │ │
41
+ │ │ └────────┘ └────────┘ └────────┘ └────────┘ └────────┘ │ │
42
+ │ └──────────────────────────────────────────────────────────┘ │
43
+ │ │
44
+ │ ┌──────────────────────────────────────────────────────────┐ │
45
+ │ │ Utility Modules │ │
46
+ │ │ ┌────────┐ │ │
47
+ │ │ │ logger │ │ │
48
+ │ │ │ Logger │ │ │
49
+ │ │ │Loggable│ │ │
50
+ │ │ │DebugTab│ │ │
51
+ │ │ └────────┘ │ │
52
+ │ └──────────────────────────────────────────────────────────┘ │
53
+ │ │
54
+ └─────────────────────────────────────────────────────────────────┘
55
+ ```
56
+
57
+ ## Module Responsibilities
58
+
59
+ ### Core Modules
60
+
61
+ | Module | Responsibility | Key Classes |
62
+ |--------|---------------|-------------|
63
+ | **shapes** | Visual primitives and rendering | `Shape`, `Circle`, `Rectangle`, `Group`, `Transformable` |
64
+ | **game** | Game loop, lifecycle, object management | `Game`, `Pipeline`, `GameObject`, `Scene` |
65
+ | **painter** | Canvas context abstraction | `Painter`, `PainterShapes`, `PainterText` |
66
+
67
+ ### Support Modules
68
+
69
+ | Module | Responsibility | Key Classes |
70
+ |--------|---------------|-------------|
71
+ | **motion** | Animation and tweening | `Motion`, `Tweenetik`, `Easing`, `Tween` |
72
+ | **io** | Input handling | `EventEmitter`, `Mouse`, `Keys`, `Touch`, `Input` |
73
+ | **math** | Mathematical utilities | `Random`, `Noise`, `Complex`, `Fractals`, `Patterns` |
74
+ | **util** | Layout and positioning | `Layout`, `Position`, `ZOrderedCollection` |
75
+ | **mixins** | Composable behaviors | `applyDraggable()`, `applyAnchor()` |
76
+
77
+ ### Utility Modules
78
+
79
+ | Module | Responsibility | Key Classes |
80
+ |--------|---------------|-------------|
81
+ | **logger** | Debug and logging | `Logger`, `Loggable`, `DebugTab` |
82
+
83
+ ## Data Flow
84
+
85
+ ```
86
+ User Input Game Loop
87
+ │ │
88
+ ▼ ▼
89
+ ┌────────┐ events ┌────────┐
90
+ │ IO │ ──────────────────►│ Game │
91
+ └────────┘ └────────┘
92
+
93
+ ┌──────────────┼──────────────┐
94
+ ▼ ▼ ▼
95
+ ┌──────────┐ ┌──────────┐ ┌──────────┐
96
+ │ Pipeline │ │ Tweenetik│ │ Painter │
97
+ │ update() │ │ update() │ │ clear() │
98
+ └──────────┘ └──────────┘ └──────────┘
99
+
100
+
101
+ ┌──────────┐
102
+ │GameObject│
103
+ │ update() │
104
+ │ render() │
105
+ └──────────┘
106
+
107
+
108
+ ┌──────────┐
109
+ │ Shape │
110
+ │ draw() │
111
+ └──────────┘
112
+
113
+
114
+ ┌──────────┐
115
+ │ Painter │
116
+ │ Canvas │
117
+ └──────────┘
118
+ ```
119
+
120
+ ## Design Patterns
121
+
122
+ ### 1. Inheritance Chain (Shapes)
123
+
124
+ Shapes use a linear inheritance hierarchy where each class adds specific functionality:
125
+
126
+ ```
127
+ Euclidian → Geometry2d → Traceable → Renderable → Transformable → Shape
128
+ ```
129
+
130
+ See: [Rendering Pipeline](./rendering-pipeline.md)
131
+
132
+ ### 2. Static Singleton (Painter)
133
+
134
+ `Painter` is a static utility class initialized once with the canvas context:
135
+
136
+ ```js
137
+ Painter.init(ctx);
138
+ Painter.shapes.circle(100, 100, 50);
139
+ ```
140
+
141
+ ### 3. Component Pattern (GameObject + Shape)
142
+
143
+ GameObjects compose shapes rather than inheriting from them:
144
+
145
+ ```js
146
+ class Player extends GameObject {
147
+ constructor(game) {
148
+ super(game);
149
+ this.shape = new Circle(40, { color: 'blue' });
150
+ }
151
+ }
152
+ ```
153
+
154
+ ### 4. Mixin Pattern (Behaviors)
155
+
156
+ Optional behaviors are applied via mixin functions:
157
+
158
+ ```js
159
+ applyDraggable(gameObject, gameObject.shape);
160
+ applyAnchor(gameObject, { anchor: 'top-right' });
161
+ ```
162
+
163
+ ### 5. Observer Pattern (Events)
164
+
165
+ The `EventEmitter` provides pub-sub event handling:
166
+
167
+ ```js
168
+ game.events.on('click', (e) => { ... });
169
+ game.events.emit('custom-event', data);
170
+ ```
171
+
172
+ ## Entry Point
173
+
174
+ The main entry point (`src/index.js`) re-exports all modules:
175
+
176
+ ```js
177
+ export * from "./util";
178
+ export * from "./math";
179
+ export * from "./logger";
180
+ export * from "./painter";
181
+ export * from "./shapes";
182
+ export * from "./io";
183
+ export * from "./game";
184
+ export * from "./motion";
185
+ export * from "./mixins";
186
+ ```
187
+
188
+ This allows importing any component from the main package:
189
+
190
+ ```js
191
+ import { Game, Circle, Painter, Motion } from '@guinetik/gcanvas';
192
+ ```
193
+
194
+ ## Related
195
+
196
+ - [Two-Layer Architecture](./two-layer-architecture.md) - Shape vs Game layer
197
+ - [Rendering Pipeline](./rendering-pipeline.md) - Shape inheritance chain
198
+ - [Game Lifecycle](./lifecycle.md) - Update/render cycle
199
+
200
+ ## See Also
201
+
202
+ - [Shapes Module](../modules/shapes/README.md)
203
+ - [Game Module](../modules/game/README.md)
204
+ - [Painter Module](../modules/painter/README.md)