Skip to content

Instantly share code, notes, and snippets.

@bellbind
bellbind / caos.html
Last active August 29, 2015 14:05
[javascript][threejs]caos with lorenz system
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r68/three.min.js"
></script>
<script src="https://rawgit.com/mrdoob/three.js/master/examples/js/controls/TrackballControls.js"
></script>
<script src="caos.js"></script>
</head>
@bellbind
bellbind / nd.js
Last active August 29, 2015 14:05
[nodejs] normal distribution chart on terminal
var data = [];
for (var i = 0; i < 80; i++) {
var x = 5 * ((i / 80) - 0.5);
var y = Math.exp(-x*x) / Math.sqrt(Math.PI);
data.push(y);
}
for (var j = 0; j < 20; j ++) {
var low = 0.7 * (1 - (j + 1) / 20);
console.log(data.map(function (y) {
return y > low ? "*" : " ";
@bellbind
bellbind / mt.js
Last active August 29, 2015 14:06
[javascript]Mersenne Twister Pseudo Random Number Generator
// Mersenne Twister Random Generator
// see: http://en.wikipedia.org/wiki/Mersenne_twister
var MT = function MT(seed) {
seed = typeof seed === "number" ? seed: Date.now();
var self = Object.create(MT.prototype, {
mt: {value: new Array(MT.N)},
index: {value: 0, writable: true},
});
// initialize from a seed with LCG PRNG
var pre = self.mt[0] = seed & MT.MASK_F;
@bellbind
bellbind / fp.c
Last active August 29, 2015 14:06
[floating point][c99][intel cpu]understanding a representation of floating point number (IEEE754)
#include <stdint.h>
#include <math.h>
#include <stdio.h>
// for intel CPU: little endian byte order
typedef union {
double v;
uint8_t b[8];
struct {
unsigned fl: 32;
@bellbind
bellbind / earth.jpg
Last active August 29, 2015 14:06
[threejs]template for displaying raw computed geometry
earth.jpg
@bellbind
bellbind / geom.html
Last active August 29, 2015 14:06
[threejs]cylindrical object generator
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r68/three.min.js"
></script>
<script src="https://rawgit.com/mrdoob/three.js/master/examples/js/controls/TrackballControls.js"
></script>
<script src="geom.js"></script>
<script src="stl.js"></script>
@bellbind
bellbind / arrow.js
Last active August 29, 2015 14:07
[threejs][html5]gyro with radar
var ArrowMesh = (function () {
"use strict";
var arrowGeometry = function (length, headR, headL, barR) {
var barL = length - headL;
var bar = new THREE.CylinderGeometry(barR, barR, barL);
var head = new THREE.CylinderGeometry(0, headR, headL);
var barm = new THREE.Matrix4().makeTranslation(0, barL / 2, 0);
var headm = new THREE.Matrix4().makeTranslation(
0, barL + headL / 2, 0);
@bellbind
bellbind / pi.js
Created December 10, 2014 14:39
[javascript]Calculating PI
// calculating PI
console.log(Math.PI);
var pi1 = function (n) {
// Bailey-Borwein-Plouffe
var r = 0;
for (var i = 0; i < n; i++) {
var b = 8 * i;
r += (4/(b+1) - 2/(b+4) - 1/(b+5) - 1/(b+6)) / Math.pow(16, i);
}
@bellbind
bellbind / index.html
Created January 15, 2015 07:36
[javascript][canvas]L-system (canvas 2d draw)
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>basic L-system</title>
<script src="lsystem.js"></script>
</head>
<body>
<canvas id="canvas" width="300" height="300" />
</body>
@bellbind
bellbind / flipflop.v
Created January 16, 2015 08:27
[verilog]flipflop example
// [install] brew install icarus-verilog
// [compile] iverilog -o flipflop flipflop.v
// [simulate] vvp flipflop
module flipflop(input wire set, input wire reset,
output wire q, output wire nq);
nand n1(q, ~set, nq);
nand n2(nq, ~reset, q);
endmodule // flipflop
module main;