Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⬇️🚤 Updated with Glitch #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: ritchse
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
35 changes: 33 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,33 @@
# Hydra-strudel-extension
Hydra extension to support strudel code and mini-notation
# hydra-strudel
[WIP]

made by olivia & TACHA~

### Usage
```javascript
await loadScript("https://hydra-strudel.glitch.me/hydra-strudel.js")
```

### Example
[live](https://hydra.ojack.xyz/dev/?code=JTJGJTJGJTIwbGljZW5zZWQlMjB3aXRoJTIwQ0MlMjBCWS1OQy1TQSUyMDQuMCUyMGh0dHBzJTNBJTJGJTJGY3JlYXRpdmVjb21tb25zLm9yZyUyRmxpY2Vuc2VzJTJGYnktbmMtc2ElMkY0LjAlMkYlMEFhd2FpdCUyMGxvYWRTY3JpcHQoJTIyaHR0cHMlM0ElMkYlMkZoeWRyYS1zdHJ1ZGVsLmdsaXRjaC5tZSUyRmh5ZHJhLXN0cnVkZWwuanMlMjIpJTBBJTBBJTBBJTJGJTJGbXlQYXR0ZXJuJTIwJTNEJTIwbWluaSgnMCUyMDEwJTIwJTVCMiUyMDUxJTVEKjQnKS5zbG93KDIpJTBBJTJGJTJGbm90ZShteVBhdHRlcm4pLnBsYXkoKSUwQSUyRiUyRm9zYygoKSUyMCUzRCUzRSUyMDEwJTIwKiUyMG15UGF0dGVybi52YWx1ZSgpKS5vdXQoKSUwQSUyRiUyRnNodXNoKCklMEElMEElMEElMEE%3D)
```javascript
await loadScript("https://hydra-strudel.glitch.me/hydra-strudel.js")


//myPattern = mini('0 10 [2 51]*4').slow(2)
//note(myPattern).play()
//osc(() => 10 * myPattern.value()).out()
//shush()

```
### To do:

- only run after load // fix loading error
- why not synced?
- add key command for stopping sound
- make strings evaluate directly
- check whether already loaded and only load once
- make always live?
- `hush()` in HYDRA not working

#
83 changes: 83 additions & 0 deletions doc/ES/hydra-glsl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# hydra-glsl

Este hack/extensión te permite codear GLSL casi que directamente adentro de Hydra. Añade 5 functiones, 1 por cada tipo de glsl-function que hay en Hydra

## Ejemplo:
```js
glsl('vec4(sin(((_st.x*54.)+time*2.)*vec3(0.1,0.102,0.101)),1.0)')
.diff(o0)
.glslColor('vec4(c0.brg,1.)')
.glslCoord('xy*=(1.0/vec2(i0, i0)); return xy',.25)
.glslCombine('return c0-c1',o1)
.glslCombineCoord('uv+(vec2(c0.r,c0.b)*0.1)',o1)
.out()
```
[Miralo en hydra!](https://hydra.ojack.xyz/?sketch_id=agiUw1vmrGmmf4Zy)

---

## Funciones:

| función | argumentos dsps del código | tipo correspondiente | argumentos de glsl : aliases |
|--------------------------|------------------|--------------------|-----------------------------------|
| glsl() | ...args | 'src' | _st : st, uv, xy |
| osc().glslColor() | ...args | 'color' | _c0 : c0, color |
| osc().glslCoord() | ...args | 'coord' | _st : st, uv, xy |
| osc().glslCombine() | texture, ...args | 'combine' | _c0 : c0, color0; _c1: c1, color1 |
| osc().glslCombineCoord() | texture, ...args | 'combineCoord' | _st : st, uv, xy; _c0: c0, color |

*Nótese que `osc()` es meramente un ejemplo*

### Extra functions

| función | argumentos dsps del código | tipo correspondiente | descripción |
|--------------------------|------------------|--------------------|-----------------------------------|
| osc().glslHsv() | ...args | 'color' | Convierte los colores de c0 a HSV. Podés acceder y modificar estos valores desde un `vec3 hsv` |

---

## Argumentos

Cada función trae con sigo 10 argumentos predeterminados con nombres `i0`,`i1`,`i2`...`i9`. Todos estos se inicializan con el valor por default de `1`. Podés usar estos 10 argumentos o definir los tuyos al mandar cada argumento en un array con un formate de `['nombre',valor]`.

#### Importante:
Todos los argumentos son del tipo `float`.

### Ejemplo:

```js
glsl('vec4(sin(uv.x*i0+(time*i1*vec3(i2,i2*2.,i2*3.))),1.0)',16,2,.3)
.glslColor('vec4(c0.brg-(sin(c0.b)*miVariable),1.)',['miVariable',0.2])
.out()
```

Hasta podés mandar funciones como variables como se suele hacer en Hydra:

```js
glsl('vec4(sin(uv.x*i0+(time*i1*vec3(i2,i2*2.,i2*3.))),1.0)',16,2,.3)
.glslColor('vec4(c0.brg-(sin(c0.b)*miVariable),1.)',['miVariable',()=>time%1])
.out()
```

---

## Sobre el codigo (y el lazy code)

* Podés usar de una cualquiera de los aliases descritos arriba.
* Podés omitir el semicolón al final.
* Podés omitir la palabra reservada "return".
* Podes mandar código que ocupe múltiples líneas.
* Solo podés omitir el semicolón en la ultima linea.
* Podés aún así omitir la palabra return.
* Podés escribir tus propias `c0`s, `st`s o cualquier otra variable llamada como alguna de los aliases de arriba. El script se fija que no hayas instanciado ninguna variable llamada así antes de definir los aliases.
* No podes usar el mismo nombre de un alias como el nombre de un argumento

---

## Tip

Tené la consola del browser abierta. Hydra no tira errores de frag a la consola integrada.

## Nota

Este hack funciona llenando de nuevas funciones al contexto global (`window`) y/o al constructor de GlslSource. No te asustes si ves un montón de funciones llamdas `glsl_ext_NODE_`-algo.
113 changes: 113 additions & 0 deletions doc/hydra-arithmetics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# hydra-arithmetics

Adds many functions related to visual arithmetics.

## Operators

All operators in this extension are actually wrappers that let you operate by either a number (or array or function as with regular hydra) or a texture. This basically means you can both do `osc().add(noise())` or `osc().add(1)` and both will work as expected.

### div

`.div( divisor )`

Divide a texture by some value or texture

### add, sub, mult

| single value | texture |
|----------------|------------------------|
|`.add( value )` | `.add( tex , amount )` |
|`.sub( value )` | `.sub( tex , amount )` |
|`.mult( value )`| `.mult( tex , amount )`|

These act the same as in regular Hydra, with the added functionality of working with regular values too.

### mod

`.mod( x )`

Calculates the modulo `x` for the texture that calls it.

### min, max

`.min( x )`, `.max( x )`

Returns the minimum or maximum value when compared to the texture that calls it, accordingly.

### step

`.step( x )`

Generates a step function by comparing x to the texture that calls it.

### amp, offset

`.amp( singleValue ) == .amplitude( singleValue )`, `.offset( singleValue ) == .off( singleValue )`

These are basically aliases for `.mult()` and `.add()` for single values.

---

## Bipolar and unipolar

### bipolar

`.bipolar( amp = 1 )`

Takes unipolar values (values ranged from 0 to 1) and turns them to bipolar (ranged from -1 to 1). The `amp` argument let's you multiply the result by some value if needed.

### unipolar

`.unipolar( amp = 1 )`

Takes bipolar values (-1 to 1) and turns them to unipolar (0 to 1). The `amp` argument let's you multiply the result by some value if needed.

---

## Ranges

### range

`.range( min = 0, max = 1 )`

Allows you to change the range the range of unipolar values to one between `min` and `max`.

### birange

`.birange( min = 0, max = 1 )`

Allows you to change the range the range of bipolar values to one between `min` and `max`.

### clamp

`.clamp( min = 0, max = 1 )`

`clamp` will constrain values between a range from `min` to `max`.

---

## Other transformations

This extension also adds many argument-less transforms. You can use them as such, for example: `osc().abs()`.

### abs, fract, sign

#### abs

Returns the absolute value.

#### fract

Returns only the fractional part of a value.

#### sign

Sign function, will return 1 for positive values and -1 for negative values.

### Trigonometic functions

The following are included: `sin`, `cos`, `tan`, `asin`, `acos`, `atan`

### Exponential and rational functions

The following are included: `exp`, `log`, `exp2`, `log2`, `sqrt`, `inversesqrt`
67 changes: 67 additions & 0 deletions doc/hydra-arrays.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# hydra-arrays

Extends the functionality of arrays in Hydra, letting you operate between different arrays and generate new ones.

## Operators

### Regular operators

`.add`, `.sub`, `.mult`, `.div`, `.mod`

These will let you add either a constant or an array to another array. If the second array is smaller than the first one, it simply stops there. For example:

```
[0,1,2,3].add(1) == [1,2,3,4]
[0,1,2,3].add([1,2]) == [1,3,2,3]
```

### Wrap operators

`.addWrap`, `.subWrap`, `.multWrap`, `.divWrap`, `.modWrap`

These are just like the regular operators, but if the second array is smaller than the first one, it'll repeat itself until going through every single element in the first array.

```
[0,1,2,3].add([1,2]) == [1,3,2,3]
[0,1,2,3].addWrap([1,2]) == [1,3,3,5]
```

## Methods

### shuffle

`.shuffle()`

Will return a shuffled version of any array.

### zfill

`.zfill(length, z = 0)`

Will concat `z` to the array repeatedly until the array reaches the desired length. Inspired by python's zfill, however, the one shown here adds the zeroes at the end of the array.

### rotate

`.rotate(n)` / `.rot(n)`

Will rotate the array by `n` steps. Works with negative values.

## Generators

### Array.random

`Array.random(length = 10, min = 0, max = 1)`

Generates a new array of a given length and fills it with random values between the range `min` to `max`.

### Array.range

`Array.range(start, end, step = 1)`

Generates a new array of numbers starting from `start`, then each element increases by `step` until `end` (non-inclusive).

### Array.run

`Array.range(end = 10, step = 1)`

Generates a new array of numbers starting from 0, then each element increses by `step` until `end` (non-inclusive).
50 changes: 50 additions & 0 deletions doc/hydra-blend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# hydra-blend

A port of [glsl-blend](https://github.com/jamieowen/glsl-blend) to Hydra.

## Overview

This extension adds most of the blending modes that you see on raster image software to Hydra. You should use them with the following syntax: `tex.blendModeName(tex2, opacity)`, where tex and tex2 are any two Hydra textures and opacity is a number (or array or function as in regular Hydra).

Please read the [disclaimer about alpha here below](#important)

## List of blending modes

* darken
* multiply
* colorBurn
* linearBurn
* lighten
* screen
* colorDodge
* linearDodge
* overlay
* softLight
* hardLight
* vividLight
* linearLight
* pinLight
* hardMix
* difference
* exclusion
* subtract
* divide
* negation / negate
* add2 (i didn't want to replace the regular Hydra `add`)
* glow
* reflect
* phoenix

## About the alpha channel

`glsl-blend` doesn't have any functions that work with RGBA, all function work with opaque textures of RGB. After lots of playing around with Photopea I realized that what most raster image softwares do is apply the blending over premultiplied sources and then, wherever the base texture is transparent, layer over the texture to be blended, and that's how I implemented it

### Important

This extension overwrites Hydra's `layer`, `luma` and `mask` in order for them to stricly use premultiplied alpha. This means that if something doesn't look as expected, it's probably because the textures you're using aren't premultiplied and in a range from 0.0 to 1.0. `noise` will surely give you problems as it ranges from -1 to 1.

I could've handled this inside the blending modes but I didn't want to taker over your ability to purposefully glitch stuff. If something doesn't look as you expect it to look you can try to premultiply it by doing `tex.premultiply()` alias `tex.pm()`. It's a function I've added that will take care of any overloaded or mismatched values.

### Note

If you're interested in alpha compositing inside Hydra, please join the discussion [here](https://github.com/hydra-synth/hydra-synth/issues/109)
Loading