Skip to main content

Convert GeoGebra constructions into high-quality SVG images and MP4 animations using manim

Project description

AnimaGeo

Installation

pip install --upgrade animageo

Using in terminal

animageo test.ggb -s default.json -px 240 auto

Description:

usage: animageo [-h] [-o OUTPUT] [-px PX PX] [-s STYLE] [-d] ggbfile

Converting GeoGebra construction file into SVG image.

positional arguments:
  ggbfile              GeoGebra file to convert

options:
  -h, --help           show this help message and exit
  -o, --output OUTPUT  SVG file to export into
  -px PX PX            image width and height in px (values: num or auto)
  -s, --style STYLE    JSON file with style definitions
  -d, --debug          print options

Using in code

  1. Prepare code scene.py:
from animageo import *

class TestScene(AnimaGeoScene):
    def construct(self):
        # ............................................................
        # Load geometric construction directly from GeoGebra-file     
        self.loadGGB('scene.ggb', style_file = 'default.json', px_size = [400, 'auto'])
        
        # ............................................................
        # Load your own simplified python-style Code-file for manipulations with geometric construction
        # - add new vars and elements
        # - change previous definitions
        self.loadCode('scene_code.py')

        # ............................................................
        # Stylize elements using their names from GeoGebra-file or from your Code-file
        # - use any predefined attributes from style_file or from Manim
        self.element('a').style['stroke'] = self.style.col 
        self.element('A_1').style['fill'] = self.style.col_accent

        # ............................................................
        # Export current scene to image with px_size width/height
        self.exportSVG('scene.svg')

        # ............................................................
        # Do whatever you do with Manim, but also specific things:

        # - add special ValueTracker and link it to Var in geometric construction
        x = self.addVar('x', 5)

        # - use predefined methods to Show, Hide and Update geometric elements without animation
        self.HideAll()
        self.Show(['A', 'B'])

        # - use predefined methods to Show, Hide and Update geometric elements with animation
        self.playShow(['a'])
        self.element('b').style['stroke_opacity'] = 0.5
        self.playUpdate(['b'])

        # - use tracker values for animation
        self.addUpdater(x)
        self.play(x.animate.set_value(10))
        self.clearUpdater(x)

        # - you may also want to change geometric elements as Manim objects (but without affecting geometric construction)
        a = self.mobject('a')
        b = self.mobject('b')
        self.play(VGroup(a, b).animate.arrange(buff=1).shift(DOWN))
        self.play(FadeOut(a, b))        

and code scene_code.py:

from animageo.dsl import *   # IDE-only; dropped by DSL transform at runtime

A = Point(x, 0)
B = Intersect(b, c)
a = Segment(A, B)
  1. Run compilation:
manim 'scene.py' TestScene

Style definitions in JSON

JSON-стиль делится на пять верхнеуровневых секций:

  • palette — именованные цвета;
  • presets — размерные варианты (point_size / line_width × main/bold/aux);
  • defaults — геометрические дефолты (углы, тики, стрелки, шрифт);
  • rendering — настройки рендера и пайплайна;
  • import — правила импорта GGB-значений + встроенная ImportPolicy.

Полный пример:

{
    "name": "default",
    "version": 0.1,

    "palette": {
        "main":         "#2581b5",
        "light":        "#bef3fc",
        "accent":       "#ef60ab",
        "accent_light": "#ffd2ee",
        "aux":          "#000000",
        "black":        "#000000",
        "white":        "#ffffff"
    },

    "presets": {
        "point_size":  { "main": 7, "bold": 9,   "aux": 5 },
        "line_width":  { "main": 2, "bold": 2.5, "aux": 1.5 }
    },

    "defaults": {
        "angle":  { "line_width": 1, "radius": 20, "radius_shift": 3, "radius_right": 14 },
        "tick":   { "width": 1, "length": 12, "shift": 4 },
        "arrow":  { "width": 7.5, "length": 10.5 },
        "font":   { "size": 17 }
    },

    "rendering": {
        "line_cap":               "round",
        "right_angle_joint":      "miter",
        "polygon_boundary_layer": "top",
        "points_display":         "only_labels",
        "scale_export":           0.75
    },

    "import": {
        "colors": {
            "#1565c0":     "main",
            "#1565c0 0.1": "main 0",
            "#d32f2f":     "accent",
            "#d32f2f 0.1": "accent_light 1",
            "#616161":     "aux",
            "#000000 0.6": "main",
            "#000000 0.1": "light 1",
            "#1565c0 0":   "white 1",
            "#d32f2f 0":   "white 1"
        },
        "point_size": { "5": "main" },
        "line_width": { "5": "main", "3": "aux" }
    }
}

rendering — настройки рендера

Ключ Значения Эффект
line_cap "butt" | "round" | "square" окончания линий
right_angle_joint "auto" | "bevel" | "miter" | "round" соединение сторон прямого угла
polygon_boundary_layer "top" | null "top" — контур полигона поверх заливки (z-index=10). Касается сегментов-сторон, создаваемых автоматически GeoGebra
points_display "auto" | "only_labels" | "only_points" скрыть точки / надписи глобально
label_anchor одна из 9 позиций ("TL""BR", "MC" и т. д.) default-якорь подписей
scale_export число множитель px_size и общего масштаба экспорта
angle_radius объект опциональное авто-скалирование радиуса дуги по мере угла
label_placement объект параметры автораскладки подписей

import — правила импорта из GeoGebra

Ключ Тип Назначение
colors dict "#hex [opacity]" → "palette_name [opacity]" ремап цветов из GGB на именованные из palette
point_size dict "N" → "preset_name" маппинг GGB-размера точек на пресет из presets.point_size
line_width dict "N" → "preset_name" маппинг GGB-толщины линий на пресет из presets.line_width
policy объект ImportPolicy гибкие правила конверсии (scalar/DSL/callable), per_type/per_name. См. docs/import_policies.md

Миграция со старой схемы

Если у вас стили в старом формате (style.dot.*, technic, ggb_export на верхнем уровне), прогоните скрипт:

python scripts/migrate_style_json.py --in-place path/to/style.json

Полная таблица «было → стало» — в docs/style_guide/migration.md. Полный справочник всех имён через 5 слоёв (GGB / animageo / JSON / manim / SVG) — в docs/field_names.md.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

animageo-1.0.2.tar.gz (155.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

animageo-1.0.2-py3-none-any.whl (164.0 kB view details)

Uploaded Python 3

File details

Details for the file animageo-1.0.2.tar.gz.

File metadata

  • Download URL: animageo-1.0.2.tar.gz
  • Upload date:
  • Size: 155.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for animageo-1.0.2.tar.gz
Algorithm Hash digest
SHA256 d20bd0b1b505bd04fe35a9e7ee8f3aa5120a49cec4f86e73bd5598608aaeb156
MD5 4783c577c08266ec9bcb45c089dcd9ee
BLAKE2b-256 a643e25858b59d73c788adc4d039e1b87b19e604feb20df5fc39294941222391

See more details on using hashes here.

File details

Details for the file animageo-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: animageo-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 164.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for animageo-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7399a28a2df187ca70d6abeadb36a2c73a04c5a528c02d9e95d7267760579ebb
MD5 8003092c96f7ee6a70631b2613bb7d6d
BLAKE2b-256 8bffdced3d12f4ebd2ea1a00515eb2ca738a748d3fbb94e4672798b49cefb836

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page