Modular Video Synth Basics #
Hydra is inspired by modular synthesis.
Instead of connecting cables you connect different kinds of javascript functions.
source Sandin Image Processor #
Press the run button to run this code and update the visuals on the screen. You should see some scrolling stripes appear in the background.
This creates a visual oscillator. Try modifying the parameters of the oscillator by putting a number inside the parentheses of osc()
, for example osc(10).out()
.
Re-run the code by pressing the run button again, and seeing the visuals update. Try adding other values to control the oscillator’s frequency
, sync
, and color offset
.
Trick: you can also use the keyboard shortcut ‘ctrl + shift + enter’ to have the same effect as the run button.
Adding transformations #
We can add another transformation to the oscillator from above, by adding the function rotate()
after the oscillator:
As you can see, you have first an input source osc()
and things that come after (rotate()
and out()
) are connected with a dot ‘.’
In this sense,
You can continue adding transformations to this chain of functions. For example:
Repeat:
For more available sources and transformations, see the interactive function reference.
The logic is to start with a source (such as osc()
, shape()
, or noise()
), and then add transformations to geometry and color (such as .rotate()
, .kaleid()
, .pixelate()
), and in the end always connect the chain of transformations to the output screen .out()
.
What is an error? #
Sometimes, you will try to run a line of code, and nothing will happen. If you have an error you’ll notice text in red at the left-bottom on your screen. Something like ‘Unexpected token ‘.’ (in red) will appear. This doesn’t affect your code, but you won’t be able to continue coding until you fix the error. Usually it is a typing error or something related to the syntax.
What is a comment? #
// Hello I’m a comment line. I’m a text that won’t change your code. You can write notations, your name or even a poem here.
Multiple outputs #
By default, hydra contains four separate virtual outputs that can each render different visuals, and can be mixed with each other to create more complex visuals. The variables o0
, o1
, o2
, and o3
correspond to the different outputs.
To see all four of the outputs at once, use the render()
function. This will divide the screen into four, showing each output in a different section of the screen.
Using a different variable inside the .out()
function renders the chain to a different output. For example, .out(o1)
will render a function chain to graphics buffer o1
.
By default, only output o0
is rendered to the screen, while the render()
command divides the screen in four. Show a specific output on the screen by adding it inside of render()
, for example render(o2)
to show buffer o2
.
Trick: try to create different sketches and switch them in your live performance or even combine them.
Blending multiple visual sources together #
You can use blend functions to combine multiple visual sources. .blend()
combines the colors from two sources to create a third source.
Try adding transformations to the above sources (such as osc(10).rotate(0, 0.1).out(o1)
) to see how it affects the combined image. You can also specify the amount of blending by adding a separate parameter to .blend()
, for example .blend(o1, 0.9)
.
There are multiple blend modes in hydra, similar to blend modes you might find in a graphics program such as photoshop or gimp. See the function reference for more possibilities.
Modulation #
While blend functions combine the colors from two visual sources, modulate functions use the colors from one source to affect the geometry of the second source. This creates a sort of warping or distorting effect. An analogy in the real world would be looking through a texture glass window.
modulate()
does not change color or luminosity but distorts one visual source using another visual source.
Using the same sources from above, we can use an oscillator to modulate or warp the camera image:
You can add a second parameter to the modulate()
function to control the amount of warping: modulate(o1, 0.9)
. In this case, the red and green channels of the oscillator are being converted to x and y displacement of the camera image.
All geometry transformations have corresponding modulate functions that allow you to use one source to warp another source. For example, .modulateRotate()
is similar to .rotate()
, but it allows you to apply different amounts of rotation to different parts of the visual source. See the function reference for more examples.
More blending and modulating #
In addition to using multiple outputs to combine visuals, you can also combine multiple sources within the same function chain, without rendering them to separate outputs.
This allows you to use many sources, blend modes, and modulation, all from within the same chain of functions.
Trick: use ctrl + shift + f
from the web editor to auto-format your code
Modulating with the camera #
We have now covered all of the basic types of functions within hydra: source, geometry, color, blending, and modulation! See what you can come up with by mixing these together.