Skip to content

Instantly share code, notes, and snippets.

@DarkWiiPlayer
Last active January 12, 2022 03:38
Show Gist options
  • Save DarkWiiPlayer/6abc4042e3e4b786e8cf7a63125178e8 to your computer and use it in GitHub Desktop.
Save DarkWiiPlayer/6abc4042e3e4b786e8cf7a63125178e8 to your computer and use it in GitHub Desktop.
love2d version badge generator

LÖVE badge generator

This is just a small snippet that generates a github badge with supported version of love2d that you can use for your game projects.

It makes use of MoonXML to make generate the actual SVG (XML) code and a string buffer to save the result, which wouldn't be needed in most production situations.

height = 20
width = 100
split = 6/10
tag = (number, color='#ea316e') ->
buf = require'strbuffer'!
generator = require'moonxml'.xml ->
svg {
xmlns: 'http://www.w3.org/2000/svg'
:width
:height
viewBox: "0 0 #{width} #{height}"
fill: 'white'
['font-family']: 'sans-serif'
}, ->
linearGradient {id:'gradient', x2: '0', y2: '100%'}, ->
stop offset: 0, ['stop-color']: '#bbb', ['stop-opacity']: .1
stop offset: 1, ['stop-opacity']: .1
clipPath {id: 'clip'}, ->
rect
:width
:height
rx: 3
g {['clip-path']: "url('#clip')"}, ->
rect
fill: '#555'
:height
:width
rect
fill: color
:height
width: width*(1-split)
x: width*split
rect
fill: 'url(#gradient)'
:height
:width
text 'Löve ♥',
['text-anchor']: 'middle'
['alignment-baseline']: 'central'
x: width*split / 2
y: height/2
text number,
['text-anchor']: 'middle'
['alignment-baseline']: 'central'
x: width*split + width*(1-split) / 2
y: height/2
generator buf\append
buf
print tag '11.1'
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment