@wolsok/thanos 18.3.3 → 18.4.0

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 (43) hide show
  1. package/README.md +23 -0
  2. package/esm2022/lib/canvas-particle-renderer.js +31 -24
  3. package/esm2022/lib/canvas-particle-renderer.js.map +1 -1
  4. package/esm2022/lib/capture-scale.js +9 -6
  5. package/esm2022/lib/capture-scale.js.map +1 -1
  6. package/esm2022/lib/choose-particle-renderer.js +4 -3
  7. package/esm2022/lib/choose-particle-renderer.js.map +1 -1
  8. package/esm2022/lib/create-ws-thanos-options.js +2 -0
  9. package/esm2022/lib/create-ws-thanos-options.js.map +1 -1
  10. package/esm2022/lib/flow-field.js +58 -0
  11. package/esm2022/lib/flow-field.js.map +1 -0
  12. package/esm2022/lib/frame-rate.js +13 -0
  13. package/esm2022/lib/frame-rate.js.map +1 -0
  14. package/esm2022/lib/particle-renderer.js.map +1 -1
  15. package/esm2022/lib/particles.js +20 -10
  16. package/esm2022/lib/particles.js.map +1 -1
  17. package/esm2022/lib/simplex-noise.js +8 -4
  18. package/esm2022/lib/simplex-noise.js.map +1 -1
  19. package/esm2022/lib/vaporizing-front.js +32 -9
  20. package/esm2022/lib/vaporizing-front.js.map +1 -1
  21. package/esm2022/lib/webgl/webgl-particle-renderer.js +67 -9
  22. package/esm2022/lib/webgl/webgl-particle-renderer.js.map +1 -1
  23. package/esm2022/lib/webgl/webgl-shaders.js +50 -16
  24. package/esm2022/lib/webgl/webgl-shaders.js.map +1 -1
  25. package/esm2022/lib/wind.js +55 -0
  26. package/esm2022/lib/wind.js.map +1 -0
  27. package/esm2022/lib/ws-thanos.options.js.map +1 -1
  28. package/esm2022/lib/ws-thanos.service.js +47 -26
  29. package/esm2022/lib/ws-thanos.service.js.map +1 -1
  30. package/lib/canvas-particle-renderer.d.ts +9 -7
  31. package/lib/capture-scale.d.ts +6 -5
  32. package/lib/choose-particle-renderer.d.ts +3 -2
  33. package/lib/flow-field.d.ts +24 -0
  34. package/lib/frame-rate.d.ts +10 -0
  35. package/lib/particle-renderer.d.ts +6 -0
  36. package/lib/particles.d.ts +14 -6
  37. package/lib/vaporizing-front.d.ts +26 -4
  38. package/lib/webgl/webgl-particle-renderer.d.ts +3 -2
  39. package/lib/webgl/webgl-shaders.d.ts +7 -0
  40. package/lib/wind.d.ts +40 -0
  41. package/lib/ws-thanos.options.d.ts +6 -0
  42. package/lib/ws-thanos.service.d.ts +2 -1
  43. package/package.json +1 -1
@@ -15,11 +15,10 @@ export declare class WebGlParticleRenderer implements ParticleRenderer {
15
15
  readonly kind = "webgl";
16
16
  readonly crumble: WsThanosCrumble;
17
17
  private readonly count;
18
- private readonly maxParticleX;
19
- private readonly minParticleY;
20
18
  private readonly updateProgram;
21
19
  private readonly drawProgram;
22
20
  private readonly buffers;
21
+ private readonly flowField;
23
22
  private readonly stateBuffers;
24
23
  private readonly updateVaos;
25
24
  private readonly drawVaos;
@@ -35,6 +34,8 @@ export declare class WebGlParticleRenderer implements ParticleRenderer {
35
34
  dispose(): void;
36
35
  /** run the bound vertex array through the bound program into the target buffer */
37
36
  private runTransformFeedback;
37
+ /** render the flow field once into a texture, the update program samples it */
38
+ private createFlowField;
38
39
  /** run the crack program once: shard center and crack distances per particle */
39
40
  private createCracks;
40
41
  private uniformLocations;
@@ -20,6 +20,13 @@ export declare const CRACK_LENGTH = 5;
20
20
  export declare const CRACK_VERTEX_SHADER: string;
21
21
  /** moves the particles, the GPU port of updateParticlesOnCpu plus the crumble modes */
22
22
  export declare const UPDATE_VERTEX_SHADER: string;
23
+ /** one triangle that covers the whole viewport */
24
+ export declare const FULL_VIEWPORT_VERTEX_SHADER = "#version 300 es\nvoid main() {\n vec2 corner = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2));\n gl_Position = vec4(corner * 2.0 - 1.0, 0.0, 1.0);\n}\n";
25
+ /**
26
+ * Runs once: the noise field released particles flow along, a texel covers uCell device pixels.
27
+ * Red and green are the x and y flow, simplex noise mapped to [0, 1], the same noise as FlowField on the CPU.
28
+ */
29
+ export declare const FLOW_FIELD_FRAGMENT_SHADER: string;
23
30
  /** transform feedback only, nothing is rasterized */
24
31
  export declare const FEEDBACK_FRAGMENT_SHADER = "#version 300 es\nprecision mediump float;\nout vec4 outColor;\nvoid main() {\n outColor = vec4(0.0);\n}\n";
25
32
  /** draws every particle as one device pixel */
package/lib/wind.d.ts ADDED
@@ -0,0 +1,40 @@
1
+ /** the dust blows to the top right unless told otherwise */
2
+ export declare const DEFAULT_WIND_DIRECTION = 45;
3
+ /**
4
+ * Where the dust blows to. The simulation is written for the default wind,
5
+ * every force it applies is rotated by the difference to this one.
6
+ */
7
+ export interface Wind {
8
+ /** unit vector of the direction in screen coordinates, y points down */
9
+ x: number;
10
+ y: number;
11
+ /** rotation from the default wind to this one */
12
+ cos: number;
13
+ sin: number;
14
+ }
15
+ /**
16
+ * room around the element for the dust to fly in, in element widths (left, right)
17
+ * and element heights (top, bottom)
18
+ */
19
+ export interface EffectMargins {
20
+ left: number;
21
+ right: number;
22
+ top: number;
23
+ bottom: number;
24
+ }
25
+ /**
26
+ * @param degrees direction the dust blows to, clockwise from up like a css gradient angle:
27
+ * 0 up, 90 right, 180 down, 270 left
28
+ */
29
+ export declare function windOf(degrees?: number): Wind;
30
+ /**
31
+ * The effect canvas reaches past the element where the dust can fly:
32
+ * for the default wind one width to the right and four heights up, like before there was a wind.
33
+ */
34
+ export declare function effectMargins(degrees?: number): EffectMargins;
35
+ /** size of the effect canvas in element sizes */
36
+ export interface EffectScale {
37
+ width: number;
38
+ height: number;
39
+ }
40
+ export declare function effectScale(margins: EffectMargins): EffectScale;
@@ -25,6 +25,12 @@ export interface WsThanosOptions {
25
25
  soundVolume: number;
26
26
  /** how the element breaks apart */
27
27
  crumble: WsThanosCrumble;
28
+ /**
29
+ * the direction the dust blows to in degrees, clockwise from up like a css gradient angle:
30
+ * 0 up, 90 right, 180 down, 270 left. The vaporizing front sweeps against it.
31
+ * 45, to the top right, when unset.
32
+ */
33
+ windDirection?: number;
28
34
  /** warm up the effect while the browser is idle, so the first snap does not stutter */
29
35
  preload: boolean;
30
36
  }
@@ -25,8 +25,9 @@ export declare class WsThanosService {
25
25
  private chooseRenderer;
26
26
  /** draw the element into an image at the scale the renderer needs */
27
27
  private capture;
28
+ /** the effect canvas reaches past the element where the wind blows the dust */
28
29
  private createRenderer;
29
- /** the element sits at the bottom left of the larger effect canvas */
30
+ /** the effect canvas covers the element and the margins around it */
30
31
  private placeEffectCanvas;
31
32
  /** position of the element inside its parent, where absolute children are placed */
32
33
  private offsetInParent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wolsok/thanos",
3
- "version": "18.3.3",
3
+ "version": "18.4.0",
4
4
  "description": "Wolf Soko's implementation of a cool Thanos snapping vaporizing effect for destroying dom elements",
5
5
  "bugs": {
6
6
  "url": "https://github.com/WolfSoko/wol-sok-mono/issues"