Skip to content

Instantly share code, notes, and snippets.

let radius = 100.0;
let cb = Math.cbrt(Math.random()); // 一様乱数の立方根
let yc = Math.random() * 2.0 - 1.0; // Y 方向のコサイン相当を単に乱数から得る
let yr = Math.sqrt(1.0 - yc * yc); // 逆数
let th = Math.random() * Math.PI * 2.0; // XZ 平面に対するシータ
let point = [
radius * cb * yr * Math.cos(th),
radius * cb * yc,
radius * cb * yr * Math.sin(th)
];
@doxas
doxas / async_await_test.js
Created December 7, 2018 08:30
testing async/await in `for` statement
(async () => {
let v = 0;
for(let i = 0; i < 10; ++i){
x = await ((index) => {
setTimeout(() => {
console.log('🔥'.repeat(index + 1));
}, index * 500);
return index * index;
})(i);
console.log(x);
class Emitter {
static get EVENTS(){return [
'renderingComplete',
'focusComplete'
];}
constructor(){
this.listeners = {};
}
emit(eventName, arg){
if(this.listeners.hasOwnProperty(eventName) === true){
function checkExistsFile(a, b){
// 空白等が指定されていないか
if(a == null || a === '' || b == null || b === ''){return false;}
let arrA = Array.from(a);
let arrB = Array.from(b);
// サロゲートペアを考慮した上での文字数が一致しているか
if(arrA.length === 0 || arrA.length !== arrB.length || arrB.length === 0){return false;}
// ループで位置文字ずつ一致状況を調べる
let flag = true;
for(let i = 0; i < arrA.length; ++i){
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>noisy</title>
<script src="https://wgld.org/j/noiseX.js" type="text/javascript"></script>
<script type="text/javascript">
let octave = 6;
let offset = 4;
let persistence = 0.5;
let baseWidth = Math.pow(2, octave + offset);
@doxas
doxas / csharp.js
Created June 13, 2018 05:18
inline c# spawn
/**
* Windows のプロセス ID を受け取り対象プロセスのウィンドウを前面に出す
* @param {number} pid - process id
*/
function setForegroundWindowFromProcess(pid){
let className = 'hoge' + Date.now();
let source = `
Add-Type @"
using System;
@doxas
doxas / qtn.js
Last active September 12, 2017 14:47
quaternion to matrix
/**
* @class InteractionCamera
* @example
* let camera = new InteractionCamera();
* window.addEventListener('mousedown', camera.startEvent, false);
* window.addEventListener('mousemove', camera.moveEvent, false);
* window.addEventListener('mouseup', camera.endEvent, false);
* camera.update();
* mMatrix = gl3.Math.Qtn.toMat4(camera.qtn, mMatrix);
*/
class DrawCanvas {
constructor(size){
this.canvas = document.createElement('canvas');
this.canvas.width = this.canvas.height = size;
this.ctx = this.canvas.getContext('2d');
}
drawGradationShadow(colorRGB){
let center = [this.canvas.width / 2, this.canvas.height / 2];
let radius = Math.min(center[0], center[1]) * 0.9;
let colorFill = 'rgba(' + colorRGB.join(',') + ', 0.0)';
@doxas
doxas / gist:46d4ab9f0eaed38dca4581fde9f91cbe
Created December 19, 2016 02:34
show currentbasebranch
git show-branch | grep '*' | grep -v "$(git rev-parse --abbrev-ref HEAD)" | head -1 | awk -F'[]~^[]' '{print $2}'
$ git fetch origin pull/ID/head:BRANCHNAME