Created
June 11, 2022 20:54
-
-
Save trovster/3b00417dfb1bcc6d6c24430667e0e396 to your computer and use it in GitHub Desktop.
Using shrhdk/text-to-svg to convert "TM" to SVG paths, using font and multiple colours.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const TextToSVG = require('text-to-svg') | |
const textToSVG = TextToSVG.loadSync('fonts/Inter.woff') | |
const colours = Object.values({ | |
blue: '#2490BA', | |
pink: '#d60058', | |
purple: '#5f01ad', | |
green: '#048242', | |
orange: '#e87204' | |
}).reverse() | |
const offset = 15 | |
const colour = colours[Math.floor(Math.random() * colours.length)] | |
const attributes = { fill: colour } | |
const options = { fontSize: 450, y: 640, fontWeight: '900', anchor: 'center middle', attributes: attributes } | |
colours.forEach(function (colour, index) { | |
const t = textToSVG.getSVG('T', { | |
...options, | |
x: 330 + (offset * index), | |
y: 640 - (offset * index), | |
attributes: { | |
...attributes, | |
fill: colour | |
} | |
}).replace( | |
'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="245.25" height="450">', | |
'' | |
).replace('</svg>', '') | |
const m = textToSVG.getSVG('M', { | |
...options, | |
x: 650 + (offset * index), | |
y: 640 - (offset * index), | |
attributes: { | |
...attributes, | |
fill: colour | |
} | |
}).replace( | |
'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="371.25" height="450">', | |
'' | |
).replace('</svg>', '') | |
console.log(t, m) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment