question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I’m working in a feature/hud branch to test out the idea of a built-in GUI system for canvas-sketch. It would be like dat.gui but a bit more opinionated, a lot more declarative, and will integrate easily with canvas-sketch as well as features like exporting/importing serialized data (for example, making prints parameters reproducible).

Here is an example, no fancy styling yet:

screen shot 2018-10-01 at 5 19 13 pm

And a video in this tweet.

It would be built with Preact to keep the canvas-sketch library small.

Syntax

I don’t want to introduce a lot of new API concepts to users, and I want it to be declarative and in line with the rest of the ethos of pure render functions. My current thought is to have something like this:

  • When params is passed to settings or update() function, the sketch will be added to a global HUD panel, and the panel will be made visible if it has one or more sketches attached to it.
  • If the param is an object it can include settings like display name, min/max, etc.
  • In the sketch & renderer functions, the param prop is converted into literal values (e.g. instead of a descriptor with options, you just get the raw number value).
const canvasSketch = require('canvas-sketch');

const settings = {
  dimensions: [ 640, 640 ],
  params: {
    background: 'pink',
    time: {
      value: 0.5,
      min: 0,
      max: 1,
      step: 0.001
    },
    number: 0.25,
    text: 'some text',
    download: ({ exportFrame }) => exportFrame()
  }
};

canvasSketch(() => {
  return ({ params }) => {
    const { background, radius } = params;
    console.log('Current background:', background); // e.g. #ff0000
    console.log('Current radius:', radius); // e.g. 0.523
  };
}, settings);

Motivation

It won’t be all that different than dat.gui, but:

  • It will work well out of the box, and will require zero “wiring” to get properties hooked up to GUIs or render events
  • It will be declarative, so it can technically be stripped away by a higher-order function that passes props down (like React props & components)
  • It will integrate well with canvas-sketch already, but can also make some nice considerations for exporting, e.g. serialize JSON to a file so that each frame/export is saved with the parameters, or adding a --params flag to the CLI tool to override params with a JSON file
  • The global HUD can be a place for other requested features to canvas-sketch, like a play/pause, export button, etc

Features

Should support:

  • Text input, number spinners, sliders, color input, 2D XY pad, 3D orbit rotation (?), drop-down, checkbox, buttons, file drag & drop (images etc), …?
  • Fuzzy searching of parameters to quickly drill down big lists?
  • Folders or some other way of letting the user organize things?

Questions

  • Syntax for buttons/click events? Often users will want to handle the event within the sketch function, rather than before the sketch loads. Maybe some sort of event system?
  • Should the parameters be persisted with localStorage? etc.
  • How to serialize/unserialize the parameters?
  • How to map params to built-in sketch properties like time, dimensions, duration etc?
  • Is this a can of worms I don’t even want to get into?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:18
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
mattdeslcommented, Nov 9, 2019

Here’s an example showing basically the same thing, but also re-rendering the frame when a GUI parameter changes (fairly useful for static sketches).

https://gist.github.com/mattdesl/04ceca544e637ce1da4d2cf5200d71af

2reactions
RafalWilinskicommented, Nov 9, 2019

I’ve managed to add https://github.com/dataarts/dat.gui with minimal amount of effort.

  1. npm install dat.gui --save
  2. Instantiate GUI
import * as dat from 'dat.gui';
const gui = new dat.GUI();  
  1. Extend settings Object with something like params
const settings = {
  suffix: Random.getSeed(),
  dimensions: 'A4',
  orientation: 'portrait',
  pixelsPerInch: 300,
  params: {
    myControlledVar: 10
  },
  1. Add params to be controlled by datGui
gui.add(settings.params, 'myControlledVar', 1, 50);
  1. Reference it inside render function returned by sketch:
const sketch = (props) => {

  return (props) => {
    const { myControlledVar } = settings.params;
    ...
  1. Profit

Screenshot 2019-11-09 at 13 09 30

Read more comments on GitHub >

github_iconTop Results From Across the Web

Features | GitHub
Keep feature requests, bugs, and more organized with GitHub Issues — engineered for software teams. Coordinate initiatives big and small with project tables ......
Read more >
7 essential GitHub features for dev, project management
1. Iteration support · 2. Command Palette navigation control · 3. Codespaces · 4. Code scanning support for Ruby · 5. Customizable fields...
Read more >
What is GitHub And How To Use It? [Updated]
What are GitHub's Features? · 1. Easy Project Management · 2. Increased Safety With Packages · 3. Effective Team Management · 4. Improved...
Read more >
7 GitHub Features You Should Know - Bits and Pieces
7 GitHub Features You Should Know · 1. GitHub Developer Environment · 2. GitHub Command Line Interface · 3. GitHub Student Developer Pack...
Read more >
Everything new from GitHub Universe 2022
With GitHub Codespaces and new search and navigation functionality, you can easily find what you need to keep you in the flow.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found