Skip to content

Instantly share code, notes, and snippets.

View vectorsize's full-sized avatar

Victor Saiz vectorsize

View GitHub Profile
@vectorsize
vectorsize / linearScale.js
Last active December 20, 2022 14:30
Quick linear scale inspired by d3.js scales, based on the processing.org map() function.takes in an object with a domain array and a rage array, gives you back a function that receives a value and returns the scaled value.
// based on https://github.com/processing/processing/blob/a6e0e227a948e7e2dc042c04504d6f5b8cf0c1a6/core/src/processing/core/PApplet.java#L5093
var scale = function(opts){
var istart = opts.domain[0],
istop = opts.domain[1],
ostart = opts.range[0],
ostop = opts.range[1];
return function scale(value) {
return ostart + (ostop - ostart) * ((value - istart) / (istop - istart));
/* url sets the path */
font-url(file)
return '/public/stylesheets/fonts/' + file
/* abstracts all the specifics*/
webfont(family, file, style, weight)
@font-face
font-family family
font-weight weight
font-style style
vendor(prop, args)
-webkit-{prop} args
-moz-{prop} args
-ms-{prop} args
-o-{prop} args
{prop} args
border-radius()
vendor('border-radius', arguments)
@vectorsize
vectorsize / composer-overlap-example.js
Last active December 11, 2015 07:19
Overlap detection inside the Composer app.
// This snippet is an example on how the detecting overlaping annotations
// was implemented inside the Substance Composer app.
function annotate(type) {
// Check for existing annotation
var sel = this.surface.selection();
if (!sel) return;
if (_.include(["em", "str"], type)) {
// Returns the absolute offset from the top of the container
function getCharacterOffsetWithin(sel, node) {
var range = sel.getRangeAt(0);
var selStr = sel.toString();
// we sanitize linebreaks and white spaces
selLen = selStr.replace(/[^A-Za-z0-9.-:\/$ ]/g, "").replace(/(\r\n|\n|\r|\s+)/gm, ' ').length;
var treeWalker = document.createTreeWalker( node, NodeFilter.SHOW_TEXT, function(node) {