@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
@@ -1,243 +1,243 @@
1
- # Transformable
2
-
3
- > Rotation and scaling with transformed bounding boxes.
4
-
5
- **Module:** [shapes](../README.md) | **Extends:** [Renderable](./renderable.md) | **Source:** `src/shapes/transformable.js`
6
-
7
- ## Overview
8
-
9
- Transformable adds canvas transformation support:
10
- - **Rotation** in degrees
11
- - **Scaling** (horizontal and vertical)
12
- - **Transformed bounds** calculation
13
-
14
- This is the final base layer before custom shape styling is introduced.
15
-
16
- ## Constructor
17
-
18
- ```js
19
- new Transformable(options)
20
- ```
21
-
22
- ### Options
23
-
24
- | Option | Type | Default | Description |
25
- |--------|------|---------|-------------|
26
- | `rotation` | `number` | `0` | Rotation in degrees (clockwise) |
27
- | `scaleX` | `number` | `1` | Horizontal scale factor |
28
- | `scaleY` | `number` | `1` | Vertical scale factor |
29
-
30
- Plus all options from [Renderable](./renderable.md).
31
-
32
- ## Properties
33
-
34
- ### Inherited
35
-
36
- From Euclidian: `x`, `y`, `width`, `height`, `debug`, `debugColor`
37
-
38
- From Geometry2d: `minX`, `maxX`, `minY`, `maxY`, `crisp`, `boundsDirty`
39
-
40
- From Renderable: `visible`, `opacity`, `active`, `zIndex`, `shadowColor`, `shadowBlur`, `shadowOffsetX`, `shadowOffsetY`, `tick`
41
-
42
- ### Own Properties
43
-
44
- | Property | Type | Description |
45
- |----------|------|-------------|
46
- | `rotation` | `number` | Rotation angle in degrees |
47
- | `scaleX` | `number` | Horizontal scale (1 = normal) |
48
- | `scaleY` | `number` | Vertical scale (1 = normal) |
49
-
50
- ## Methods
51
-
52
- ### draw()
53
-
54
- Applies transforms before subclass drawing. Always call `super.draw()` in subclasses.
55
-
56
- ```js
57
- class MyShape extends Transformable {
58
- draw() {
59
- super.draw(); // Apply transforms
60
- // Custom drawing (in transformed space)
61
- }
62
- }
63
- ```
64
-
65
- ### applyTransforms()
66
-
67
- Applies rotation and scale to the canvas context. Called by `draw()`.
68
-
69
- ```js
70
- applyTransforms() {
71
- Painter.rotate(this._rotation);
72
- Painter.scale(this._scaleX, this._scaleY);
73
- }
74
- ```
75
-
76
- Transform order: **rotate → scale**
77
-
78
- ### calculateBounds()
79
-
80
- Returns the bounding box after applying rotation and scale.
81
-
82
- ```js
83
- const bounds = shape.getBounds();
84
- // Returns axis-aligned bounding box of the rotated/scaled shape
85
- ```
86
-
87
- ## Rotation
88
-
89
- Rotation is specified in **degrees** (converted to radians internally):
90
-
91
- ```js
92
- const shape = new Rectangle({
93
- width: 100,
94
- height: 50,
95
- rotation: 45 // 45 degrees clockwise
96
- });
97
-
98
- // Update rotation
99
- shape.rotation = 90; // 90 degrees
100
- shape.rotation = -30; // 30 degrees counter-clockwise
101
- ```
102
-
103
- ## Scaling
104
-
105
- Scale factors multiply the shape's dimensions:
106
-
107
- ```js
108
- const shape = new Circle(50, {
109
- scaleX: 2, // Twice as wide
110
- scaleY: 0.5 // Half as tall
111
- });
112
-
113
- // Result: ellipse 200 wide, 50 tall
114
- ```
115
-
116
- Common patterns:
117
-
118
- ```js
119
- // Uniform scale
120
- shape.scaleX = 2;
121
- shape.scaleY = 2; // 2x size in both dimensions
122
-
123
- // Flip horizontally
124
- shape.scaleX = -1;
125
-
126
- // Flip vertically
127
- shape.scaleY = -1;
128
- ```
129
-
130
- ## Transform Order
131
-
132
- Transforms are applied in this order:
133
-
134
- 1. **Translate** to (x, y) — from Renderable
135
- 2. **Rotate** by rotation angle
136
- 3. **Scale** by scaleX, scaleY
137
-
138
- ```js
139
- // Canvas transform stack:
140
- ctx.translate(x, y); // Move to position
141
- ctx.rotate(rotation); // Rotate around position
142
- ctx.scale(scaleX, scaleY); // Scale from position
143
- ```
144
-
145
- ## Transformed Bounds
146
-
147
- `getBounds()` returns the axis-aligned bounding box that contains the rotated/scaled shape:
148
-
149
- ```js
150
- const rect = new Rectangle({
151
- x: 100,
152
- y: 100,
153
- width: 100,
154
- height: 50,
155
- rotation: 45
156
- });
157
-
158
- const bounds = rect.getBounds();
159
- // Returns AABB that contains the rotated rectangle
160
- // bounds.width and bounds.height will be larger than original
161
- ```
162
-
163
- ```
164
- Original: Rotated 45°:
165
- ┌──────────┐ ◇
166
- │ │ ╱ ╲
167
- │ ● │ ╱ ╲
168
- │ │ ◇ ● ◇
169
- └──────────┘ ╲ ╱
170
- ╲ ╱
171
-
172
- ┌───────┐
173
- │ AABB │
174
- └───────┘
175
- ```
176
-
177
- ## Example: Spinning Shape
178
-
179
- ```js
180
- import { Rectangle, Painter } from 'gcanvas';
181
-
182
- const canvas = document.getElementById('canvas');
183
- Painter.init(canvas.getContext('2d'));
184
-
185
- const rect = new Rectangle({
186
- x: 400,
187
- y: 300,
188
- width: 100,
189
- height: 60,
190
- color: '#4ecdc4'
191
- });
192
-
193
- function animate() {
194
- Painter.clear();
195
-
196
- // Rotate 1 degree per frame
197
- rect.rotation += 1;
198
-
199
- rect.draw();
200
- requestAnimationFrame(animate);
201
- }
202
-
203
- animate();
204
- ```
205
-
206
- ## Example: Pulsing Scale
207
-
208
- ```js
209
- let time = 0;
210
-
211
- function animate() {
212
- Painter.clear();
213
- time += 0.05;
214
-
215
- // Pulse between 0.8x and 1.2x
216
- const scale = 1 + Math.sin(time) * 0.2;
217
- shape.scaleX = scale;
218
- shape.scaleY = scale;
219
-
220
- shape.draw();
221
- requestAnimationFrame(animate);
222
- }
223
- ```
224
-
225
- ## Inheritance
226
-
227
- ```
228
- Renderable
229
- └── Transformable <── You are here
230
- └── Shape
231
- └── Circle, Rectangle, Star, ...
232
- ```
233
-
234
- ## Related
235
-
236
- - [Renderable](./renderable.md) - Parent class
237
- - [Shape](./shape.md) - Adds fill/stroke styling
238
- - [Shape Hierarchy](../hierarchy.md) - Full inheritance diagram
239
-
240
- ## See Also
241
-
242
- - [Shapes Module](../README.md)
243
- - [Rendering Pipeline](../../../concepts/rendering-pipeline.md)
1
+ # Transformable
2
+
3
+ > Rotation and scaling with transformed bounding boxes.
4
+
5
+ **Module:** [shapes](../README.md) | **Extends:** [Renderable](./renderable.md) | **Source:** `src/shapes/transformable.js`
6
+
7
+ ## Overview
8
+
9
+ Transformable adds canvas transformation support:
10
+ - **Rotation** in degrees
11
+ - **Scaling** (horizontal and vertical)
12
+ - **Transformed bounds** calculation
13
+
14
+ This is the final base layer before custom shape styling is introduced.
15
+
16
+ ## Constructor
17
+
18
+ ```js
19
+ new Transformable(options)
20
+ ```
21
+
22
+ ### Options
23
+
24
+ | Option | Type | Default | Description |
25
+ |--------|------|---------|-------------|
26
+ | `rotation` | `number` | `0` | Rotation in degrees (clockwise) |
27
+ | `scaleX` | `number` | `1` | Horizontal scale factor |
28
+ | `scaleY` | `number` | `1` | Vertical scale factor |
29
+
30
+ Plus all options from [Renderable](./renderable.md).
31
+
32
+ ## Properties
33
+
34
+ ### Inherited
35
+
36
+ From Euclidian: `x`, `y`, `width`, `height`, `debug`, `debugColor`
37
+
38
+ From Geometry2d: `minX`, `maxX`, `minY`, `maxY`, `crisp`, `boundsDirty`
39
+
40
+ From Renderable: `visible`, `opacity`, `active`, `zIndex`, `shadowColor`, `shadowBlur`, `shadowOffsetX`, `shadowOffsetY`, `tick`
41
+
42
+ ### Own Properties
43
+
44
+ | Property | Type | Description |
45
+ |----------|------|-------------|
46
+ | `rotation` | `number` | Rotation angle in degrees |
47
+ | `scaleX` | `number` | Horizontal scale (1 = normal) |
48
+ | `scaleY` | `number` | Vertical scale (1 = normal) |
49
+
50
+ ## Methods
51
+
52
+ ### draw()
53
+
54
+ Applies transforms before subclass drawing. Always call `super.draw()` in subclasses.
55
+
56
+ ```js
57
+ class MyShape extends Transformable {
58
+ draw() {
59
+ super.draw(); // Apply transforms
60
+ // Custom drawing (in transformed space)
61
+ }
62
+ }
63
+ ```
64
+
65
+ ### applyTransforms()
66
+
67
+ Applies rotation and scale to the canvas context. Called by `draw()`.
68
+
69
+ ```js
70
+ applyTransforms() {
71
+ Painter.rotate(this._rotation);
72
+ Painter.scale(this._scaleX, this._scaleY);
73
+ }
74
+ ```
75
+
76
+ Transform order: **rotate → scale**
77
+
78
+ ### calculateBounds()
79
+
80
+ Returns the bounding box after applying rotation and scale.
81
+
82
+ ```js
83
+ const bounds = shape.getBounds();
84
+ // Returns axis-aligned bounding box of the rotated/scaled shape
85
+ ```
86
+
87
+ ## Rotation
88
+
89
+ Rotation is specified in **degrees** (converted to radians internally):
90
+
91
+ ```js
92
+ const shape = new Rectangle({
93
+ width: 100,
94
+ height: 50,
95
+ rotation: 45 // 45 degrees clockwise
96
+ });
97
+
98
+ // Update rotation
99
+ shape.rotation = 90; // 90 degrees
100
+ shape.rotation = -30; // 30 degrees counter-clockwise
101
+ ```
102
+
103
+ ## Scaling
104
+
105
+ Scale factors multiply the shape's dimensions:
106
+
107
+ ```js
108
+ const shape = new Circle(50, {
109
+ scaleX: 2, // Twice as wide
110
+ scaleY: 0.5 // Half as tall
111
+ });
112
+
113
+ // Result: ellipse 200 wide, 50 tall
114
+ ```
115
+
116
+ Common patterns:
117
+
118
+ ```js
119
+ // Uniform scale
120
+ shape.scaleX = 2;
121
+ shape.scaleY = 2; // 2x size in both dimensions
122
+
123
+ // Flip horizontally
124
+ shape.scaleX = -1;
125
+
126
+ // Flip vertically
127
+ shape.scaleY = -1;
128
+ ```
129
+
130
+ ## Transform Order
131
+
132
+ Transforms are applied in this order:
133
+
134
+ 1. **Translate** to (x, y) — from Renderable
135
+ 2. **Rotate** by rotation angle
136
+ 3. **Scale** by scaleX, scaleY
137
+
138
+ ```js
139
+ // Canvas transform stack:
140
+ ctx.translate(x, y); // Move to position
141
+ ctx.rotate(rotation); // Rotate around position
142
+ ctx.scale(scaleX, scaleY); // Scale from position
143
+ ```
144
+
145
+ ## Transformed Bounds
146
+
147
+ `getBounds()` returns the axis-aligned bounding box that contains the rotated/scaled shape:
148
+
149
+ ```js
150
+ const rect = new Rectangle({
151
+ x: 100,
152
+ y: 100,
153
+ width: 100,
154
+ height: 50,
155
+ rotation: 45
156
+ });
157
+
158
+ const bounds = rect.getBounds();
159
+ // Returns AABB that contains the rotated rectangle
160
+ // bounds.width and bounds.height will be larger than original
161
+ ```
162
+
163
+ ```
164
+ Original: Rotated 45°:
165
+ ┌──────────┐ ◇
166
+ │ │ ╱ ╲
167
+ │ ● │ ╱ ╲
168
+ │ │ ◇ ● ◇
169
+ └──────────┘ ╲ ╱
170
+ ╲ ╱
171
+
172
+ ┌───────┐
173
+ │ AABB │
174
+ └───────┘
175
+ ```
176
+
177
+ ## Example: Spinning Shape
178
+
179
+ ```js
180
+ import { Rectangle, Painter } from '@guinetik/gcanvas';
181
+
182
+ const canvas = document.getElementById('canvas');
183
+ Painter.init(canvas.getContext('2d'));
184
+
185
+ const rect = new Rectangle({
186
+ x: 400,
187
+ y: 300,
188
+ width: 100,
189
+ height: 60,
190
+ color: '#4ecdc4'
191
+ });
192
+
193
+ function animate() {
194
+ Painter.clear();
195
+
196
+ // Rotate 1 degree per frame
197
+ rect.rotation += 1;
198
+
199
+ rect.draw();
200
+ requestAnimationFrame(animate);
201
+ }
202
+
203
+ animate();
204
+ ```
205
+
206
+ ## Example: Pulsing Scale
207
+
208
+ ```js
209
+ let time = 0;
210
+
211
+ function animate() {
212
+ Painter.clear();
213
+ time += 0.05;
214
+
215
+ // Pulse between 0.8x and 1.2x
216
+ const scale = 1 + Math.sin(time) * 0.2;
217
+ shape.scaleX = scale;
218
+ shape.scaleY = scale;
219
+
220
+ shape.draw();
221
+ requestAnimationFrame(animate);
222
+ }
223
+ ```
224
+
225
+ ## Inheritance
226
+
227
+ ```
228
+ Renderable
229
+ └── Transformable <── You are here
230
+ └── Shape
231
+ └── Circle, Rectangle, Star, ...
232
+ ```
233
+
234
+ ## Related
235
+
236
+ - [Renderable](./renderable.md) - Parent class
237
+ - [Shape](./shape.md) - Adds fill/stroke styling
238
+ - [Shape Hierarchy](../hierarchy.md) - Full inheritance diagram
239
+
240
+ ## See Also
241
+
242
+ - [Shapes Module](../README.md)
243
+ - [Rendering Pipeline](../../../concepts/rendering-pipeline.md)
@@ -9,7 +9,7 @@ The state module provides a `StateMachine` class for managing states with enter/
9
9
  ## Quick Start
10
10
 
11
11
  ```js
12
- import { StateMachine } from 'gcanvas';
12
+ import { StateMachine } from '@guinetik/gcanvas';
13
13
 
14
14
  // Basic state machine
15
15
  const fsm = new StateMachine({
@@ -421,7 +421,7 @@ fsm.onStateChange = (newState, oldState, data) => {
421
421
  A complete entity with states, phases, and game integration:
422
422
 
423
423
  ```js
424
- import { GameObject, StateMachine } from 'gcanvas';
424
+ import { GameObject, StateMachine } from '@guinetik/gcanvas';
425
425
 
426
426
  class Boss extends GameObject {
427
427
  constructor(game) {
@@ -52,7 +52,7 @@ GCanvas provides a pseudo-3D system that projects 3D coordinates to 2D canvas:
52
52
  ## Basic 3D Setup
53
53
 
54
54
  ```js
55
- import { Game, Camera3D, Scene3D, GameObject, Rectangle } from 'gcanvas';
55
+ import { Game, Camera3D, Scene3D, GameObject, Rectangle } from '@guinetik/gcanvas';
56
56
 
57
57
  class My3DDemo extends Game {
58
58
  init() {
@@ -15,7 +15,7 @@ Camera3D provides 3D to 2D projection for creating pseudo-3D effects on a 2D can
15
15
  ## Quick Start
16
16
 
17
17
  ```js
18
- import { Camera3D } from 'gcanvas';
18
+ import { Camera3D } from '@guinetik/gcanvas';
19
19
 
20
20
  // Create camera with initial rotation
21
21
  const camera = new Camera3D({
@@ -224,7 +224,7 @@ camera.lookAt(100, 50, 200); // Look toward point
224
224
  The most common usage - let Scene3D handle projection automatically:
225
225
 
226
226
  ```js
227
- import { Camera3D, Scene3D, GameObject } from 'gcanvas';
227
+ import { Camera3D, Scene3D, GameObject } from '@guinetik/gcanvas';
228
228
 
229
229
  class MyDemo extends Game {
230
230
  init() {
@@ -262,7 +262,7 @@ class MyDemo extends Game {
262
262
  For 3D particle effects:
263
263
 
264
264
  ```js
265
- import { Camera3D, ParticleSystem, ParticleEmitter, Updaters } from 'gcanvas';
265
+ import { Camera3D, ParticleSystem, ParticleEmitter, Updaters } from '@guinetik/gcanvas';
266
266
 
267
267
  const camera = new Camera3D({ rotationX: 0.3 });
268
268
  camera.enableMouseControl(canvas);
@@ -16,7 +16,7 @@ Scene3D bridges the GameObject/Scene system with Camera3D. It allows you to posi
16
16
  ## Quick Start
17
17
 
18
18
  ```js
19
- import { Game, Camera3D, Scene3D, GameObject, Rectangle } from 'gcanvas';
19
+ import { Game, Camera3D, Scene3D, GameObject, Rectangle } from '@guinetik/gcanvas';
20
20
 
21
21
  class BoxObject extends GameObject {
22
22
  constructor(game) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guinetik/gcanvas",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Canvas Utilities and 2d Primitives",
5
5
  "main": "index.js",
6
6
  "types": "types/index.d.ts",
@@ -43,7 +43,9 @@
43
43
  "homepage": "https://github.com/guinetik/gcanvas#readme",
44
44
  "devDependencies": {
45
45
  "@testing-library/jest-dom": "^6.6.3",
46
+ "better-docs": "^2.7.3",
46
47
  "gh-pages": "^6.3.0",
48
+ "jsdoc": "^4.0.4",
47
49
  "jsdom": "^26.1.0",
48
50
  "terser": "^5.39.0",
49
51
  "vite": "^6.2.5",
package/readme.md CHANGED
@@ -57,9 +57,13 @@ GCanvas includes TypeScript definitions (`gcanvas.d.ts`) for full IDE intellisen
57
57
 
58
58
  ## 🧑‍💻 Installation
59
59
 
60
- ️⚠️Coming soon to NPM.
60
+ **NPM (Recommended):**
61
61
 
62
- For now, clone this repo:
62
+ ```bash
63
+ npm install @guinetik/gcanvas
64
+ ```
65
+
66
+ **Or clone this repo:**
63
67
 
64
68
  ```bash
65
69
  git clone https://github.com/guinetik/gcanvas.git
@@ -89,13 +93,23 @@ npm run build:debug
89
93
 
90
94
  ## 🚀 Quick Start
91
95
 
92
- ### Using via ESM:
96
+ ### Using via NPM:
97
+
98
+ ```js
99
+ import { Circle, Painter } from '@guinetik/gcanvas';
100
+
101
+ Painter.init(ctx);
102
+ const circle = new Circle(50, { x: 100, y: 100, color: 'red' });
103
+ circle.draw();
104
+ ```
105
+
106
+ ### Using via ESM (standalone):
93
107
 
94
108
  ```js
95
109
  import { Circle } from './dist/gcanvas.es.min.js';
96
110
 
97
- const circle = new Circle(100, 100, 50, { fillColor: 'red' });
98
- circle.draw(); // uses static Painter.ctx internally
111
+ const circle = new Circle(50, { x: 100, y: 100, color: 'red' });
112
+ circle.draw();
99
113
  ```
100
114
 
101
115
  ### Using via inline script: