Skip to content

Instantly share code, notes, and snippets.

View loktar00's full-sized avatar
🏠
Working from home

Jason loktar00

🏠
Working from home
View GitHub Profile
@loktar00
loktar00 / gist:2885768
Created June 7, 2012 00:43
Metaball part 1
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});
};
@loktar00
loktar00 / gist:2885780
Created June 7, 2012 00:47
metaball part 3
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 / sum.js
Created August 23, 2012 04:18
Random Sum function
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 September 5, 2012 17:22
Wave sim based off an excellent xna tutorial.
<canvas id="canvas"></canvas>​
@loktar00
loktar00 / script.js
Created September 5, 2012 17:23
Just a random thing I did with some spare time.
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;
@loktar00
loktar00 / index.html
Created September 9, 2012 01:58
Eyes that follow your cursor. He gets mad when you you make him cross eyed! I'm getting in the Halloween spirit a bit early this year.
<div id="hitarea">
<div id="a-1" class="hitbox"></div>
<div id="a-2" class="hitbox"></div>
<div id="a-3" class="hitbox"></div>
<div id="a-4" class="hitbox"></div>
<div id="a-5" class="hitbox"></div>
<div id="b-1" class="hitbox"></div>
<div id="b-2" class="hitbox"></div>
<div id="b-3" class="hitbox"></div>
<div id="b-4" class="hitbox"></div>
@loktar00
loktar00 / index.html
Created September 20, 2012 22:15
Looks like slimey germs :P
<canvas id="canvas"></canvas>
@loktar00
loktar00 / index.html
Created September 23, 2012 02:23
Love playing with these. For more check out http://somethinghitme.com/projects/cell/
<canvas id="canvas"></canvas>
@loktar00
loktar00 / gist:3794579
Created September 27, 2012 15:19
Get dimensions and position of element
function getOffsetRect(elem) {
var box = elem.getBoundingClientRect(),
body = document.body,
docElem = document.documentElement,
scrollTop = window.pageYOffset || docElem.scrollTop || body.scrollTop,
scrollLeft = window.pageXOffset || docElem.scrollLeft || body.scrollLeft,
clientTop = docElem.clientTop || body.clientTop || 0,
clientLeft = docElem.clientLeft || body.clientLeft || 0,
top = box.top + scrollTop - clientTop,
left = box.left + scrollLeft - clientLeft,
@loktar00
loktar00 / gist:3837820
Created October 5, 2012 03:03
simple XMLHttpRequest
function post(url, data, callback){
var ajaxRequest = new XMLHttpRequest();
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4 || ajaxRequest.readyState == 200){
callback(ajaxRequest.responseText);
}
}
ajaxRequest.open("POST", url);
ajaxRequest.setRequestHeader("Content-Type", "application/json;charset=UTF-8");