Skip to content

Instantly share code, notes, and snippets.

@ayamflow
ayamflow / .js
Created January 23, 2016 20:27
Canvas fit letter height
'use strict';
/*
This function will resize a letter until it fits the specified height
options:
- height: the height to fit
- precision: how much pixels +/-
- size: the start font size
- increment: the step of each iteration
@ayamflow
ayamflow / math.js
Created February 4, 2016 16:38
Math extra
// Point position on a line
// (see also https://github.com/ayamflow/point-in-line)
pointInLine: function(p1, p2, t)
return {
p1.x + t * (p2.x - p1.x)
p1.y + t * (p2.y - p1.y)
};
}
clamp: function(value, min, max) {
@ayamflow
ayamflow / .js
Created February 16, 2016 01:37
Three.js - get visible width/height in pixels for an object
// http://stackoverflow.com/a/13351534
var vFOV = this.camera.fov * Math.PI / 180;;
var h = 2 * Math.tan( vFOV / 2 ) * this.camera.position.z;
var aspect = width / height;
var w = h * aspect;
$(window).on('devicemotion', this._onOrientation);
_onOrientation: function(event) {
var x = 0.25 * ((size.width * 0.5) - (event.originalEvent.accelerationIncludingGravity.y * size.width));
var y = 0.25 * ((size.height * 0.5) - (event.originalEvent.accelerationIncludingGravity.x * size.height));
}
@ayamflow
ayamflow / .js
Created February 25, 2016 01:51
Loop a value between 2 corners
function loop(val, min, max){
if (val < min) return ((val + 1) % max) + (max - 1);
return val % max;
}
function screenToWorldAtZ(positionX, positionY, z){
var vector = new THREE.Vector3();
var dX, dY, dZ;
if(this.curObject && this.curObject.parent ){
dX = this.curObject.parent.position.x;
dY = this.curObject.parent.position.y;
dZ = this.curObject.parent.position.z;
}else{
dX = 0; dY = 0, dZ = 0;
@ayamflow
ayamflow / MeshLine.js
Created February 29, 2016 16:34 — forked from superguigui/MeshLine.js
THREE.Meshline from spite in ES6 with update method
import THREE from 'three';
export default class MeshLine {
constructor() {
this.attributes = {};
this.positions = [];
this.geometry = new THREE.BufferGeometry();
this.widthCallback = null;
}
@ayamflow
ayamflow / adblock-blacklist.css
Created March 11, 2016 16:00 — forked from spyesx/adblock-blacklist.css
Class and ID to avoid because of AdBlock
.sidebar_newsletter_sign_up,
.sidebar_subscribe,
.sign-up-form-single,
.signup-form--header,
.signup-with-checkboxes,
.skinny-sign-up,
.slidedown-newsletter,
.small-newsletter,
.social-link-mail,
.social_newsletter_box,
@ayamflow
ayamflow / gist:cb9071e875ef24db1c1c1a28ae1eaee1
Created March 29, 2016 23:16
iphone 5 hide bars on iOS 8+
// Bars will always show when clicking close to the top/botton of the device
html, body {
width: 100%;
height: 100%;
overflow: hidden;
}
body {
height: 101%;
@ayamflow
ayamflow / matrix.js
Last active April 1, 2016 18:33
Transform matrix for scale including transform origin
// http://stackoverflow.com/a/6714140
transform="matrix(sx, 0, 0, sy, cx - sx * cx, cy - sy * cy)"