Olivia Jack
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    1
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Hydra synth There are five types of functions in hydra: [source](##Sources), [geometry](##Geometry), [color](##Color), [blend](##Blend), and [modulate](##Modulate). Hydra functions generally start with a [source](##Sources) function, followed by transformations to geometry and color, blending and modulation. See Getting Started for more information. <!--<iframe style="width:120%;height:600px;border:none" src="https://hydra.ojack.xyz/api/#functions/repeatX/0"> </iframe>---> ## Sources ### osc ```javascript osc(6, 0.05, 0.8).out() // osc( frequency = 60, sync = 0.1, offset = 0 ) ``` ### noise ### voronoi ### shape ### gradient ### src ### solid ## Geometry ### rotate ### scale ### pixelate ### repeat ### repeatX ### repeatY ### kaleid ### scroll ### scrollX ### scrollY ## Color ### posterize ### shift ### invert ### contrast ### brightness ### luma ### thresh ### color ### saturate ### hue ### colorama ### sum ## Blend You can use blend functions to combine multiple visual sources. `.blend()` combines the colors from two sources to create a third source. ... ## Modulate 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 External Sources ### initCam ```javascript s0.initCam() s0.initCam(2) // if you have many cameras, you can select one specifically ``` ### initScreen ```javascript s0.initScreen() ``` ### initImage ```javascript s0.initImage("https://www.somewebpage.org/urlto/image.jpg") ``` When running Hydra in Atom, or any other local manner, you can load local files referring to them by URI: ```javascript s0.initImage("file:///home/user/Images/image.png") ``` supported formats: `.jpeg`, `.png`, `.bmp` as well as `.gif` and `.webp` (although animation won't work). ### initVideo ```javascript s0.initVideo("https://www.somewebpage.org/urlto/video.mp4") ``` supported formats: `.mp4`, `.ogg`, `.webm` ### initStream ### init # 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. ![](https://i.imgur.com/m5Q0Na6.jpg) 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`. ```hydra gradient(1).out(o0) // render a gradient to output o0 osc().out(o1) // render voronoi to output o1 voronoi().out(o2) // render voronoi to output o2 noise().out(o3) // render noise to output o3 render() // show all outputs ``` 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`. ```hydra gradient(1).out(o0) // render a gradient to output o0 osc().out(o1) // render voronoi to output o1 voronoi().out(o2) // render voronoi to output o2 noise().out(o3) // render noise to output o3 render(o2) // show only output o2 ``` ### .out() ### render() Note: 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. ```hydra osc(10, 0.1, 1.2).blend(noise(3)).out(o0) render(o0) // render output o0 ``` # Sequencing and Interactivity .... ## Arrays When you send an Array as an input, Hydra will automatically switch and jump from each element from the Array to the next one. When there are no more elements, it wraps all the way back to the beginning. Let's see it in action: ```hydra osc([20,30,50,60],.1,[0,1.5]) .out() ``` ### fast Hydra adds a couple of methods to all Arrays to be used inside Hydra. `.fast` will control the speed at which Hydra takes elements from the Array. It receives a Number as argument, by which the global speed will be multiplied. So calling `.fast(1)` on an Array is the same as nothing. Higher values will generate faster switching, while lower than 1 values will be slower. ```hydra bpm = 45 osc([20,30,50,60],.1,[0,1.5].fast(1.5)) // 50% faster //.rotate([-.2,0,.2].fast(1)) // try different speeds for each array .out() ``` ### smooth Interpolating between values You can also interpolate between values instead of jumping from one to the other. That is, smoothly transition between values. For this you can use the `.smooth` method. It may take a Number argument (defaulted to 1) which controls the smoothness. ```hydra bpm = 50 arr = [0,0.8,2] osc(50,.1,arr.smooth()) .rotate(arr.fit(-Math.PI/4,Math.PI/4).smooth()) .out() ``` ### ease The default interpolation used by Hydra on an Array that called `.smooth` is linear interpolation. You can select a different easing function as follows: ```hydra bpm = 50 arr = [0,0.8,2] osc(50,.1,arr.ease('easeInQuad')) .rotate(arr.fit(-Math.PI/4,Math.PI/4).ease('easeOutQuad')) .out() // try other easing functions ! ``` The following are the available easing functions: * linear: no easing, no acceleration * easeInQuad: accelerating from zero velocity * easeOutQuad: decelerating to zero velocity * easeInOutQuad: acceleration until halfway, then deceleration * easeInCubic * easeOutCubic * easeInOutCubic * easeInQuart * easeOutQuart * easeInOutQuart * easeInQuint * easeOutQuint * easeInOutQuint * sin: sinusoidal shape * ### offset Another one of the methods Hydra adds to Arrays, allows you to offset the timing at which Hydra will switch from one element of the Array to the next one. The method `.offset` takes a Number from 0 to 1. ```hydra bpm = 45 osc([20,30,50,60],.1,[0,1.5].offset(.5)) // try changing the offset .out() ``` ### fit Fitting the values of an Array within a range Sometimes you have an Array whose values aren't very useful when used as input for a some Hydra function. Hydra adds a `.fit` method to Arrays which takes a minimum and a maximum to which fit the values into: ```hydra bpm = 120 arr = ()=> [1,2,4,8,16,32,64,128,256,512] osc(50,.1,arr().fit(0,Math.PI)) .scale(arr().fit(1,2)) .out() ``` Array example: ```hydra bpm = 40 src(o0) .scale([1,1.02]) .layer(osc(9,.1,2).mask(shape(4,.3,0))) .out(o0) osc(30,.1,[0,1.5].fast(1.5)) .diff(shape(16,[0,.3],.1)) .out(o1) osc() .rotate([1,4,2,5,3].fit(0,3.14).smooth()) .out(o2) sh = ()=> [.2,.5,.7,.8].ease('easeInQuart') noise(2) .shift(sh() ,sh().offset(1/3) ,sh().offset(2/3)) .out(o3) render() ``` ## Custom Functions Each parameter can be defined as a function rather than a static variable. When Hydra takes a function as an argument, it will evaluate that function every time a new frame is rendered. The return of the function will be used as the value for that parameter during that frame render. So you can use a function to simply keep track of a value that you know will change over time, for example, mouse position (which we'll see later). Hydra has several globally-defined variables that are helpful in writing your own functions: mouse (keeps track of mouse position), width, height, and time ## mouse ```hydra gradient() .hue(()=>mouse.x/3000) .scale(1,1,()=>mouse.y/2000) .out(o0) ``` ### width ### height ## time When you use functions that can take numerical arguments, `time` will allow you to have their values evolve through... time. If you multiply time by some value it's as if time goes faster, while dividing while act as making time go slower. For example `Math.sin(time*4)` will go 4 times faster than `Math.sin(time)`. ```hydra voronoi(5,.1,()=>Math.sin(time*4)) .out() ``` Those users more familiar with mathematics might see this as: * `y(t) = t` : `()=>time` * `y(t) = A sin(f t + ph)` : `()=>amplitude*Math.sin(freq*time + phase)` We recommend getting familiar with some of the methods in the JS built-in `Math` object. Learn more about it [here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math) Further explanation in the [advanced guide](guides/advanced#functions). ## Audio Audio-reactive functionality is available via an audio object accessed via "a". The editor uses https://github.com/meyda/meyda for audio analysis. ### show To show the realtime audio analysis, run the following: ```javascript a.show() // show what hydra's listening to ``` ### hide This will show a small graphic on the lower right corner of the screen. To hide, run: ```javascript a.hide() ``` ### fft ```javascript noise(2) .modulate(o0,()=>a.fft[1]*.5) // listening to the 2nd band .out() ``` ### setSmooth ```javascript a.setSmooth(.8) // audio reactivity smoothness from 0 to 1, uses linear interpolation ``` ### setCutoff ```javascript a.setCutoff(4) // loudness from which to start listening to (maps to 0) ``` ### setScale ```javascript a.setScale(8) // loudness upper limit (maps to 0) ``` ### setBins ```javascript a.setBins(5) // amount of bins (bands) to separate the audio spectrum ``` # Configuring the synth ### setResolution ### speed ### bpm ### update ```hydra toggle = 0; rotation = .01 src(o0) .scale(1.017) .rotate(()=>rotation) .layer( osc(10,.25,2) .mask(shape(4,.2)) .mult(solid(0,0,0,0),()=>1-toggle) ) .out() frameCount = 0 update = (dt) => { toggle = 0 if(frameCount % 120 == 0){ toggle = 1; rotation *= -1; } frameCount++ } ``` Further explanation in the [advanced guide](guides/advanced#using-the-update-function). ### hush use `hush()` to reset hydra ```hydra hush() // fps, bpm and speed won't be reset to their defaults by calling hush // their defaults are: fps = undefined, bpm = 30, speed = 1 ``` ### setFunction # External Libraries ### loadScript The `await loadScript()` function lets you load other packaged javascript libraries within the hydra editor. Any javascript code can run in the hydra editor. Here is an example using Three.js from the web editor: ```javascript await loadScript("https://threejs.org/build/three.js") scene = new THREE.Scene() camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000) renderer = new THREE.WebGLRenderer() renderer.setSize(width, height) geometry = new THREE.BoxGeometry() material = new THREE.MeshBasicMaterial({color: 0x00ff00}) cube = new THREE.Mesh(geometry, material); scene.add(cube) camera.position.z = 1.5 // 'update' is a reserved function that will be run every time the main hydra rendering context is updated update = () => { cube.rotation.x += 0.01; cube.rotation.y += 0.01; renderer.render( scene, camera ); } s0.init({ src: renderer.domElement }) src(s0).repeat().out() ``` And here is an example loading the Tone.js library: ```javascript await loadScript("https://unpkg.com/tone") synth = new Tone.Synth().toDestination(); synth.triggerAttackRelease("C4", "8n"); ``` # Streaming using WebRTC ...

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully