This file contains hidden or 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
| function deepClone(target) { | |
| if (!target || typeof target !== 'object') | |
| return target | |
| const clone = Array.isArray(target) ? [] : {} | |
| for (const [key, value] of Object.entries(target)) { | |
| clone[key] = deepClone(value) |
This file contains hidden or 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
| function ScreenScalar(props = { p1:1, p2:1 }) { | |
| const compute = () => this.value = 1 - Object.values(props).reduce((r, v) => r * (1 - v), 1) | |
| compute() | |
| for (const key of Object.keys(props)) { | |
| Object.defineProperty(this, key, { | |
| get: () => props[key], | |
| set: value => { |
This file contains hidden or 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
| // https://gist.github.com/jniac/39eabea6b06a9be5be348c11447c249c | |
| /** | |
| * 'prune' will simplify any tree (target) by removing any 'autoKey' | |
| * found by its inner value. eg: | |
| * | |
| * `prune({ text:{ en:'foo', fr:'toto' }}, 'en') // -> { text:'foo' }` | |
| * `prune({ text:{ en:'foo', fr:'toto' }}, 'fr') // -> { text:'toto' }` | |
| * @param {object} target | |
| * @param {...string} autoKeys | |
| */ |
This file contains hidden or 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
| D = n => Math.ceil(n * Math.random()) | |
| run = ({ name = 'run', d1, d2, n = 100000 } = {}) => { | |
| result = { | |
| win: 0, | |
| loose: 0, | |
| equals: 0, | |
| } |
This file contains hidden or 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
| let VertigoCamera | |
| const init = THREE => { | |
| const { | |
| Camera, | |
| PerspectiveCamera, | |
| OrthographicCamera, |
This file contains hidden or 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
| // https://gist.github.com/jniac/1f1b8e57dbb320138af00680c090f94e | |
| const parser = new DOMParser() | |
| const html = (strings, ...inserts) => { | |
| if (typeof strings === 'string') { | |
| // html is used as a regular function, eg: | |
| // html(`<div>${foo}</div>`) |
This file contains hidden or 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 removeHeadingWhitespaces = str => { | |
| const lines = str.split('\n') | |
| while (lines.length > 0 && /^\s*$/.test(lines[0])) { | |
| lines.shift() | |
| } | |
| while (lines.length > 0 && /^\s*$/.test(lines[lines.length - 1])) { | |
| lines.pop() |
This file contains hidden or 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
| import fetch from 'node-fetch' | |
| import fs from 'fs-extra' | |
| const safeName = str => str.replace(/\W/g, '-') | |
| const parseFontFace = fontFace => { | |
| const [, url] = fontFace.match(/url\((.*?)\)/) | |
| const [, family] = fontFace.match(/font-family: '(.*?)';/) | |
| const [, style] = fontFace.match(/font-style: (.*?);/) | |
| const [, weight] = fontFace.match(/font-weight: (.*?);/) |
This file contains hidden or 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
| /** | |
| * returns [1, 4, 12] from [4, 3, 2] | |
| * @param {number[]} array | |
| */ | |
| function getArrayScale (array) { | |
| let scale = 1 | |
| return array.map(dim => { | |
| const x = scale | |
| scale *= dim | |
| return x |
This file contains hidden or 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
| import { WebGLRenderer, PerspectiveCamera, Scene } from 'https://threejs.org/build/three.module.js' | |
| import { OrbitControls } from 'https://threejs.org/examples/jsm/controls/OrbitControls.js' | |
| const renderer = new WebGLRenderer({ antialias: true }) | |
| renderer.setPixelRatio(window.devicePixelRatio) | |
| renderer.setSize(window.innerWidth, window.innerHeight) | |
| document.body.append(renderer.domElement) | |
| const camera = new PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 100) | |
| camera.position.z = 5 |