// http://www.michaelbromley.co.uk/blog/90/simple-1d-noise-in-javascript
var Simple1DNoise = function() {
var MAX_VERTICES = 256;
var MAX_VERTICES_MASK = MAX_VERTICES -1;
var amplitude = 1;
var scale = 1;
var r = [];
for ( var i = 0; i < MAX_VERTICES; ++i ) {
r.push(Math.random());
}
var getVal = function( x ){
var scaledX = x * scale;
var xFloor = Math.floor(scaledX);
var t = scaledX - xFloor;
var tRemapSmoothstep = t * t * ( 3 - 2 * t );
/// Modulo using &
var xMin = xFloor & MAX_VERTICES_MASK;
var xMax = ( xMin + 1 ) & MAX_VERTICES_MASK;
var y = lerp( r[ xMin ], r[ xMax ], tRemapSmoothstep );
return y * amplitude;
};
/**
* Linear interpolation function.
* @param a The lower integer value
* @param b The upper integer value
* @param t The value between the two
* @returns {number}
*/
var lerp = function(a, b, t ) {
return a * ( 1 - t ) + b * t;
};
// return the API
return {
getVal: getVal,
setAmplitude: function(newAmplitude) {
amplitude = newAmplitude;
},
setScale: function(newScale) {
scale = newScale;
}
};
};
// --------------------------------------------------
// we create an array where we define all the bookmarks to choose from
var bookmark_img_sources = ["http://doekewartena.nl/olya/b01.png",
"http://doekewartena.nl/olya/b02.png",
"http://doekewartena.nl/olya/b03.png",
"http://doekewartena.nl/olya/b04.png",
"http://doekewartena.nl/olya/b05.png"
];
$(function() {
console.log("jquery ok");
// see how many bookmarks we have:
console.log("bookmark_img_sources.length: "+bookmark_img_sources.length);
// now we have to choose one
// random gives a number between 0 and 1
//...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.