cables DocumentationHow To UseWorking with filesKeyboard ShortcutsUser Interface WalkthroughBeginner TutorialBeginner 1: Drawing A CircleBeginner 2: TransformationsBeginner 3: ColorMore TransformationsIntermediateImage CompositionsPost-Processing 3D ScenesExporting And EmbeddingHow to serve files externally and fix CORS headersExporting PatchesExport using the cables command line interfaceExport via IframeExport creating a standalone executableExport to github (pages)Export and deploy to netlifyExport full PatchExport a ZIP fileExternal triggers / functionsUsing variablesPreviewing / uploading exported cables patchesExamples for EmbeddingPermissionsUsersPatchesTeamsOpsMultiplayerPatchlistsCoding OpsCreating AttachmentsGeneral op/Port CallbacksPortsDynamic PortsArray PortsBoolean portsInteger Number PortsObject PortsString portsTrigger PortsFloating Point Number PortsGUI/UI attributesHello Op - Part 1LibrariesDeveloping OpsRenaming / Creating a new versionCreating Viz OpsGuidelinesObject PortsPatching Ops / SubPatchOpsWriting ShadersWeb Audio Op DevelopmentDeveloping CablesRepositoriesSet up local environmentScriptsHow to work with forksGenerated DocumentationLightingLightsShadowsWorking With AudioBasic Audio SetupWorking with EffectsReal-Time Audio Analyzation & Audio VisualizationOffline Audio Visualization & AnalyzationCommunicationcables APIOptimizing Performance In PatchesTools for debugging your patchHow to optimize cables patches with the Performance opHow to optimize cables patches with the ProfilerCommon pitfalls with the "usual suspects"Optimizing arraysDebugging Shaders with ShaderInfoFAQAudio in web browsersHow to make demoscene demos with cables.glEmbeddingHow to integrate my cables patch into my CMS (webflow/wix/squarespace/...)?How to remove grey rectangles on touch (mobile)?Why doesn't the DownloadTexture op work on iOS?How to disable page scrolling on mobile?Mobile tippsHow to run exported patches on your local machineTransparent CanvasFeatures and SupportHow to contribute code to cablesWill there be support for (animated) GIFs?Can i use a website as a texture?Screenshots and Video recordingHow to report a bug in cablesHow can I share a patch to get help?How can I support cables?Video playback in cablesGeneral questionsWhat is dev.cables.glHTML And CSS In CablesJavascript Frameworkscordova / phonegapelectronreactvuejsLicenses and paymentWhat license do i need to use cables?Will I have to pay for it in the future?How is my work licensed when using cables?Does cables support midi and OSC?Patch PermissionsMy User Profile & Social MediaShadertoyCables at schools and universitiesTechnical questionsWebGL1 and WebGL2

Examples for Embedding

Any exported cables patch can be easily integrated into your website with just a few lines
of javascript. The index.html of any export will give you a good example on how to integrate your patch into any
website.

For further 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>
        let 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 an clearAlpha checkboxes are NOT checked in MainLoop.

In patch options set the following canvas context attributes:

canvas: {
    "alpha": true,
    "premultipliedAlpha": true
}

Also check this FAQ Article on Transparent Canvas.


Found a problem? Edit this file on github and contribute to cables!