Giter VIP home page Giter VIP logo

svg2love's Introduction

svg2love

Proof of concept perl script to convert simple SVGs to LÖVE graphic drawing commands.

Motivation

Take the output of primitive and place it in LÖVE, to enable easy graphics for Zomia, a roguelike game I am writing to learn Lua.

Approach

Simple line-oriented parser that converts one command at a time to LÖVE graphics environment directives. Does not respect unrecognized primitives.

Status

Currently, the script only recognizes rectangles, arbitrary-point polygons, ellipses (and circles drawn as ellipses), and these are all assumed to be filled. Colours are opacity are respected, and SVG groups (including rotation, translation and scaling) are supported.

Usage

You need perl installed. This is normal on any type of Unix-like, including MacOSX. On Windows you can install it easily enough as well.

Then, run the script as follows:

svg2love file.svg >>some.lua

This will read file.svg, show some debugging information, and add the translated LÖVE code output to the file some.lua. (You can shut the debug up by adding 2>/dev/null before the >>.)

Notes

SVGs can have data that goes beyond the border of their defined image boundary. Primitive generates SVGs of this type. In order to display these cleanly, take a look at the demo code, which uses love.graphics.setScissor() to draw to a specific area of the screen, and coordinate system manipulation to properly scale and crop the image.

Demo

A demonstration in the demo subdirectory includes loading the generated drawing commands from a lua source file, scaling them to an arbitrary window size and displaying them.

You will need to have LÖVE installed to run it.

To run it on Unix-like systems, enter the directory and type:

love .

What it does is take the following SVG input file from primitive...

Demo source SVG

... load the svg2love-converted form (ie. LÖVE draw commands) from a file, and turn the resulting image in to a scaled and cropped form to fit a specified region of the window...

Demo screenshot

It may not look like much, but there seemed to be no other lua libraries out there to read SVGs and I'm not much of a graphics programmer, so I'm very glad it works!

To Do

  • Turn it in to a proper library written in Lua that is capable of loading files on the fly. (There's no sense in storing the converted commands really, SVG is smaller on disk and this reduces filesystem and programmer headache/complexity.) This is now underway over here.

svg2love's People

Stargazers

 avatar  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.