Skip to content

Instantly share code, notes, and snippets.

import dateFormat from 'dateformat';
export const exportFrame = (canvas, fileFunction = null) => {
const link = document.createElement('a');
const timestamp = dateFormat(new Date(), 'yyyy-mm-dd-HH-MM-ss');
const extension = '.png';
let filename = `${timestamp}${extension}`;
if (fileFunction) filename = fileFunction({ canvas, timestamp, extension });
export const getDateIni = (date) => {
const d = date.getUTCDate();
const m = date.getUTCMonth();
const y = date.getUTCFullYear();
// 00:00
const ini = new Date(Date.UTC(y, m, d));
return ini;
};
@brunoimbrizi
brunoimbrizi / CustomMaterial.js
Last active June 17, 2020 12:06
Custom material extending THREE.MeshStandardMaterial with glslify
import * as THREE from 'three';
import glslify from 'glslify';
export default class CustomMaterial extends THREE.MeshStandardMaterial {
constructor (opt) {
super(opt);
this.type = 'CustomMaterial';
this.uniforms = THREE.UniformsUtils.merge([
let alreadyTested = false;
let passiveSupported = false;
const isSupported = () => {
if (alreadyTested) return passiveSupported;
alreadyTested = true;
// Test via a getter in the options object to see if the passive property is accessed
try {
let opts = Object.defineProperty({}, 'passive', {
import locale2 from 'locale2';
import { getParam } from './query.utils';
const getLocale = (_list, _default) => {
const list = _list || ['en'];
const detected = getParam('locale') || locale2;
const short = detected.split('-')[0];
const defaultLocale = _default || list[0];
const addWheelListener = (el, cb, useCapture = false) => {
let prefix = '';
let listener;
let eventName;
if (window.addEventListener) listener = 'addEventListener';
else {
listener = 'attachEvent';
prefix = 'on';
}
const hexToRGB = (hex, normalized) => {
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
const factor = normalized ? 255 : 1;
return result ? {
r: parseInt(result[1], 16) / factor,
g: parseInt(result[2], 16) / factor,
b: parseInt(result[3], 16) / factor
} : null;
};
// file.utils.js
const addFileDropListener = (el, callback) => {
if (window.FileReader) {
const cancel = (e) => {
if (e.preventDefault) e.preventDefault();
return false;
};
const getComputedTranslate = (el) => {
const t = { x: 0, y: 0, z: 0 };
if (!window.getComputedStyle) return t;
const style = getComputedStyle(el);
const transform = style.transform || style.webkitTransform || style.mozTransform;
let mat, x, y, z;
mat = transform.match(/^matrix3d\((.+)\)$/);
export const addLeadingZero = (num, zeros = 1) => {
let string = String(num);
for (let i = 0; i < zeros; i++) {
if (num < Math.pow(10, (i + 1)) && num > -1) string = `0${string}`;
}
return string;
};