Skip to content

Instantly share code, notes, and snippets.

class Grid {
constructor(tileSize) {
this.tileSize = tileSize;
}
createCanvas() {
this.canvas = document.createElement('canvas');
this.ctx = this.canvas.getContext('2d');
this.canvas.width = this.width;
this.canvas.height = this.height;
@Kuzcoo
Kuzcoo / spatial.js
Last active December 19, 2016 16:34
class Grid {
constructor(w,h,cellSize) {
this.grid = [];
this.cellSize = cellSize;
//
this.createGrid(w,h);
}
createGrid(w,h) {
@Kuzcoo
Kuzcoo / haiku.js
Last active December 14, 2016 20:21
Array.prototype.pickRand = function () {
return this[Math.floor(Math.random()*this.length)];
};
// grammar from Daniel Howe
// http://rednoise.org/rita/examples/p5js/HaikuGrammar/#source2
let grammar = {
"start": "<5L> <7L> <5L>",
"<5L>": "<1> <4>|<1> <3> <1>|<1> <1> <3>|<1> <2> <2>|<1> <2> <1> <1>|<1> <1> <2> <1>|<1> <1> <1> <2>|<1> <1> <1> <1> <1>|<2> <3>|<2> <2> <1>|<2> <1> <2>|<2> <1> <1> <1>|<3> <2>|<3> <1> <1>|<4> <1>|<5>",
@Kuzcoo
Kuzcoo / 99lisp.clj
Last active December 11, 2016 20:04
(defn my-last [a]
"P01 - find the last box of a list"
((fn my-last-recur [b c]
(if (empty? c)
b
(my-last-recur (first c) (rest c))
))
(first a)
(rest a))
)
Array.prototype.findHalf = function () {
return Math.floor(this.length/2);
};
Array.prototype.isEmpty = function () {
return this.length === 0;
};
Array.prototype.first = function () {
return this[0];
@Kuzcoo
Kuzcoo / z.js
Created December 4, 2016 21:29
let setSize = function (w,h=w) {
this.width = w;
this.height = h;
};
let createCanvas = (w,h) => {
let canvas = document.createElement('canvas');
if (w) {
setSize.call(canvas,w,h);
}
@Kuzcoo
Kuzcoo / vector.js
Last active November 18, 2016 14:20
class Vector {
constructor(x,y) {
this.x = x;
this.y = y;
}
static add (v1,v2) {
return new Vector(v1.xv2.x,v1.y+v2.y);
}
(function () {
[].slice.call(document.querySelectorAll('span.read-more'))
.forEach(function (el, i) {
el.onclick = function (e) {
if (e.target.classList.contains('read-less')) { return; }
var content = this.querySelector('span.read-more-content');
var text = this.childNodes[0];
text.textContent = '';
let debounce = function (eventName, time, fn) {
// locker
let locker = function () {
let isLocked = false;
let unlock = function (boolLock, fn) {
setTimeout(function () {
isLocked = false;
fn();
},time);
};
@Kuzcoo
Kuzcoo / iframes.js
Created March 3, 2016 20:34
Full width iframes (for example, videos)
(function () {
let ratios = [];
let resizeIframes = function (iframes, ratio) {
let winW = window.innerWidth;
iframes.forEach( (iframe,i) => {
let [w, h] = [iframe.clientWidth, iframe.clientHeight],
_ratio = ratio && ratio[i] || h/w;
// set iframe size
iframe.style.height = winW*_ratio+'px';