Skip to content

Instantly share code, notes, and snippets.

@egonelbre
egonelbre / gist:938938
Created April 23, 2011 20:19
wave generation speed up
freq = 770; len = 10; rate = 44100; vol = 1.0;
start = new Date();
w = '';
phase = 0;
sin = Math.sin;
chr = String.fromCharCode;
total = len*rate;
@egonelbre
egonelbre / gist:1126487
Created August 4, 2011 22:46
keno loto simulation
function PickNumbers(count, total){
var i, set = [],
result = [];
for(i=total; i--;)
set.push(i);
for(i=count; i--;){
var picked = (Math.random() * set.length) | 0;
result.push(set[picked]);
set.splice(picked,1);
}
@egonelbre
egonelbre / def.js
Created October 2, 2011 11:27
javascript simplifier
"use strict";
if( typeof Object.create !== 'function' ){
Object.create = function(o){
var F = function( ){};
F.prototype = o;
return new F();
};
}
function CollisionContoller(width, height) {
this.draw = function(){
document.write("drawing\n");
};
};
CollisionContoller.prototype.registerPlanet = function(image, position, type){
this.draw();
}
@egonelbre
egonelbre / gist:1311842
Created October 25, 2011 08:28
Design Patterns in GO
///////
// Warning, code untested
///////
type Thinger interface {
SomeMethod( arg bool ) bool
}
type RealThing struct {
state bool
@egonelbre
egonelbre / gist:1321824
Created October 28, 2011 07:44
experimental image from code
// http://www.reddit.com/r/programming/comments/lrg7f/experimental_images_from_very_short_programs/
function start() {
var t = pt = 0;
clearTimeout(timer);
var func = ""+
"function animate() {" +
" var x = y = pi = 0, W = w, S = size; " +
" for (var i = 0; i < S;) { " +
" img.data[i] = <code>; i++; t++; " +
@egonelbre
egonelbre / gist:1383253
Created November 21, 2011 17:05
html knowledge test
<!doctype html>
<meta charset=utf-8 />
<title>Hello World</title>
<style>
body { margin: 30px auto; width: 500px; }
header { font-size: 20px; padding-bottom: 10px; }
article { padding : 20px; }
footer { font-size: 10px;}
#magic value { font-size: 10px;}
</style>
@egonelbre
egonelbre / gist:1755115
Last active March 24, 2022 15:26
Prolog Explanation
daytime.
clear_skies.
% I want to have empty tables (facts) `daytime` and `clear_skies`
round(earth).
round(ball).
small(mouse).
small(ball).
@egonelbre
egonelbre / gist:1852609
Created February 17, 2012 10:47
flower packing
Packed with http://iteral.com/jscrush/ 1216B --> 955B
from 1216B
O=a.getImageData(0,0,c.height=f=W=256,f);U=O.data;D={};F=[];function J(p){p[5]=Q=0;for(j=3;j--;)if(!D[Q=(p[j]>>=2)+Q*f])D[Q]=F.push(p)}setInterval(function(){for(i=1e3;i--;){c=i%42*1.35;H=T;T=Math.random();A=H*2-1;B=T*2-1;J([Math.sin(H*7)*(o=13+5/(.2+Math.pow(T*4,4)))-T*50,T*550+500,(l=Math.cos(H*7))*o,(G=l/7+.5)-T/4,G]);if(A*A+B*B<1)if(c>32){J([(o=.5/(H+.01)-H*300)*Math.cos(n=(j=c&1)?6:4)+(w=T*-f)*Math.sin(n)+j*630-390,o*Math.sin(n)-w*Math.cos(n)+999-j*350,Math.cos(B+A)*99-j*50,(Math.pow(l=1-B*B,f*6)+Math.cos(H+T)+Math.pow(Math.cos((o*H+o+(B>0?w:-w))/25),30)*l-H+2)/5,o/1e3+.7-o*w/3e5]);J([(o=H*45-20)*Math.cos(l=c/.86)+(w=T*T)*f*Math.sin(l),Math.cos(B/2)*99-w*T*60+436,o*Math.sin(l)-w*f*Math.cos(l),w*.3+.3,T*.7])}else J([(o=A*(2-T)*(80-c*2))*Math.cos(c)-(w=99-Math.cos(A)*120-Math.cos(T)*(f-c*5)+Math.cos(Math.pow(1-T,7))*50+c*2)*Math.sin(c),(B*2-Math.cos(Math.pow(T,7))+9)*50,o*Math.sin(c)+w*Math.cos(c),1-T*.7,Math.pow(1-T,9)/4])}for(i=0;i<f*f;M
@egonelbre
egonelbre / gist:2318466
Created April 6, 2012 09:27
simple random number generator in javascript
function newRandom(A,B,seed){
return function(){
seed = (A*seed+B)%(1<<31); return (seed >> 16) & 0x7fff
}
}
r1 = newRandom(69069, 1, 0)
r2 = newRandom(1103515245, 12345, 0)
r3 = newRandom(214013, 2531011, 0)