Code.Movie

Quick start

Code.Movie is a JavaScript library that turns code snippets into animations built from HTML and CSS. Think git diffs meets syntax highlighting meets CSS transitions. To get to a bit of basic animated JSON like this...

1234
["Hello","World"]
[]
["World"]
["Hello", "World"]
[
  "Hello",
  "World"
]

...your first declare your keyframes as a list of strings...

let keyframes = [
  { code: `[]` }, // animate from this...
  { code: `["World"]` }, // ... to this ...
  { code: `["Hello", "World"]` }, //  ... to this ...
  { code: `[\n  "Hello",\n  "World"\n]` }, // ... and end with this
];
123456
let keyframes = [
  { code: `[]` }, // animate from this...
  { code: `["World"]` }, // ... to this ...
  { code: `["Hello", "World"]` }, //  ... to this ...
  { code: `[\n  "Hello",\n  "World"\n]` }, // ... and end with this
];

... then load the core library, a theme and the language module, then pass the keyframes to a function:

let keyframes = [
  /* keyframes go here */
];

import { animateHTML, monokaiDark } from "@codemovie/code-movie";
import json from "@codemovie/code-movie/languages/json";

// HTML = string of bog-standard HTML and CSS
let html = animateHTML(keyframes, {
  tabSize: 2,
  language: json(),
  theme: monokaiDark,
});
12345678910111213
let keyframes = [
  /* keyframes go here */
];

import { animateHTML, monokaiDark } from "@codemovie/code-movie";
import json from "@codemovie/code-movie/languages/json";

// HTML = string of bog-standard HTML and CSS
let html = animateHTML(keyframes, {
  tabSize: 2,
  language: json(),
  theme: monokaiDark,
});

The end result is animated, syntax highlighted code ready for your next slide deck, coding tutorial, or other project needing to visualize code changes. If you want to get ambitious, you can also add a wide variety of decoration to highlight important snippets or direct your audiences attention:

1234
["Hello","World"]
➡️🚫
[]
["World"]
["Hello", "World"]
[
  "Hello",
  "World"
]

Things to note:

This obviously skipped over a ton of details, but captures the gist of Code Movie. Check out the full tutorial for a more in-depth explanation of the above steps!

Apart from going through the tutorial, you might want to read up on the many CSS variables that you can change to tweak your animations. If you want to discuss something or want to report a bug, head over to the CodeMovie meta repository on Github.