Skip to content

Instantly share code, notes, and snippets.

@watab0shi
watab0shi / AltitudeCalculator.cs
Last active June 7, 2022 08:28
Unity ARCore Geospatial API Altitude Calculator
/*
The MIT License (MIT)
Copyright 2022 watab0shi
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFT
@watab0shi
watab0shi / flip-p5js-editor-bookmarklet.js
Last active March 28, 2022 12:27
p5.js Editor の左右を入れ替えるブックマークレット
javascript:(()=>{const e=document.querySelector('.editor-preview-container>.SplitPane>.Pane>.SplitPane');e.style.flexDirection=e.style.flexDirection==='row'?'row-reverse':'row';})()
@watab0shi
watab0shi / GLCanvas.js
Last active October 21, 2021 04:58
three.js で render ループ中に canvas 要素の dataURL を取得する
/**
* three.js canvas
*/
class GLCanvas {
/**
* @param {Object} param
* @param {HTMLCanvasElement} param.element
*/
constructor({ element }) {
this._element = element;
@watab0shi
watab0shi / index.js
Last active October 4, 2021 03:13
自作SPAでGAのページビューを発火
let isGACreated = false;
window.addEventListener('hashchange', () => {
const hash = location.hash.length > 0 ? location.hash.slice(1) : 'index';// '#' を削除, 空だったら index にする
if (typeof window.ga === 'function') {
if (!isGACreated) {// 初回のみ create する
ga('create', 'UA-XXXXXXXXX', 'auto');
isGACreated = true;
}
const pathname = location.pathname.slice(0, location.pathname.lastIndexOf('/') + 1);// ファイル名ついてたら削除
@watab0shi
watab0shi / AutoReloadShader.cpp
Last active June 2, 2021 11:28
openFrameworks ofShader with live reload
#include "AutoReloadShader.h"
//--------------------------------------------------------------
bool AutoReloadShader::load(const std::filesystem::path& _vertName, const std::filesystem::path& _fragName) {
vertFile.open(_vertName);
fragFile.open(_fragName);
vertLastWriteTime = "";
fragLastWriteTime = "";
return shader.load(_vertName, _fragName);
@watab0shi
watab0shi / main.cpp
Created May 14, 2021 08:04
oF_serialReadExample
#include "ofMain.h"
#include "ofApp.h"
//========================================================================
int main( ){
ofSetupOpenGL(1024,768,OF_WINDOW); // <-------- setup the GL context
// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
// pass in width and height too:
@watab0shi
watab0shi / index.js
Last active February 5, 2021 12:13
three.js resolve shader includes
import { PlaneGeometry } from 'three/src/geometries/PlaneGeometry';
import { MeshStandardMaterial } from 'three/src/materials/MeshStandardMaterial';
import { Mesh } from 'three/src/objects/Mesh';
import { resolveShaderIncludes } from './resolveShaderIncludes';
const geo = new PlaneGeometry();
const mat = new MeshStandardMaterial();
mat.onBeforeCompile = (shader) => {
const { vertexShader, fragmentShader } = shader;
@watab0shi
watab0shi / PMREMGenerator.js
Created February 2, 2021 09:20
three.js Rotate envMap
import {
CubeUVReflectionMapping,
GammaEncoding,
LinearEncoding,
NoToneMapping,
NearestFilter,
NoBlending,
RGBDEncoding,
RGBEEncoding,
RGBEFormat,
@watab0shi
watab0shi / loopArray.js
Created September 2, 2020 10:36
Loop back/forward Array
// loop back
const arr1 = [0, 1, 2, 3, 4];
arr1.splice(0, 0, arr1.slice(-1)[0]);
arr1.splice(-1, 1);
console.log(arr1);// [4, 0, 1, 2, 3]
// loop forward
const arr2 = [0, 1, 2, 3, 4];
arr2.splice(arr2.length, 0, arr2.slice(0)[0]);
arr2.splice(0, 1);
@watab0shi
watab0shi / index.html
Last active August 28, 2020 07:26
requestAnimationFrame with Function.prototype.bind()
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<p>Time: <span id="txt-time">0</span></p>
<script>