@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.
- package/demos/fluid-simple.html +22 -0
- package/demos/fluid.html +37 -0
- package/demos/index.html +2 -0
- package/demos/js/blob.js +18 -5
- package/demos/js/fluid-simple.js +253 -0
- package/demos/js/fluid.js +527 -0
- package/demos/js/tde/accretiondisk.js +64 -11
- package/demos/js/tde/blackholescene.js +2 -2
- package/demos/js/tde/config.js +2 -2
- package/demos/js/tde/index.js +152 -27
- package/demos/js/tde/lensedstarfield.js +32 -25
- package/demos/js/tde/tdestar.js +78 -98
- package/demos/js/tde/tidalstream.js +23 -7
- package/docs/README.md +230 -222
- package/docs/api/FluidSystem.md +173 -0
- package/docs/concepts/architecture-overview.md +204 -204
- package/docs/concepts/rendering-pipeline.md +279 -279
- package/docs/concepts/two-layer-architecture.md +229 -229
- package/docs/fluid-dynamics.md +97 -0
- package/docs/getting-started/first-game.md +354 -354
- package/docs/getting-started/installation.md +175 -157
- package/docs/modules/collision/README.md +2 -2
- package/docs/modules/fluent/README.md +6 -6
- package/docs/modules/game/README.md +303 -303
- package/docs/modules/isometric-camera.md +2 -2
- package/docs/modules/isometric.md +1 -1
- package/docs/modules/painter/README.md +328 -328
- package/docs/modules/particle/README.md +3 -3
- package/docs/modules/shapes/README.md +221 -221
- package/docs/modules/shapes/base/euclidian.md +123 -123
- package/docs/modules/shapes/base/shape.md +262 -262
- package/docs/modules/shapes/base/transformable.md +243 -243
- package/docs/modules/state/README.md +2 -2
- package/docs/modules/util/README.md +1 -1
- package/docs/modules/util/camera3d.md +3 -3
- package/docs/modules/util/scene3d.md +1 -1
- package/package.json +3 -1
- package/readme.md +19 -5
- package/src/collision/collision.js +75 -0
- package/src/game/index.js +2 -1
- package/src/game/pipeline.js +3 -3
- package/src/game/systems/FluidSystem.js +835 -0
- package/src/game/systems/index.js +11 -0
- package/src/game/ui/button.js +39 -18
- package/src/game/ui/cursor.js +14 -0
- package/src/game/ui/fps.js +12 -4
- package/src/game/ui/index.js +2 -0
- package/src/game/ui/stepper.js +549 -0
- package/src/game/ui/theme.js +121 -0
- package/src/game/ui/togglebutton.js +9 -3
- package/src/game/ui/tooltip.js +11 -4
- package/src/math/fluid.js +507 -0
- package/src/math/index.js +2 -0
- package/src/mixins/anchor.js +17 -7
- package/src/motion/tweenetik.js +16 -0
- package/src/shapes/index.js +1 -0
- package/src/util/camera3d.js +218 -12
- package/types/fluent.d.ts +361 -0
- package/types/game.d.ts +303 -0
- package/types/index.d.ts +144 -5
- package/types/math.d.ts +361 -0
- package/types/motion.d.ts +271 -0
- package/types/particle.d.ts +373 -0
- package/types/shapes.d.ts +107 -9
- package/types/util.d.ts +353 -0
- package/types/webgl.d.ts +109 -0
- package/disk_example.png +0 -0
- package/tde.png +0 -0
|
@@ -13,8 +13,8 @@ import { applyGravitationalLensing } from "../../../src/math/gr.js";
|
|
|
13
13
|
// Stream-specific config
|
|
14
14
|
const STREAM_CONFIG = {
|
|
15
15
|
gravity: 120000, // Strong gravity (linear falloff G/r)
|
|
16
|
-
maxParticles:
|
|
17
|
-
particleLifetime:
|
|
16
|
+
maxParticles: 6000,
|
|
17
|
+
particleLifetime: 20, // Seconds - long lifetime so particles can orbit the BH
|
|
18
18
|
|
|
19
19
|
// Velocity inheritance - how much of star's velocity particles get
|
|
20
20
|
// Lower = particles emit more "from" the star, not ahead of it
|
|
@@ -259,6 +259,12 @@ export class TidalStream extends GameObject {
|
|
|
259
259
|
// Build render list with projection
|
|
260
260
|
const renderList = [];
|
|
261
261
|
|
|
262
|
+
// Project black hole position once for all particles
|
|
263
|
+
// This is crucial when camera has moved (e.g., following the star)
|
|
264
|
+
const bhProjected = this.camera.project(0, 0, 0);
|
|
265
|
+
const bhScreenX = bhProjected.x;
|
|
266
|
+
const bhScreenY = bhProjected.y;
|
|
267
|
+
|
|
262
268
|
// Young particles stay invisible (appear to emerge from star)
|
|
263
269
|
const fadeInTime = 0.05; // seconds before particles become visible
|
|
264
270
|
const fadeInDuration = 0.1; // seconds to fade from invisible to full opacity
|
|
@@ -299,24 +305,34 @@ export class TidalStream extends GameObject {
|
|
|
299
305
|
let screenY = projected.y;
|
|
300
306
|
|
|
301
307
|
if (STREAM_CONFIG.lensing.enabled && this.bhRadius > 0) {
|
|
308
|
+
// Calculate particle position RELATIVE to black hole's screen position
|
|
309
|
+
const relX = screenX - bhScreenX;
|
|
310
|
+
const relY = screenY - bhScreenY;
|
|
311
|
+
|
|
302
312
|
const effectRadius = this.bhRadius * STREAM_CONFIG.lensing.effectRadiusMult;
|
|
303
313
|
const strength = this.bhRadius * STREAM_CONFIG.lensing.strengthMult;
|
|
304
314
|
const minDist = this.bhRadius * STREAM_CONFIG.lensing.minDistanceMult;
|
|
305
315
|
|
|
316
|
+
// Apply lensing in BH-relative space (lensing curves toward origin)
|
|
306
317
|
const lensed = applyGravitationalLensing(
|
|
307
|
-
|
|
318
|
+
relX, relY,
|
|
308
319
|
effectRadius,
|
|
309
320
|
strength,
|
|
310
321
|
STREAM_CONFIG.lensing.falloff,
|
|
311
322
|
minDist
|
|
312
323
|
);
|
|
313
|
-
|
|
314
|
-
|
|
324
|
+
|
|
325
|
+
// Transform back to screen space
|
|
326
|
+
screenX = lensed.x + bhScreenX;
|
|
327
|
+
screenY = lensed.y + bhScreenY;
|
|
315
328
|
}
|
|
316
329
|
|
|
317
330
|
// Check if particle is visually inside the black hole
|
|
318
|
-
|
|
319
|
-
const
|
|
331
|
+
// Use pre-calculated BH screen position
|
|
332
|
+
const dxBH = screenX - bhScreenX;
|
|
333
|
+
const dyBH = screenY - bhScreenY;
|
|
334
|
+
const screenDistFromBH = Math.sqrt(dxBH * dxBH + dyBH * dyBH);
|
|
335
|
+
const insideBH = screenDistFromBH < this.bhRadius;
|
|
320
336
|
|
|
321
337
|
// Screen position = center + lensed offset
|
|
322
338
|
renderList.push({
|
package/docs/README.md
CHANGED
|
@@ -1,222 +1,230 @@
|
|
|
1
|
-
# GCanvas Documentation
|
|
2
|
-
|
|
3
|
-
> A minimalist 2D canvas rendering library built for learning, expression, and creative coding.
|
|
4
|
-
|
|
5
|
-
GCanvas is a modular 2D rendering and game framework built on top of the HTML5 Canvas API. Inspired by the simplicity of p5.js and the composability of game engines.
|
|
6
|
-
|
|
7
|
-
## Quick Navigation
|
|
8
|
-
|
|
9
|
-
| Section | Description |
|
|
10
|
-
|---------|-------------|
|
|
11
|
-
| [Getting Started](./getting-started/installation.md) | Installation and first steps |
|
|
12
|
-
| [Concepts](./concepts/architecture-overview.md) | Core architecture and design |
|
|
13
|
-
| [Shapes Module](./modules/shapes/README.md) | Drawing primitives and hierarchy |
|
|
14
|
-
| [Game Module](./modules/game/README.md) | Game loop and GameObjects |
|
|
15
|
-
| [Particle Module](./modules/particle/README.md) | High-performance particle systems |
|
|
16
|
-
| [Util Module](./modules/util/README.md) | Camera3D, Scene3D, layouts |
|
|
17
|
-
| [Collision Module](./modules/collision/README.md) | Collision detection and management |
|
|
18
|
-
| [State Module](./modules/state/README.md) | State machines for entities and games |
|
|
19
|
-
| [Painter Module](./modules/painter/README.md) | Low-level canvas API |
|
|
20
|
-
|
|
21
|
-
## Architecture Overview
|
|
22
|
-
|
|
23
|
-
```
|
|
24
|
-
┌─────────────────────────────────────────────────────────────┐
|
|
25
|
-
│ GCanvas │
|
|
26
|
-
├─────────────────────────────────────────────────────────────┤
|
|
27
|
-
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │
|
|
28
|
-
│ │ Shapes │ │ Game │ │ Painter │ │
|
|
29
|
-
│ │ (Drawing) │ │ (Lifecycle) │ │ (Canvas API) │ │
|
|
30
|
-
│ └─────────────┘ └─────────────┘ └─────────────────────┘ │
|
|
31
|
-
├─────────────────────────────────────────────────────────────┤
|
|
32
|
-
│ ┌───────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │
|
|
33
|
-
│ │ Collision │ │ State │ │ Motion │ │ IO │ ... │
|
|
34
|
-
│ │ (Physics) │ │ (FSM) │ │ (Anim) │ │ (Input) │ │
|
|
35
|
-
│ └───────────┘ └─────────┘ └─────────┘ └─────────┘ │
|
|
36
|
-
└─────────────────────────────────────────────────────────────┘
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
GCanvas is organized into **12 core modules**:
|
|
40
|
-
|
|
41
|
-
| Module | Purpose |
|
|
42
|
-
|--------|---------|
|
|
43
|
-
| **[shapes](./modules/shapes/README.md)** | 40+ drawable primitives and shape classes |
|
|
44
|
-
| **[game](./modules/game/README.md)** | Core game loop, Pipeline, GameObjects, Scenes |
|
|
45
|
-
| **[particle](./modules/particle/README.md)** | High-performance particle systems with pooling |
|
|
46
|
-
| **[collision](./modules/collision/README.md)** | Collision detection algorithms and group management |
|
|
47
|
-
| **[state](./modules/state/README.md)** | State machines with lifecycle callbacks |
|
|
48
|
-
| **[painter](./modules/painter/README.md)** | Low-level canvas drawing API |
|
|
49
|
-
| **[util](./modules/util/README.md)** | Camera3D, Scene3D, Layout, Position utilities |
|
|
50
|
-
| **motion** | Animation with Tweenetik and Motion patterns |
|
|
51
|
-
| **io** | Input handling (Mouse, Keyboard, Touch, Events) |
|
|
52
|
-
| **math** | Random, Noise, Fractals, Patterns |
|
|
53
|
-
| **mixins** | Draggable, Anchor behaviors |
|
|
54
|
-
| **logger** | Debug logging system |
|
|
55
|
-
|
|
56
|
-
## Two-Layer Architecture
|
|
57
|
-
|
|
58
|
-
GCanvas provides two complementary ways to work:
|
|
59
|
-
|
|
60
|
-
### Shape Layer (Declarative Drawing)
|
|
61
|
-
|
|
62
|
-
For static visuals and simple graphics. Use shapes directly without a game loop:
|
|
63
|
-
|
|
64
|
-
```js
|
|
65
|
-
import { Circle, Rectangle, Painter } from 'gcanvas';
|
|
66
|
-
|
|
67
|
-
Painter.init(ctx);
|
|
68
|
-
|
|
69
|
-
const circle = new Circle(100, { x: 200, y: 150, color: 'red' });
|
|
70
|
-
circle.draw();
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
### Game Layer (Interactive Entities)
|
|
74
|
-
|
|
75
|
-
For games, simulations, and interactive applications:
|
|
76
|
-
|
|
77
|
-
```js
|
|
78
|
-
import { Game, Scene, GameObject, Circle } from 'gcanvas';
|
|
79
|
-
|
|
80
|
-
class Player extends GameObject {
|
|
81
|
-
constructor(game) {
|
|
82
|
-
super(game);
|
|
83
|
-
this.shape = new Circle(40, { color: 'blue' });
|
|
84
|
-
this.enableInteractivity(this.shape);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
update(dt) {
|
|
88
|
-
// Game logic here
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
render() {
|
|
92
|
-
this.shape.draw();
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
[Learn more about the Two-Layer Architecture](./concepts/two-layer-architecture.md)
|
|
98
|
-
|
|
99
|
-
## The Rendering Pipeline
|
|
100
|
-
|
|
101
|
-
Every visual element inherits from a chain of base classes:
|
|
102
|
-
|
|
103
|
-
```
|
|
104
|
-
Euclidian ─── Position (x, y) and size (width, height)
|
|
105
|
-
│
|
|
106
|
-
Geometry2d ─── Bounding boxes and constraints
|
|
107
|
-
│
|
|
108
|
-
Traceable ─── Debug visualization
|
|
109
|
-
│
|
|
110
|
-
Renderable ─── Visibility, opacity, shadows
|
|
111
|
-
│
|
|
112
|
-
Transformable ─── Rotation and scaling
|
|
113
|
-
│
|
|
114
|
-
Shape ─── Fill color, stroke, line styling
|
|
115
|
-
│
|
|
116
|
-
[Circle, Rectangle, Star, Cube, ...] ─── Concrete implementations
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
[Learn more about the Rendering Pipeline](./concepts/rendering-pipeline.md)
|
|
120
|
-
|
|
121
|
-
## Quick Start
|
|
122
|
-
|
|
123
|
-
### Installation
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
npm install
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
- **
|
|
185
|
-
- **
|
|
186
|
-
- **
|
|
187
|
-
- **
|
|
188
|
-
- **
|
|
189
|
-
- **
|
|
190
|
-
- **
|
|
191
|
-
- **
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
- [
|
|
216
|
-
- [
|
|
217
|
-
- [
|
|
218
|
-
- [
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
1
|
+
# GCanvas Documentation
|
|
2
|
+
|
|
3
|
+
> A minimalist 2D canvas rendering library built for learning, expression, and creative coding.
|
|
4
|
+
|
|
5
|
+
GCanvas is a modular 2D rendering and game framework built on top of the HTML5 Canvas API. Inspired by the simplicity of p5.js and the composability of game engines.
|
|
6
|
+
|
|
7
|
+
## Quick Navigation
|
|
8
|
+
|
|
9
|
+
| Section | Description |
|
|
10
|
+
|---------|-------------|
|
|
11
|
+
| [Getting Started](./getting-started/installation.md) | Installation and first steps |
|
|
12
|
+
| [Concepts](./concepts/architecture-overview.md) | Core architecture and design |
|
|
13
|
+
| [Shapes Module](./modules/shapes/README.md) | Drawing primitives and hierarchy |
|
|
14
|
+
| [Game Module](./modules/game/README.md) | Game loop and GameObjects |
|
|
15
|
+
| [Particle Module](./modules/particle/README.md) | High-performance particle systems |
|
|
16
|
+
| [Util Module](./modules/util/README.md) | Camera3D, Scene3D, layouts |
|
|
17
|
+
| [Collision Module](./modules/collision/README.md) | Collision detection and management |
|
|
18
|
+
| [State Module](./modules/state/README.md) | State machines for entities and games |
|
|
19
|
+
| [Painter Module](./modules/painter/README.md) | Low-level canvas API |
|
|
20
|
+
|
|
21
|
+
## Architecture Overview
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
25
|
+
│ GCanvas │
|
|
26
|
+
├─────────────────────────────────────────────────────────────┤
|
|
27
|
+
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │
|
|
28
|
+
│ │ Shapes │ │ Game │ │ Painter │ │
|
|
29
|
+
│ │ (Drawing) │ │ (Lifecycle) │ │ (Canvas API) │ │
|
|
30
|
+
│ └─────────────┘ └─────────────┘ └─────────────────────┘ │
|
|
31
|
+
├─────────────────────────────────────────────────────────────┤
|
|
32
|
+
│ ┌───────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │
|
|
33
|
+
│ │ Collision │ │ State │ │ Motion │ │ IO │ ... │
|
|
34
|
+
│ │ (Physics) │ │ (FSM) │ │ (Anim) │ │ (Input) │ │
|
|
35
|
+
│ └───────────┘ └─────────┘ └─────────┘ └─────────┘ │
|
|
36
|
+
└─────────────────────────────────────────────────────────────┘
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
GCanvas is organized into **12 core modules**:
|
|
40
|
+
|
|
41
|
+
| Module | Purpose |
|
|
42
|
+
|--------|---------|
|
|
43
|
+
| **[shapes](./modules/shapes/README.md)** | 40+ drawable primitives and shape classes |
|
|
44
|
+
| **[game](./modules/game/README.md)** | Core game loop, Pipeline, GameObjects, Scenes |
|
|
45
|
+
| **[particle](./modules/particle/README.md)** | High-performance particle systems with pooling |
|
|
46
|
+
| **[collision](./modules/collision/README.md)** | Collision detection algorithms and group management |
|
|
47
|
+
| **[state](./modules/state/README.md)** | State machines with lifecycle callbacks |
|
|
48
|
+
| **[painter](./modules/painter/README.md)** | Low-level canvas drawing API |
|
|
49
|
+
| **[util](./modules/util/README.md)** | Camera3D, Scene3D, Layout, Position utilities |
|
|
50
|
+
| **motion** | Animation with Tweenetik and Motion patterns |
|
|
51
|
+
| **io** | Input handling (Mouse, Keyboard, Touch, Events) |
|
|
52
|
+
| **math** | Random, Noise, Fractals, Patterns |
|
|
53
|
+
| **mixins** | Draggable, Anchor behaviors |
|
|
54
|
+
| **logger** | Debug logging system |
|
|
55
|
+
|
|
56
|
+
## Two-Layer Architecture
|
|
57
|
+
|
|
58
|
+
GCanvas provides two complementary ways to work:
|
|
59
|
+
|
|
60
|
+
### Shape Layer (Declarative Drawing)
|
|
61
|
+
|
|
62
|
+
For static visuals and simple graphics. Use shapes directly without a game loop:
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
import { Circle, Rectangle, Painter } from '@guinetik/gcanvas';
|
|
66
|
+
|
|
67
|
+
Painter.init(ctx);
|
|
68
|
+
|
|
69
|
+
const circle = new Circle(100, { x: 200, y: 150, color: 'red' });
|
|
70
|
+
circle.draw();
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Game Layer (Interactive Entities)
|
|
74
|
+
|
|
75
|
+
For games, simulations, and interactive applications:
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
import { Game, Scene, GameObject, Circle } from '@guinetik/gcanvas';
|
|
79
|
+
|
|
80
|
+
class Player extends GameObject {
|
|
81
|
+
constructor(game) {
|
|
82
|
+
super(game);
|
|
83
|
+
this.shape = new Circle(40, { color: 'blue' });
|
|
84
|
+
this.enableInteractivity(this.shape);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
update(dt) {
|
|
88
|
+
// Game logic here
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
render() {
|
|
92
|
+
this.shape.draw();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
[Learn more about the Two-Layer Architecture](./concepts/two-layer-architecture.md)
|
|
98
|
+
|
|
99
|
+
## The Rendering Pipeline
|
|
100
|
+
|
|
101
|
+
Every visual element inherits from a chain of base classes:
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
Euclidian ─── Position (x, y) and size (width, height)
|
|
105
|
+
│
|
|
106
|
+
Geometry2d ─── Bounding boxes and constraints
|
|
107
|
+
│
|
|
108
|
+
Traceable ─── Debug visualization
|
|
109
|
+
│
|
|
110
|
+
Renderable ─── Visibility, opacity, shadows
|
|
111
|
+
│
|
|
112
|
+
Transformable ─── Rotation and scaling
|
|
113
|
+
│
|
|
114
|
+
Shape ─── Fill color, stroke, line styling
|
|
115
|
+
│
|
|
116
|
+
[Circle, Rectangle, Star, Cube, ...] ─── Concrete implementations
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
[Learn more about the Rendering Pipeline](./concepts/rendering-pipeline.md)
|
|
120
|
+
|
|
121
|
+
## Quick Start
|
|
122
|
+
|
|
123
|
+
### Installation
|
|
124
|
+
|
|
125
|
+
**NPM (Recommended):**
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
npm install @guinetik/gcanvas
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
**Or clone the repository:**
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
git clone https://github.com/guinetik/gcanvas.git
|
|
135
|
+
cd gcanvas
|
|
136
|
+
npm install
|
|
137
|
+
npm run dev
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Hello World
|
|
141
|
+
|
|
142
|
+
```html
|
|
143
|
+
<canvas id="game"></canvas>
|
|
144
|
+
<script type="module">
|
|
145
|
+
import { Game, Scene, Rectangle, TextShape, Group } from '@guinetik/gcanvas';
|
|
146
|
+
|
|
147
|
+
class HelloWorld extends Game {
|
|
148
|
+
init() {
|
|
149
|
+
this.enableFluidSize();
|
|
150
|
+
this.backgroundColor = 'black';
|
|
151
|
+
|
|
152
|
+
const box = new Rectangle(200, 80, {
|
|
153
|
+
color: '#111',
|
|
154
|
+
stroke: '#0f0',
|
|
155
|
+
lineWidth: 2
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
const label = new TextShape('Hello World!', {
|
|
159
|
+
font: '18px monospace',
|
|
160
|
+
color: '#0f0',
|
|
161
|
+
align: 'center',
|
|
162
|
+
baseline: 'middle'
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
const group = new Group({ x: this.width / 2, y: this.height / 2 });
|
|
166
|
+
group.add(box);
|
|
167
|
+
group.add(label);
|
|
168
|
+
|
|
169
|
+
const scene = new Scene(this);
|
|
170
|
+
scene.add(group);
|
|
171
|
+
this.pipeline.add(scene);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const game = new HelloWorld(document.getElementById('game'));
|
|
176
|
+
game.start();
|
|
177
|
+
</script>
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
[Full getting started guide](./getting-started/hello-world.md)
|
|
181
|
+
|
|
182
|
+
## Features
|
|
183
|
+
|
|
184
|
+
- **40+ Shape Primitives** - Circle, Rectangle, Star, Polygon, Heart, and more
|
|
185
|
+
- **2.5D Shapes** - Cube, Cylinder, Sphere, Cone, Prism with pseudo-3D rendering
|
|
186
|
+
- **Groups** - Composite shapes with collective transforms
|
|
187
|
+
- **Transforms** - Rotation, scale, opacity, constraints
|
|
188
|
+
- **Painter API** - Direct canvas control when needed
|
|
189
|
+
- **GameObjects** - Interactive entities with lifecycle methods
|
|
190
|
+
- **Scenes & Scene3D** - Hierarchical organization with optional 3D projection
|
|
191
|
+
- **Camera3D** - Pseudo-3D projection with mouse-controlled rotation
|
|
192
|
+
- **Particle Systems** - High-performance particles with object pooling and composable updaters
|
|
193
|
+
- **Collision Detection** - AABB, circles, lines, sweep tests, and group management
|
|
194
|
+
- **State Machines** - FSM with enter/update/exit lifecycle, timed transitions
|
|
195
|
+
- **UI Components** - Button, ToggleButton, Cursor, Layout managers
|
|
196
|
+
- **Motion System** - Stateless animation patterns (orbit, bounce, spiral...)
|
|
197
|
+
- **Tweenetik** - Property-based tweening with easing
|
|
198
|
+
- **Event System** - Mouse, touch, keyboard with unified input
|
|
199
|
+
- **Zero Dependencies** - Pure JavaScript, works everywhere
|
|
200
|
+
|
|
201
|
+
## Demo
|
|
202
|
+
|
|
203
|
+
See GCanvas in action: [gcanvas.guinetik.com](https://gcanvas.guinetik.com)
|
|
204
|
+
|
|
205
|
+
Or run locally:
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
npm run dev
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## API Documentation
|
|
212
|
+
|
|
213
|
+
- [Shapes Module](./modules/shapes/README.md) - All drawable primitives
|
|
214
|
+
- [Game Module](./modules/game/README.md) - Game loop and objects
|
|
215
|
+
- [Particle Module](./modules/particle/README.md) - Particle systems
|
|
216
|
+
- [Util Module](./modules/util/README.md) - Camera3D, Scene3D, layouts
|
|
217
|
+
- [Collision Module](./modules/collision/README.md) - Collision detection
|
|
218
|
+
- [State Module](./modules/state/README.md) - State machines
|
|
219
|
+
- [Painter Module](./modules/painter/README.md) - Canvas abstraction
|
|
220
|
+
|
|
221
|
+
## Learn More
|
|
222
|
+
|
|
223
|
+
- [Architecture Overview](./concepts/architecture-overview.md)
|
|
224
|
+
- [Rendering Pipeline](./concepts/rendering-pipeline.md)
|
|
225
|
+
- [Game Lifecycle](./concepts/lifecycle.md)
|
|
226
|
+
- [Installation Guide](./getting-started/installation.md)
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
**Source:** [github.com/guinetik/gcanvas](https://github.com/guinetik/gcanvas)
|