A pure-lua vector graphics processing and rendering library for LÖVE 2D
lövector is a pure-lua vector graphics processing and rendering library for the LÖVE game framework. It isn't tied to any particular vector graphics format: implementations of various vector graphics formats (SVG, EPS, PDF, custom...) are welcome, but for now, lövector only has an SVG implementation.
local lovector = require "lovector"
local house = nil
local tiggie = nil
-- You first create the vector graphics images once:
function love.load()
--- Example: Build a path
-- Create a path
-- Most methods return "self", so you can chain method calls
local roof_path = lovector.PathBuilder()
:move_to(50, 140)
:line_to(150, 60)
:line_to(250, 140)
:close_path()
--- Example: Build a house
-- Create a vector graphics image with "Graphics"
-- It dynamically generates a LÖVE draw function we can use later
-- Most methods return "self"
house = lovector.Graphics()
-- Set line width
:set_line_width(10)
-- Wall
:rect(75, 140, 150, 110)
:stroke_path()
-- Door
:begin_path()
:rect(130, 190, 40, 60)
:fill_path()
-- You can also use a manually created Path!
:stroke_path(roof_path)
--- Example: Load an SVG
-- It just does all the work for you, but it's a lovector.Graphics too!
tiggie = lovector.SVG("demo_files/ghostscript-tiger.svg")
end
-- Then, you can draw them anywhere, as many times as you want!
function love.draw()
--- Example: Drawing stuff!
-- Arguments are:
-- 1. x_pos (default = 0)
-- 2. y_pos (default = 0)
-- 3. x_scale (default = 1)
-- 4. y_scale (default = x_scale)
house:draw(0, 0)
tiggie:draw(300, 0, 10)
end
The main.lua
file at the root contains a demo code, showing some of the
features of lövector. You can move the camera and zoom-in as much as you want.
move_to
, line_to
and other <canvas>
-like commands.
Supports cubic and quadratic Bézier curves, and elliptical arcs.Here's a summary table of what lövector does and doesn't support for now:
feature | supported |
---|---|
Non-Zero Fill Rule | :heavy_check_mark: |
Even-Odd Fill Rule | :heavy_check_mark: |
Solid Colors | :heavy_check_mark: |
Linear Gradients | :x: |
Radial Gradients | :x: |
Line Dashes | :x: |
Line Joins | :heavy_check_mark: |
Line Caps | :heavy_check_mark: |
Note: This table is for the SVG 1.1 specification. Some SVG 2 features (such as "arcs" joins) might not be implemented yet.
circle
,
defs
,
ellipse
,
g
,
line
,
path
,
polygon
,
polyline
,
rect
,
svg
,
use
Feel free to fork, hack, make changes and merge/pull requests! Though, try to follow these coding style guidelines as much as possible:
As a rule of thumb, try to keep the coding style consistent with what's already there!
PascalCase
.snake_case
.shortname
, onlylowercase
and with nothing between
words.ALL_CAPS_WITH_UNDERSCORES
.,
.,
.=
, +
and -
.*
and /
isn't mandatory if
they're part of a mathematic expression where they have an implicit higher
precedence than other operators. Example: a*b + c*d
, a * b + c * d
,
a * b + c*d
are okay, but a*b * c
isn't.Assume that the 80 chars limit is right here: ----------------------------->
This is bad.
Really bad.
Don't do that.
It's weird.
Instead, you can do this. It makes the Markdown source code look more like
the HTML it produces.
You are still allowed to have _explicit_ line-breaks in a paragraph, by
having two-spaces at the end of a line, like the previous one.
*
for first-level lists and -
for every other level of nesting.lövector is licensed under the MIT license:
MIT License
Copyright (c) 2019 nasso <nassomails ~ at ~ gmail {dot} com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.