Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Jason loktar00

🏠
Working from home
View GitHub Profile
@loktar00
loktar00 / gist:1211640
Created Sep 12, 2011
Get elements by classname cross browser
View gist:1211640
function byClass(matchClass){
if (!document.getElementsByClassName){
var elements = document.getElementsByTagName('*'),
i=0,
nodeList = [],
reg = new RegExp('(^|\\s)' + matchClass + '(\\s|$)')
for (i=0; i < elements.length;i++)
{
if(elements[i].className.match(reg) !== null){
@loktar00
loktar00 / gist:1228163
Created Sep 20, 2011
Finds all the points between 2 coordinates.
View gist:1228163
// find all points between 2 pooints http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
var x1 = mouseX,
x2 = lastX,
y1 = mouseY,
y2 = lastY;
var steep = (Math.abs(y2 - y1) > Math.abs(x2 - x1));
if (steep){
var x = x1;
@loktar00
loktar00 / extend.js
Created Feb 8, 2012
Extend a js object
View extend.js
// For extending the default object with properties
extend = function(obj, extObj){
for(var i in extObj){
if(obj.hasOwnProperty(i)){
obj[i] = extObj[i];
}
}
}
View gist:2885768
for(var i = 0; i < 50; i++){
var x = Math.random()*width,
y = Math.random()*height,
vx = (Math.random()*8)-4,
vy = (Math.random()*8)-4,
size = Math.floor(Math.random()*60)+60;
points.push({x:x,y:y,vx:vx,vy:vy, size:size});
};
View gist:2885774
var grad = tempCtx.createRadialGradient(point.x, point.y, 1, point.x, point.y, point.size);
tempCtx.beginPath();
grad.addColorStop(0, 'rgba(' + colors.r +',' + colors.g + ',' + colors.b + ',1)');
grad.addColorStop(1, 'rgba(' + colors.r +',' + colors.g + ',' + colors.b + ',0)');
tempCtx.fillStyle = grad;
tempCtx.arc(point.x, point.y, point.size, 0, Math.PI*2);
tempCtx.fill();
View gist:2885780
function metabalize(){
var imageData = tempCtx.getImageData(0,0,width,height),
pix = imageData.data;
for (var i = 0, n = pix.length; i <n; i += 4) {
// Checks threshold
if(pix[i+3]<threshold){
pix[i+3]=0;
}
}
@loktar00
loktar00 / gist:2885786
Created Jun 7, 2012
2d metaballs source
View gist:2885786
var canvas = document.getElementById("canvas"),
ctx = canvas.getContext("2d"),
tempCanvas = document.createElement("canvas"),
tempCtx = tempCanvas.getContext("2d"),
width = 512,
height = 512,
threshold = 210,
colors = {r:255,g:0,b:0}, cycle = 0,
points = [];
@loktar00
loktar00 / sum.js
Created Aug 23, 2012
Random Sum function
View sum.js
var sum = function(){
var arr = [].slice.apply(arguments),
total = arr.reduce(function(a,b){
b = parseInt(b);
if(!isNaN(b)){
return a+b;
}else{
return a;
}
});
@loktar00
loktar00 / index.html
Created Sep 5, 2012
Wave sim based off an excellent xna tutorial.
View index.html
<canvas id="canvas"></canvas>
@loktar00
loktar00 / script.js
Created Sep 5, 2012
Just a random thing I did with some spare time.
View script.js
var cards = [];
function initDeck(){
for(var cardNum = 1; cardNum < 14; cardNum++){
for(var i = 0; i < 4; i++){
var suit = i;
switch(i){
case 0:
suit = "\u2665";
break;