• Stars
    star
    104
  • Rank 330,604 (Top 7 %)
  • Language
    Julia
  • License
    Other
  • Created almost 10 years ago
  • Updated about 4 years ago

Reviews

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

Repository Details

computations caught on camera

Reel

Build Status

Film computations

Quickstart

Installation

Pkg.add("Reel")

This package now relies on FFMPEG.jl. For versions lower than 1.2 you will need ffmpeg and imagemagick installed to use Reel. This package supersedes ComposeVideo.jl

Usage

Reel exports the all-important function roll which you can use to roll the camera on various arguments:

using Reel
using Plots

function render(t, dt)
    # t is the time into the sequence
    # dt is the time to advance for the next frame

    # any expression that results in an object which can be
    # rendered as png or jpg
    plot([x -> sin(x+t*Ο€), x -> cos(x+t*Ο€)], 0, 6)
end

film = roll(render, fps=30, duration=2)

write("output.gif", film) # Write to a gif file

# Or
write("file.webm", film) # Write to a webm video

# Or
write("file.mp4", film)  # An mp4 formatted video

The same thing can be concisely written with Julia's do syntax:

film = roll(fps=30, duration=2) do t, dt
    plot([x -> sin(x+t*Ο€), x -> cos(x+t*Ο€)], 0, 6)
end

write("output.gif", film)

Note that the fps you specify to roll will be enforced no matter how long the computation actually takes: you set the speed at which you want to watch it.

Reel can also render an abstract array of objects:

using Compose
import Cairo, Fontconfig

Compose.set_default_graphic_size(3inch, 3inch) # Square

# draw a regular n-gon
ngon(n) = compose(context(units=UnitBox(-1, -1, 2, 2)), fill("lightblue"),
                polygon([(cos(x), sin(x)) for x in Ο€/2:2Ο€/n:3.5Ο€]))

roll(map(ngon, vcat(3:10, 9:-1:3)), fps=5)

Reel exports Frames, a type for a collection of frames.

Frames constructor takes a MIME type of the frames, and the fps at which the animation should be rendered. e.g.

You can push a new frames to a Frames object using push!.

# A Glider gun from Conway's game of Life

using Reel
frames = Frames(MIME("image/png"), fps=2)

g = glider_gun # initial board state
for i=1:31
    push!(frames, draw(g))
    g = decidefate(g)
end

frames

You can render a Frames object as usual:

write("output.webm", frames)

In IJulia

A call to roll returns a Frames object. A method writemime(::IO, ::MIME{symbol("text/html"),::Frames) orchestrates the rendering of a Frames object in IJulia. Any cell which results in a Frames results in the animation being rendered. By default, a webm video is generated. You can change this behavior:

Reel.set_output_type("gif") # or "mp4"

They see me rollin', they hatin'

# particles in a box.

using Color, Compose

box(x) = let i = floor(x)
    i%2==0 ? x-i : 1+i-x
end

colors = distinguishable_colors(10, lchoices=[82.])

dots(points) = [(context(p[1], p[2], .03, .03), fill(colors[i%10+1]), circle())
    for (i, p) in enumerate(points)]

velocities = [(rand(), rand()) for i in 1:40]

roll(fps=30, duration=10.0) do t, dt

    compose(context(),
            dots([map(v -> box(v*t + 0.5), (vx, vy)) for (vx, vy) in velocities])...)
end

# Solution of Helmholtz equation with Dirichlet BC using ApproxFun

using ApproxFun

B=dirichlet(d)
Ξ”=lap(d)

plots = [ApproxFun.contour(pdesolve([B,Ξ”+k*I],ones(4),150))
            for k=vcat([1:1.0:100], [99:-1.0:1])]

roll(plots, fps=24)

# Warning: this gif is 8 mb!


Fin.

More Repositories

1

FileTrees.jl

Parallel computing with a tree of files metaphor
Julia
88
star
2

APL.jl

Julia
63
star
3

ijulia-notebooks

Interesting IJulia notebooks
26
star
4

Patchwork.jl

Virtual DOM for Julia
JavaScript
22
star
5

StatusNet

StatusNet, the Free Software micro-blogging platform.
PHP
14
star
6

ArrayMeta.jl

metaprogramming for Julia arrays
Julia
13
star
7

elm-on-meteor

Some example Elm scripts that compile to meteor
JavaScript
10
star
8

phosphene

A library for music visualization
Python
9
star
9

Amb.jl

It's ambiguous what this is
Julia
8
star
10

WebDriver.jl

A julian wrapper around Selenium's python WebDriver client http://selenium-python.readthedocs.io/api.html
Julia
7
star
11

octet

Code for an upcoming 8x8x8 3D LED cube. Has an OpenGL simulator to try out effects.
C
5
star
12

tardis

The code behind "Down Memory Lane"
JavaScript
5
star
13

2d-physics

A 2D physics engine using a point as the only primitive. For a college mini-project.
C
4
star
14

bridge

A multi-player bridge card game. Written on top of Meteor.
JavaScript
3
star
15

960gs-print

960gs for A4 size print.
Python
3
star
16

escher-demo

Slide show and REPL for talks on Escher
Julia
3
star
17

fuconf-talk

Elm code for my talk at Functional Conference 2014
Elm
3
star
18

note

note, the extensible note maker.
2
star
19

ComposeDiff.jl

Compose graphics diff-patching for efficient updates
Julia
2
star
20

18.337-class-website

Jupyter Notebook
2
star
21

IJuliaNotebooks

tutorial notebooks for juliabox.org
2
star
22

IJuliaWidgets.jl

Interactive widgets for IJulia
Julia
2
star
23

CSP.jl

Experimental communicating sequential processes in Julia
Julia
2
star
24

Homework.jl

Homeworks on JuliaBox
Julia
1
star
25

shellsparrow

Command line shell over XMPP
1
star
26

org

.org notes
Haskell
1
star
27

16413-project

Jupyter Notebook
1
star
28

confusional

the super-easy conference planner
JavaScript
1
star
29

colorpool

A color manipulation library in PHP
PHP
1
star
30

config

config files
Vim Script
1
star
31

rst2ipynb

ReST (eventually Sphinx) to IPython Notebook converter
Julia
1
star
32

whoisok

RHoK hack
Python
1
star
33

GadflyDiff.jl

Diff-patching of gadfly plots for efficient updates
Julia
1
star
34

Relational.jl

Julia
1
star
35

octavo

A wisdom engine.
PHP
1
star
36

chic

Code & Presentations for Computer History and Internet Culture SIG in College
JavaScript
1
star