beta
cables is under heavy development.
There might be one or another bug, please let us know about it!
cables Documentation      How To Use            Working with files            Keyboard Shortcuts            User Interface Walkthrough      Beginner Tutorial            Beginner 1: Drawing A Circle            Beginner 2: Transformations            Beginner 3: Color            More Transformations      intermediate            Image Compositions            Post-Processing 3D Scenes      communication            cables API            Communication with an Arduino via Serial            Communicating with Arduino over MQTT      Exporting And Embedding            How to serve files externally and fix CORS headers            Embedding Patches            External triggers / functions            Embedding Patches            Previewing / uploading exported cables patches      coding ops            Creating Attachments            General op/Port Callbacks            Ports                  Dynamic Ports                  Array Ports                  Boolean ports                  Integer Number Ports                  Object Ports                  String ports                  Trigger Ports                  Floating Point Number Ports            GUI/UI attributes            Hello Op - Part 1            Libraries            Developing Ops            Guidelines            Object Ports            Writing Shaders            Web Audio Op Development      HTML and CSS in cables      Lighting            Lights            Shadows      FAQ            Embedding                  How to remove grey rectangles on touch (mobile)?                  Why doesn't the DownloadTexture op work on iOS?                  How to disable page scrolling on mobile?                  Transparent Canvas            Features and Support                  Will there be support for (animated) GIFs?            General questions            Licences and payment                  What licence do i need to use cables?                  Will I have to pay for it in the future?                  How is my work licenced when using cables?            Does cables support midi and OSC?            Shadertoy            Technical questions            UI / Editor            WebGL1 and WebGL2

Embedding Patches

cables-Patches can be exported as a zip-file and embedded into any website. The size of the exported patches are relatively small as only the ops which you use in your patch are packed into the zip-file.

  • In your project settings click Export Static Archive
  • A .zip-archive containing all your project data is created
  • The archive contains an index.html-file – put this on a web-server and load it, your project should be shown. You can open your browser’s developer tools to check if there are any errors.
  • An easy way to start a local web-server on your computer is by using a program like anvil – after you downloaded the zip file of your project and unpacked it, just drag the extracted folder onto the menu bar icon of anvil and click on the newly created local web-server to open it in your browser

Examples

Have a look at our github example repository: github

Simple: Insert patch into an HTML container element

use CABLES.EMBED.addPatch(...) to create a canvas element and insert it into a container element. You can then set the Size of the container Element and the canvas will be resized automatically.

<html>
<head>
    <title>cables</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <style type="text/css">
        #mypatch
        {
            width:800px;
            height:480px;
        }
    </style>
</head>
<body>
    <div id="mypatch"></div>

    <script type="text/javascript" src="js/libs.core.min.js"></script>
    <script type="text/javascript" src="js/cables.min.js"></script>
    <script type="text/javascript" src="js/ops.js"></script>

    <script>
        CABLES.EMBED.addPatch("mypatch",
        {
            patchFile:'js/city.json',
            prefixAssetPath:''
        });
    </script>
</body>
</html>

Advanced: Create Canvas and Patch

Create the Canvas Element yourself. Load the Patch and use the canvas id as parameter. Cables will then use this canvas. The Canvas is not resized automatically.
You should subscribe to the CABLES.jsLoaded event to initialize the patch, this assures all the javascript is loaded (even when loading "async").

<html>
<head>
    <title>cables</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>

    <canvas id="glcanvas" width="800" height="480"></canvas>

    <script type="text/javascript" src="js/libs.core.min.js" async></script>
    <script type="text/javascript" src="js/cables.min.js" async></script>
    <script type="text/javascript" src="js/ops.js" async></script>

    <script>

        var patch=null

        document.addEventListener("CABLES.jsLoaded", function(event)
        {
            patch=new CABLES.Patch(
            {
                patchFile:'js/city.json',
                prefixAssetPath:'',
                glCanvasId:'glcanvas',
                onError:alert
            });
        });


    </script>
</body>
</html>

Pausing the Patch

For performance Reasons, you should pause the patch, when its not visible usingpatch.pause() . To Resume rendering use patch.resume()

Patch Option Parameters

  • canvas canvas context attributes (see https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext)
  • glCanvasId (string): The element ID of your canvas object
  • prefixAssetPath (string): Path where to find the assets folder
  • onError (function): Function to be called if a critical error occurs (e.g. browser has no WebGL / Web Audio)
  • onFinishedLoading: Function to be called when cables is done loading the patch and all assets
  • silent (bool): Enable / disable all logging to console.
  • glCanvasResizeToWindow Resize the Canvas to the size of the window
  • glCanvasResizeToParent Resize the Canvas to the size of the parent (container) element

Transparent Patch

make sure clear checkbox is NOT checked in mainloop.

in patch options set the following canvas context attributes:

canvas:{
    alpha:true,
    premultipliedAlpha:true
}

help cables get better and edit this file on github