Agile SVG maker for python

Related tags

Deep LearningASVG
Overview

Agile SVG Maker

Need to draw hundreds of frames for a GIF? Need to change the style of all pictures in a PPT? Need to draw similar images with different parameters? Try ASVG!

Under construction, not so agile yet...

Basically aimed at academic illustrations.

Simple Example

from ASVG import *

# A 500x300 canvas
a = Axis((500, 300)) 

# Draw a rectangle on a, at level 1, from (0,0) to (200,100)
# With (5,5) round corner, fill with red color.
rect(a, 1, 0, 0, 200, 100, 5, 5, fill='red')

# Draw a circle on a, at level 3
# Centered (50,50) with 50 radius, fill with blue color.
circle(a, 3, 50, 50, 50, fill='blue')

# Draw this picture to example.svg
draw(a, "example.svg")

Parameterized Sub-image

def labeledRect(
        level: int,
        width: float,
        height: float,
        s: Union[str, TextRepresent],
        font_size: float,
        textShift: Tuple[float, float] = (0, 0),
        font: str = "Arial",
        rx: float = 0,
        ry: float = 0,
        margin: float = 5,
        attrib: Attrib = Attrib(),
        rectAttrib: Attrib = Attrib(),
        textAttrib: Attrib = Attrib(),
        **kwargs):
    e = ComposedElement((width + 2 * margin, height + 2 * margin),
                        level, attrib + kwargs)
    rect(e, 0, margin, margin, width, height, rx, ry, attrib=rectAttrib)

    textX = width / 2 + textShift[0] + margin
    textY = height / 2 + textShift[1] + (font_size / 2) + margin
    text(e, 1, s, textX, textY, font_size, font, attrib=textAttrib)
    return e

a = Axis((300,200))
a.addElement(labeledRect(...))

Nested Canvas

Canvas and Axis

Create a canvas axis with Axis(size, viewport) size=(width, height) is the physical size of the canvas in pixels. viewport=(x, y) is the logical size of the axis, by default its the same of the physical size.

# A 1600x900 canvas, axis range [0,1600)x[0,900)
a = Axis((1600, 900))

# A 1600x900 canva, with normalized axis range[0,1),[0,1)
b = Axis((1600, 900), (1.0, 1.0))

ComposedElement

A composed element is a sub-image.

ComposedElement(size, level, attrib) size=(width, height): the size of the axis of this element. level: the higher the level is, the fronter the composed element is. attrib: the common attributes of this element

Add a composed element into the big canvas:axis.addElement(element, shift) shift=(x,y) is the displacement of the element in the outer axis.

A composed element can have other composed elements as sub-pictures: element.addElement(subElement, shift)

Basic Elements

The basic element comes from SVG. Basicly, every element needs a axis and a level argument. axis can be a Axis or ComposedElement. The bigger the level is, the fronter the element is. level is only comparable when two elements are under the same axis.

# Rectangle
rect(
    axis: Union[core.Axis, core.ComposedElement],
    level: int,
    x: float, # top left
    y: float,
    width: float,
    height: float,
    rx: float = 0.0, # round corner radius
    ry: float = 0.0,
    attrib: core.Attrib = core.Attrib(),
    **kwargs
)
# Circle
circle(
    axis: Union[core.Axis, core.ComposedElement],
    level: int,
    cx: float, # center
    cy: float,
    r: float, # radius
    attrib: core.Attrib = core.Attrib(),
    **kwargs
)
# Ellipse
ellipse(
    axis: Union[core.Axis, core.ComposedElement],
    level: int,
    cx: float, # center
    cy: float,
    rx: float, # radius
    ry: float,
    attrib: core.Attrib = core.Attrib(),
    **kwargs
)
# Straight line
line(
    axis: Union[core.Axis, core.ComposedElement],
    level: int,
    x1: float, # Start
    y1: float,
    x2: float, # End
    y2: float,
    attrib: core.Attrib = core.Attrib(),
    **kwargs
)
# Polyline
polyline(
    axis: Union[core.Axis, core.ComposedElement],
    level: int,
    points: List[Tuple[float, float]],
    attrib: core.Attrib = core.Attrib(),
    **kwargs
)
# Polygon
polygon(
    axis: Union[core.Axis, core.ComposedElement],
    level: int,
    points: List[Tuple[float, float]],
    attrib: core.Attrib = core.Attrib(),
    **kwargs
)
# Path
path(
    axis: Union[core.Axis, core.ComposedElement],
    level: int,
    d: PathD,
    attrib: core.Attrib = core.Attrib(),
    **kwargs
)

PathD is a sequence of path descriptions, the actions is like SVG's path element. View Path tutorial We use ?To() for captial letters and ?For() for lower-case letters. close() and open() is for closing or opening the path. Example:

d = PathD()
d.moveTo(100,100)
d.hlineFor(90)
d.close()
# Equivilent: d = PathD(["M 80 80", "h 90",  "Z"])

path(a, 0, d)

Text

text(
    axis: Union[core.Axis, core.ComposedElement],
    level: int,
    s: Union[str, TextRepresent],
    x: float,
    y: float,
    fontSize: int,
    font: str = "Arial",
    anchor: str = "middle",
    attrib: core.Attrib = core.Attrib(),
    **kwargs
)

anchor is where (x,y) is in the text. Can be either start, middle or end.

TextRepresent means formatted text. Normal string with \n in it will be converted into multilines. You can use TextSpan to add some attributes to a span of text.

Examples:

text(
    a, 10,
    "Hello\n???" + \
    TextSpan("!!!\n", fill='#00ffff', font_size=25) +\
    "???\nabcdef",
    30, 30, 20, anchor="start")

Arrow

# Straight arrow
arrow(
    axis: Union[core.Axis, core.ComposedElement],
    level: int,
    x: float, # Position of the tip
    y: float,
    fromX: float, # Position of the other end
    fromY: float,
    tipSize: float = 10.0,
    tipAngle: float = 60.0,
    tipFilled: bool = True,
    **kwargs
)
# Polyline arrow
polyArrow(
    axis: Union[core.Axis, core.ComposedElement],
    level: int,
    points: List[Tuple[float, float]],
    tipSize: float = 10.0,
    tipAngle: float = 60.0,
    tipFilled: bool = True,
    **kwargs
)

Attributes

Attributes is for customizing the style of the elements.

myStyle = Attrib(
    fill = "#1bcd20",
    stroke = "black",
    stroke_width = "1pt"
)

alertStype = myStyle.copy()
alertStype.fill = "#ff0000"

rect(..., attrib=myStyle)
circle(..., attrib=alertStyle)

The name of the attribute are the same as in SVG elements, except use underline _ instead of dash -

Attributs of ComposedElement applies on <group> element.

For convinent, you can directly write some attributes in **kwargs.

rect(..., fill="red")

# Equivilient
rect(..., attrib=Attrib(fill="red))
Owner
SemiWaker
A student in Peking University Department of Electronic Engineering and Computer Science, Major in Artificial Intelligence.
SemiWaker
Implementation of a memory efficient multi-head attention as proposed in the paper, "Self-attention Does Not Need O(n²) Memory"

Memory Efficient Attention Pytorch Implementation of a memory efficient multi-head attention as proposed in the paper, Self-attention Does Not Need O(

Phil Wang 180 Jan 05, 2023
PyTorch code for EMNLP 2021 paper: Don't be Contradicted with Anything! CI-ToD: Towards Benchmarking Consistency for Task-oriented Dialogue System

Don’t be Contradicted with Anything!CI-ToD: Towards Benchmarking Consistency for Task-oriented Dialogue System This repository contains the PyTorch im

Libo Qin 25 Sep 06, 2022
[NeurIPS 2021] Shape from Blur: Recovering Textured 3D Shape and Motion of Fast Moving Objects

[NeurIPS 2021] Shape from Blur: Recovering Textured 3D Shape and Motion of Fast Moving Objects YouTube | arXiv Prerequisites Kaolin is available here:

Denys Rozumnyi 107 Dec 26, 2022
Pytorch modules for paralel models with same architecture. Ideal for multi agent-based systems

WideLinears Pytorch parallel Neural Networks A package of pytorch modules for fast paralellization of separate deep neural networks. Ideal for agent-b

1 Dec 17, 2021
[ICCV 2021 Oral] NerfingMVS: Guided Optimization of Neural Radiance Fields for Indoor Multi-view Stereo

NerfingMVS Project Page | Paper | Video | Data NerfingMVS: Guided Optimization of Neural Radiance Fields for Indoor Multi-view Stereo Yi Wei, Shaohui

Yi Wei 369 Dec 24, 2022
Unofficial PyTorch implementation of Neural Additive Models (NAM) by Agarwal, et al.

nam-pytorch Unofficial PyTorch implementation of Neural Additive Models (NAM) by Agarwal, et al. [abs, pdf] Installation You can access nam-pytorch vi

Rishabh Anand 11 Mar 14, 2022
Keras community contributions

keras-contrib : Keras community contributions Keras-contrib is deprecated. Use TensorFlow Addons. The future of Keras-contrib: We're migrating to tens

Keras 1.6k Dec 21, 2022
This is the implementation of our work Deep Extreme Cut (DEXTR), for object segmentation from extreme points.

This is the implementation of our work Deep Extreme Cut (DEXTR), for object segmentation from extreme points.

Sergi Caelles 828 Jan 05, 2023
Computational Methods Course at UdeA. Forked and size reduced from:

Computational Methods for Physics & Astronomy Book version at: https://restrepo.github.io/ComputationalMethods by: Sebastian Bustamante 2014/2015 Dieg

Diego Restrepo 11 Sep 10, 2022
StyleTransfer - Open source style transfer project, based on VGG19

StyleTransfer - Open source style transfer project, based on VGG19

Patrick martins de lima 9 Dec 13, 2021
CLIP2Video: Mastering Video-Text Retrieval via Image CLIP

CLIP2Video: Mastering Video-Text Retrieval via Image CLIP The implementation of paper CLIP2Video: Mastering Video-Text Retrieval via Image CLIP. CLIP2

168 Dec 29, 2022
Satellite labelling tool for manual labelling of storm top features such as overshooting tops, above-anvil plumes, cold U/Vs, rings etc.

Satellite labelling tool About this app A tool for manual labelling of storm top features such as overshooting tops, above-anvil plumes, cold U/Vs, ri

Czech Hydrometeorological Institute - Satellite Department 10 Sep 14, 2022
A framework for annotating 3D meshes using the predictions of a 2D semantic segmentation model.

Semantic Meshes A framework for annotating 3D meshes using the predictions of a 2D semantic segmentation model. Paper If you find this framework usefu

Florian 40 Dec 09, 2022
Python scripts for performing lane detection using the LSTR model in ONNX

ONNX LSTR Lane Detection Python scripts for performing lane detection using the Lane Shape Prediction with Transformers (LSTR) model in ONNX. Requirem

Ibai Gorordo 29 Aug 30, 2022
CCPD: a diverse and well-annotated dataset for license plate detection and recognition

CCPD (Chinese City Parking Dataset, ECCV) UPdate on 10/03/2019. CCPD Dataset is now updated. We are confident that images in subsets of CCPD is much m

detectRecog 1.8k Dec 30, 2022
Invert and perturb GAN images for test-time ensembling

GAN Ensembling Project Page | Paper | Bibtex Ensembling with Deep Generative Views. Lucy Chai, Jun-Yan Zhu, Eli Shechtman, Phillip Isola, Richard Zhan

Lucy Chai 93 Dec 08, 2022
A semantic segmentation toolbox based on PyTorch

Introduction vedaseg is an open source semantic segmentation toolbox based on PyTorch. Features Modular Design We decompose the semantic segmentation

407 Dec 15, 2022
Discretized Integrated Gradients for Explaining Language Models (EMNLP 2021)

Discretized Integrated Gradients for Explaining Language Models (EMNLP 2021) Overview of paths used in DIG and IG. w is the word being attributed. The

INK Lab @ USC 17 Oct 27, 2022
QQ Browser 2021 AI Algorithm Competition Track 1 1st Place Program

QQ Browser 2021 AI Algorithm Competition Track 1 1st Place Program

249 Jan 03, 2023
百度2021年语言与智能技术竞赛机器阅读理解Pytorch版baseline

项目说明: 百度2021年语言与智能技术竞赛机器阅读理解Pytorch版baseline 比赛链接:https://aistudio.baidu.com/aistudio/competition/detail/66?isFromLuge=true 官方的baseline版本是基于paddlepadd

周俊贤 54 Nov 23, 2022