Skip to content

Instantly share code, notes, and snippets.

@ayamflow
ayamflow / gist:b602ab436ac9f05660d9c15190f4fd7b
Created May 9, 2016 19:10
Safari border-radius + overflow: hidden + CSS transform fix
// Add on element with overflow
-webkit-mask-image: -webkit-radial-gradient(white, black);
@ayamflow
ayamflow / .md
Created June 7, 2016 20:58
Video, Blob and Canvas support

canvasvideo.js / video Blob

Desktop

  • All work as expected
  • Blob: TODO test drag buffering

iOS

  • canvasvideo.js: autoplay without sound, with sound need interaction
  • Blob: load without interaction, needs interaction to play
  • Blob + canvas: works without interaction
@ayamflow
ayamflow / trim-canvas.js
Created July 26, 2016 18:13 — forked from remy/trim-canvas.js
Trims the surrounding transparent pixels from a canvas
// MIT http://rem.mit-license.org
function trim(c) {
var ctx = c.getContext('2d'),
copy = document.createElement('canvas').getContext('2d'),
pixels = ctx.getImageData(0, 0, c.width, c.height),
l = pixels.data.length,
i,
bound = {
top: null,
@ayamflow
ayamflow / lightning.glsl
Last active January 12, 2017 20:02
Basic glsl lightning
// Vertex
varying vec3 vNormal;
void main() {
vNormal = normal;
gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.0);
}
// Fragment
@ayamflow
ayamflow / frag.glsl
Created January 13, 2017 01:40
Spherical mapping
// from inear
http://www.inear.se/2011/09/set-a-sphere-on-fire-with-three-js/
float PI = 3.14159265;
float TWOPI = 6.28318531;
float BaseRadius = 1.0;
vec3 sphere( float u, float v) {
u *= PI;
@ayamflow
ayamflow / force-play.js
Created April 7, 2017 00:00
Force play video
// https://github.com/hay/gifvideo/blob/master/gifvideo.js
var start;
var previousTime;
video.load();
// requestAnimationFrame automatically provides Date.now()
function play(now) {
// only play if it has the data,
// without waiting for ambiguous events
@ayamflow
ayamflow / gist:7a08af758933c8542ca320c53b9ab1ec
Created April 12, 2017 22:04
Facebook sharer.php custom
http://www.facebook.com/dialog/feed?app_id=[FACEBOOK_APP_ID]' +
'&link=[FULLY_QUALIFIED_LINK_TO_SHARE_CONTENT]' +
'&picture=[LINK_TO_IMAGE]' +
'&name=' + encodeURIComponent('[CONTENT_TITLE]') +
'&caption=' + encodeURIComponent('[CONTENT_CAPTION]) +
'&description=' + encodeURIComponent('[CONTENT_DESCRIPTION]') +
'&redirect_uri=' + FBVars.baseURL + '[URL_TO_REDIRECT_TO_AFTER_SHARE]'
@ayamflow
ayamflow / gist:96a1f554c3f88eef2f9d0024fc42940f
Last active April 3, 2025 22:26
Threejs Fit plane to screen
var cameraZ = camera.position.z;
var planeZ = 5;
var distance = cameraZ - planeZ;
var aspect = viewWidth / viewHeight;
var vFov = camera.fov * Math.PI / 180;
var planeHeightAtDistance = 2 * Math.tan(vFov / 2) * distance;
var planeWidthAtDistance = planeHeightAtDistance * aspect;
// or
@ayamflow
ayamflow / gpu-infos.js
Last active January 12, 2021 08:25
GPU infos
// https://stackoverflow.com/questions/31775686/is-there-a-way-to-know-anything-about-hardware-resources-of-platform-accessing/31896597#31896597
// https://stackoverflow.com/questions/15464896/get-cpu-gpu-memory-information
var canvas = document.createElement('canvas')
var gl = canvas.getContext('experimental-webgl');
var params = [gl.RENDERER, gl.VENDOR, gl.VERSION, gl.SHADING_LANGUAGE_VERSION];
var infos = gl.getExtension('WEBGL_debug_renderer_info');
params.push(infos.UNMASKED_RENDERER_WEBGL, infos.UNMASKED_VENDOR_WEBGL);
params.forEach(function(param) {
@ayamflow
ayamflow / 2darray.js
Last active August 19, 2021 07:48
Simulate 2D array with 1D array
// Get x/y
let x = i % this.size;
let y = (i - i % this.size) / this.size;
// Set from x/y
this.array[this.size * row + col] = value;
// ----
let index = y * width + x
let y = index / width;