• Stars
    star
    312
  • Rank 130,130 (Top 3 %)
  • Language
    JavaScript
  • Created over 11 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Tweak values in JavaScript without having to reload.

JavaScript source transformation to support Bret Victor-style value-scrubbing interfaces with the information without having to recompile code every time the value changes.

Try it out!

API

To use scrubby in your project, just include scrubby.all.js in your page and mark any scripts you want to scrub with type=text/scrubby.

<!DOCTYPE html>
<script src='https://raw.githubusercontent.com/nornagon/scrubby/master/scrubby.all.js'></script>
<style>
  .ball {
    position: absolute;
    left: 100px; top: 100px;
    width: 50px; height: 50px;
    border-radius: 25px;
    background: green;
  }
</style>
<div class='ball'></div>
<script type='text/scrubby'>
var t = 0;
var lastFrame = Date.now();
setInterval(function() {
  var ball = document.querySelector('.ball');
  var now = Date.now(), dt = (now - lastFrame) / 1000 * 40;
  t += dt; lastFrame = now;
  ball.style.left = 100 + 50 * Math.sin(t * 0.2) + 'px';
  ball.style.top = 100 + 50 * Math.sin(t * 0.2 + 0.4 * Math.PI*2) + 'px';
}, 1000/60);
</script>

(See this example live.)

Scrubby adds a button to the top-left of the page for each script you specify that's scrubbable. Clicking on that button will open a new window with the code in it, and you can scrub live immediately.

Note that in this code, scrubbing the framerate (1000/60) does nothing, because the setInterval has already been called by the time you start scrubbing. Scrubbing will only work on values that are referenced again after you edit them.

If you want to re-run a piece of code when a value is scrubbed, you can listen for the 'scrubbed' event:

scrubby.on('scrubbed', function() {
  redraw()
})

(the demo code does this to update the canvas when you edit a value.)

How it works

Scrubby transforms this JavaScript:

function draw() {
  var x = 20, y = 32
  ctx.moveTo(x,y)
  ctx.lineTo(x+50, y)
}

into this:

var $values = {
  '1': 20,
  '2': 32,
  '3': 50
};
function draw() {
  var x = $values['1'], y = $values['2'];
  ctx.moveTo(x, y);
  ctx.lineTo(x + $values['3'], y);
}

When you scrub a value, scrubby updates the global $values object with the edited value. When the code runs again, it automatically uses the new value.

TODO

  • It would be nice to be able to type in a value, as well as to scrub it.
  • Editing strings would be good.
  • Strings like 'hsla(260,40%,40%,0.1)' could have a color picker attached instead of a text editor.
  • I'd like to explore indirecting not just values, but whole functions, allowing you to edit the text of a function. I'm worried that it'll break in non-obvious ways, though. The current method is very straightforward, and I'd like to preserve that.

More Repositories

1

jonesforth

Mirror of JONESFORTH
Assembly
926
star
2

saxi

Tools & library for driving the AxiDraw pen plotter
TypeScript
447
star
3

nodecraft

Minecraft server in node.js
JavaScript
95
star
4

cdda-guide

The Hitchhiker's Guide to the Cataclysm
Svelte
95
star
5

atom

a <canvas> game framework that does as little as possible
CoffeeScript
88
star
6

twitter-bookmark-archiver

Download your Twitter bookmarks and associated media
JavaScript
86
star
7

ircv

IRC inna Chrome app
CoffeeScript
72
star
8

git-rebase-all

Rebase many branches at once, useful for updating topic branches against upstream
Shell
52
star
9

flatten-svg

Flatten SVGs into points
JavaScript
52
star
10

electron-minidump

Symbolicate Electron minidumps
JavaScript
36
star
11

autowiki

Autowiki is a tool for creating networked documents.
TypeScript
22
star
12

hf-mission-planner

Mission planner for the board game High Frontier
JavaScript
21
star
13

thistle

JavaScript HSL color picker
CoffeeScript
20
star
14

stam-stable-fluids

Real-Time Fluid Dynamics for Games, Jos Stam 2003 [JS port]
JavaScript
17
star
15

mkanki

Generate Anki decks. Supports cloze models and adding media.
JavaScript
12
star
16

node-zap

a tiny testing tool for node.js
JavaScript
10
star
17

fov.js

field of vision calculation library
JavaScript
10
star
18

bf.wasm

Compile Brainfuck to WebAssembly
JavaScript
8
star
19

xray-python-opentracing

OpenTracing adapter for AWS X-Ray
Python
8
star
20

finch-trials-history

7
star
21

polarity

My entry for Ludum Dare #23: change your polarity, solve puzzles!
JavaScript
7
star
22

blox

WebGL minecraft-style voxelly goodness
JavaScript
6
star
23

World-of-Sand-DS

World of Sand for the Nintendo DS
C
6
star
24

node-conseq

A small library for making nested async calls more manageable in node.js
JavaScript
6
star
25

finch-trials

Fetch and parse Chrome's Finch trial configuration
JavaScript
6
star
26

espforth

Assembly
5
star
27

cdda-data

JavaScript
5
star
28

skia-zig

5
star
29

optimize-paths

Optimize linear paths for plotting
TypeScript
5
star
30

rust-skia-game-test

Example of using Rust + Skia to render into a native OS window
Rust
5
star
31

erthur

A mapping tool for Dwarf Fortress
JavaScript
5
star
32

growing

CoffeeScript
4
star
33

minidump-rs

Rust
4
star
34

sharevim

ShareJS + vim
CoffeeScript
3
star
35

gameplan

CoffeeScript
3
star
36

hfov

Haskell bindings to Greg McIntyre's FOV library
C
3
star
37

node-wake-lock

stop your machine from sleeping when it's doing importantâ„¢ things
C++
3
star
38

remarkable-wikilink

Parse [[MediaWiki-style links]] in Markdown with Remarkable
JavaScript
3
star
39

SpyWear

A game of deception and explosions.
Python
3
star
40

irc5

Persistent IRC client in the browser
CoffeeScript
3
star
41

scanvas

Skia-backed, lightning-fast 2D graphics library for Scala
Scala
3
star
42

cdda-more-city-locations

Makefile
3
star
43

constraint-solving-pcg

Using Constraints to Generate Content That Follows Rules
Python
3
star
44

airpaint

ASCII Art Editor
JavaScript
3
star
45

jslint-node-edition

JSLint JavaScript code quality tool ported to Node.js from Rhino
JavaScript
3
star
46

saxi-app

JavaScript
3
star
47

dillinger-app

dillinger.io wrapped in electron
JavaScript
2
star
48

Preloader

Fork of https://gitlab.com/troyengel/Preloader
PHP
2
star
49

space

CoffeeScript
2
star
50

inat-bingo

HTML
2
star
51

ponk

Pong with physics
JavaScript
2
star
52

nanites

CoffeeScript
2
star
53

wasm-minidump

Parse minidump files in the browser
Rust
2
star
54

math-snippets

Bits of math I don't want to figure out again
CoffeeScript
2
star
55

hexing-ncurses

A talk I gave at WaffleJS in June 2019 about terminals and how ncurses works
JavaScript
2
star
56

resize-text

JS helper to resize text to fit a given rectangle
JavaScript
2
star
57

live

live-edit JavaScript
CoffeeScript
2
star
58

tralien

JS+canvas scifi roguelike game
JavaScript
2
star
59

rnd-tumblr-theme

Robots & Dinosaurs tumblr theme
2
star
60

cdda-json-lsp

TypeScript
2
star
61

flickr-gesture

A tool for practicing gesture drawing.
TypeScript
1
star
62

github-notifs-plus

Enhance the GitHub Notifications UI
JavaScript
1
star
63

electron-webgl-memory-test

JavaScript
1
star
64

parse-breakpad

Parse breakpad .sym files in JS
JavaScript
1
star
65

tronic

programmer nomic
CoffeeScript
1
star
66

dot-files

Vim Script
1
star
67

kit

Scala
1
star
68

standoff

CoffeeScript
1
star
69

sat-game

TypeScript
1
star
70

torch

A realtime roguelike engine with dynamic lighting for the NDS
C
1
star
71

symbolicate-trace

Symbolicate cpu_profiler samples taken from Electron apps
JavaScript
1
star
72

gossamer

Thin shell for game
JavaScript
1
star
73

old-chrome

Get download links for old versions of Chrome
JavaScript
1
star
74

zim

zooming, collaborative vim-like editor
CoffeeScript
1
star
75

10days

CoffeeScript
1
star
76

adrift

Scala
1
star
77

wobble-tower

Like Tetris, but wobblier
GDScript
1
star
78

geo

CoffeeScript
1
star
79

pong

JavaScript
1
star
80

clickfight

CoffeeScript
1
star
81

minisat-js-ffi

C++
1
star
82

ur-a-dorf

JavaScript
1
star
83

bakermot

Chrome app to drive a MakerBot
JavaScript
1
star
84

torumekia

The Sea of Corruption
Scala
1
star
85

Gust

You are the wind.
JavaScript
1
star
86

mellifluence

Boilerplate web audio code
CoffeeScript
1
star
87

dforth

Forth on DCPU-16. Because we can.
Haskell
1
star
88

flip

Exercising the compositor, showing that it's slow
1
star
89

write-macho

JavaScript
1
star
90

quickerfort

QuickFort-like blueprint placer for Dwarf Fortress + dfhack
Lua
1
star
91

sharechat

live chat
CoffeeScript
1
star
92

continuum

Time becomes space
JavaScript
1
star
93

optimize-paths-svg-example

Example code for flatten-svg + optimize-paths
JavaScript
1
star
94

forcegod

random game doodle
JavaScript
1
star
95

play-cdda

Play Cataclysm: Dark Days Ahead in your browser
JavaScript
1
star