Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tiago Peixoto
graph-tool
Commits
807c64df
Commit
807c64df
authored
Mar 22, 2020
by
Tiago Peixoto
Browse files
Improve animation cookbook documentation
parent
97c70930
Changes
4
Hide whitespace changes
Inline
Side-by-side
doc/demos/animation/animation.rst
View file @
807c64df
...
...
@@ -9,6 +9,32 @@ manner. Here we show some examples which uses `GTK+
file. The idea is to easily generate visualisations which can be used in
presentations, and embedded in websites.
Simple interactive animations
-----------------------------
The :func:`~graph_tool.draw.graph_draw` function can optionally return
and be passed a GTK+ window object where drawing can be updated. In this
way, simple animations can be done very easily, specially when done in
an interactive shell. For example, the following will simulate from an
Ising model (see :class:`~graph_tool.dynamics.IsingGlauberState`) and
show the states in an interactive window:
.. doctest::
>>> g = gt.collection.data["football"]
>>> state = gt.IsingGlauberState(g, beta=1.5/10)
>>> win = None
>>> for i in range(100):
... ret = state.iterate_sync(niter=100)
... win = gt.graph_draw(g, g.vp.pos, vertex_fill_color=state.get_state(),
... vcmap=matplotlib.cm.bone_r, window=win, return_window=True,
... main=False)
Although sufficient for many simple animations, the above method is not
the most efficient, as it requires a certain amount of redundant
processing for each drawing. The examples below show more efficient
approaches that can be more suitable in some more elaborate scenarios.
SIRS epidemics
--------------
...
...
@@ -155,7 +181,7 @@ format <http://www.webmproject.org>`_:
.. code-block:: bash
$ mencoder mf://frames/dancing*.png -mf w=500:h=400:type=png -ovc raw -of rawvideo -vf format=i420 -nosound -o dancing.yuy
$ vpxenc dancing.yuy -o dancing.webm -w 500 -h 400 --fps=100/1 --target-bitrate=5000 --good --threads=
4
$ vpxenc dancing.yuy -o dancing.webm -w 500 -h 400 --fps=100/1 --target-bitrate=5000 --good --threads=
16
.. doctest::
...
...
@@ -164,7 +190,7 @@ format <http://www.webmproject.org>`_:
>>> import subprocess
>>> subprocess.call("mencoder mf://frames/dancing*.png -mf w=500:h=400:type=png -ovc raw -of rawvideo -vf format=i420 -nosound -o demos/animation/dancing.yuy".split())
0
>>> subprocess.call("vpxenc demos/animation/dancing.yuy -o demos/animation/dancing.webm -w 500 -h 400 --fps=100/1 --target-bitrate=2000 --good --threads=
4
".split())
>>> subprocess.call("vpxenc demos/animation/dancing.yuy -o demos/animation/dancing.webm -w 500 -h 400 --fps=100/1 --target-bitrate=2000 --good --threads=
16
".split())
0
...
...
@@ -209,7 +235,7 @@ file, so we can encode the animation with the `WebM format
.. code-block:: bash
$ mencoder mf://frames/bfs*.png -mf w=type=png -ovc raw -of rawvideo -vf format=i420,scale=500:400 -nosound -o bfs.yuy
$ vpxenc bfs.yuy -o bfs.webm -w 500 -h 400 --fps=5/1 --target-bitrate=5000 --good --threads=
4
$ vpxenc bfs.yuy -o bfs.webm -w 500 -h 400 --fps=5/1 --target-bitrate=5000 --good --threads=
16
.. doctest::
...
...
@@ -218,7 +244,7 @@ file, so we can encode the animation with the `WebM format
>>> import subprocess
>>> subprocess.call("mencoder mf://frames/bfs*.png -mf type=png -ovc raw -of rawvideo -vf format=i420,scale=500:400 -nosound -o demos/animation/bfs.yuy".split())
0
>>> subprocess.call("vpxenc demos/animation/bfs.yuy -o demos/animation/bfs.webm -w 500 -h 400 --fps=5/1 --target-bitrate=2000 --good --threads=
4
".split())
>>> subprocess.call("vpxenc demos/animation/bfs.yuy -o demos/animation/bfs.webm -w 500 -h 400 --fps=5/1 --target-bitrate=2000 --good --threads=
16
".split())
0
...
...
doc/demos/animation/animation_dancing.py
View file @
807c64df
...
...
@@ -16,7 +16,7 @@ seed(42)
seed_rng
(
42
)
# We need some Gtk and gobject functions
from
gi.repository
import
Gtk
,
Gdk
,
GdkPixbuf
,
GObject
from
gi.repository
import
Gtk
,
Gdk
,
GdkPixbuf
,
GObject
,
GLib
# We will generate a small random network
g
=
random_graph
(
150
,
lambda
:
1
+
poisson
(
5
),
directed
=
False
)
...
...
@@ -100,7 +100,7 @@ def update_state():
# Bind the function above as an 'idle' callback.
cid
=
G
Object
.
idle_add
(
update_state
)
cid
=
G
Lib
.
idle_add
(
update_state
)
# We will give the user the ability to stop the program by closing the window.
win
.
connect
(
"delete_event"
,
Gtk
.
main_quit
)
...
...
doc/demos/animation/animation_sirs.py
View file @
807c64df
...
...
@@ -22,7 +22,7 @@ seed(42)
seed_rng
(
42
)
# We need some Gtk and gobject functions
from
gi.repository
import
Gtk
,
Gdk
,
GdkPixbuf
,
GObject
from
gi.repository
import
Gtk
,
Gdk
,
GdkPixbuf
,
GObject
,
GLib
# We will use the network of network scientists, and filter out the largest
# component
...
...
@@ -137,7 +137,7 @@ def update_state():
# Bind the function above as an 'idle' callback.
cid
=
G
Object
.
idle_add
(
update_state
)
cid
=
G
Lib
.
idle_add
(
update_state
)
# We will give the user the ability to stop the program by closing the window.
win
.
connect
(
"delete_event"
,
Gtk
.
main_quit
)
...
...
doc/demos/animation/animation_zombies.py
View file @
807c64df
...
...
@@ -23,7 +23,7 @@ seed(42)
seed_rng
(
42
)
# We need some Gtk and gobject functions
from
gi.repository
import
Gtk
,
Gdk
,
GdkPixbuf
,
GObject
from
gi.repository
import
Gtk
,
Gdk
,
GdkPixbuf
,
GObject
,
GLib
# We will use the karate-club network
g
=
collection
.
data
[
"karate"
]
...
...
@@ -158,7 +158,7 @@ def update_state():
# Bind the function above as an 'idle' callback.
cid
=
G
Object
.
idle_add
(
update_state
)
cid
=
G
Lib
.
idle_add
(
update_state
)
# We will give the user the ability to stop the program by closing the window.
win
.
connect
(
"delete_event"
,
Gtk
.
main_quit
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment