{"id":17068709,"url":"https://github.com/folz/hydra-ts","last_synced_at":"2025-04-12T18:20:44.674Z","repository":{"id":37424624,"uuid":"368008528","full_name":"folz/hydra-ts","owner":"folz","description":"A fork of ojack/hydra-synth in typescript, focusing on interoperability.","archived":false,"fork":false,"pushed_at":"2023-10-17T13:43:39.000Z","size":9309,"stargazers_count":53,"open_issues_count":11,"forks_count":7,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-26T12:37:49.543Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/folz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-16T23:50:58.000Z","updated_at":"2025-03-25T17:56:45.000Z","dependencies_parsed_at":"2023-02-07T17:55:13.100Z","dependency_job_id":null,"html_url":"https://github.com/folz/hydra-ts","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/folz%2Fhydra-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/folz%2Fhydra-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/folz%2Fhydra-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/folz%2Fhydra-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/folz","download_url":"https://codeload.github.com/folz/hydra-ts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248610685,"owners_count":21132984,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T11:14:40.190Z","updated_at":"2025-04-12T18:20:44.645Z","avatar_url":"https://github.com/folz.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `hydra-ts`\n\n`hydra-ts` is a fork of [ojack/hydra-synth][1] in typescript, focusing on interoperability with other projects. It\nseeks to be fully compatible with the original's end-user syntax (`osc().out()`) while rewriting much of the internal\nimplementation to make it easier to use as a library.\n\n## Installation\n\n```shell\n# yarn\nyarn add hydra-ts\n```\n\n```shell\n# npm\nnpm install -S hydra-ts\n```\n\n## Background\n\nhydra-synth is a fantastically designed visual synth and shader compiler that I've wanted to use in a variety of other\nprojects. However, I've found that its implementation is tightly coupled to [ojack/hydra][2], the online editor created\nto showcase hydra-synth. I've also found that it generally assumes a single running instance and a modifiable global\nenvironment.\n\nThese things have caused unexpected behavior for me when I used hydra-synth outside of hydra-the-editor, or in multiple\nplaces on the same page where I wanted each place to be self-contained from the others. Although the hydra community\nhas found workarounds to many of these behaviors, I wanted to create a fork which directly fixes root causes so that\nworkarounds are no longer needed.\n\nTo address these, hydra-ts has rewritten internals to avoid globals and mutable state, removed non-shader-compilation\nfeatures present in the original (such as audio analysis), and modified the public API to prefer referential equality\nover named lookup.\n\n## Documentation\n\n_For general information about using Hydra, refer to [`hydra`'s documentation][2]._\n\n#### Creating a Hydra instance:\n\n```ts\nimport REGL from 'regl';\nimport Hydra from 'hydra-ts';\n\nconst regl = REGL(/*...*/);\n\nconst hydra = new Hydra({\n  regl,\n  width: 1080,\n  height: 1080,\n  /*\n  numOutputs?: 4,\n  numSources?: 4,\n  precision?: 'mediump', // 'highp' | 'mediump' | 'lowp'\n  */\n});\n```\n\nThe Hydra constructor expects a regl instance, width, and height. The width and height are the internal buffer\ndimensions, not the dimensions of the canvas element. This means you can e.g. pass in double the size of the canvas\ndimensions to avoid sampling/pixelation of high-resolution sketches until finally rendering back out to the canvas.\n\nYou can optionally provide a non-negative number for numOutputs and numSources, as well as a Precision value.\n\n#### Recreating the hydra-editor global environment\n\n```ts\nimport { Hydra, generators } from 'hydra-ts';\n\nconst hydra = new Hydra(/* ... */);\n\nconst { src, osc, gradient, shape, voronoi, noise } = generators;\nconst { sources, outputs } = hydra;\n\nconst [s0, s1, s2, s3] = sources;\nconst [o0, o1, o2, o3] = outputs;\nconst { hush, loop, render } = hydra;\n\nloop.start();\n```\n\nGenerators are no longer dependent on the Hydra environment, so you can import them directly from `'hydra-ts'`;\n\nSources and outputs may be named when destructuring from their respective properties on the hydra instance.\n\nHelper methods may also be destructured from the hydra instance.\n\n#### Adding custom generator or modifier hydra functions (e.g. `setFunction`)\n\n```ts\nimport {\n  createGenerators,\n  defaultGenerators,\n  defaultModifiers,\n} from 'hydra-ts';\n\nconst generators = createGenerators({\n  generators: [...defaultGenerators, myGeneratorDefinition],\n  modifiers: [...defaultModifiers, myModifierDefinition],\n});\n\nconst { src, osc, /* ... , */ myGen } = generators;\n```\n\nWhere `myGeneratorDefinition` and `myModifierDefinition` match the object you would have passed to `setFunction`.\n\nA \"generator\" is a definition with `{type: 'src'}`, and a \"modifier\" is a definition of any other type.\n\n#### Recreating bidirectional global changes (e.g. assigning `bpm`/`speed` globals)\n\nThis is not presently supported.\n\n## Differences from the original hydra-synth\n\nPresently, you must pass an output instance to `.out(o#)` - it does not infer the \"default\" output if none is passed.\nPRs to address this are welcome.\n\nYou must also call ArrayUtils.init() once before any instance of hydra is used.\n\n## Contributing\n\nContributions are welcome. In particular, contributions around tests, performance, correctness, and type safety are\nvery appreciated. I'm also open to contributions which help you integrate this into your own projects.\n\nPlease remember that this fork has a goal of full compatibility with the original implementation, so if you're\nproposing new syntax or breaking changes, they will need to be upstreamed before being implemented here. If in doubt,\nfeel free to open an issue discussing the changes before starting work on them.\n\n[1]: https://github.com/ojack/hydra-synth#readme\n[2]: https://github.com/ojack/hydra#readme\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffolz%2Fhydra-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffolz%2Fhydra-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffolz%2Fhydra-ts/lists"}