From af385473f8ab3c47024612635151bf0f98288f7d Mon Sep 17 00:00:00 2001 From: Naoki Pross Date: Sun, 24 Oct 2021 23:23:40 +0200 Subject: Create TimeDependentComplexPlane tool for video To draw a QAM signal we will need a way to plot a time dependent complex function. So I made a thing that is just a complex plane + a time axis. --- video/manimgl.nix | 30 ---------------- video/manimpango.nix | 22 ------------ video/mapbox-earcut.nix | 25 -------------- video/nix/manimgl.nix | 30 ++++++++++++++++ video/nix/manimpango.nix | 22 ++++++++++++ video/nix/mapbox-earcut.nix | 25 ++++++++++++++ video/qam.py | 83 ++++++++++++++++++++++++++++++++++++++++++--- video/shell.nix | 12 +++---- 8 files changed, 161 insertions(+), 88 deletions(-) delete mode 100644 video/manimgl.nix delete mode 100644 video/manimpango.nix delete mode 100644 video/mapbox-earcut.nix create mode 100644 video/nix/manimgl.nix create mode 100644 video/nix/manimpango.nix create mode 100644 video/nix/mapbox-earcut.nix diff --git a/video/manimgl.nix b/video/manimgl.nix deleted file mode 100644 index cdab07e..0000000 --- a/video/manimgl.nix +++ /dev/null @@ -1,30 +0,0 @@ -{ lib, pkgs, buildPythonApplication, buildPythonPackage, fetchPypi, pythonOlder, - manimpango, mapbox-earcut }: - -buildPythonApplication rec { - pname = "manimgl"; - version = "1.2.0"; - - src = fetchPypi { - inherit pname version; - sha256 = "1bsrn72vjzfz3ldh3cjn9r2gxr18408ja2shz50qwh7jnwi8alyb"; - }; - - preConfigure = '' - sed -i '/argparse/d' manimgl.egg-info/requires.txt - sed -i '/argparse/d' setup.cfg - ''; - - doCheck = false; - - propagatedBuildInputs = [ manimpango mapbox-earcut ] ++ (with pkgs; [ - texlive.combined.scheme-full ffmpeg - ]) ++ (with pkgs.python3Packages; [ - cython sympy numpy pydub scipy pyyaml pyopengl pyopengl-accelerate moderngl moderngl-window - matplotlib colour rich screeninfo tqdm validators - ]); - - disabled = pythonOlder "3.7"; - - meta = { }; -} diff --git a/video/manimpango.nix b/video/manimpango.nix deleted file mode 100644 index 97b5e97..0000000 --- a/video/manimpango.nix +++ /dev/null @@ -1,22 +0,0 @@ -{ lib, pkgs, buildPythonPackage, fetchPypi }: - -buildPythonPackage rec { - pname = "ManimPango"; - version = "0.3.1"; - - src = fetchPypi { - inherit pname version; - sha256 = "09fc7zv953ni7pilv869ldbjgz59j41a8vbz637rqzjh2yjfb9x3"; - }; - - nativeBuildInputs = with pkgs; [ - gcc pkgconfig - ]; - - propagatedBuildInputs = with pkgs; [ pango ] - ++ (with pkgs.python3Packages; [ - cython pytest numpy pillow - ]); - - meta = with lib; {}; -} diff --git a/video/mapbox-earcut.nix b/video/mapbox-earcut.nix deleted file mode 100644 index d325401..0000000 --- a/video/mapbox-earcut.nix +++ /dev/null @@ -1,25 +0,0 @@ -{ lib, pkgs, buildPythonPackage, fetchPypi }: - -buildPythonPackage rec { - pname = "mapbox_earcut"; - version = "0.12.10"; - src = fetchPypi { - inherit pname version; - format = "setuptools"; - sha256 = "0ly48lijgd9inq07x42pfp9c24fn16vn9axpmfwqrkn979krbnah"; - }; - - dontUseCmakeConfigure = true; - - nativeBuildInputs = with pkgs; [ cmake ]; - - buildInputs = with pkgs.python3Packages; [ - setuptools_scm pybind11 - ]; - - propagatedBuildInputs = with pkgs.python3Packages; [ - numpy - ]; - - meta = with lib; {}; -} diff --git a/video/nix/manimgl.nix b/video/nix/manimgl.nix new file mode 100644 index 0000000..cdab07e --- /dev/null +++ b/video/nix/manimgl.nix @@ -0,0 +1,30 @@ +{ lib, pkgs, buildPythonApplication, buildPythonPackage, fetchPypi, pythonOlder, + manimpango, mapbox-earcut }: + +buildPythonApplication rec { + pname = "manimgl"; + version = "1.2.0"; + + src = fetchPypi { + inherit pname version; + sha256 = "1bsrn72vjzfz3ldh3cjn9r2gxr18408ja2shz50qwh7jnwi8alyb"; + }; + + preConfigure = '' + sed -i '/argparse/d' manimgl.egg-info/requires.txt + sed -i '/argparse/d' setup.cfg + ''; + + doCheck = false; + + propagatedBuildInputs = [ manimpango mapbox-earcut ] ++ (with pkgs; [ + texlive.combined.scheme-full ffmpeg + ]) ++ (with pkgs.python3Packages; [ + cython sympy numpy pydub scipy pyyaml pyopengl pyopengl-accelerate moderngl moderngl-window + matplotlib colour rich screeninfo tqdm validators + ]); + + disabled = pythonOlder "3.7"; + + meta = { }; +} diff --git a/video/nix/manimpango.nix b/video/nix/manimpango.nix new file mode 100644 index 0000000..97b5e97 --- /dev/null +++ b/video/nix/manimpango.nix @@ -0,0 +1,22 @@ +{ lib, pkgs, buildPythonPackage, fetchPypi }: + +buildPythonPackage rec { + pname = "ManimPango"; + version = "0.3.1"; + + src = fetchPypi { + inherit pname version; + sha256 = "09fc7zv953ni7pilv869ldbjgz59j41a8vbz637rqzjh2yjfb9x3"; + }; + + nativeBuildInputs = with pkgs; [ + gcc pkgconfig + ]; + + propagatedBuildInputs = with pkgs; [ pango ] + ++ (with pkgs.python3Packages; [ + cython pytest numpy pillow + ]); + + meta = with lib; {}; +} diff --git a/video/nix/mapbox-earcut.nix b/video/nix/mapbox-earcut.nix new file mode 100644 index 0000000..d325401 --- /dev/null +++ b/video/nix/mapbox-earcut.nix @@ -0,0 +1,25 @@ +{ lib, pkgs, buildPythonPackage, fetchPypi }: + +buildPythonPackage rec { + pname = "mapbox_earcut"; + version = "0.12.10"; + src = fetchPypi { + inherit pname version; + format = "setuptools"; + sha256 = "0ly48lijgd9inq07x42pfp9c24fn16vn9axpmfwqrkn979krbnah"; + }; + + dontUseCmakeConfigure = true; + + nativeBuildInputs = with pkgs; [ cmake ]; + + buildInputs = with pkgs.python3Packages; [ + setuptools_scm pybind11 + ]; + + propagatedBuildInputs = with pkgs.python3Packages; [ + numpy + ]; + + meta = with lib; {}; +} diff --git a/video/qam.py b/video/qam.py index 917fdeb..88096e9 100644 --- a/video/qam.py +++ b/video/qam.py @@ -1,14 +1,87 @@ from manimlib import * +from scipy import signal as sig -class QamModulation(Scene): + +class TimeDependentComplexPlane(ComplexPlane): CONFIG = { - "camera_class": ThreeDCamera, + "dimension": 3, + "t_range": np.array([0., 5., 1.]), + "t_axis_config": { + "include_ticks": True, + }, + "background_line_style": { + "stroke_color": GREY_D, + }, + "depth": 8, } + def __init__(self, **kwargs): + ComplexPlane.__init__(self, **kwargs) + + t_axis = self.create_axis(self.t_range, self.t_axis_config, self.depth) + t_axis.rotate(-PI / 2, UP, about_point=ORIGIN) + t_axis.shift(self.n2p(0)) + + self.t_axis = t_axis + self.add(t_axis) + self.axes.add(t_axis) + + def number_to_point(self, number, time=0): + return self.coords_to_point(number.real, number.imag, time) + + def n2p(self, number, time=0): + return self.number_to_point(number, time) + + def get_t_axis(self): + return self.axes[2] + + def get_graph(self, function, axis, t_range=None, **kwargs): + # sample range + s_range = np.array(self.t_range, dtype=float) + + if t_range is not None: + s_range[:len(t_range)] = t_range + + if t_range is None or len(t_range) < 3: + s_range[2] /= self.num_sampled_graph_points_per_tick + + graph = ParametricCurve( + lambda t: self.t_axis.number_to_point(t) + axis.number_to_point(function(t)), + t_range=s_range, + **kwargs + ) + graph.underlying_function = function + graph.t_range = t_range + return graph + + def get_inphase_graph(self, function, **kwargs): + return self.get_graph(function, self.get_x_axis(), **kwargs) + + def get_quadrature_graph(self, function, **kwargs): + return self.get_graph(function, self.get_y_axis(), **kwargs) + + +class QamModulation(Scene): + CONFIG = {} + def construct(self): - circle = Circle() - self.play(FadeIn(circle)) - self.wait(3) + cplane = TimeDependentComplexPlane() + + self.play(ShowCreation(cplane)) + self.play(self.camera.frame.animate.move_to(2 * OUT)) + + graph_y = cplane.get_inphase_graph(lambda t: 2 * np.cos(2 * t), color=RED) + graph_x = cplane.get_quadrature_graph(lambda t: 1 * sig.square(4 * t), color=BLUE) + + self.play(self.camera.frame.animate.reorient(90, 90, 90)) + self.play(ShowCreation(graph_x)) + + self.play(self.camera.frame.animate.reorient(0, 90, 90)) + self.play(ShowCreation(graph_y)) + + self.play(self.camera.frame.animate.reorient(80, 90, 90)) + + # arrow = Arrow( # open an interactive IPython shell here self.embed() diff --git a/video/shell.nix b/video/shell.nix index 9bd9680..4ee2e41 100644 --- a/video/shell.nix +++ b/video/shell.nix @@ -1,16 +1,16 @@ with import {}; let - manimpango = callPackage ./manimpango.nix { + manimpango = callPackage ./nix/manimpango.nix { buildPythonPackage = pkgs.python3Packages.buildPythonPackage; fetchPypi = pkgs.python3Packages.fetchPypi; }; - mapbox-earcut = callPackage ./mapbox-earcut.nix { + mapbox-earcut = callPackage ./nix/mapbox-earcut.nix { buildPythonPackage = pkgs.python3Packages.buildPythonPackage; fetchPypi = pkgs.python3Packages.fetchPypi; }; - manimgl = callPackage ./manimgl.nix { + manimgl = callPackage ./nix/manimgl.nix { buildPythonApplication = pkgs.python3Packages.buildPythonApplication; buildPythonPackage = pkgs.python3Packages.buildPythonPackage; fetchPypi = pkgs.python3Packages.fetchPypi; @@ -21,7 +21,7 @@ let in mkShell { buildInputs = [ manimpango manimgl ]; - shellHook = '' - manimgl qam.py - ''; + # shellHook = '' + # manimgl qam.py + # ''; } -- cgit v1.2.1