├── .prettierrc.json
├── jest.setup.ts
├── dev
├── style.css
└── index.ts
├── tsconfig.json
├── index.html
├── index.ts
├── src
├── glsl
│ ├── index.ts
│ ├── Glsl.ts
│ ├── ImmutableList.ts
│ ├── createGenerators.ts
│ ├── utilityFunctions.ts
│ └── transformDefinitions.ts
├── lib
│ ├── Screen.ts
│ ├── Webcam.ts
│ ├── easing-functions.ts
│ └── array-utils.ts
├── Loop.ts
├── Output.ts
├── compiler
│ ├── compileWithEnvironment.ts
│ ├── formatArguments.ts
│ └── generateGlsl.ts
├── Source.ts
└── Hydra.ts
├── .eslintrc.json
├── .gitignore
├── .eslintignore
├── .prettierignore
├── package.json
├── README.md
└── LICENSE
/.prettierrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "printWidth": 80,
3 | "trailingComma": "all",
4 | "singleQuote": true
5 | }
6 |
--------------------------------------------------------------------------------
/jest.setup.ts:
--------------------------------------------------------------------------------
1 | document.body.innerHTML = `
2 |
3 | `;
4 |
--------------------------------------------------------------------------------
/dev/style.css:
--------------------------------------------------------------------------------
1 | body {
2 | min-height: 100vh;
3 | }
4 |
5 | @media (prefers-color-scheme: dark) {
6 | body {
7 | background-color: #2a2a2a;
8 | color: #fefefe;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "exclude": ["dev", "dist", "test"],
3 | "extends": "@tsconfig/recommended/tsconfig.json",
4 | "compilerOptions": {
5 | "declaration": true,
6 | "module": "ES2020",
7 | "moduleResolution": "Node",
8 | "outDir": "dist/"
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | hydra-synth
5 |
6 |
7 |
8 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/index.ts:
--------------------------------------------------------------------------------
1 | export { Hydra } from './src/Hydra';
2 | export { Source } from './src/Source';
3 | export { Output } from './src/Output';
4 | export * as generators from './src/glsl';
5 | export {
6 | generatorTransforms as defaultGenerators,
7 | modifierTransforms as defaultModifiers,
8 | } from './src/glsl/transformDefinitions';
9 | export {
10 | createGenerators,
11 | createTransformChainClass,
12 | } from './src/glsl/createGenerators';
13 |
--------------------------------------------------------------------------------
/src/glsl/index.ts:
--------------------------------------------------------------------------------
1 | import {
2 | createGenerators,
3 | createTransformChainClass,
4 | } from './createGenerators';
5 | import {
6 | generatorTransforms,
7 | modifierTransforms,
8 | } from './transformDefinitions';
9 |
10 | const TransformChainClass = createTransformChainClass(modifierTransforms);
11 | const generators = createGenerators(generatorTransforms, TransformChainClass);
12 |
13 | export const { gradient, noise, osc, shape, solid, src, voronoi } = generators;
14 |
--------------------------------------------------------------------------------
/src/lib/Screen.ts:
--------------------------------------------------------------------------------
1 | export function Screen(
2 | options?: DisplayMediaStreamConstraints,
3 | ): Promise {
4 | return new Promise(function (resolve, reject) {
5 | navigator.mediaDevices
6 | .getDisplayMedia(options)
7 | .then((stream) => {
8 | const video = document.createElement('video');
9 | video.srcObject = stream;
10 |
11 | video.addEventListener('loadedmetadata', () => {
12 | video.play();
13 | resolve(video);
14 | });
15 | })
16 | .catch((err) => reject(err));
17 | });
18 | }
19 |
--------------------------------------------------------------------------------
/src/glsl/Glsl.ts:
--------------------------------------------------------------------------------
1 | import { Output } from '../Output';
2 | import ImmutableList from './ImmutableList';
3 | import { ProcessedTransformDefinition } from './transformDefinitions';
4 |
5 | export interface TransformApplication {
6 | transform: ProcessedTransformDefinition;
7 | userArgs: unknown[];
8 | }
9 |
10 | export class Glsl {
11 | transforms: ImmutableList;
12 |
13 | constructor(transforms: ImmutableList) {
14 | this.transforms = transforms;
15 | }
16 |
17 | out(output: Output) {
18 | output.render(this.transforms.toArray());
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "root": true,
3 | "parser": "@typescript-eslint/parser",
4 | "plugins": ["@typescript-eslint"],
5 | "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
6 | "env": {
7 | "browser": true,
8 | "commonjs": true,
9 | "es2021": true,
10 | "node": true
11 | },
12 | "parserOptions": {
13 | "ecmaVersion": 12,
14 | "sourceType": "module"
15 | },
16 | "rules": {
17 | "@typescript-eslint/no-empty-function": "off",
18 | "@typescript-eslint/ban-ts-comment": "off",
19 | "@typescript-eslint/no-unused-vars": [
20 | "error",
21 | { "argsIgnorePattern": "^_" }
22 | ]
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/glsl/ImmutableList.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * Bare bones append only immutable list.
3 | */
4 | export default class ImmutableList {
5 | readonly parent: ImmutableList | undefined;
6 |
7 | readonly element: T;
8 |
9 | constructor(element: T, parent?: ImmutableList) {
10 | this.parent = parent;
11 | this.element = element;
12 | }
13 |
14 | append(element: T): ImmutableList {
15 | return new ImmutableList(element, this);
16 | }
17 |
18 | toArray(): T[] {
19 | if (!this.parent) {
20 | return [this.element];
21 | }
22 | const elements = this.parent.toArray();
23 | elements.push(this.element);
24 | return elements;
25 | }
26 |
27 | forEach(callbackfn: (value: T, index: number, array: T[]) => void) {
28 | this.toArray().forEach(callbackfn);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/dev/index.ts:
--------------------------------------------------------------------------------
1 | import REGL from 'regl';
2 | import { Hydra, generators } from '../index';
3 | import ArrayUtils from '../src/lib/array-utils';
4 |
5 | import './style.css';
6 |
7 | const WIDTH = 1080;
8 | const HEIGHT = 1080;
9 | const DENSITY = 2;
10 |
11 | const canvas = document.createElement('canvas');
12 | canvas.style.backgroundColor = '#000000';
13 | canvas.width = WIDTH;
14 | canvas.height = HEIGHT;
15 | document.body.appendChild(canvas);
16 |
17 | ArrayUtils.init();
18 |
19 | const regl = REGL(canvas);
20 |
21 | const hydra = new Hydra({
22 | width: WIDTH * DENSITY,
23 | height: HEIGHT * DENSITY,
24 | precision: 'mediump',
25 | regl,
26 | });
27 |
28 | hydra.loop.start();
29 |
30 | const { sources, outputs, render } = hydra;
31 | const [s0, s1, s2, s3] = sources;
32 | const [o0, o1, o2, o3] = outputs;
33 | const { src, osc, gradient, shape, voronoi, noise } = generators;
34 |
35 | osc(() => 4 * Math.PI)
36 | .add(o0, [0, 0.5].smooth())
37 | .mult(src(o0).rotate(Math.PI / 2), 0.6)
38 | .out(o0);
39 |
40 | src(o0).scrollX(0.1, -0.1).scrollY(0.1, -0.1).out(o1);
41 |
42 | render(o1);
43 |
--------------------------------------------------------------------------------
/src/lib/Webcam.ts:
--------------------------------------------------------------------------------
1 | export function Webcam(deviceId: number): Promise {
2 | return navigator.mediaDevices
3 | .enumerateDevices()
4 | .then((devices) =>
5 | devices.filter((devices) => devices.kind === 'videoinput'),
6 | )
7 | .then((cameras) => {
8 | const constraints: MediaStreamConstraints = {
9 | audio: false,
10 | video: true,
11 | };
12 |
13 | if (cameras[deviceId]) {
14 | constraints['video'] = {
15 | deviceId: {
16 | exact: cameras[deviceId].deviceId,
17 | },
18 | };
19 | }
20 |
21 | return window.navigator.mediaDevices.getUserMedia(constraints);
22 | })
23 | .then((stream) => {
24 | const video = document.createElement('video');
25 | video.setAttribute('autoplay', '');
26 | video.setAttribute('muted', '');
27 | video.setAttribute('playsinline', '');
28 | video.srcObject = stream;
29 |
30 | return new Promise((resolve, _reject) => {
31 | video.addEventListener('loadedmetadata', () => {
32 | video.play().then(() => resolve(video));
33 | });
34 | });
35 | });
36 | }
37 |
--------------------------------------------------------------------------------
/src/Loop.ts:
--------------------------------------------------------------------------------
1 | type OnTick = (dt: number) => void;
2 |
3 | export class Loop {
4 | #ts: number = performance.now();
5 | #running = false;
6 | #raf?: number;
7 | readonly #fn: OnTick;
8 |
9 | constructor(fn: OnTick) {
10 | this.#fn = fn;
11 | }
12 |
13 | start = (): this => {
14 | if (this.#running) {
15 | return this;
16 | }
17 |
18 | this.#running = true;
19 | this.#ts = performance.now();
20 | this.#raf = requestAnimationFrame(this.tick);
21 |
22 | return this;
23 | };
24 |
25 | stop = (): this => {
26 | this.#running = false;
27 | if (this.#raf) {
28 | cancelAnimationFrame(this.#raf);
29 | }
30 | this.#raf = undefined;
31 |
32 | return this;
33 | };
34 |
35 | toggle = (): this => {
36 | if (this.#running) {
37 | this.stop();
38 | } else {
39 | this.start();
40 | }
41 |
42 | return this;
43 | };
44 |
45 | tick = (): this => {
46 | this.#raf = requestAnimationFrame(this.tick);
47 |
48 | const time = performance.now();
49 | const dt = time - this.#ts;
50 |
51 | this.#fn(dt);
52 |
53 | this.#ts = time;
54 |
55 | return this;
56 | };
57 | }
58 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 |
4 | dist/
5 |
6 | # Logs
7 | logs
8 | *.log
9 | npm-debug.log*
10 | yarn-debug.log*
11 | yarn-error.log*
12 |
13 | # Runtime data
14 | pids
15 | *.pid
16 | *.seed
17 | *.pid.lock
18 |
19 | # Directory for instrumented libs generated by jscoverage/JSCover
20 | lib-cov
21 |
22 | # Coverage directory used by tools like istanbul
23 | coverage
24 |
25 | # nyc test coverage
26 | .nyc_output
27 |
28 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
29 | .grunt
30 |
31 | # Bower dependency directory (https://bower.io/)
32 | bower_components
33 |
34 | # node-waf configuration
35 | .lock-wscript
36 |
37 | # Compiled binary addons (https://nodejs.org/api/addons.html)
38 | build/Release
39 |
40 | # Dependency directories
41 | node_modules/
42 | jspm_packages/
43 |
44 | # Typescript v1 declaration files
45 | typings/
46 |
47 | # Optional npm cache directory
48 | .npm
49 |
50 | # Optional eslint cache
51 | .eslintcache
52 |
53 | # Optional REPL history
54 | .node_repl_history
55 |
56 | # Output of 'npm pack'
57 | *.tgz
58 |
59 | # Yarn Integrity file
60 | .yarn-integrity
61 |
62 | # dotenv environment variables file
63 | .env
64 |
65 | # next.js build output
66 | .next
67 |
68 | # jetbrains config
69 | .idea
70 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 |
4 | dist/
5 |
6 | # Logs
7 | logs
8 | *.log
9 | npm-debug.log*
10 | yarn-debug.log*
11 | yarn-error.log*
12 |
13 | # Runtime data
14 | pids
15 | *.pid
16 | *.seed
17 | *.pid.lock
18 |
19 | # Directory for instrumented libs generated by jscoverage/JSCover
20 | lib-cov
21 |
22 | # Coverage directory used by tools like istanbul
23 | coverage
24 |
25 | # nyc test coverage
26 | .nyc_output
27 |
28 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
29 | .grunt
30 |
31 | # Bower dependency directory (https://bower.io/)
32 | bower_components
33 |
34 | # node-waf configuration
35 | .lock-wscript
36 |
37 | # Compiled binary addons (https://nodejs.org/api/addons.html)
38 | build/Release
39 |
40 | # Dependency directories
41 | node_modules/
42 | jspm_packages/
43 |
44 | # Typescript v1 declaration files
45 | typings/
46 |
47 | # Optional npm cache directory
48 | .npm
49 |
50 | # Optional eslint cache
51 | .eslintcache
52 |
53 | # Optional REPL history
54 | .node_repl_history
55 |
56 | # Output of 'npm pack'
57 | *.tgz
58 |
59 | # Yarn Integrity file
60 | .yarn-integrity
61 |
62 | # dotenv environment variables file
63 | .env
64 |
65 | # next.js build output
66 | .next
67 |
68 | # jetbrains config
69 | .idea
70 |
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 |
4 | dist/
5 |
6 | # Logs
7 | logs
8 | *.log
9 | npm-debug.log*
10 | yarn-debug.log*
11 | yarn-error.log*
12 |
13 | # Runtime data
14 | pids
15 | *.pid
16 | *.seed
17 | *.pid.lock
18 |
19 | # Directory for instrumented libs generated by jscoverage/JSCover
20 | lib-cov
21 |
22 | # Coverage directory used by tools like istanbul
23 | coverage
24 |
25 | # nyc test coverage
26 | .nyc_output
27 |
28 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
29 | .grunt
30 |
31 | # Bower dependency directory (https://bower.io/)
32 | bower_components
33 |
34 | # node-waf configuration
35 | .lock-wscript
36 |
37 | # Compiled binary addons (https://nodejs.org/api/addons.html)
38 | build/Release
39 |
40 | # Dependency directories
41 | node_modules/
42 | jspm_packages/
43 |
44 | # Typescript v1 declaration files
45 | typings/
46 |
47 | # Optional npm cache directory
48 | .npm
49 |
50 | # Optional eslint cache
51 | .eslintcache
52 |
53 | # Optional REPL history
54 | .node_repl_history
55 |
56 | # Output of 'npm pack'
57 | *.tgz
58 |
59 | # Yarn Integrity file
60 | .yarn-integrity
61 |
62 | # dotenv environment variables file
63 | .env
64 |
65 | # next.js build output
66 | .next
67 |
68 | # jetbrains config
69 | .idea
70 |
--------------------------------------------------------------------------------
/src/lib/easing-functions.ts:
--------------------------------------------------------------------------------
1 | // from https://gist.github.com/gre/1650294
2 |
3 | export default {
4 | // no easing, no acceleration
5 | linear(t: number) {
6 | return t;
7 | },
8 | // accelerating from zero velocity
9 | easeInQuad(t: number) {
10 | return t * t;
11 | },
12 | // decelerating to zero velocity
13 | easeOutQuad(t: number) {
14 | return t * (2 - t);
15 | },
16 | // acceleration until halfway, then deceleration
17 | easeInOutQuad(t: number) {
18 | return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
19 | },
20 | // accelerating from zero velocity
21 | easeInCubic(t: number) {
22 | return t * t * t;
23 | },
24 | // decelerating to zero velocity
25 | easeOutCubic(t: number) {
26 | return --t * t * t + 1;
27 | },
28 | // acceleration until halfway, then deceleration
29 | easeInOutCubic(t: number) {
30 | return t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1;
31 | },
32 | // accelerating from zero velocity
33 | easeInQuart(t: number) {
34 | return t * t * t * t;
35 | },
36 | // decelerating to zero velocity
37 | easeOutQuart(t: number) {
38 | return 1 - --t * t * t * t;
39 | },
40 | // acceleration until halfway, then deceleration
41 | easeInOutQuart(t: number) {
42 | return t < 0.5 ? 8 * t * t * t * t : 1 - 8 * --t * t * t * t;
43 | },
44 | // accelerating from zero velocity
45 | easeInQuint(t: number) {
46 | return t * t * t * t * t;
47 | },
48 | // decelerating to zero velocity
49 | easeOutQuint(t: number) {
50 | return 1 + --t * t * t * t * t;
51 | },
52 | // acceleration until halfway, then deceleration
53 | easeInOutQuint(t: number) {
54 | return t < 0.5 ? 16 * t * t * t * t * t : 1 + 16 * --t * t * t * t * t;
55 | },
56 | // sin shape
57 | sin(t: number) {
58 | return (1 + Math.sin(Math.PI * t - Math.PI / 2)) / 2;
59 | },
60 | } as const;
61 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "hydra-ts",
3 | "license": "AGPL",
4 | "version": "1.0.0",
5 | "description": "A fork of ojack/hydra-synth in typescript, focusing on interoperability.",
6 | "main": "dist/index.js",
7 | "types": "dist/index.d.ts",
8 | "type": "module",
9 | "scripts": {
10 | "test": "node --experimental-vm-modules node_modules/.bin/jest",
11 | "dev": "vite",
12 | "coverage": "nyc npm run test",
13 | "prepack": "tsc || true"
14 | },
15 | "repository": {
16 | "type": "git",
17 | "url": "git+https://github.com/folz/hydra-ts.git"
18 | },
19 | "keywords": [
20 | "webgl",
21 | "regl",
22 | "graphics",
23 | "livecoding",
24 | "synth"
25 | ],
26 | "author": "folz",
27 | "bugs": {
28 | "url": "https://github.com/folz/hydra-ts/issues"
29 | },
30 | "homepage": "https://github.com/folz/hydra-ts#readme",
31 | "dependencies": {
32 | "regl": "^1.3.9"
33 | },
34 | "devDependencies": {
35 | "@tsconfig/recommended": "^1.0.1",
36 | "@types/gl": "^4.1.0",
37 | "@types/jest": "^27.0.3",
38 | "@types/node": "^17.0.5",
39 | "@typescript-eslint/eslint-plugin": "^5.8.1",
40 | "@typescript-eslint/parser": "^5.8.1",
41 | "eslint": "^8.5.0",
42 | "gl": "^4.9.2",
43 | "jest": "^27.4.5",
44 | "jest-environment-jsdom": "^27.4.4",
45 | "jest-environment-jsdom-global": "^3.0.0",
46 | "jsdom": "^19.0.0",
47 | "jsdom-global": "^3.0.2",
48 | "nyc": "^15.1.0",
49 | "prettier": "^2.5.1",
50 | "typescript": "^4.5.4",
51 | "vite": "^2.7.10"
52 | },
53 | "nyc": {
54 | "include": [
55 | "src/**/*.js",
56 | "index.js"
57 | ],
58 | "reporter": [
59 | "text",
60 | "html"
61 | ],
62 | "cache": false
63 | },
64 | "jest": {
65 | "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
66 | "extensionsToTreatAsEsm": [
67 | ".ts"
68 | ],
69 | "setupFilesAfterEnv": [
70 | "./jest.setup.js"
71 | ],
72 | "testEnvironment": "jest-environment-jsdom-global"
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/Output.ts:
--------------------------------------------------------------------------------
1 | import { Attributes, DrawCommand, Framebuffer2D } from 'regl';
2 | import { GlEnvironment } from './Hydra';
3 | import { TransformApplication } from './glsl/Glsl';
4 | import { compileWithEnvironment } from './compiler/compileWithEnvironment';
5 |
6 | export class Output {
7 | attributes: Attributes;
8 | draw: DrawCommand;
9 | fbos: Framebuffer2D[];
10 | environment: GlEnvironment;
11 | vert: string;
12 | pingPongIndex = 0;
13 |
14 | constructor(environment: GlEnvironment) {
15 | this.environment = environment;
16 |
17 | // eslint-disable-next-line @typescript-eslint/ban-ts-comment
18 | // @ts-ignore
19 | this.draw = () => {};
20 |
21 | this.vert = `
22 | precision ${environment.precision} float;
23 | attribute vec2 position;
24 | varying vec2 uv;
25 |
26 | void main () {
27 | uv = position;
28 | gl_Position = vec4(2.0 * position - 1.0, 0, 1);
29 | }`;
30 |
31 | this.attributes = {
32 | position: environment.regl.buffer([
33 | [-2, 0],
34 | [0, -2],
35 | [2, 2],
36 | ]),
37 | };
38 |
39 | // for each output, create two fbos for pingponging
40 | this.fbos = Array(2)
41 | .fill(undefined)
42 | .map(() =>
43 | environment.regl.framebuffer({
44 | color: environment.regl.texture({
45 | mag: 'nearest',
46 | width: environment.width,
47 | height: environment.height,
48 | format: 'rgba',
49 | }),
50 | depthStencil: false,
51 | }),
52 | );
53 | }
54 |
55 | resize(width: number, height: number) {
56 | this.fbos.forEach((fbo) => {
57 | fbo.resize(width, height);
58 | });
59 | }
60 |
61 | getCurrent() {
62 | return this.fbos[this.pingPongIndex];
63 | }
64 |
65 | // Used by glsl-utils/formatArguments
66 | getTexture() {
67 | const index = this.pingPongIndex ? 0 : 1;
68 | return this.fbos[index];
69 | }
70 |
71 | render(transformApplications: TransformApplication[]) {
72 | if (transformApplications.length === 0) {
73 | return;
74 | }
75 |
76 | const pass = compileWithEnvironment(
77 | transformApplications,
78 | this.environment,
79 | );
80 |
81 | this.draw = this.environment.regl({
82 | frag: pass.frag,
83 | vert: this.vert,
84 | attributes: this.attributes,
85 | uniforms: pass.uniforms,
86 | count: 3,
87 | framebuffer: () => {
88 | this.pingPongIndex = this.pingPongIndex ? 0 : 1;
89 | return this.fbos[this.pingPongIndex];
90 | },
91 | });
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/src/lib/array-utils.ts:
--------------------------------------------------------------------------------
1 | // WIP utils for working with arrays
2 | // Possibly should be integrated with lfo extension, etc.
3 | // to do: transform time rather than array values, similar to working with coordinates in hydra
4 |
5 | import easing from './easing-functions';
6 |
7 | const map = (
8 | num: number,
9 | in_min: number,
10 | in_max: number,
11 | out_min: number,
12 | out_max: number,
13 | ) => {
14 | return ((num - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min;
15 | };
16 |
17 | type Easing = keyof typeof easing;
18 |
19 | declare global {
20 | // eslint-disable-next-line @typescript-eslint/no-unused-vars
21 | interface Array {
22 | _speed: number;
23 | _smooth: number;
24 | _ease: (t: number) => number;
25 | _offset: number;
26 |
27 | fast(speed: number): this;
28 | smooth(smooth: number): this;
29 | ease(ease: Easing): this;
30 | offset(offset: number): this;
31 | fit(low: number, high: number): this;
32 | }
33 | }
34 |
35 | export default {
36 | init: () => {
37 | Array.prototype.fast = function (speed = 1) {
38 | this._speed = speed;
39 | return this;
40 | };
41 |
42 | Array.prototype.smooth = function (smooth = 1) {
43 | this._smooth = smooth;
44 | return this;
45 | };
46 |
47 | Array.prototype.ease = function (ease = 'linear') {
48 | if (typeof ease == 'function') {
49 | this._smooth = 1;
50 | this._ease = ease;
51 | } else if (easing[ease]) {
52 | this._smooth = 1;
53 | this._ease = easing[ease];
54 | }
55 | return this;
56 | };
57 |
58 | Array.prototype.offset = function (offset = 0.5) {
59 | this._offset = offset % 1.0;
60 | return this;
61 | };
62 |
63 | Array.prototype.fit = function (low = 0, high = 1) {
64 | const lowest = Math.min(...this);
65 | const highest = Math.max(...this);
66 | const newArr = this.map((num) => map(num, lowest, highest, low, high));
67 | newArr._speed = this._speed;
68 | newArr._smooth = this._smooth;
69 | newArr._ease = this._ease;
70 | return newArr;
71 | };
72 | },
73 |
74 | getValue:
75 | (arr: any[] = []) =>
76 | ({ time, bpm }: any) => {
77 | const speed = arr._speed ? arr._speed : 1;
78 | const smooth = arr._smooth ? arr._smooth : 0;
79 | const index = time * speed * (bpm / 60) + (arr._offset || 0);
80 |
81 | if (smooth !== 0) {
82 | const ease = arr._ease ? arr._ease : easing['linear'];
83 | const _index = index - smooth / 2;
84 | const currValue = arr[Math.floor(_index % arr.length)];
85 | const nextValue = arr[Math.floor((_index + 1) % arr.length)];
86 | const t = Math.min((_index % 1) / smooth, 1);
87 | return ease(t) * (nextValue - currValue) + currValue;
88 | } else {
89 | return arr[Math.floor(index % arr.length)];
90 | }
91 | },
92 | };
93 |
--------------------------------------------------------------------------------
/src/compiler/compileWithEnvironment.ts:
--------------------------------------------------------------------------------
1 | import { GlEnvironment } from '../Hydra';
2 | import { TypedArg } from './formatArguments';
3 | import { utilityFunctions } from '../glsl/utilityFunctions';
4 | import { TransformApplication } from '../glsl/Glsl';
5 | import { DynamicVariable, DynamicVariableFn, Texture2D, Uniform } from 'regl';
6 | import { generateGlsl } from './generateGlsl';
7 |
8 | export type CompiledTransform = {
9 | frag: string;
10 | uniforms: {
11 | [name: string]:
12 | | string
13 | | Uniform
14 | | ((context: any, props: any) => number | number[])
15 | | Texture2D
16 | | DynamicVariable
17 | | DynamicVariableFn
18 | | undefined;
19 | };
20 | };
21 |
22 | export interface ShaderParams {
23 | uniforms: TypedArg[];
24 | transformApplications: TransformApplication[];
25 | fragColor: string;
26 | }
27 |
28 | export function compileWithEnvironment(
29 | transformApplications: TransformApplication[],
30 | environment: GlEnvironment,
31 | ): CompiledTransform {
32 | const shaderParams = compileGlsl(transformApplications);
33 |
34 | const uniforms: Record = {};
35 | shaderParams.uniforms.forEach((uniform) => {
36 | uniforms[uniform.name] = uniform.value;
37 | });
38 |
39 | const frag = `
40 | precision ${environment.precision} float;
41 | ${Object.values(shaderParams.uniforms)
42 | .map((uniform) => {
43 | return `
44 | uniform ${uniform.type} ${uniform.name};`;
45 | })
46 | .join('')}
47 | uniform float time;
48 | uniform vec2 resolution;
49 | varying vec2 uv;
50 |
51 | ${Object.values(utilityFunctions)
52 | .map((transform) => {
53 | return `
54 | ${transform.glsl}
55 | `;
56 | })
57 | .join('')}
58 |
59 | ${shaderParams.transformApplications
60 | .map((transformApplication) => {
61 | return `
62 | ${transformApplication.transform.glsl}
63 | `;
64 | })
65 | .join('')}
66 |
67 | void main () {
68 | vec4 c = vec4(1, 0, 0, 1);
69 | vec2 st = gl_FragCoord.xy/resolution.xy;
70 | gl_FragColor = ${shaderParams.fragColor};
71 | }
72 | `;
73 |
74 | return {
75 | frag: frag,
76 | uniforms: { ...environment.defaultUniforms, ...uniforms },
77 | };
78 | }
79 |
80 | export function compileGlsl(
81 | transformApplications: TransformApplication[],
82 | ): ShaderParams {
83 | const shaderParams: ShaderParams = {
84 | uniforms: [],
85 | transformApplications: [],
86 | fragColor: '',
87 | };
88 |
89 | // Note: generateGlsl() also mutates shaderParams.transformApplications
90 | shaderParams.fragColor = generateGlsl(
91 | transformApplications,
92 | shaderParams,
93 | )('st');
94 |
95 | // remove uniforms with duplicate names
96 | const uniforms: Record = {};
97 | shaderParams.uniforms.forEach(
98 | (uniform) => (uniforms[uniform.name] = uniform),
99 | );
100 | shaderParams.uniforms = Object.values(uniforms);
101 |
102 | return shaderParams;
103 | }
104 |
--------------------------------------------------------------------------------
/src/glsl/createGenerators.ts:
--------------------------------------------------------------------------------
1 | import {
2 | ProcessedTransformDefinition,
3 | TransformDefinition,
4 | TransformDefinitionType,
5 | } from './transformDefinitions.js';
6 | import { Glsl } from './Glsl';
7 | import ImmutableList from './ImmutableList.js';
8 |
9 | type Generator = (...args: unknown[]) => Glsl;
10 |
11 | export function createTransformChainClass<
12 | T extends readonly TransformDefinition[],
13 | >(modifierTransforms: T): typeof Glsl {
14 | const sourceClass = class extends Glsl {};
15 |
16 | for (const transform of modifierTransforms) {
17 | const processed = processGlsl(transform);
18 |
19 | addTransformChainMethod(sourceClass, processed);
20 | }
21 |
22 | return sourceClass;
23 | }
24 |
25 | export function createGenerator(
26 | generatorTransform: TransformDefinition,
27 | TransformChainClass: typeof Glsl,
28 | ): Generator {
29 | const processed = processGlsl(generatorTransform);
30 |
31 | return (...args: unknown[]) =>
32 | new TransformChainClass(
33 | new ImmutableList({
34 | transform: processed,
35 | userArgs: args,
36 | }),
37 | );
38 | }
39 |
40 | export function createGenerators(
41 | generatorTransforms: readonly TransformDefinition[],
42 | sourceClass: typeof Glsl,
43 | ): Record {
44 | const generatorMap: Record = {};
45 |
46 | for (const transform of generatorTransforms) {
47 | generatorMap[transform.name] = createGenerator(transform, sourceClass);
48 | }
49 |
50 | return generatorMap;
51 | }
52 |
53 | export function addTransformChainMethod(
54 | cls: typeof Glsl,
55 | processedTransformDefinition: ProcessedTransformDefinition,
56 | ) {
57 | function addTransformApplicationToInternalChain(
58 | this: Glsl,
59 | ...args: unknown[]
60 | ): Glsl {
61 | const transform = {
62 | transform: processedTransformDefinition,
63 | userArgs: args,
64 | };
65 |
66 | return new cls(this.transforms.append(transform));
67 | }
68 |
69 | // @ts-ignore
70 | cls.prototype[processedTransformDefinition.name] =
71 | addTransformApplicationToInternalChain;
72 | }
73 |
74 | const typeLookup: Record<
75 | TransformDefinitionType,
76 | { returnType: string; implicitFirstArg: string }
77 | > = {
78 | src: {
79 | returnType: 'vec4',
80 | implicitFirstArg: 'vec2 _st',
81 | },
82 | coord: {
83 | returnType: 'vec2',
84 | implicitFirstArg: 'vec2 _st',
85 | },
86 | color: {
87 | returnType: 'vec4',
88 | implicitFirstArg: 'vec4 _c0',
89 | },
90 | combine: {
91 | returnType: 'vec4',
92 | implicitFirstArg: 'vec4 _c0',
93 | },
94 | combineCoord: {
95 | returnType: 'vec2',
96 | implicitFirstArg: 'vec2 _st',
97 | },
98 | };
99 |
100 | export function processGlsl(
101 | transformDefinition: TransformDefinition,
102 | ): ProcessedTransformDefinition {
103 | const { implicitFirstArg, returnType } = typeLookup[transformDefinition.type];
104 |
105 | const signature = [
106 | implicitFirstArg,
107 | ...transformDefinition.inputs.map((input) => `${input.type} ${input.name}`),
108 | ].join(', ');
109 |
110 | const glslFunction = `
111 | ${returnType} ${transformDefinition.name}(${signature}) {
112 | ${transformDefinition.glsl}
113 | }
114 | `;
115 |
116 | return {
117 | ...transformDefinition,
118 | glsl: glslFunction,
119 | processed: true,
120 | };
121 | }
122 |
--------------------------------------------------------------------------------
/src/Source.ts:
--------------------------------------------------------------------------------
1 | import { Webcam } from './lib/Webcam';
2 | import { Screen } from './lib/Screen';
3 | import { Texture2D, TextureImageData } from 'regl';
4 | import { GlEnvironment, Synth } from './Hydra';
5 |
6 | export class Source {
7 | environment: GlEnvironment;
8 | src?: TextureImageData;
9 | dynamic: boolean;
10 | tex: Texture2D;
11 |
12 | constructor(environment: GlEnvironment) {
13 | this.environment = environment;
14 | this.src = undefined;
15 | this.dynamic = true;
16 | this.tex = environment.regl.texture({
17 | shape: [1, 1],
18 | });
19 | }
20 |
21 | init = (opts: { src: Source['src']; dynamic: boolean }) => {
22 | if (opts.src) {
23 | this.src = opts.src;
24 | this.tex = this.environment.regl.texture(this.src);
25 | }
26 |
27 | if (opts.dynamic) {
28 | this.dynamic = opts.dynamic;
29 | }
30 | };
31 |
32 | initCam = (index: number) => {
33 | Webcam(index)
34 | .then((video) => {
35 | this.src = video;
36 | this.dynamic = true;
37 | this.tex = this.environment.regl.texture(video);
38 | })
39 | .catch((err) => console.log('could not get camera', err));
40 | };
41 |
42 | initVideo = (url = '') => {
43 | const vid = document.createElement('video');
44 | vid.crossOrigin = 'anonymous';
45 | vid.autoplay = true;
46 | vid.loop = true;
47 | // mute in order to load without user interaction
48 | vid.muted = true;
49 | vid.addEventListener('loadeddata', () => {
50 | this.src = vid;
51 | vid.play();
52 | this.tex = this.environment.regl.texture(this.src);
53 | this.dynamic = true;
54 | });
55 | vid.src = url;
56 | };
57 |
58 | initImage = (url = '') => {
59 | const img = document.createElement('img');
60 | img.crossOrigin = 'anonymous';
61 | img.src = url;
62 | img.onload = () => {
63 | this.src = img;
64 | this.dynamic = false;
65 | this.tex = this.environment.regl.texture(this.src);
66 | };
67 | };
68 |
69 | initScreen = () => {
70 | Screen()
71 | .then((video) => {
72 | this.src = video;
73 | this.tex = this.environment.regl.texture(this.src);
74 | this.dynamic = true;
75 | })
76 | .catch((err) => console.log('could not get screen', err));
77 | };
78 |
79 | clear = () => {
80 | if (this.src && 'srcObject' in this.src && this.src.srcObject) {
81 | if ('getTracks' in this.src.srcObject && this.src.srcObject.getTracks) {
82 | this.src.srcObject
83 | .getTracks()
84 | .forEach((track: MediaStreamTrack) => track.stop());
85 | }
86 | }
87 | this.src = undefined;
88 | this.tex = this.environment.regl.texture({ shape: [1, 1] });
89 | };
90 |
91 | draw = (_props: Synth) => {
92 | if (this.src && this.dynamic) {
93 | if (
94 | 'videoWidth' in this.src &&
95 | this.src.videoWidth &&
96 | this.src.videoWidth !== this.tex.width
97 | ) {
98 | this.tex.resize(this.src.videoWidth, this.src.videoHeight);
99 | }
100 |
101 | if (
102 | 'width' in this.src &&
103 | this.src.width &&
104 | this.src.width !== this.tex.width
105 | ) {
106 | this.tex.resize(this.src.width, this.src.height);
107 | }
108 |
109 | this.tex.subimage(this.src);
110 | }
111 | };
112 |
113 | // Used by glsl-utils/formatArguments
114 | getTexture = () => {
115 | return this.tex;
116 | };
117 | }
118 |
--------------------------------------------------------------------------------
/src/glsl/utilityFunctions.ts:
--------------------------------------------------------------------------------
1 | // functions that are only used within other functions
2 |
3 | export const utilityFunctions = {
4 | _luminance: {
5 | type: 'util',
6 | glsl: `float _luminance(vec3 rgb){
7 | const vec3 W = vec3(0.2125, 0.7154, 0.0721);
8 | return dot(rgb, W);
9 | }`,
10 | },
11 | _noise: {
12 | type: 'util',
13 | glsl: `
14 | // Simplex 3D Noise
15 | // by Ian McEwan, Ashima Arts
16 | vec4 permute(vec4 x){return mod(((x*34.0)+1.0)*x, 289.0);}
17 | vec4 taylorInvSqrt(vec4 r){return 1.79284291400159 - 0.85373472095314 * r;}
18 |
19 | float _noise(vec3 v){
20 | const vec2 C = vec2(1.0/6.0, 1.0/3.0) ;
21 | const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);
22 |
23 | // First corner
24 | vec3 i = floor(v + dot(v, C.yyy) );
25 | vec3 x0 = v - i + dot(i, C.xxx) ;
26 |
27 | // Other corners
28 | vec3 g = step(x0.yzx, x0.xyz);
29 | vec3 l = 1.0 - g;
30 | vec3 i1 = min( g.xyz, l.zxy );
31 | vec3 i2 = max( g.xyz, l.zxy );
32 |
33 | // x0 = x0 - 0. + 0.0 * C
34 | vec3 x1 = x0 - i1 + 1.0 * C.xxx;
35 | vec3 x2 = x0 - i2 + 2.0 * C.xxx;
36 | vec3 x3 = x0 - 1. + 3.0 * C.xxx;
37 |
38 | // Permutations
39 | i = mod(i, 289.0 );
40 | vec4 p = permute( permute( permute(
41 | i.z + vec4(0.0, i1.z, i2.z, 1.0 ))
42 | + i.y + vec4(0.0, i1.y, i2.y, 1.0 ))
43 | + i.x + vec4(0.0, i1.x, i2.x, 1.0 ));
44 |
45 | // Gradients
46 | // ( N*N points uniformly over a square, mapped onto an octahedron.)
47 | float n_ = 1.0/7.0; // N=7
48 | vec3 ns = n_ * D.wyz - D.xzx;
49 |
50 | vec4 j = p - 49.0 * floor(p * ns.z *ns.z); // mod(p,N*N)
51 |
52 | vec4 x_ = floor(j * ns.z);
53 | vec4 y_ = floor(j - 7.0 * x_ ); // mod(j,N)
54 |
55 | vec4 x = x_ *ns.x + ns.yyyy;
56 | vec4 y = y_ *ns.x + ns.yyyy;
57 | vec4 h = 1.0 - abs(x) - abs(y);
58 |
59 | vec4 b0 = vec4( x.xy, y.xy );
60 | vec4 b1 = vec4( x.zw, y.zw );
61 |
62 | vec4 s0 = floor(b0)*2.0 + 1.0;
63 | vec4 s1 = floor(b1)*2.0 + 1.0;
64 | vec4 sh = -step(h, vec4(0.0));
65 |
66 | vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ;
67 | vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww ;
68 |
69 | vec3 p0 = vec3(a0.xy,h.x);
70 | vec3 p1 = vec3(a0.zw,h.y);
71 | vec3 p2 = vec3(a1.xy,h.z);
72 | vec3 p3 = vec3(a1.zw,h.w);
73 |
74 | //Normalise gradients
75 | vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));
76 | p0 *= norm.x;
77 | p1 *= norm.y;
78 | p2 *= norm.z;
79 | p3 *= norm.w;
80 |
81 | // Mix final noise value
82 | vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0);
83 | m = m * m;
84 | return 42.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1),
85 | dot(p2,x2), dot(p3,x3) ) );
86 | }
87 | `,
88 | },
89 |
90 | _rgbToHsv: {
91 | type: 'util',
92 | glsl: `vec3 _rgbToHsv(vec3 c){
93 | vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
94 | vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
95 | vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
96 |
97 | float d = q.x - min(q.w, q.y);
98 | float e = 1.0e-10;
99 | return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
100 | }`,
101 | },
102 | _hsvToRgb: {
103 | type: 'util',
104 | glsl: `vec3 _hsvToRgb(vec3 c){
105 | vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
106 | vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
107 | return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
108 | }`,
109 | },
110 | _rotate: {
111 | type: 'util',
112 | glsl: `vec2 _rotate(vec2 uv, vec2 cp, float a, bool side) {
113 | float angle = a * 3.141592;
114 | vec2 n = vec2(sin(angle), cos(angle));
115 | float d = dot(uv - cp, n);
116 | if (side) {
117 | uv -= n * max(0.0, d) * 2.0;
118 | } else {
119 | uv -= n * min(0.0, d) * 2.0;
120 | }
121 | return uv;
122 | }`,
123 | },
124 | };
125 |
--------------------------------------------------------------------------------
/src/compiler/formatArguments.ts:
--------------------------------------------------------------------------------
1 | import { Glsl, TransformApplication } from '../glsl/Glsl';
2 | import arrayUtils from '../lib/array-utils';
3 | import { TransformDefinitionInput } from '../glsl/transformDefinitions';
4 | import { Source } from '../Source';
5 | import { Output } from '../Output';
6 | import { src } from '../glsl/index';
7 |
8 | export interface TypedArg {
9 | value: TransformDefinitionInput['default'];
10 | type: TransformDefinitionInput['type'];
11 | isUniform: boolean;
12 | name: TransformDefinitionInput['name'];
13 | vecLen: number;
14 | }
15 |
16 | export function formatArguments(
17 | transformApplication: TransformApplication,
18 | startIndex: number,
19 | ): TypedArg[] {
20 | const { transform, userArgs } = transformApplication;
21 | const { inputs } = transform;
22 |
23 | return inputs.map((input, index) => {
24 | const vecLen = input.vecLen ?? 0;
25 |
26 | let value: any = input.default;
27 | let isUniform = false;
28 |
29 | if (input.type === 'float') {
30 | value = ensureDecimalDot(value);
31 | }
32 |
33 | // if user has input something for this argument
34 | if (userArgs.length > index) {
35 | const arg = userArgs[index];
36 |
37 | value = arg;
38 | // do something if a composite or transformApplication
39 |
40 | if (typeof arg === 'function') {
41 | if (vecLen > 0) {
42 | // expected input is a vector, not a scalar
43 | value = (context: any, props: any) =>
44 | fillArrayWithDefaults(arg(props), vecLen);
45 | } else {
46 | value = (context: any, props: any) => {
47 | try {
48 | return arg(props);
49 | } catch (e) {
50 | console.log('ERROR', e);
51 | return input.default;
52 | }
53 | };
54 | }
55 |
56 | isUniform = true;
57 | } else if (Array.isArray(arg)) {
58 | if (vecLen > 0) {
59 | // expected input is a vector, not a scalar
60 | isUniform = true;
61 | value = fillArrayWithDefaults(value, vecLen);
62 | } else {
63 | // is Array
64 | value = (context: any, props: any) => arrayUtils.getValue(arg)(props);
65 | isUniform = true;
66 | }
67 | }
68 | }
69 |
70 | if (value instanceof Glsl) {
71 | // GLSLSource
72 |
73 | isUniform = false;
74 | } else if (input.type === 'float' && typeof value === 'number') {
75 | // Number
76 |
77 | value = ensureDecimalDot(value);
78 | } else if (input.type.startsWith('vec') && Array.isArray(value)) {
79 | // Vector literal (as array)
80 |
81 | isUniform = false;
82 | value = `${input.type}(${value.map(ensureDecimalDot).join(', ')})`;
83 | } else if (input.type === 'sampler2D') {
84 | const ref = value;
85 |
86 | value = () => ref.getTexture();
87 | isUniform = true;
88 | } else if (value instanceof Source || value instanceof Output) {
89 | const ref = value;
90 |
91 | value = src(ref);
92 | isUniform = false;
93 | }
94 |
95 | // Add to uniform array if is a function that will pass in a different value on each render frame,
96 | // or a texture/ external source
97 |
98 | let { name } = input;
99 | if (isUniform) {
100 | name += startIndex;
101 | }
102 |
103 | return {
104 | value,
105 | type: input.type,
106 | isUniform,
107 | vecLen,
108 | name,
109 | };
110 | });
111 | }
112 |
113 | export function ensureDecimalDot(val: any): string {
114 | val = val.toString();
115 | if (val.indexOf('.') < 0) {
116 | val += '.';
117 | }
118 | return val;
119 | }
120 |
121 | export function fillArrayWithDefaults(arr: any[], len: number) {
122 | // fill the array with default values if it's too short
123 | while (arr.length < len) {
124 | if (arr.length === 3) {
125 | // push a 1 as the default for .a in vec4
126 | arr.push(1.0);
127 | } else {
128 | arr.push(0.0);
129 | }
130 | }
131 | return arr.slice(0, len);
132 | }
133 |
--------------------------------------------------------------------------------
/src/compiler/generateGlsl.ts:
--------------------------------------------------------------------------------
1 | import { Texture2D } from 'regl';
2 | import { TransformApplication } from '../glsl/Glsl';
3 | import { formatArguments, TypedArg } from './formatArguments';
4 | import { ShaderParams } from './compileWithEnvironment';
5 |
6 | export type GlslGenerator = (uv: string) => string;
7 |
8 | export function generateGlsl(
9 | transformApplications: TransformApplication[],
10 | shaderParams: ShaderParams,
11 | ): GlslGenerator {
12 | let fragColor: GlslGenerator = () => '';
13 |
14 | transformApplications.forEach((transformApplication) => {
15 | let f1: (
16 | uv: string,
17 | ) =>
18 | | string
19 | | number
20 | | number[]
21 | | ((context: any, props: any) => number | number[])
22 | | Texture2D
23 | | undefined;
24 |
25 | const typedArgs = formatArguments(
26 | transformApplication,
27 | shaderParams.uniforms.length,
28 | );
29 |
30 | typedArgs.forEach((typedArg) => {
31 | if (typedArg.isUniform) {
32 | shaderParams.uniforms.push(typedArg);
33 | }
34 | });
35 |
36 | // add new glsl function to running list of functions
37 | if (!contains(transformApplication, shaderParams.transformApplications)) {
38 | shaderParams.transformApplications.push(transformApplication);
39 | }
40 |
41 | // current function for generating frag color shader code
42 | const f0 = fragColor;
43 | if (transformApplication.transform.type === 'src') {
44 | fragColor = (uv) =>
45 | `${shaderString(uv, transformApplication, typedArgs, shaderParams)}`;
46 | } else if (transformApplication.transform.type === 'coord') {
47 | fragColor = (uv) =>
48 | `${f0(
49 | `${shaderString(uv, transformApplication, typedArgs, shaderParams)}`,
50 | )}`;
51 | } else if (transformApplication.transform.type === 'color') {
52 | fragColor = (uv) =>
53 | `${shaderString(
54 | `${f0(uv)}`,
55 | transformApplication,
56 | typedArgs,
57 | shaderParams,
58 | )}`;
59 | } else if (transformApplication.transform.type === 'combine') {
60 | // combining two generated shader strings (i.e. for blend, mult, add funtions)
61 | f1 =
62 | // @ts-ignore
63 | typedArgs[0].value && typedArgs[0].value.transforms
64 | ? (uv: string) =>
65 | // @ts-ignore
66 | `${generateGlsl(typedArgs[0].value.transforms, shaderParams)(uv)}`
67 | : typedArgs[0].isUniform
68 | ? () => typedArgs[0].name
69 | : () => typedArgs[0].value;
70 | fragColor = (uv) =>
71 | `${shaderString(
72 | `${f0(uv)}, ${f1(uv)}`,
73 | transformApplication,
74 | typedArgs.slice(1),
75 | shaderParams,
76 | )}`;
77 | } else if (transformApplication.transform.type === 'combineCoord') {
78 | // combining two generated shader strings (i.e. for modulate functions)
79 | f1 =
80 | // @ts-ignore
81 | typedArgs[0].value && typedArgs[0].value.transforms
82 | ? (uv: string) =>
83 | // @ts-ignore
84 | `${generateGlsl(typedArgs[0].value.transforms, shaderParams)(uv)}`
85 | : typedArgs[0].isUniform
86 | ? () => typedArgs[0].name
87 | : () => typedArgs[0].value;
88 | fragColor = (uv) =>
89 | `${f0(
90 | `${shaderString(
91 | `${uv}, ${f1(uv)}`,
92 | transformApplication,
93 | typedArgs.slice(1),
94 | shaderParams,
95 | )}`,
96 | )}`;
97 | }
98 | });
99 | return fragColor;
100 | }
101 |
102 | function shaderString(
103 | uv: string,
104 | transformApplication: TransformApplication,
105 | inputs: TypedArg[],
106 | shaderParams: ShaderParams,
107 | ): string {
108 | const str = inputs
109 | .map((input) => {
110 | if (input.isUniform) {
111 | return input.name;
112 | // @ts-ignore
113 | } else if (input.value && input.value.transforms) {
114 | // this by definition needs to be a generator, hence we start with 'st' as the initial value for generating the glsl fragment
115 | // @ts-ignore
116 | return `${generateGlsl(input.value.transforms, shaderParams)('st')}`;
117 | }
118 | return input.value;
119 | })
120 | .reduce((p, c) => `${p}, ${c}`, '');
121 |
122 | return `${transformApplication.transform.name}(${uv}${str})`;
123 | }
124 |
125 | function contains(
126 | transformApplication: TransformApplication,
127 | transformApplications: TransformApplication[],
128 | ): boolean {
129 | for (let i = 0; i < transformApplications.length; i++) {
130 | if (
131 | transformApplication.transform.name ==
132 | transformApplications[i].transform.name
133 | ) {
134 | return true;
135 | }
136 | }
137 | return false;
138 | }
139 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # `hydra-ts`
2 |
3 | `hydra-ts` is a fork of [ojack/hydra-synth][1] in typescript, focusing on interoperability with other projects. It
4 | seeks to be fully compatible with the original's end-user syntax (`osc().out()`) while rewriting much of the internal
5 | implementation to make it easier to use as a library.
6 |
7 | ## Installation
8 |
9 | ```shell
10 | # yarn
11 | yarn add hydra-ts
12 | ```
13 |
14 | ```shell
15 | # npm
16 | npm install -S hydra-ts
17 | ```
18 |
19 | ## Background
20 |
21 | hydra-synth is a fantastically designed visual synth and shader compiler that I've wanted to use in a variety of other
22 | projects. However, I've found that its implementation is tightly coupled to [ojack/hydra][2], the online editor created
23 | to showcase hydra-synth. I've also found that it generally assumes a single running instance and a modifiable global
24 | environment.
25 |
26 | These things have caused unexpected behavior for me when I used hydra-synth outside of hydra-the-editor, or in multiple
27 | places on the same page where I wanted each place to be self-contained from the others. Although the hydra community
28 | has found workarounds to many of these behaviors, I wanted to create a fork which directly fixes root causes so that
29 | workarounds are no longer needed.
30 |
31 | To address these, hydra-ts has rewritten internals to avoid globals and mutable state, removed non-shader-compilation
32 | features present in the original (such as audio analysis), and modified the public API to prefer referential equality
33 | over named lookup.
34 |
35 | ## Documentation
36 |
37 | _For general information about using Hydra, refer to [`hydra`'s documentation][2]._
38 |
39 | #### Creating a Hydra instance:
40 |
41 | ```ts
42 | import REGL from 'regl';
43 | import { Hydra } from 'hydra-ts';
44 |
45 | const regl = REGL(/*...*/);
46 |
47 | const hydra = new Hydra({
48 | regl,
49 | width: 1080,
50 | height: 1080,
51 | /*
52 | numOutputs?: 4,
53 | numSources?: 4,
54 | precision?: 'mediump', // 'highp' | 'mediump' | 'lowp'
55 | */
56 | });
57 | ```
58 |
59 | The Hydra constructor expects a regl instance, width, and height. The width and height are the internal buffer
60 | dimensions, not the dimensions of the canvas element. This means you can e.g. pass in double the size of the canvas
61 | dimensions to avoid sampling/pixelation of high-resolution sketches until finally rendering back out to the canvas.
62 |
63 | You can optionally provide a non-negative number for numOutputs and numSources, as well as a Precision value.
64 |
65 | #### Recreating the hydra-editor global environment
66 |
67 | ```ts
68 | import { Hydra, generators } from 'hydra-ts';
69 |
70 | const hydra = new Hydra(/* ... */);
71 |
72 | const { src, osc, gradient, shape, voronoi, noise } = generators;
73 | const { sources, outputs } = hydra;
74 |
75 | const [s0, s1, s2, s3] = sources;
76 | const [o0, o1, o2, o3] = outputs;
77 | const { hush, loop, render } = hydra;
78 |
79 | loop.start();
80 | ```
81 |
82 | Generators are no longer dependent on the Hydra environment, so you can import them directly from `'hydra-ts'`;
83 |
84 | Sources and outputs may be named when destructuring from their respective properties on the hydra instance.
85 |
86 | Helper methods may also be destructured from the hydra instance.
87 |
88 | #### Adding custom generator or modifier hydra functions (e.g. `setFunction`)
89 |
90 | ```ts
91 | import {
92 | createGenerators,
93 | defaultGenerators,
94 | defaultModifiers,
95 | } from 'hydra-ts';
96 |
97 | const generators = createGenerators({
98 | generators: [...defaultGenerators, myGeneratorDefinition],
99 | modifiers: [...defaultModifiers, myModifierDefinition],
100 | });
101 |
102 | const { src, osc, /* ... , */ myGen } = generators;
103 | ```
104 |
105 | Where `myGeneratorDefinition` and `myModifierDefinition` match the object you would have passed to `setFunction`.
106 |
107 | A "generator" is a definition with `{type: 'src'}`, and a "modifier" is a definition of any other type.
108 |
109 | #### Recreating bidirectional global changes (e.g. assigning `bpm`/`speed` globals)
110 |
111 | This is not presently supported.
112 |
113 | ## Differences from the original hydra-synth
114 |
115 | Presently, you must pass an output instance to `.out(o#)` - it does not infer the "default" output if none is passed.
116 | PRs to address this are welcome.
117 |
118 | You must also call ArrayUtils.init() once before any instance of hydra is used.
119 |
120 | ## Contributing
121 |
122 | Contributions are welcome. In particular, contributions around tests, performance, correctness, and type safety are
123 | very appreciated. I'm also open to contributions which help you integrate this into your own projects.
124 |
125 | Please remember that this fork has a goal of full compatibility with the original implementation, so if you're
126 | proposing new syntax or breaking changes, they will need to be upstreamed before being implemented here. If in doubt,
127 | feel free to open an issue discussing the changes before starting work on them.
128 |
129 | [1]: https://github.com/ojack/hydra-synth#readme
130 | [2]: https://github.com/ojack/hydra#readme
131 |
--------------------------------------------------------------------------------
/src/Hydra.ts:
--------------------------------------------------------------------------------
1 | import {
2 | DefaultContext,
3 | DrawCommand,
4 | DynamicVariable,
5 | DynamicVariableFn,
6 | Regl,
7 | Resource,
8 | } from 'regl';
9 | import { Output } from './Output';
10 | import { Loop } from './Loop';
11 | import { Source } from './Source';
12 | import { solid } from './glsl';
13 |
14 | export type Precision = 'lowp' | 'mediump' | 'highp';
15 |
16 | export type Resolution = readonly [number, number];
17 |
18 | export interface HydraFboUniforms {
19 | resolution: Resolution;
20 | tex0: Resource;
21 | }
22 |
23 | export interface HydraDrawUniforms {
24 | resolution: Resolution;
25 | time: number;
26 | }
27 |
28 | export interface Synth {
29 | bpm: number;
30 | fps?: number;
31 | resolution: Resolution;
32 | speed: number;
33 | stats: {
34 | fps: number;
35 | };
36 | time: number;
37 | }
38 |
39 | export interface GlEnvironment {
40 | defaultUniforms: {
41 | [name: string]: DynamicVariable | DynamicVariableFn;
42 | };
43 | height: number;
44 | precision: Precision;
45 | regl: Regl;
46 | width: number;
47 | }
48 |
49 | interface HydraRendererOptions {
50 | height: number;
51 | numOutputs?: number;
52 | numSources?: number;
53 | precision?: Precision;
54 | regl: Regl;
55 | width: number;
56 | }
57 |
58 | export class Hydra {
59 | readonly loop: Loop;
60 | readonly synth: Synth;
61 | readonly outputs: Output[];
62 | readonly sources: Source[];
63 | #output: Output;
64 | readonly #renderFbo: DrawCommand;
65 | #timeSinceLastUpdate = 0;
66 |
67 | constructor({
68 | height,
69 | numOutputs = 4,
70 | numSources = 4,
71 | precision = 'mediump',
72 | regl,
73 | width,
74 | }: HydraRendererOptions) {
75 | const outputs = [];
76 | const sources = [];
77 |
78 | const synth = {
79 | bpm: 30,
80 | fps: undefined,
81 | resolution: [width, height],
82 | speed: 1,
83 | stats: {
84 | fps: 0,
85 | },
86 | time: 0,
87 | } as const;
88 |
89 | const defaultUniforms = {
90 | time: regl.prop('time'),
91 | resolution: regl.prop(
92 | 'resolution',
93 | ),
94 | };
95 |
96 | const glEnvironment = {
97 | regl,
98 | width,
99 | height,
100 | precision,
101 | defaultUniforms,
102 | };
103 |
104 | const renderFbo = regl({
105 | frag: `
106 | precision ${glEnvironment.precision} float;
107 | varying vec2 uv;
108 | uniform vec2 resolution;
109 | uniform sampler2D tex0;
110 |
111 | void main () {
112 | gl_FragColor = texture2D(tex0, vec2(1.0 - uv.x, uv.y));
113 | }
114 | `,
115 | vert: `
116 | precision ${glEnvironment.precision} float;
117 | attribute vec2 position;
118 | varying vec2 uv;
119 |
120 | void main () {
121 | uv = position;
122 | gl_Position = vec4(1.0 - 2.0 * position, 0, 1);
123 | }`,
124 | attributes: {
125 | position: [
126 | [-2, 0],
127 | [0, -2],
128 | [2, 2],
129 | ],
130 | },
131 | uniforms: {
132 | tex0: regl.prop('tex0'),
133 | resolution: regl.prop(
134 | 'resolution',
135 | ),
136 | },
137 | count: 3,
138 | depth: { enable: false },
139 | });
140 |
141 | for (let i = 0; i < numSources; i++) {
142 | const s = new Source(glEnvironment);
143 | sources.push(s);
144 | }
145 |
146 | for (let i = 0; i < numOutputs; i++) {
147 | const o = new Output(glEnvironment);
148 | outputs.push(o);
149 | }
150 |
151 | this.loop = new Loop(this.tick);
152 | this.outputs = outputs;
153 | this.sources = sources;
154 | this.synth = synth;
155 | this.#output = outputs[0];
156 | this.#renderFbo = renderFbo;
157 | }
158 |
159 | hush = () => {
160 | this.outputs.forEach((output) => {
161 | solid(1, 1, 1, 0).out(output);
162 | });
163 | };
164 |
165 | setResolution = (width: number, height: number) => {
166 | this.synth.resolution = [width, height];
167 |
168 | this.outputs.forEach((output) => {
169 | output.resize(width, height);
170 | });
171 | };
172 |
173 | render = (output?: Output) => {
174 | this.#output = output ?? this.outputs[0];
175 | };
176 |
177 | // dt in ms
178 | tick = (dt: number) => {
179 | this.synth.time += dt * 0.001 * this.synth.speed;
180 |
181 | this.#timeSinceLastUpdate += dt;
182 |
183 | if (!this.synth.fps || this.#timeSinceLastUpdate >= 1000 / this.synth.fps) {
184 | this.synth.stats.fps = Math.ceil(1000 / this.#timeSinceLastUpdate);
185 |
186 | this.sources.forEach((source) => {
187 | source.draw(this.synth);
188 | });
189 |
190 | this.outputs.forEach((output) => {
191 | output.draw(this.synth);
192 | });
193 |
194 | this.#renderFbo({
195 | tex0: this.#output.getCurrent(),
196 | resolution: this.synth.resolution,
197 | });
198 |
199 | this.#timeSinceLastUpdate = 0;
200 | }
201 | };
202 | }
203 |
--------------------------------------------------------------------------------
/src/glsl/transformDefinitions.ts:
--------------------------------------------------------------------------------
1 | /*
2 | Format for adding functions to hydra. For each entry in this file, hydra automatically generates a glsl function and javascript function with the same name. You can also ass functions dynamically using setFunction(object).
3 |
4 | {
5 | name: 'osc', // name that will be used to access function in js as well as in glsl
6 | type: 'src', // can be 'src', 'color', 'combine', 'combineCoords'. see below for more info
7 | inputs: [
8 | {
9 | name: 'freq',
10 | type: 'float',
11 | default: 0.2
12 | },
13 | {
14 | name: 'sync',
15 | type: 'float',
16 | default: 0.1
17 | },
18 | {
19 | name: 'offset',
20 | type: 'float',
21 | default: 0.0
22 | }
23 | ],
24 | glsl: `
25 | vec2 st = _st;
26 | float r = sin((st.x-offset*2/freq+time*sync)*freq)*0.5 + 0.5;
27 | float g = sin((st.x+time*sync)*freq)*0.5 + 0.5;
28 | float b = sin((st.x+offset/freq+time*sync)*freq)*0.5 + 0.5;
29 | return vec4(r, g, b, 1.0);
30 | `
31 | }
32 |
33 | // The above code generates the glsl function:
34 | `vec4 osc(vec2 _st, float freq, float sync, float offset){
35 | vec2 st = _st;
36 | float r = sin((st.x-offset*2/freq+time*sync)*freq)*0.5 + 0.5;
37 | float g = sin((st.x+time*sync)*freq)*0.5 + 0.5;
38 | float b = sin((st.x+offset/freq+time*sync)*freq)*0.5 + 0.5;
39 | return vec4(r, g, b, 1.0);
40 | }`
41 |
42 |
43 | Types and default arguments for hydra functions.
44 | The value in the 'type' field lets the parser know which type the function will be returned as well as default arguments.
45 |
46 | const types = {
47 | 'src': {
48 | returnType: 'vec4',
49 | implicitFirstArg: ['vec2 _st']
50 | },
51 | 'coord': {
52 | returnType: 'vec2',
53 | implicitFirstArg: ['vec2 _st']
54 | },
55 | 'color': {
56 | returnType: 'vec4',
57 | implicitFirstArg: ['vec4 _c0']
58 | },
59 | 'combine': {
60 | returnType: 'vec4',
61 | implicitFirstArg: ['vec4 _c0', 'vec4 _c1']
62 | },
63 | 'combineCoord': {
64 | returnType: 'vec2',
65 | implicitFirstArg: ['vec2 _st', 'vec4 _c0']
66 | }
67 | }
68 |
69 | */
70 |
71 | import { Texture2D } from 'regl';
72 |
73 | export type TransformDefinitionType =
74 | | 'src'
75 | | 'coord'
76 | | 'color'
77 | | 'combine'
78 | | 'combineCoord';
79 |
80 | export type TransformDefinitionInputTypeFloat = {
81 | type: 'float';
82 | default?:
83 | | number
84 | | number[]
85 | | ((context: any, props: any) => number | number[]);
86 | };
87 |
88 | export type TransformDefinitionInputTypeSampler2D = {
89 | type: 'sampler2D';
90 | default?: Texture2D | number;
91 | };
92 |
93 | export type TransformDefinitionInputTypeVec4 = {
94 | type: 'vec4';
95 | default?: string | number;
96 | };
97 |
98 | export type TransformDefinitionInputUnion =
99 | | TransformDefinitionInputTypeFloat
100 | | TransformDefinitionInputTypeSampler2D
101 | | TransformDefinitionInputTypeVec4;
102 |
103 | export type TransformDefinitionInput = TransformDefinitionInputUnion & {
104 | name: string;
105 | vecLen?: number;
106 | };
107 |
108 | export interface TransformDefinition {
109 | name: string;
110 | type: TransformDefinitionType;
111 | inputs: readonly TransformDefinitionInput[];
112 | glsl: string;
113 | }
114 |
115 | export interface ProcessedTransformDefinition extends TransformDefinition {
116 | processed: true;
117 | }
118 |
119 | export const generatorTransforms = [
120 | {
121 | name: 'noise',
122 | type: 'src',
123 | inputs: [
124 | {
125 | type: 'float',
126 | name: 'scale',
127 | default: 10,
128 | },
129 | {
130 | type: 'float',
131 | name: 'offset',
132 | default: 0.1,
133 | },
134 | ],
135 | glsl: ` return vec4(vec3(_noise(vec3(_st*scale, offset*time))), 1.0);`,
136 | },
137 | {
138 | name: 'voronoi',
139 | type: 'src',
140 | inputs: [
141 | {
142 | type: 'float',
143 | name: 'scale',
144 | default: 5,
145 | },
146 | {
147 | type: 'float',
148 | name: 'speed',
149 | default: 0.3,
150 | },
151 | {
152 | type: 'float',
153 | name: 'blending',
154 | default: 0.3,
155 | },
156 | ],
157 | glsl: ` vec3 color = vec3(.0);
158 | // Scale
159 | _st *= scale;
160 | // Tile the space
161 | vec2 i_st = floor(_st);
162 | vec2 f_st = fract(_st);
163 | float m_dist = 10.; // minimun distance
164 | vec2 m_point; // minimum point
165 | for (int j=-1; j<=1; j++ ) {
166 | for (int i=-1; i<=1; i++ ) {
167 | vec2 neighbor = vec2(float(i),float(j));
168 | vec2 p = i_st + neighbor;
169 | vec2 point = fract(sin(vec2(dot(p,vec2(127.1,311.7)),dot(p,vec2(269.5,183.3))))*43758.5453);
170 | point = 0.5 + 0.5*sin(time*speed + 6.2831*point);
171 | vec2 diff = neighbor + point - f_st;
172 | float dist = length(diff);
173 | if( dist < m_dist ) {
174 | m_dist = dist;
175 | m_point = point;
176 | }
177 | }
178 | }
179 | // Assign a color using the closest point position
180 | color += dot(m_point,vec2(.3,.6));
181 | color *= 1.0 - blending*m_dist;
182 | return vec4(color, 1.0);`,
183 | },
184 | {
185 | name: 'osc',
186 | type: 'src',
187 | inputs: [
188 | {
189 | type: 'float',
190 | name: 'frequency',
191 | default: 60,
192 | },
193 | {
194 | type: 'float',
195 | name: 'sync',
196 | default: 0.1,
197 | },
198 | {
199 | type: 'float',
200 | name: 'offset',
201 | default: 0,
202 | },
203 | ],
204 | glsl: ` vec2 st = _st;
205 | float r = sin((st.x-offset/frequency+time*sync)*frequency)*0.5 + 0.5;
206 | float g = sin((st.x+time*sync)*frequency)*0.5 + 0.5;
207 | float b = sin((st.x+offset/frequency+time*sync)*frequency)*0.5 + 0.5;
208 | return vec4(r, g, b, 1.0);`,
209 | },
210 | {
211 | name: 'shape',
212 | type: 'src',
213 | inputs: [
214 | {
215 | type: 'float',
216 | name: 'sides',
217 | default: 3,
218 | },
219 | {
220 | type: 'float',
221 | name: 'radius',
222 | default: 0.3,
223 | },
224 | {
225 | type: 'float',
226 | name: 'smoothing',
227 | default: 0.01,
228 | },
229 | ],
230 | glsl: ` vec2 st = _st * 2. - 1.;
231 | // Angle and radius from the current pixel
232 | float a = atan(st.x,st.y)+3.1416;
233 | float r = (2.*3.1416)/sides;
234 | float d = cos(floor(.5+a/r)*r-a)*length(st);
235 | return vec4(vec3(1.0-smoothstep(radius,radius + smoothing + 0.0000001,d)), 1.0);`,
236 | },
237 | {
238 | name: 'gradient',
239 | type: 'src',
240 | inputs: [
241 | {
242 | type: 'float',
243 | name: 'speed',
244 | default: 0,
245 | },
246 | ],
247 | glsl: ` return vec4(_st, sin(time*speed), 1.0);`,
248 | },
249 | {
250 | name: 'src',
251 | type: 'src',
252 | inputs: [
253 | {
254 | type: 'sampler2D',
255 | name: 'tex',
256 | default: NaN,
257 | },
258 | ],
259 | glsl: `return texture2D(tex, fract(_st));`,
260 | },
261 | {
262 | name: 'solid',
263 | type: 'src',
264 | inputs: [
265 | {
266 | type: 'float',
267 | name: 'r',
268 | default: 0,
269 | },
270 | {
271 | type: 'float',
272 | name: 'g',
273 | default: 0,
274 | },
275 | {
276 | type: 'float',
277 | name: 'b',
278 | default: 0,
279 | },
280 | {
281 | type: 'float',
282 | name: 'a',
283 | default: 1,
284 | },
285 | ],
286 | glsl: ` return vec4(r, g, b, a);`,
287 | },
288 | ] as const;
289 |
290 | export const modifierTransforms = [
291 | {
292 | name: 'rotate',
293 | type: 'coord',
294 | inputs: [
295 | {
296 | type: 'float',
297 | name: 'angle',
298 | default: 10,
299 | },
300 | {
301 | type: 'float',
302 | name: 'speed',
303 | default: 0,
304 | },
305 | ],
306 | glsl: ` vec2 xy = _st - vec2(0.5);
307 | float ang = angle + speed *time;
308 | xy = mat2(cos(ang),-sin(ang), sin(ang),cos(ang))*xy;
309 | xy += 0.5;
310 | return xy;`,
311 | },
312 | {
313 | name: 'scale',
314 | type: 'coord',
315 | inputs: [
316 | {
317 | type: 'float',
318 | name: 'amount',
319 | default: 1.5,
320 | },
321 | {
322 | type: 'float',
323 | name: 'xMult',
324 | default: 1,
325 | },
326 | {
327 | type: 'float',
328 | name: 'yMult',
329 | default: 1,
330 | },
331 | {
332 | type: 'float',
333 | name: 'offsetX',
334 | default: 0.5,
335 | },
336 | {
337 | type: 'float',
338 | name: 'offsetY',
339 | default: 0.5,
340 | },
341 | ],
342 | glsl: ` vec2 xy = _st - vec2(offsetX, offsetY);
343 | xy*=(1.0/vec2(amount*xMult, amount*yMult));
344 | xy+=vec2(offsetX, offsetY);
345 | return xy;
346 | `,
347 | },
348 | {
349 | name: 'pixelate',
350 | type: 'coord',
351 | inputs: [
352 | {
353 | type: 'float',
354 | name: 'pixelX',
355 | default: 20,
356 | },
357 | {
358 | type: 'float',
359 | name: 'pixelY',
360 | default: 20,
361 | },
362 | ],
363 | glsl: ` vec2 xy = vec2(pixelX, pixelY);
364 | return (floor(_st * xy) + 0.5)/xy;`,
365 | },
366 | {
367 | name: 'posterize',
368 | type: 'color',
369 | inputs: [
370 | {
371 | type: 'float',
372 | name: 'bins',
373 | default: 3,
374 | },
375 | {
376 | type: 'float',
377 | name: 'gamma',
378 | default: 0.6,
379 | },
380 | ],
381 | glsl: ` vec4 c2 = pow(_c0, vec4(gamma));
382 | c2 *= vec4(bins);
383 | c2 = floor(c2);
384 | c2/= vec4(bins);
385 | c2 = pow(c2, vec4(1.0/gamma));
386 | return vec4(c2.xyz, _c0.a);`,
387 | },
388 | {
389 | name: 'shift',
390 | type: 'color',
391 | inputs: [
392 | {
393 | type: 'float',
394 | name: 'r',
395 | default: 0.5,
396 | },
397 | {
398 | type: 'float',
399 | name: 'g',
400 | default: 0,
401 | },
402 | {
403 | type: 'float',
404 | name: 'b',
405 | default: 0,
406 | },
407 | {
408 | type: 'float',
409 | name: 'a',
410 | default: 0,
411 | },
412 | ],
413 | glsl: ` vec4 c2 = vec4(_c0);
414 | c2.r = fract(c2.r + r);
415 | c2.g = fract(c2.g + g);
416 | c2.b = fract(c2.b + b);
417 | c2.a = fract(c2.a + a);
418 | return vec4(c2.rgba);`,
419 | },
420 | {
421 | name: 'repeat',
422 | type: 'coord',
423 | inputs: [
424 | {
425 | type: 'float',
426 | name: 'repeatX',
427 | default: 3,
428 | },
429 | {
430 | type: 'float',
431 | name: 'repeatY',
432 | default: 3,
433 | },
434 | {
435 | type: 'float',
436 | name: 'offsetX',
437 | default: 0,
438 | },
439 | {
440 | type: 'float',
441 | name: 'offsetY',
442 | default: 0,
443 | },
444 | ],
445 | glsl: ` vec2 st = _st * vec2(repeatX, repeatY);
446 | st.x += step(1., mod(st.y,2.0)) * offsetX;
447 | st.y += step(1., mod(st.x,2.0)) * offsetY;
448 | return fract(st);`,
449 | },
450 | {
451 | name: 'modulateRepeat',
452 | type: 'combineCoord',
453 | inputs: [
454 | {
455 | name: 'color',
456 | type: 'vec4',
457 | vecLen: 4,
458 | },
459 | {
460 | type: 'float',
461 | name: 'repeatX',
462 | default: 3,
463 | },
464 | {
465 | type: 'float',
466 | name: 'repeatY',
467 | default: 3,
468 | },
469 | {
470 | type: 'float',
471 | name: 'offsetX',
472 | default: 0.5,
473 | },
474 | {
475 | type: 'float',
476 | name: 'offsetY',
477 | default: 0.5,
478 | },
479 | ],
480 | glsl: ` vec2 st = _st * vec2(repeatX, repeatY);
481 | st.x += step(1., mod(st.y,2.0)) + color.r * offsetX;
482 | st.y += step(1., mod(st.x,2.0)) + color.g * offsetY;
483 | return fract(st);`,
484 | },
485 | {
486 | name: 'repeatX',
487 | type: 'coord',
488 | inputs: [
489 | {
490 | type: 'float',
491 | name: 'reps',
492 | default: 3,
493 | },
494 | {
495 | type: 'float',
496 | name: 'offset',
497 | default: 0,
498 | },
499 | ],
500 | glsl: ` vec2 st = _st * vec2(reps, 1.0);
501 | // float f = mod(_st.y,2.0);
502 | st.y += step(1., mod(st.x,2.0))* offset;
503 | return fract(st);`,
504 | },
505 | {
506 | name: 'modulateRepeatX',
507 | type: 'combineCoord',
508 | inputs: [
509 | {
510 | name: 'color',
511 | type: 'vec4',
512 | vecLen: 4,
513 | },
514 | {
515 | type: 'float',
516 | name: 'reps',
517 | default: 3,
518 | },
519 | {
520 | type: 'float',
521 | name: 'offset',
522 | default: 0.5,
523 | },
524 | ],
525 | glsl: ` vec2 st = _st * vec2(reps, 1.0);
526 | // float f = mod(_st.y,2.0);
527 | st.y += step(1., mod(st.x,2.0)) + color.r * offset;
528 | return fract(st);`,
529 | },
530 | {
531 | name: 'repeatY',
532 | type: 'coord',
533 | inputs: [
534 | {
535 | type: 'float',
536 | name: 'reps',
537 | default: 3,
538 | },
539 | {
540 | type: 'float',
541 | name: 'offset',
542 | default: 0,
543 | },
544 | ],
545 | glsl: ` vec2 st = _st * vec2(1.0, reps);
546 | // float f = mod(_st.y,2.0);
547 | st.x += step(1., mod(st.y,2.0))* offset;
548 | return fract(st);`,
549 | },
550 | {
551 | name: 'modulateRepeatY',
552 | type: 'combineCoord',
553 | inputs: [
554 | {
555 | name: 'color',
556 | type: 'vec4',
557 | vecLen: 4,
558 | },
559 | {
560 | type: 'float',
561 | name: 'reps',
562 | default: 3,
563 | },
564 | {
565 | type: 'float',
566 | name: 'offset',
567 | default: 0.5,
568 | },
569 | ],
570 | glsl: ` vec2 st = _st * vec2(reps, 1.0);
571 | // float f = mod(_st.y,2.0);
572 | st.x += step(1., mod(st.y,2.0)) + color.r * offset;
573 | return fract(st);`,
574 | },
575 | {
576 | name: 'kaleid',
577 | type: 'coord',
578 | inputs: [
579 | {
580 | type: 'float',
581 | name: 'nSides',
582 | default: 4,
583 | },
584 | ],
585 | glsl: ` vec2 st = _st;
586 | st -= 0.5;
587 | float r = length(st);
588 | float a = atan(st.y, st.x);
589 | float pi = 2.*3.1416;
590 | a = mod(a,pi/nSides);
591 | a = abs(a-pi/nSides/2.);
592 | return r*vec2(cos(a), sin(a));`,
593 | },
594 | {
595 | name: 'modulateKaleid',
596 | type: 'combineCoord',
597 | inputs: [
598 | {
599 | name: 'color',
600 | type: 'vec4',
601 | vecLen: 4,
602 | },
603 | {
604 | type: 'float',
605 | name: 'nSides',
606 | default: 4,
607 | },
608 | ],
609 | glsl: ` vec2 st = _st - 0.5;
610 | float r = length(st);
611 | float a = atan(st.y, st.x);
612 | float pi = 2.*3.1416;
613 | a = mod(a,pi/nSides);
614 | a = abs(a-pi/nSides/2.);
615 | return (color.r+r)*vec2(cos(a), sin(a));`,
616 | },
617 | {
618 | name: 'scroll',
619 | type: 'coord',
620 | inputs: [
621 | {
622 | type: 'float',
623 | name: 'scrollX',
624 | default: 0.5,
625 | },
626 | {
627 | type: 'float',
628 | name: 'scrollY',
629 | default: 0.5,
630 | },
631 | {
632 | type: 'float',
633 | name: 'speedX',
634 | default: 0,
635 | },
636 | {
637 | type: 'float',
638 | name: 'speedY',
639 | default: 0,
640 | },
641 | ],
642 | glsl: `
643 | _st.x += scrollX + time*speedX;
644 | _st.y += scrollY + time*speedY;
645 | return fract(_st);`,
646 | },
647 | {
648 | name: 'scrollX',
649 | type: 'coord',
650 | inputs: [
651 | {
652 | type: 'float',
653 | name: 'scrollX',
654 | default: 0.5,
655 | },
656 | {
657 | type: 'float',
658 | name: 'speed',
659 | default: 0,
660 | },
661 | ],
662 | glsl: ` _st.x += scrollX + time*speed;
663 | return fract(_st);`,
664 | },
665 | {
666 | name: 'modulateScrollX',
667 | type: 'combineCoord',
668 | inputs: [
669 | {
670 | name: 'color',
671 | type: 'vec4',
672 | vecLen: 4,
673 | },
674 | {
675 | type: 'float',
676 | name: 'scrollX',
677 | default: 0.5,
678 | },
679 | {
680 | type: 'float',
681 | name: 'speed',
682 | default: 0,
683 | },
684 | ],
685 | glsl: ` _st.x += color.r*scrollX + time*speed;
686 | return fract(_st);`,
687 | },
688 | {
689 | name: 'scrollY',
690 | type: 'coord',
691 | inputs: [
692 | {
693 | type: 'float',
694 | name: 'scrollY',
695 | default: 0.5,
696 | },
697 | {
698 | type: 'float',
699 | name: 'speed',
700 | default: 0,
701 | },
702 | ],
703 | glsl: ` _st.y += scrollY + time*speed;
704 | return fract(_st);`,
705 | },
706 | {
707 | name: 'modulateScrollY',
708 | type: 'combineCoord',
709 | inputs: [
710 | {
711 | name: 'color',
712 | type: 'vec4',
713 | vecLen: 4,
714 | },
715 | {
716 | type: 'float',
717 | name: 'scrollY',
718 | default: 0.5,
719 | },
720 | {
721 | type: 'float',
722 | name: 'speed',
723 | default: 0,
724 | },
725 | ],
726 | glsl: ` _st.y += color.r*scrollY + time*speed;
727 | return fract(_st);`,
728 | },
729 | {
730 | name: 'add',
731 | type: 'combine',
732 | inputs: [
733 | {
734 | name: 'color',
735 | type: 'vec4',
736 | vecLen: 4,
737 | },
738 | {
739 | type: 'float',
740 | name: 'amount',
741 | default: 1,
742 | },
743 | ],
744 | glsl: ` return (_c0+color)*amount + _c0*(1.0-amount);`,
745 | },
746 | {
747 | name: 'sub',
748 | type: 'combine',
749 | inputs: [
750 | {
751 | name: 'color',
752 | type: 'vec4',
753 | vecLen: 4,
754 | },
755 | {
756 | type: 'float',
757 | name: 'amount',
758 | default: 1,
759 | },
760 | ],
761 | glsl: ` return (_c0-color)*amount + _c0*(1.0-amount);`,
762 | },
763 | {
764 | name: 'layer',
765 | type: 'combine',
766 | inputs: [
767 | {
768 | name: 'color',
769 | type: 'vec4',
770 | vecLen: 4,
771 | },
772 | ],
773 | glsl: ` return vec4(mix(_c0.rgb, color.rgb, color.a), _c0.a+color.a);`,
774 | },
775 | {
776 | name: 'blend',
777 | type: 'combine',
778 | inputs: [
779 | {
780 | name: 'color',
781 | type: 'vec4',
782 | vecLen: 4,
783 | },
784 | {
785 | type: 'float',
786 | name: 'amount',
787 | default: 0.5,
788 | },
789 | ],
790 | glsl: ` return _c0*(1.0-amount)+color*amount;`,
791 | },
792 | {
793 | name: 'mult',
794 | type: 'combine',
795 | inputs: [
796 | {
797 | name: 'color',
798 | type: 'vec4',
799 | vecLen: 4,
800 | },
801 | {
802 | type: 'float',
803 | name: 'amount',
804 | default: 1,
805 | },
806 | ],
807 | glsl: ` return _c0*(1.0-amount)+(_c0*color)*amount;`,
808 | },
809 | {
810 | name: 'diff',
811 | type: 'combine',
812 | inputs: [
813 | {
814 | name: 'color',
815 | type: 'vec4',
816 | vecLen: 4,
817 | },
818 | ],
819 | glsl: ` return vec4(abs(_c0.rgb-color.rgb), max(_c0.a, color.a));`,
820 | },
821 | {
822 | name: 'modulate',
823 | type: 'combineCoord',
824 | inputs: [
825 | {
826 | name: 'color',
827 | type: 'vec4',
828 | vecLen: 4,
829 | },
830 | {
831 | type: 'float',
832 | name: 'amount',
833 | default: 0.1,
834 | },
835 | ],
836 | glsl: ` // return fract(st+(color.xy-0.5)*amount);
837 | return _st + color.xy*amount;`,
838 | },
839 | {
840 | name: 'modulateScale',
841 | type: 'combineCoord',
842 | inputs: [
843 | {
844 | name: 'color',
845 | type: 'vec4',
846 | vecLen: 4,
847 | },
848 | {
849 | type: 'float',
850 | name: 'multiple',
851 | default: 1,
852 | },
853 | {
854 | type: 'float',
855 | name: 'offset',
856 | default: 1,
857 | },
858 | ],
859 | glsl: ` vec2 xy = _st - vec2(0.5);
860 | xy*=(1.0/vec2(offset + multiple*color.r, offset + multiple*color.g));
861 | xy+=vec2(0.5);
862 | return xy;`,
863 | },
864 | {
865 | name: 'modulatePixelate',
866 | type: 'combineCoord',
867 | inputs: [
868 | {
869 | name: 'color',
870 | type: 'vec4',
871 | vecLen: 4,
872 | },
873 | {
874 | type: 'float',
875 | name: 'multiple',
876 | default: 10,
877 | },
878 | {
879 | type: 'float',
880 | name: 'offset',
881 | default: 3,
882 | },
883 | ],
884 | glsl: ` vec2 xy = vec2(offset + color.x*multiple, offset + color.y*multiple);
885 | return (floor(_st * xy) + 0.5)/xy;`,
886 | },
887 | {
888 | name: 'modulateRotate',
889 | type: 'combineCoord',
890 | inputs: [
891 | {
892 | name: 'color',
893 | type: 'vec4',
894 | vecLen: 4,
895 | },
896 | {
897 | type: 'float',
898 | name: 'multiple',
899 | default: 1,
900 | },
901 | {
902 | type: 'float',
903 | name: 'offset',
904 | default: 0,
905 | },
906 | ],
907 | glsl: ` vec2 xy = _st - vec2(0.5);
908 | float angle = offset + color.x * multiple;
909 | xy = mat2(cos(angle),-sin(angle), sin(angle),cos(angle))*xy;
910 | xy += 0.5;
911 | return xy;`,
912 | },
913 | {
914 | name: 'modulateHue',
915 | type: 'combineCoord',
916 | inputs: [
917 | {
918 | name: 'color',
919 | type: 'vec4',
920 | vecLen: 4,
921 | },
922 | {
923 | type: 'float',
924 | name: 'amount',
925 | default: 1,
926 | },
927 | ],
928 | glsl: ` return _st + (vec2(color.g - color.r, color.b - color.g) * amount * 1.0/resolution);`,
929 | },
930 | {
931 | name: 'invert',
932 | type: 'color',
933 | inputs: [
934 | {
935 | type: 'float',
936 | name: 'amount',
937 | default: 1,
938 | },
939 | ],
940 | glsl: ` return vec4((1.0-_c0.rgb)*amount + _c0.rgb*(1.0-amount), _c0.a);`,
941 | },
942 | {
943 | name: 'contrast',
944 | type: 'color',
945 | inputs: [
946 | {
947 | type: 'float',
948 | name: 'amount',
949 | default: 1.6,
950 | },
951 | ],
952 | glsl: ` vec4 c = (_c0-vec4(0.5))*vec4(amount) + vec4(0.5);
953 | return vec4(c.rgb, _c0.a);`,
954 | },
955 | {
956 | name: 'brightness',
957 | type: 'color',
958 | inputs: [
959 | {
960 | type: 'float',
961 | name: 'amount',
962 | default: 0.4,
963 | },
964 | ],
965 | glsl: ` return vec4(_c0.rgb + vec3(amount), _c0.a);`,
966 | },
967 | {
968 | name: 'mask',
969 | type: 'combine',
970 | inputs: [
971 | {
972 | name: 'color',
973 | type: 'vec4',
974 | vecLen: 4,
975 | },
976 | ],
977 | glsl: ` float a = _luminance(color.rgb);
978 | return vec4(_c0.rgb*a, a);`,
979 | },
980 | {
981 | name: 'luma',
982 | type: 'color',
983 | inputs: [
984 | {
985 | type: 'float',
986 | name: 'threshold',
987 | default: 0.5,
988 | },
989 | {
990 | type: 'float',
991 | name: 'tolerance',
992 | default: 0.1,
993 | },
994 | ],
995 | glsl: ` float a = smoothstep(threshold-(tolerance+0.0000001), threshold+(tolerance+0.0000001), _luminance(_c0.rgb));
996 | return vec4(_c0.rgb*a, a);`,
997 | },
998 | {
999 | name: 'thresh',
1000 | type: 'color',
1001 | inputs: [
1002 | {
1003 | type: 'float',
1004 | name: 'threshold',
1005 | default: 0.5,
1006 | },
1007 | {
1008 | type: 'float',
1009 | name: 'tolerance',
1010 | default: 0.04,
1011 | },
1012 | ],
1013 | glsl: ` return vec4(vec3(smoothstep(threshold-(tolerance+0.0000001), threshold+(tolerance+0.0000001), _luminance(_c0.rgb))), _c0.a);`,
1014 | },
1015 | {
1016 | name: 'color',
1017 | type: 'color',
1018 | inputs: [
1019 | {
1020 | type: 'float',
1021 | name: 'r',
1022 | default: 1,
1023 | },
1024 | {
1025 | type: 'float',
1026 | name: 'g',
1027 | default: 1,
1028 | },
1029 | {
1030 | type: 'float',
1031 | name: 'b',
1032 | default: 1,
1033 | },
1034 | {
1035 | type: 'float',
1036 | name: 'a',
1037 | default: 1,
1038 | },
1039 | ],
1040 | glsl: ` vec4 c = vec4(r, g, b, a);
1041 | vec4 pos = step(0.0, c); // detect whether negative
1042 | // if > 0, return r * _c0
1043 | // if < 0 return (1.0-r) * _c0
1044 | return vec4(mix((1.0-_c0)*abs(c), c*_c0, pos));`,
1045 | },
1046 | {
1047 | name: 'saturate',
1048 | type: 'color',
1049 | inputs: [
1050 | {
1051 | type: 'float',
1052 | name: 'amount',
1053 | default: 2,
1054 | },
1055 | ],
1056 | glsl: ` const vec3 W = vec3(0.2125, 0.7154, 0.0721);
1057 | vec3 intensity = vec3(dot(_c0.rgb, W));
1058 | return vec4(mix(intensity, _c0.rgb, amount), _c0.a);`,
1059 | },
1060 | {
1061 | name: 'hue',
1062 | type: 'color',
1063 | inputs: [
1064 | {
1065 | type: 'float',
1066 | name: 'hue',
1067 | default: 0.4,
1068 | },
1069 | ],
1070 | glsl: ` vec3 c = _rgbToHsv(_c0.rgb);
1071 | c.r += hue;
1072 | // c.r = fract(c.r);
1073 | return vec4(_hsvToRgb(c), _c0.a);`,
1074 | },
1075 | {
1076 | name: 'colorama',
1077 | type: 'color',
1078 | inputs: [
1079 | {
1080 | type: 'float',
1081 | name: 'amount',
1082 | default: 0.005,
1083 | },
1084 | ],
1085 | glsl: ` vec3 c = _rgbToHsv(_c0.rgb);
1086 | c += vec3(amount);
1087 | c = _hsvToRgb(c);
1088 | c = fract(c);
1089 | return vec4(c, _c0.a);`,
1090 | },
1091 | {
1092 | name: 'sum',
1093 | type: 'color',
1094 | inputs: [
1095 | {
1096 | type: 'vec4',
1097 | name: 'scale',
1098 | default: 1,
1099 | },
1100 | ],
1101 | glsl: ` vec4 v = _c0 * s;
1102 | return v.r + v.g + v.b + v.a;
1103 | }
1104 | float sum(vec2 _st, vec4 s) { // vec4 is not a typo, because argument type is not overloaded
1105 | vec2 v = _st.xy * s.xy;
1106 | return v.x + v.y;`,
1107 | },
1108 | {
1109 | name: 'r',
1110 | type: 'color',
1111 | inputs: [
1112 | {
1113 | type: 'float',
1114 | name: 'scale',
1115 | default: 1,
1116 | },
1117 | {
1118 | type: 'float',
1119 | name: 'offset',
1120 | default: 0,
1121 | },
1122 | ],
1123 | glsl: ` return vec4(_c0.r * scale + offset);`,
1124 | },
1125 | {
1126 | name: 'g',
1127 | type: 'color',
1128 | inputs: [
1129 | {
1130 | type: 'float',
1131 | name: 'scale',
1132 | default: 1,
1133 | },
1134 | {
1135 | type: 'float',
1136 | name: 'offset',
1137 | default: 0,
1138 | },
1139 | ],
1140 | glsl: ` return vec4(_c0.g * scale + offset);`,
1141 | },
1142 | {
1143 | name: 'b',
1144 | type: 'color',
1145 | inputs: [
1146 | {
1147 | type: 'float',
1148 | name: 'scale',
1149 | default: 1,
1150 | },
1151 | {
1152 | type: 'float',
1153 | name: 'offset',
1154 | default: 0,
1155 | },
1156 | ],
1157 | glsl: ` return vec4(_c0.b * scale + offset);`,
1158 | },
1159 | {
1160 | name: 'a',
1161 | type: 'color',
1162 | inputs: [
1163 | {
1164 | type: 'float',
1165 | name: 'scale',
1166 | default: 1,
1167 | },
1168 | {
1169 | type: 'float',
1170 | name: 'offset',
1171 | default: 0,
1172 | },
1173 | ],
1174 | glsl: ` return vec4(_c0.a * scale + offset);`,
1175 | },
1176 | ] as const;
1177 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU AFFERO GENERAL PUBLIC LICENSE
2 | Version 3, 19 November 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU Affero General Public License is a free, copyleft license for
11 | software and other kinds of works, specifically designed to ensure
12 | cooperation with the community in the case of network server software.
13 |
14 | The licenses for most software and other practical works are designed
15 | to take away your freedom to share and change the works. By contrast,
16 | our General Public Licenses are intended to guarantee your freedom to
17 | share and change all versions of a program--to make sure it remains free
18 | software for all its users.
19 |
20 | When we speak of free software, we are referring to freedom, not
21 | price. Our General Public Licenses are designed to make sure that you
22 | have the freedom to distribute copies of free software (and charge for
23 | them if you wish), that you receive source code or can get it if you
24 | want it, that you can change the software or use pieces of it in new
25 | free programs, and that you know you can do these things.
26 |
27 | Developers that use our General Public Licenses protect your rights
28 | with two steps: (1) assert copyright on the software, and (2) offer
29 | you this License which gives you legal permission to copy, distribute
30 | and/or modify the software.
31 |
32 | A secondary benefit of defending all users' freedom is that
33 | improvements made in alternate versions of the program, if they
34 | receive widespread use, become available for other developers to
35 | incorporate. Many developers of free software are heartened and
36 | encouraged by the resulting cooperation. However, in the case of
37 | software used on network servers, this result may fail to come about.
38 | The GNU General Public License permits making a modified version and
39 | letting the public access it on a server without ever releasing its
40 | source code to the public.
41 |
42 | The GNU Affero General Public License is designed specifically to
43 | ensure that, in such cases, the modified source code becomes available
44 | to the community. It requires the operator of a network server to
45 | provide the source code of the modified version running there to the
46 | users of that server. Therefore, public use of a modified version, on
47 | a publicly accessible server, gives the public access to the source
48 | code of the modified version.
49 |
50 | An older license, called the Affero General Public License and
51 | published by Affero, was designed to accomplish similar goals. This is
52 | a different license, not a version of the Affero GPL, but Affero has
53 | released a new version of the Affero GPL which permits relicensing under
54 | this license.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | TERMS AND CONDITIONS
60 |
61 | 0. Definitions.
62 |
63 | "This License" refers to version 3 of the GNU Affero General Public License.
64 |
65 | "Copyright" also means copyright-like laws that apply to other kinds of
66 | works, such as semiconductor masks.
67 |
68 | "The Program" refers to any copyrightable work licensed under this
69 | License. Each licensee is addressed as "you". "Licensees" and
70 | "recipients" may be individuals or organizations.
71 |
72 | To "modify" a work means to copy from or adapt all or part of the work
73 | in a fashion requiring copyright permission, other than the making of an
74 | exact copy. The resulting work is called a "modified version" of the
75 | earlier work or a work "based on" the earlier work.
76 |
77 | A "covered work" means either the unmodified Program or a work based
78 | on the Program.
79 |
80 | To "propagate" a work means to do anything with it that, without
81 | permission, would make you directly or secondarily liable for
82 | infringement under applicable copyright law, except executing it on a
83 | computer or modifying a private copy. Propagation includes copying,
84 | distribution (with or without modification), making available to the
85 | public, and in some countries other activities as well.
86 |
87 | To "convey" a work means any kind of propagation that enables other
88 | parties to make or receive copies. Mere interaction with a user through
89 | a computer network, with no transfer of a copy, is not conveying.
90 |
91 | An interactive user interface displays "Appropriate Legal Notices"
92 | to the extent that it includes a convenient and prominently visible
93 | feature that (1) displays an appropriate copyright notice, and (2)
94 | tells the user that there is no warranty for the work (except to the
95 | extent that warranties are provided), that licensees may convey the
96 | work under this License, and how to view a copy of this License. If
97 | the interface presents a list of user commands or options, such as a
98 | menu, a prominent item in the list meets this criterion.
99 |
100 | 1. Source Code.
101 |
102 | The "source code" for a work means the preferred form of the work
103 | for making modifications to it. "Object code" means any non-source
104 | form of a work.
105 |
106 | A "Standard Interface" means an interface that either is an official
107 | standard defined by a recognized standards body, or, in the case of
108 | interfaces specified for a particular programming language, one that
109 | is widely used among developers working in that language.
110 |
111 | The "System Libraries" of an executable work include anything, other
112 | than the work as a whole, that (a) is included in the normal form of
113 | packaging a Major Component, but which is not part of that Major
114 | Component, and (b) serves only to enable use of the work with that
115 | Major Component, or to implement a Standard Interface for which an
116 | implementation is available to the public in source code form. A
117 | "Major Component", in this context, means a major essential component
118 | (kernel, window system, and so on) of the specific operating system
119 | (if any) on which the executable work runs, or a compiler used to
120 | produce the work, or an object code interpreter used to run it.
121 |
122 | The "Corresponding Source" for a work in object code form means all
123 | the source code needed to generate, install, and (for an executable
124 | work) run the object code and to modify the work, including scripts to
125 | control those activities. However, it does not include the work's
126 | System Libraries, or general-purpose tools or generally available free
127 | programs which are used unmodified in performing those activities but
128 | which are not part of the work. For example, Corresponding Source
129 | includes interface definition files associated with source files for
130 | the work, and the source code for shared libraries and dynamically
131 | linked subprograms that the work is specifically designed to require,
132 | such as by intimate data communication or control flow between those
133 | subprograms and other parts of the work.
134 |
135 | The Corresponding Source need not include anything that users
136 | can regenerate automatically from other parts of the Corresponding
137 | Source.
138 |
139 | The Corresponding Source for a work in source code form is that
140 | same work.
141 |
142 | 2. Basic Permissions.
143 |
144 | All rights granted under this License are granted for the term of
145 | copyright on the Program, and are irrevocable provided the stated
146 | conditions are met. This License explicitly affirms your unlimited
147 | permission to run the unmodified Program. The output from running a
148 | covered work is covered by this License only if the output, given its
149 | content, constitutes a covered work. This License acknowledges your
150 | rights of fair use or other equivalent, as provided by copyright law.
151 |
152 | You may make, run and propagate covered works that you do not
153 | convey, without conditions so long as your license otherwise remains
154 | in force. You may convey covered works to others for the sole purpose
155 | of having them make modifications exclusively for you, or provide you
156 | with facilities for running those works, provided that you comply with
157 | the terms of this License in conveying all material for which you do
158 | not control copyright. Those thus making or running the covered works
159 | for you must do so exclusively on your behalf, under your direction
160 | and control, on terms that prohibit them from making any copies of
161 | your copyrighted material outside their relationship with you.
162 |
163 | Conveying under any other circumstances is permitted solely under
164 | the conditions stated below. Sublicensing is not allowed; section 10
165 | makes it unnecessary.
166 |
167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
168 |
169 | No covered work shall be deemed part of an effective technological
170 | measure under any applicable law fulfilling obligations under article
171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
172 | similar laws prohibiting or restricting circumvention of such
173 | measures.
174 |
175 | When you convey a covered work, you waive any legal power to forbid
176 | circumvention of technological measures to the extent such circumvention
177 | is effected by exercising rights under this License with respect to
178 | the covered work, and you disclaim any intention to limit operation or
179 | modification of the work as a means of enforcing, against the work's
180 | users, your or third parties' legal rights to forbid circumvention of
181 | technological measures.
182 |
183 | 4. Conveying Verbatim Copies.
184 |
185 | You may convey verbatim copies of the Program's source code as you
186 | receive it, in any medium, provided that you conspicuously and
187 | appropriately publish on each copy an appropriate copyright notice;
188 | keep intact all notices stating that this License and any
189 | non-permissive terms added in accord with section 7 apply to the code;
190 | keep intact all notices of the absence of any warranty; and give all
191 | recipients a copy of this License along with the Program.
192 |
193 | You may charge any price or no price for each copy that you convey,
194 | and you may offer support or warranty protection for a fee.
195 |
196 | 5. Conveying Modified Source Versions.
197 |
198 | You may convey a work based on the Program, or the modifications to
199 | produce it from the Program, in the form of source code under the
200 | terms of section 4, provided that you also meet all of these conditions:
201 |
202 | a) The work must carry prominent notices stating that you modified
203 | it, and giving a relevant date.
204 |
205 | b) The work must carry prominent notices stating that it is
206 | released under this License and any conditions added under section
207 | 7. This requirement modifies the requirement in section 4 to
208 | "keep intact all notices".
209 |
210 | c) You must license the entire work, as a whole, under this
211 | License to anyone who comes into possession of a copy. This
212 | License will therefore apply, along with any applicable section 7
213 | additional terms, to the whole of the work, and all its parts,
214 | regardless of how they are packaged. This License gives no
215 | permission to license the work in any other way, but it does not
216 | invalidate such permission if you have separately received it.
217 |
218 | d) If the work has interactive user interfaces, each must display
219 | Appropriate Legal Notices; however, if the Program has interactive
220 | interfaces that do not display Appropriate Legal Notices, your
221 | work need not make them do so.
222 |
223 | A compilation of a covered work with other separate and independent
224 | works, which are not by their nature extensions of the covered work,
225 | and which are not combined with it such as to form a larger program,
226 | in or on a volume of a storage or distribution medium, is called an
227 | "aggregate" if the compilation and its resulting copyright are not
228 | used to limit the access or legal rights of the compilation's users
229 | beyond what the individual works permit. Inclusion of a covered work
230 | in an aggregate does not cause this License to apply to the other
231 | parts of the aggregate.
232 |
233 | 6. Conveying Non-Source Forms.
234 |
235 | You may convey a covered work in object code form under the terms
236 | of sections 4 and 5, provided that you also convey the
237 | machine-readable Corresponding Source under the terms of this License,
238 | in one of these ways:
239 |
240 | a) Convey the object code in, or embodied in, a physical product
241 | (including a physical distribution medium), accompanied by the
242 | Corresponding Source fixed on a durable physical medium
243 | customarily used for software interchange.
244 |
245 | b) Convey the object code in, or embodied in, a physical product
246 | (including a physical distribution medium), accompanied by a
247 | written offer, valid for at least three years and valid for as
248 | long as you offer spare parts or customer support for that product
249 | model, to give anyone who possesses the object code either (1) a
250 | copy of the Corresponding Source for all the software in the
251 | product that is covered by this License, on a durable physical
252 | medium customarily used for software interchange, for a price no
253 | more than your reasonable cost of physically performing this
254 | conveying of source, or (2) access to copy the
255 | Corresponding Source from a network server at no charge.
256 |
257 | c) Convey individual copies of the object code with a copy of the
258 | written offer to provide the Corresponding Source. This
259 | alternative is allowed only occasionally and noncommercially, and
260 | only if you received the object code with such an offer, in accord
261 | with subsection 6b.
262 |
263 | d) Convey the object code by offering access from a designated
264 | place (gratis or for a charge), and offer equivalent access to the
265 | Corresponding Source in the same way through the same place at no
266 | further charge. You need not require recipients to copy the
267 | Corresponding Source along with the object code. If the place to
268 | copy the object code is a network server, the Corresponding Source
269 | may be on a different server (operated by you or a third party)
270 | that supports equivalent copying facilities, provided you maintain
271 | clear directions next to the object code saying where to find the
272 | Corresponding Source. Regardless of what server hosts the
273 | Corresponding Source, you remain obligated to ensure that it is
274 | available for as long as needed to satisfy these requirements.
275 |
276 | e) Convey the object code using peer-to-peer transmission, provided
277 | you inform other peers where the object code and Corresponding
278 | Source of the work are being offered to the general public at no
279 | charge under subsection 6d.
280 |
281 | A separable portion of the object code, whose source code is excluded
282 | from the Corresponding Source as a System Library, need not be
283 | included in conveying the object code work.
284 |
285 | A "User Product" is either (1) a "consumer product", which means any
286 | tangible personal property which is normally used for personal, family,
287 | or household purposes, or (2) anything designed or sold for incorporation
288 | into a dwelling. In determining whether a product is a consumer product,
289 | doubtful cases shall be resolved in favor of coverage. For a particular
290 | product received by a particular user, "normally used" refers to a
291 | typical or common use of that class of product, regardless of the status
292 | of the particular user or of the way in which the particular user
293 | actually uses, or expects or is expected to use, the product. A product
294 | is a consumer product regardless of whether the product has substantial
295 | commercial, industrial or non-consumer uses, unless such uses represent
296 | the only significant mode of use of the product.
297 |
298 | "Installation Information" for a User Product means any methods,
299 | procedures, authorization keys, or other information required to install
300 | and execute modified versions of a covered work in that User Product from
301 | a modified version of its Corresponding Source. The information must
302 | suffice to ensure that the continued functioning of the modified object
303 | code is in no case prevented or interfered with solely because
304 | modification has been made.
305 |
306 | If you convey an object code work under this section in, or with, or
307 | specifically for use in, a User Product, and the conveying occurs as
308 | part of a transaction in which the right of possession and use of the
309 | User Product is transferred to the recipient in perpetuity or for a
310 | fixed term (regardless of how the transaction is characterized), the
311 | Corresponding Source conveyed under this section must be accompanied
312 | by the Installation Information. But this requirement does not apply
313 | if neither you nor any third party retains the ability to install
314 | modified object code on the User Product (for example, the work has
315 | been installed in ROM).
316 |
317 | The requirement to provide Installation Information does not include a
318 | requirement to continue to provide support service, warranty, or updates
319 | for a work that has been modified or installed by the recipient, or for
320 | the User Product in which it has been modified or installed. Access to a
321 | network may be denied when the modification itself materially and
322 | adversely affects the operation of the network or violates the rules and
323 | protocols for communication across the network.
324 |
325 | Corresponding Source conveyed, and Installation Information provided,
326 | in accord with this section must be in a format that is publicly
327 | documented (and with an implementation available to the public in
328 | source code form), and must require no special password or key for
329 | unpacking, reading or copying.
330 |
331 | 7. Additional Terms.
332 |
333 | "Additional permissions" are terms that supplement the terms of this
334 | License by making exceptions from one or more of its conditions.
335 | Additional permissions that are applicable to the entire Program shall
336 | be treated as though they were included in this License, to the extent
337 | that they are valid under applicable law. If additional permissions
338 | apply only to part of the Program, that part may be used separately
339 | under those permissions, but the entire Program remains governed by
340 | this License without regard to the additional permissions.
341 |
342 | When you convey a copy of a covered work, you may at your option
343 | remove any additional permissions from that copy, or from any part of
344 | it. (Additional permissions may be written to require their own
345 | removal in certain cases when you modify the work.) You may place
346 | additional permissions on material, added by you to a covered work,
347 | for which you have or can give appropriate copyright permission.
348 |
349 | Notwithstanding any other provision of this License, for material you
350 | add to a covered work, you may (if authorized by the copyright holders of
351 | that material) supplement the terms of this License with terms:
352 |
353 | a) Disclaiming warranty or limiting liability differently from the
354 | terms of sections 15 and 16 of this License; or
355 |
356 | b) Requiring preservation of specified reasonable legal notices or
357 | author attributions in that material or in the Appropriate Legal
358 | Notices displayed by works containing it; or
359 |
360 | c) Prohibiting misrepresentation of the origin of that material, or
361 | requiring that modified versions of such material be marked in
362 | reasonable ways as different from the original version; or
363 |
364 | d) Limiting the use for publicity purposes of names of licensors or
365 | authors of the material; or
366 |
367 | e) Declining to grant rights under trademark law for use of some
368 | trade names, trademarks, or service marks; or
369 |
370 | f) Requiring indemnification of licensors and authors of that
371 | material by anyone who conveys the material (or modified versions of
372 | it) with contractual assumptions of liability to the recipient, for
373 | any liability that these contractual assumptions directly impose on
374 | those licensors and authors.
375 |
376 | All other non-permissive additional terms are considered "further
377 | restrictions" within the meaning of section 10. If the Program as you
378 | received it, or any part of it, contains a notice stating that it is
379 | governed by this License along with a term that is a further
380 | restriction, you may remove that term. If a license document contains
381 | a further restriction but permits relicensing or conveying under this
382 | License, you may add to a covered work material governed by the terms
383 | of that license document, provided that the further restriction does
384 | not survive such relicensing or conveying.
385 |
386 | If you add terms to a covered work in accord with this section, you
387 | must place, in the relevant source files, a statement of the
388 | additional terms that apply to those files, or a notice indicating
389 | where to find the applicable terms.
390 |
391 | Additional terms, permissive or non-permissive, may be stated in the
392 | form of a separately written license, or stated as exceptions;
393 | the above requirements apply either way.
394 |
395 | 8. Termination.
396 |
397 | You may not propagate or modify a covered work except as expressly
398 | provided under this License. Any attempt otherwise to propagate or
399 | modify it is void, and will automatically terminate your rights under
400 | this License (including any patent licenses granted under the third
401 | paragraph of section 11).
402 |
403 | However, if you cease all violation of this License, then your
404 | license from a particular copyright holder is reinstated (a)
405 | provisionally, unless and until the copyright holder explicitly and
406 | finally terminates your license, and (b) permanently, if the copyright
407 | holder fails to notify you of the violation by some reasonable means
408 | prior to 60 days after the cessation.
409 |
410 | Moreover, your license from a particular copyright holder is
411 | reinstated permanently if the copyright holder notifies you of the
412 | violation by some reasonable means, this is the first time you have
413 | received notice of violation of this License (for any work) from that
414 | copyright holder, and you cure the violation prior to 30 days after
415 | your receipt of the notice.
416 |
417 | Termination of your rights under this section does not terminate the
418 | licenses of parties who have received copies or rights from you under
419 | this License. If your rights have been terminated and not permanently
420 | reinstated, you do not qualify to receive new licenses for the same
421 | material under section 10.
422 |
423 | 9. Acceptance Not Required for Having Copies.
424 |
425 | You are not required to accept this License in order to receive or
426 | run a copy of the Program. Ancillary propagation of a covered work
427 | occurring solely as a consequence of using peer-to-peer transmission
428 | to receive a copy likewise does not require acceptance. However,
429 | nothing other than this License grants you permission to propagate or
430 | modify any covered work. These actions infringe copyright if you do
431 | not accept this License. Therefore, by modifying or propagating a
432 | covered work, you indicate your acceptance of this License to do so.
433 |
434 | 10. Automatic Licensing of Downstream Recipients.
435 |
436 | Each time you convey a covered work, the recipient automatically
437 | receives a license from the original licensors, to run, modify and
438 | propagate that work, subject to this License. You are not responsible
439 | for enforcing compliance by third parties with this License.
440 |
441 | An "entity transaction" is a transaction transferring control of an
442 | organization, or substantially all assets of one, or subdividing an
443 | organization, or merging organizations. If propagation of a covered
444 | work results from an entity transaction, each party to that
445 | transaction who receives a copy of the work also receives whatever
446 | licenses to the work the party's predecessor in interest had or could
447 | give under the previous paragraph, plus a right to possession of the
448 | Corresponding Source of the work from the predecessor in interest, if
449 | the predecessor has it or can get it with reasonable efforts.
450 |
451 | You may not impose any further restrictions on the exercise of the
452 | rights granted or affirmed under this License. For example, you may
453 | not impose a license fee, royalty, or other charge for exercise of
454 | rights granted under this License, and you may not initiate litigation
455 | (including a cross-claim or counterclaim in a lawsuit) alleging that
456 | any patent claim is infringed by making, using, selling, offering for
457 | sale, or importing the Program or any portion of it.
458 |
459 | 11. Patents.
460 |
461 | A "contributor" is a copyright holder who authorizes use under this
462 | License of the Program or a work on which the Program is based. The
463 | work thus licensed is called the contributor's "contributor version".
464 |
465 | A contributor's "essential patent claims" are all patent claims
466 | owned or controlled by the contributor, whether already acquired or
467 | hereafter acquired, that would be infringed by some manner, permitted
468 | by this License, of making, using, or selling its contributor version,
469 | but do not include claims that would be infringed only as a
470 | consequence of further modification of the contributor version. For
471 | purposes of this definition, "control" includes the right to grant
472 | patent sublicenses in a manner consistent with the requirements of
473 | this License.
474 |
475 | Each contributor grants you a non-exclusive, worldwide, royalty-free
476 | patent license under the contributor's essential patent claims, to
477 | make, use, sell, offer for sale, import and otherwise run, modify and
478 | propagate the contents of its contributor version.
479 |
480 | In the following three paragraphs, a "patent license" is any express
481 | agreement or commitment, however denominated, not to enforce a patent
482 | (such as an express permission to practice a patent or covenant not to
483 | sue for patent infringement). To "grant" such a patent license to a
484 | party means to make such an agreement or commitment not to enforce a
485 | patent against the party.
486 |
487 | If you convey a covered work, knowingly relying on a patent license,
488 | and the Corresponding Source of the work is not available for anyone
489 | to copy, free of charge and under the terms of this License, through a
490 | publicly available network server or other readily accessible means,
491 | then you must either (1) cause the Corresponding Source to be so
492 | available, or (2) arrange to deprive yourself of the benefit of the
493 | patent license for this particular work, or (3) arrange, in a manner
494 | consistent with the requirements of this License, to extend the patent
495 | license to downstream recipients. "Knowingly relying" means you have
496 | actual knowledge that, but for the patent license, your conveying the
497 | covered work in a country, or your recipient's use of the covered work
498 | in a country, would infringe one or more identifiable patents in that
499 | country that you have reason to believe are valid.
500 |
501 | If, pursuant to or in connection with a single transaction or
502 | arrangement, you convey, or propagate by procuring conveyance of, a
503 | covered work, and grant a patent license to some of the parties
504 | receiving the covered work authorizing them to use, propagate, modify
505 | or convey a specific copy of the covered work, then the patent license
506 | you grant is automatically extended to all recipients of the covered
507 | work and works based on it.
508 |
509 | A patent license is "discriminatory" if it does not include within
510 | the scope of its coverage, prohibits the exercise of, or is
511 | conditioned on the non-exercise of one or more of the rights that are
512 | specifically granted under this License. You may not convey a covered
513 | work if you are a party to an arrangement with a third party that is
514 | in the business of distributing software, under which you make payment
515 | to the third party based on the extent of your activity of conveying
516 | the work, and under which the third party grants, to any of the
517 | parties who would receive the covered work from you, a discriminatory
518 | patent license (a) in connection with copies of the covered work
519 | conveyed by you (or copies made from those copies), or (b) primarily
520 | for and in connection with specific products or compilations that
521 | contain the covered work, unless you entered into that arrangement,
522 | or that patent license was granted, prior to 28 March 2007.
523 |
524 | Nothing in this License shall be construed as excluding or limiting
525 | any implied license or other defenses to infringement that may
526 | otherwise be available to you under applicable patent law.
527 |
528 | 12. No Surrender of Others' Freedom.
529 |
530 | If conditions are imposed on you (whether by court order, agreement or
531 | otherwise) that contradict the conditions of this License, they do not
532 | excuse you from the conditions of this License. If you cannot convey a
533 | covered work so as to satisfy simultaneously your obligations under this
534 | License and any other pertinent obligations, then as a consequence you may
535 | not convey it at all. For example, if you agree to terms that obligate you
536 | to collect a royalty for further conveying from those to whom you convey
537 | the Program, the only way you could satisfy both those terms and this
538 | License would be to refrain entirely from conveying the Program.
539 |
540 | 13. Remote Network Interaction; Use with the GNU General Public License.
541 |
542 | Notwithstanding any other provision of this License, if you modify the
543 | Program, your modified version must prominently offer all users
544 | interacting with it remotely through a computer network (if your version
545 | supports such interaction) an opportunity to receive the Corresponding
546 | Source of your version by providing access to the Corresponding Source
547 | from a network server at no charge, through some standard or customary
548 | means of facilitating copying of software. This Corresponding Source
549 | shall include the Corresponding Source for any work covered by version 3
550 | of the GNU General Public License that is incorporated pursuant to the
551 | following paragraph.
552 |
553 | Notwithstanding any other provision of this License, you have
554 | permission to link or combine any covered work with a work licensed
555 | under version 3 of the GNU General Public License into a single
556 | combined work, and to convey the resulting work. The terms of this
557 | License will continue to apply to the part which is the covered work,
558 | but the work with which it is combined will remain governed by version
559 | 3 of the GNU General Public License.
560 |
561 | 14. Revised Versions of this License.
562 |
563 | The Free Software Foundation may publish revised and/or new versions of
564 | the GNU Affero General Public License from time to time. Such new versions
565 | will be similar in spirit to the present version, but may differ in detail to
566 | address new problems or concerns.
567 |
568 | Each version is given a distinguishing version number. If the
569 | Program specifies that a certain numbered version of the GNU Affero General
570 | Public License "or any later version" applies to it, you have the
571 | option of following the terms and conditions either of that numbered
572 | version or of any later version published by the Free Software
573 | Foundation. If the Program does not specify a version number of the
574 | GNU Affero General Public License, you may choose any version ever published
575 | by the Free Software Foundation.
576 |
577 | If the Program specifies that a proxy can decide which future
578 | versions of the GNU Affero General Public License can be used, that proxy's
579 | public statement of acceptance of a version permanently authorizes you
580 | to choose that version for the Program.
581 |
582 | Later license versions may give you additional or different
583 | permissions. However, no additional obligations are imposed on any
584 | author or copyright holder as a result of your choosing to follow a
585 | later version.
586 |
587 | 15. Disclaimer of Warranty.
588 |
589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
597 |
598 | 16. Limitation of Liability.
599 |
600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
608 | SUCH DAMAGES.
609 |
610 | 17. Interpretation of Sections 15 and 16.
611 |
612 | If the disclaimer of warranty and limitation of liability provided
613 | above cannot be given local legal effect according to their terms,
614 | reviewing courts shall apply local law that most closely approximates
615 | an absolute waiver of all civil liability in connection with the
616 | Program, unless a warranty or assumption of liability accompanies a
617 | copy of the Program in return for a fee.
618 |
619 | END OF TERMS AND CONDITIONS
620 |
621 | How to Apply These Terms to Your New Programs
622 |
623 | If you develop a new program, and you want it to be of the greatest
624 | possible use to the public, the best way to achieve this is to make it
625 | free software which everyone can redistribute and change under these terms.
626 |
627 | To do so, attach the following notices to the program. It is safest
628 | to attach them to the start of each source file to most effectively
629 | state the exclusion of warranty; and each file should have at least
630 | the "copyright" line and a pointer to where the full notice is found.
631 |
632 |
633 | Copyright (C)
634 |
635 | This program is free software: you can redistribute it and/or modify
636 | it under the terms of the GNU Affero General Public License as published
637 | by the Free Software Foundation, either version 3 of the License, or
638 | (at your option) any later version.
639 |
640 | This program is distributed in the hope that it will be useful,
641 | but WITHOUT ANY WARRANTY; without even the implied warranty of
642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
643 | GNU Affero General Public License for more details.
644 |
645 | You should have received a copy of the GNU Affero General Public License
646 | along with this program. If not, see .
647 |
648 | Also add information on how to contact you by electronic and paper mail.
649 |
650 | If your software can interact with users remotely through a computer
651 | network, you should also make sure that it provides a way for users to
652 | get its source. For example, if your program is a web application, its
653 | interface could display a "Source" link that leads users to an archive
654 | of the code. There are many ways you could offer source, and different
655 | solutions will be better for different programs; see section 13 for the
656 | specific requirements.
657 |
658 | You should also get your employer (if you work as a programmer) or school,
659 | if any, to sign a "copyright disclaimer" for the program, if necessary.
660 | For more information on this, and how to apply and follow the GNU AGPL, see
661 | .
662 |
--------------------------------------------------------------------------------