Skip to content

Instantly share code, notes, and snippets.

View mauriciomassaia's full-sized avatar

Mauricio Massaia mauriciomassaia

View GitHub Profile
@mauriciomassaia
mauriciomassaia / .jshintrc
Created January 4, 2016 03:36
jshintrc template with THREE and TweenMax
{
"browser": true,
"node": true,
"esnext": true,
"bitwise": true,
"camelcase": true,
"curly": false,
"eqeqeq": true,
"immed": true,
"indent": 2,
@mauriciomassaia
mauriciomassaia / server.js
Created January 11, 2016 22:54
Open the default browser via node.js
const spawn = require('child_process').spawn;
// open default browser
spawn('open', ['http://localhost:9000']);
console.log('running on http://localhost:9000');
@mauriciomassaia
mauriciomassaia / force-json.js
Created January 19, 2016 05:52
Replace single quotes with double quotes and add double quotes to a property
function addQuotes(match) {
return '"' + match.substr(0, match.length-1) + '":';
}
var t = "{tags:['000000000000000000000004', '000000000000000000000003', '300833B2DDD9014000000024', '300833B2DDD9014000000045', '300833B2DDD9014000000021', '000000000000000000000005', '000000000000000000000001', '300833B2DDD9014000000022', '000000000000000000000002']}";
var k = t.replace(/\'/g, '"');
k.replace(/[a-z]*\:/g, addQuotes);
/*
output:
@mauriciomassaia
mauriciomassaia / raycaster-line.js
Created August 9, 2016 02:58
Draw a line from the Raycaster origin and dest Vectors. Threejs
drawRaycastLine(raycaster) {
let material = new THREE.LineBasicMaterial({
color: 0xff0000,
linewidth: 10
});
let geometry = new THREE.Geometry();
let startVec = new THREE.Vector3(
raycaster.ray.origin.x,
raycaster.ray.origin.y,
raycaster.ray.origin.z);
@mauriciomassaia
mauriciomassaia / Map for LED strips with RGB
Created December 20, 2016 00:00
Map index for normal arrays and pixel arrays (RGB) which runs cols by col in inverted order. top to bottom then bottom to top and so on
function ledStripMap(cols, rows) {
var total = cols * rows;
// var map
var map = new Uint8Array(total);
var index = 0;
var count = 0
for(var i = 0; i < cols; i++) {
for (var j = 0; j < rows; j++) {
if (i % 2 === 0) {
@mauriciomassaia
mauriciomassaia / colors.js
Last active September 24, 2019 06:50
Color convertion
/**
* @param {Array} arr - [140, 255, 1]
* @returns {Array} [0.5490196078, 1, 0.003921568627]
*/
export function normalizeArray (arr, value) {
return arr.map(v => v / value)
}
/**
* @param {Number} colorNum 0xff00ff
@mauriciomassaia
mauriciomassaia / pixi-app.js
Created August 2, 2017 08:49
Pixi Application es6
import { Application } from 'pixi.js'
const app = new Application({
width: window.innerWidth,
height: window.innerHeight,
resolution: window.devicePixelRatio || 1,
antialias: true
})
app.ticker.add(() => {
@mauriciomassaia
mauriciomassaia / image-data-resize.js
Created March 20, 2018 07:15
ImageData resize on Canvas
export async function resizeImageData (imageData, width, height) {
const resizeWidth = width >> 0
const resizeHeight = height >> 0
const ibm = await window.createImageBitmap(imageData, 0, 0, imageData.width, imageData.height, {
resizeWidth, resizeHeight
})
const canvas = document.createElement('canvas')
canvas.width = resizeWidth
canvas.height = resizeHeight
const ctx = canvas.getContext('2d')
@mauriciomassaia
mauriciomassaia / tween-color.js
Created April 19, 2018 03:42
GSAP + ColorPropsPlugin + Pixi.js
import { TweenMax } from 'gsap'
import 'gsap/ColorPropsPlugin'
const g = new Graphics()
g.beginFill(color, alpha)
g.drawRect(x, y, width, height)
g.endFill()
container.addChild(g)
TweenMax.to(g, 0.5, {colorProps: {tint: 0x00aaff, format: 'number'}})
@mauriciomassaia
mauriciomassaia / mm.sublime-theme
Created June 14, 2018 05:37
Sublime Theme / IBM Plex Font / 4k screen
[
{
"class": "sidebar_label",
"color": [131, 148, 150],
"font.bold": false,
"font.size": 16,
"font.face": "IBM Plex Mono"
},
{
"class": "sidebar_container",