Giter VIP home page Giter VIP logo

svg.transform's Introduction

svg.transform

It's a library to do svg.transforms.

It's been on a list of things to do for years, and I haven't implemented it, because I don't need it, and making a library you don't use is silly. But since nobody else is implementing this, even though it's perfectly simple, well, I did it anyway. Anger-Driven Development is a thing. :-D

You are welcome.

I'm already looking for someone to take over this, and I haven't even started writing code. You can take over svg.path too, I don't use it anymore either.

Usage

You make transformation matrices with the following commands:

* svg.transform.translate_matrix(tx, ty=0): Returns a matrix that will translate in x and y

* svg.transform.scale_matrix(sx, sy=None): Returns a matrix that will scale in x and y

* svg.transform.rotate_matrix(r, cx=0, cy=0): Returns a matrix that will rotate, with optional offset

* svg.transform.skewx_matrix(ax): Returns a matrix that will skew in the x axis

* svg.transform.skewy_matrix(ay): Returns a matrix that will skew in the y axis

* svg.transform.matrix_matrix(a, b, c, d, e, f): Returns a free form translation matrix

For example like this:

>>> from svg import transform
>>>
>>> transform.translate_matrix(5, 8)
array([[ 1,  0,  5],
      [ 0,  1, 10],
      [ 0,  0,  1]])

You use this matrix by applying a matrix multiplication:

>>> from array import array
>>>
>>> old_x = 10
>>> old_y = 10
>>>
>>> res = transform.translate_matrix(5, 8) @ array("f", [old_x, old_y, 1])
>>> new_x = res[0]
>>> new_y = res[1]
>>> new_x, new_y
15.0, 18.0

You can also create transformation matrices directly from the SVG transform attributes:

>>> transform.parse("translate(-10 -20) scale(2) rotate(45) translate(5 10)")
array([[  1.05064398,  -1.70180705, -21.7648506 ],
       [  1.70180705,   1.05064398,  -0.98452498],
       [  0.        ,   0.        ,   1.        ]])

svg.transform's People

Contributors

regebro avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.