JSFiddle - React, Tailwind, and code Playground
by Darby Rathbone
HTML
<div id="cont">stuff:</div>
<canvas height=128 width=128 id="canv" style="zoom:10;"></canvas>
JavaScript
var SinCosLUT = function (precision) {
if (!precision) {
precision = SinCosLUT.DEFAULT_PRECISION;
}
this.precision = precision;
this.period = 360 / this.precision;
this.quadrant = this.period >> 2;
this.deg2rad = (Math.PI / 180.0) * this.precision;
this.rad2deg = (180.0 / Math.PI) / this.precision;
this.sinLUT = [];
for (var i = 0; i < this.period; i++) {
this.sinLUT[i] = Math.sin(i * this.deg2rad);
}
};
SinCosLUT.prototype = {
/**
* Calculate cosine for the passed in angle in radians.
*
* @param theta
* @return cosine value for theta
*/
cos: function (theta) {
while (theta < 0) {
theta += mathUtils.TWO_PI;
}
return this.sinLUT[((theta * this.rad2deg) + this.quadrant) % this.period];
},
getPeriod: function () {
return this.period;
},
getPrecision: function () {
return this.precision;
},
getSinLUT: function () {
return this.sinLUT;
},
/**
* Calculates sine for the passed angle in radians.
*
* @param theta
* @return sine value for theta
*/
sin: function (theta) {
while (theta < 0) {
theta += mathUtils.TWO_PI;
}
return this.sinLUT[(theta * this.rad2deg) % this.period];
}
};
SinCosLUT.DEFAULT_PRECISION = .15;
SinCosLUT.DEFAULT_INSTANCE = undefined;
SinCosLUT.getDefaultInstance = function () {
if (SinCosLUT.DEFAULT_INSTANCE === undefined) {
SinCosLUT.DEFAULT_INSTANCE = new SinCosLUT();
}
return SinCosLUT.DEFAULT_INSTANCE;
};
PerlinNoise = function () {
this._perlin_octaves = 4; // default to medium smooth
this._perlin_amp_falloff = 0.5; // 50% reduction/octave
this.seed = 1.0;
this.mathRandom = new mersenne();
this.PERLIN_YWRAPB = 4.0;
this.PERLIN_YWRAP = 1.0 << this.PERLIN_YWRAPB;
this.PERLIN_ZWRAPB = 8.0;
this.PERLIN_ZWRAP = 1.0 <<...