Skip to content

Instantly share code, notes, and snippets.

View pseudorandom.js
var seed=Math.random()
var random3=function(x,y,z){
var f=(Math.abs(x)+1e4)*(Math.abs(y)+2e4)*(Math.abs(z)+3e4);
var a=(f%seed)/seed;
var b=(f%a)/a;
return b;
};
@supereggbert
supereggbert / gaussianRandom.js
Created Apr 26, 2018
Simple Random Gaussian Function in Javascript
View gaussianRandom.js
function gaussianRandom(mean,sigma){
var u = Math.random();
return (u%1e-8>5e-9?1:-1)*Math.sqrt(-Math.log(Math.max(1e-9,u)))*sigma+mean;
}
@supereggbert
supereggbert / index.html
Created Aug 17, 2014
Diamond-square Algorithm
View index.html
<!doctype html>
<html>
<head>
<title>Diamond-square</title>
</head>
<body>
<script>
// PRNG
function random(i) {
return (Math.sin(Math.sin(1e9*i)*1e6)+1)*0.5;
@supereggbert
supereggbert / index.html
Last active Apr 30, 2020
3D Surface Plot in D3.js
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
body{
font-family: sans;
padding: 10px;
}
svg path{
@supereggbert
supereggbert / gist:1104419
Created Jul 25, 2011
Defining a car through the API
View gist:1104419
var wheel1 = new GLGE.PhysicsWheel();
wheel1.setRadius(0.5).setLocX(1.4).setLocY(-0.2).setLocY(0.9);
var wheel1Obj=new GLGE.Collada();
wheel1Obj.setDocument("wheel.dae");
wheel1.addCollada(wheel1Obj);
var wheel2 = new GLGE.PhysicsWheel();
wheel2.setRadius(0.5).setLocX(1.4).setLocY(-0.2).setLocY(-0.9);
var wheel2Obj=new GLGE.Collada();
wheel2Obj.setDocument("wheel.dae");
@supereggbert
supereggbert / gist:1104371
Created Jul 25, 2011
XML definition of a car in GLGE
View gist:1104371
<physics_car id="car" loc_y="5.5" mass="15" width="4" depth="0.5" height="1">
<collada document="car.dae" id="carObject" scale="0.3" scale_y="-0.3" />
<physics_wheel id="wheel1" loc_x="1.4" loc_z="0.9" loc_y="-0.2" radius="0.5" travel="0.6" spring="150" side_friction="3" front_friction="10">
<collada document="wheel.dae" id="wheel1obj" scale="0.3" scale_y="-0.3" />
</physics_wheel>
<physics_wheel id="wheel2" loc_x="1.4" loc_z="-0.9" loc_y="-0.2" radius="0.5" travel="0.6" spring="150" side_friction="3" front_friction="10">
<collada document="wheel.dae" id="wheel2obj" scale="0.3" />
</physics_wheel>
<physics_wheel id="wheel3" powered="TRUE" loc_x="-1.7" loc_z="0.9" loc_y="-0.2" radius="0.5" travel="0.6" spring="150" side_friction="3" front_friction="10">
<collada document="wheel.dae" id="wheel3obj" scale="0.3" scale_y="-0.3" />
View getAbsolutePath
var getAbsolutePath=function(path,relativeto){
if(!relativeto) relativeto=window.location.href;
if(!relativeto) return path;
//remove ? and # from relative to
if(~relativeto.indexOf("?")){
relativeto=relativeto.substr(0,relativeto.indexOf("?"));
}else if(~relativeto.indexOf("#")){
relativeto=relativeto.substr(0,relativeto.indexOf("#"));
}
var pathParts=path.split("/");
View WaterMaterial.xml
<material id="water" specular="1.0" shininess="2">
<texture id="waterheight" src="waterheight.jpg" />
<material_layer texture="#waterheight" mapinput="UV1" frame_rate="25" height="0.07" animation="#flow" mapto="M_HEIGHT" scale_x="0.8" scale_y="0.8" />
<texture id="waternormal" src="waternormal.jpg" />
<material_layer texture="#waternormal" mapinput="UV1" mapto="M_NOR" scale_x="0.5" scale_y="0.5" />
<texture_camera camera="#mainCamera" id="watercolor1" clip_axis="POS_ZAXIS" />
<material_layer texture="#watercolor1" mapinput="MAP_VIEW" mapto="M_COLOR" />
View gist:378280
<material id="skyMat">
<texture_cube id="sky" src_pos_x="posx.png" src_neg_x="negx.png" src_pos_y="posy.png" src_neg_y="negy.png" src_pos_z="posz.png" src_neg_z="negz.png" />
<material_layer texture="#sky" mapinput="MAP_ENV" mapto="M_COLOR" />
</material>