text stringlengths 9 39.2M | dir stringlengths 26 295 | lang stringclasses 185
values | created_date timestamp[us] | updated_date timestamp[us] | repo_name stringlengths 1 97 | repo_full_name stringlengths 7 106 | star int64 1k 183k | len_tokens int64 1 13.8M |
|---|---|---|---|---|---|---|---|---|
```javascript
// Quota Storage Management API
// This API can be used to check how much quota an origin is using and request more
// Currently only implemented in Chrome.
// path_to_url
// By Addy Osmani
Modernizr.addTest('quotamanagement', function(){
var storage = Modernizr.prefixed('StorageInfo', window);
return !!(storage && 'TEMPORARY' in storage && 'PERSISTENT' in storage);
});
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/quota-management-api.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 94 |
```javascript
// Detects whether input form="form_id" is available on the platform
// E.g. IE 10 (and below), don't support this
Modernizr.addTest("formattribute", function() {
var form = document.createElement("form"),
input = document.createElement("input"),
div = document.createElement("div"),
id = "formtest"+(new Date().getTime()),
attr,
bool = false;
form.id = id;
//IE6/7 confuses the form idl attribute and the form content attribute
if(document.createAttribute){
attr = document.createAttribute("form");
attr.nodeValue = id;
input.setAttributeNode(attr);
div.appendChild(form);
div.appendChild(input);
document.documentElement.appendChild(div);
bool = form.elements.length === 1 && input.form == form;
div.parentNode.removeChild(div);
}
return bool;
});
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/forms-formattribute.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 184 |
```javascript
// code.google.com/speed/webp/
// by rich bradshaw, ryan seddon, and paul irish
// This test is asynchronous. Watch out.
(function(){
var image = new Image();
image.onerror = function() {
Modernizr.addTest('webp', false);
};
image.onload = function() {
Modernizr.addTest('webp', function() { return image.width == 1; });
};
image.src = 'data:image/webp;base64,UklGRiwAAABXRUJQVlA4ICAAAAAUAgCdASoBAAEAL/3+/3+CAB/AAAFzrNsAAP5QAAAAAA==';
}());
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/img-webp.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 152 |
```javascript
Modernizr.addTest('fullscreen',function(){
for(var i = 0; i < Modernizr._domPrefixes.length; i++) {
if( document[Modernizr._domPrefixes[i].toLowerCase() + 'CancelFullScreen'])
return true;
}
return !!document['cancelFullScreen'] || false;
});
// path_to_url#//apple_ref/doc/uid/TP40009523-CH3-SW20
// path_to_url
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/fullscreen-api.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 97 |
```javascript
// strict mode
// test by @kangax
Modernizr.addTest('strictmode', function(){
return (function(){ "use strict"; return !this; })();
});
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/es5-strictmode.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 39 |
```javascript
// Test for `sandbox` attribute in iframes.
//
// Spec: path_to_url#attr-iframe-sandbox
Modernizr.addTest('sandbox', 'sandbox' in document.createElement('iframe'));
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/iframe-sandbox.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 42 |
```javascript
/*
path_to_url
path_to_url#background-position
Example: path_to_url
*/
(function() {
var elem = document.createElement('a'),
eStyle = elem.style,
val = "right 10px bottom 10px";
Modernizr.addTest('bgpositionshorthand', function(){
eStyle.cssText = "background-position: " + val + ";";
return (eStyle.backgroundPosition === val);
});
}());
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/css-backgroundposition-shorthand.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 97 |
```javascript
// Blob constructor
// path_to_url#constructorBlob
Modernizr.addTest('blobconstructor', function () {
try {
return !!new Blob();
} catch (e) {
return false;
}
});
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/blob-constructor.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 47 |
```javascript
// by james a rosen.
// path_to_url
Modernizr.addTest('createelement-attrs', function() {
try {
return document.createElement("<input name='test' />").getAttribute('name') == 'test';
} catch(e) {
return false;
}
});
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/dom-createElement-attrs.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 62 |
```javascript
// native JSON support.
// developer.mozilla.org/en/JSON
// this will also succeed if you've loaded the JSON2.js polyfill ahead of time
// ... but that should be obvious. :)
Modernizr.addTest('json', !!window.JSON && !!JSON.parse);
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/json.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 58 |
```javascript
// tests if page is iframed
// github.com/Modernizr/Modernizr/issues/242
Modernizr.addTest('framed', function(){
return window.location != top.location;
});
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/window-framed.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 43 |
```javascript
// display: table and table-cell test. (both are tested under one name "table-cell" )
// By @scottjehl
// all additional table display values are here: path_to_url though Scott has seen some IE false positives with that sort of weak detection.
// more testing neccessary perhaps.
Modernizr.addTest( "display-table",function(){
var doc = window.document,
docElem = doc.documentElement,
parent = doc.createElement( "div" ),
child = doc.createElement( "div" ),
childb = doc.createElement( "div" ),
ret;
parent.style.cssText = "display: table";
child.style.cssText = childb.style.cssText = "display: table-cell; padding: 10px";
parent.appendChild( child );
parent.appendChild( childb );
docElem.insertBefore( parent, docElem.firstChild );
ret = child.offsetLeft < childb.offsetLeft;
docElem.removeChild(parent);
return ret;
});
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/css-displaytable.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 217 |
```javascript
// input[type="number"] localized input/output
// // Detects whether input type="number" is capable of receiving and
// // displaying localized numbers, e.g. with comma separator
// // path_to_url
// // Based on path_to_url#L9
// // By Peter Janes
Modernizr.addTest('localizedNumber', function() {
var doc = document,
el = document.createElement('div'),
fake,
root,
input,
diff;
root = doc.body || (function() {
var de = doc.documentElement;
fake = true;
return de.insertBefore(doc.createElement('body'), de.firstElementChild || de.firstChild);
}());
el.innerHTML = '<input type="number" value="1.0" step="0.1"/>';
input = el.childNodes[0];
root.appendChild(el);
input.focus();
try {
doc.execCommand('InsertText', false, '1,1');
} catch(e) { // prevent warnings in IE
}
diff = input.type === 'number' && input.valueAsNumber === 1.1 && input.checkValidity();
root.removeChild(el);
fake && root.parentNode.removeChild(root);
return diff;
});
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/forms-inputnumber-l10n.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 257 |
```javascript
// DataView
// path_to_url
// By Addy Osmani
Modernizr.addTest('dataview', (typeof DataView !== 'undefined' && 'getFloat64' in DataView.prototype));
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/dataview-api.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 42 |
```javascript
// Track element + Timed Text Track API
// path_to_url#the-track-element
// path_to_url#text-track-api
//
// While IE10 has implemented the track element, IE10 does not expose the underlying APIs to create timed text tracks by JS (really sad)
// By Addy Osmani
Modernizr.addTest({
texttrackapi: (typeof (document.createElement('video').addTextTrack) === 'function'),
// a more strict test for track including UI support: document.createElement('track').kind === 'subtitles'
track: ('kind' in document.createElement('track'))
});
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/elem-track.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 127 |
```javascript
// path_to_url
// documentMode is needed for false positives in oldIE, please see issue above
Modernizr.addTest('cssfilters', function() {
var el = document.createElement('div');
el.style.cssText = Modernizr._prefixes.join('filter' + ':blur(2px); ');
return !!el.style.length && ((document.documentMode === undefined || document.documentMode > 9));
});
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/css-filters.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 88 |
```javascript
// Dart
// By Theodoor van Donge
// path_to_url
Modernizr.addTest('dart', !!Modernizr.prefixed('startDart', navigator));
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/dart.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 37 |
```javascript
/*
* Test for SubPixel Font Rendering
* (to infer if GDI or DirectWrite is used on Windows)
* Authors: @derSchepp, @gerritvanaaken, @rodneyrehm, @yatil, @ryanseddon
* Web: path_to_url
*/
Modernizr.addTest('subpixelfont', function() {
var bool,
styles = "#modernizr{position: absolute; top: -10em; visibility:hidden; font: normal 10px arial;}#subpixel{float: left; font-size: 33.3333%;}";
// see path_to_url#L97
Modernizr.testStyles(styles, function(elem) {
var subpixel = elem.firstChild;
subpixel.innerHTML = 'This is a text written in Arial';
bool = window.getComputedStyle ?
window.getComputedStyle(subpixel, null).getPropertyValue("width") !== '44px'
: false;
}, 1, ['subpixel']);
return bool;
});
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/css-subpixelfont.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 217 |
```javascript
// developer.mozilla.org/en/CSS/background-repeat
// test page: jsbin.com/uzesun/
// path_to_url
(function(){
function getBgRepeatValue(elem){
return (window.getComputedStyle ?
getComputedStyle(elem, null).getPropertyValue('background') :
elem.currentStyle['background']);
}
Modernizr.testStyles(' #modernizr { background-repeat: round; } ', function(elem, rule){
Modernizr.addTest('bgrepeatround', getBgRepeatValue(elem) == 'round');
});
Modernizr.testStyles(' #modernizr { background-repeat: space; } ', function(elem, rule){
Modernizr.addTest('bgrepeatspace', getBgRepeatValue(elem) == 'space');
});
})();
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/css-backgroundrepeat.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 155 |
```javascript
// requestAnimationFrame
// Offload animation repainting to browser for optimized performance.
// path_to_url
// By Addy Osmani
Modernizr.addTest('raf', !!Modernizr.prefixed('requestAnimationFrame', window));
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/requestanimationframe.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 49 |
```javascript
// Tests for the ability to use Web Intents (path_to_url
// By Eric Bidelman
Modernizr.addTest('webintents', function() {
return !!Modernizr.prefixed('startActivity', navigator);
});
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/web-intents.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 49 |
```javascript
// Filesystem API
// dev.w3.org/2009/dap/file-system/file-dir-sys.html
// The API will be present in Chrome incognito, but will throw an exception.
// See crbug.com/93417
//
// By Eric Bidelman (@ebidel)
Modernizr.addTest('filesystem', !!Modernizr.prefixed('requestFileSystem', window));
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/file-filesystem.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 79 |
```javascript
// last-child pseudo selector
// path_to_url
Modernizr.addTest('lastchild', function(){
return Modernizr.testStyles("#modernizr div {width:100px} #modernizr :last-child{width:200px;display:block}", function (elem) {
return elem.lastChild.offsetWidth > elem.firstChild.offsetWidth;
}, 2);
});
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/css-lastchild.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 74 |
```javascript
// path_to_url
// path_to_url
Modernizr.addTest('cssvmaxunit', function(){
var bool;
Modernizr.testStyles("#modernizr { width: 50vmax; }", function(elem, rule) {
var one_vw = window.innerWidth/100,
one_vh = window.innerHeight/100,
compWidth = parseInt((window.getComputedStyle ?
getComputedStyle(elem, null) :
elem.currentStyle)['width'],10);
bool = ( parseInt(Math.max(one_vw, one_vh)*50,10) == compWidth );
});
return bool;
});
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/css-vmaxunit.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 129 |
```javascript
// path_to_url
// path_to_url
Modernizr.addTest('cssvminunit', function(){
var bool;
Modernizr.testStyles("#modernizr { width: 50vmin; }", function(elem, rule) {
var one_vw = window.innerWidth/100,
one_vh = window.innerHeight/100,
compWidth = parseInt((window.getComputedStyle ?
getComputedStyle(elem, null) :
elem.currentStyle)['width'],10);
bool = ( parseInt(Math.min(one_vw, one_vh)*50,10) == compWidth );
});
return bool;
});
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/css-vminunit.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 129 |
```javascript
// path_to_url
// path_to_url
Modernizr.addTest('cssvwunit', function(){
var bool;
Modernizr.testStyles("#modernizr { width: 50vw; }", function(elem, rule) {
var width = parseInt(window.innerWidth/2,10),
compStyle = parseInt((window.getComputedStyle ?
getComputedStyle(elem, null) :
elem.currentStyle)["width"],10);
bool= (compStyle == width);
});
return bool;
});
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/css-vwunit.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 105 |
```javascript
/* see path_to_url
path_to_url
There are three tests:
1. csshyphens - tests hyphens:auto actually adds hyphens to text
2. softhyphens - tests that ­ does its job
3. softhyphensfind - tests that in-browser Find functionality still works correctly with ­
These tests currently require document.body to be present
Hyphenation is language specific, sometimes.
See for more details: path_to_url#sc_svn975_313
If loading Hyphenator.js via Modernizr.load, be cautious of issue 158: path_to_url
More details at path_to_url
*/
(function() {
if (!document.body){
window.console && console.warn('document.body doesn\'t exist. Modernizr hyphens test needs it.');
return;
}
// functional test of adding hyphens:auto
function test_hyphens_css() {
try {
/* create a div container and a span within that
* these have to be appended to document.body, otherwise some browsers can give false negative */
var div = document.createElement('div'),
span = document.createElement('span'),
divStyle = div.style,
spanHeight = 0,
spanWidth = 0,
result = false,
firstChild = document.body.firstElementChild || document.body.firstChild;
div.appendChild(span);
span.innerHTML = 'Bacon ipsum dolor sit amet jerky velit in culpa hamburger et. Laborum dolor proident, enim dolore duis commodo et strip steak. Salami anim et, veniam consectetur dolore qui tenderloin jowl velit sirloin. Et ad culpa, fatback cillum jowl ball tip ham hock nulla short ribs pariatur aute. Pig pancetta ham bresaola, ut boudin nostrud commodo flank esse cow tongue culpa. Pork belly bresaola enim pig, ea consectetur nisi. Fugiat officia turkey, ea cow jowl pariatur ullamco proident do laborum velit sausage. Magna biltong sint tri-tip commodo sed bacon, esse proident aliquip. Ullamco ham sint fugiat, velit in enim sed mollit nulla cow ut adipisicing nostrud consectetur. Proident dolore beef ribs, laborum nostrud meatball ea laboris rump cupidatat labore culpa. Shankle minim beef, velit sint cupidatat fugiat tenderloin pig et ball tip. Ut cow fatback salami, bacon ball tip et in shank strip steak bresaola. In ut pork belly sed mollit tri-tip magna culpa veniam, short ribs qui in andouille ham consequat. Dolore bacon t-bone, velit short ribs enim strip steak nulla. Voluptate labore ut, biltong swine irure jerky. Cupidatat excepteur aliquip salami dolore. Ball tip strip steak in pork dolor. Ad in esse biltong. Dolore tenderloin exercitation ad pork loin t-bone, dolore in chicken ball tip qui pig. Ut culpa tongue, sint ribeye dolore ex shank voluptate hamburger. Jowl et tempor, boudin pork chop labore ham hock drumstick consectetur tri-tip elit swine meatball chicken ground round. Proident shankle mollit dolore. Shoulder ut duis t-bone quis reprehenderit. Meatloaf dolore minim strip steak, laboris ea aute bacon beef ribs elit shank in veniam drumstick qui. Ex laboris meatball cow tongue pork belly. Ea ball tip reprehenderit pig, sed fatback boudin dolore flank aliquip laboris eu quis. Beef ribs duis beef, cow corned beef adipisicing commodo nisi deserunt exercitation. Cillum dolor t-bone spare ribs, ham hock est sirloin. Brisket irure meatloaf in, boudin pork belly sirloin ball tip. Sirloin sint irure nisi nostrud aliqua. Nostrud nulla aute, enim officia culpa ham hock. Aliqua reprehenderit dolore sunt nostrud sausage, ea boudin pork loin ut t-bone ham tempor. Tri-tip et pancetta drumstick laborum. Ham hock magna do nostrud in proident. Ex ground round fatback, venison non ribeye in.';
document.body.insertBefore(div, firstChild);
/* get size of unhyphenated text */
divStyle.cssText = 'position:absolute;top:0;left:0;width:5em;text-align:justify;text-justification:newspaper;';
spanHeight = span.offsetHeight;
spanWidth = span.offsetWidth;
/* compare size with hyphenated text */
divStyle.cssText = 'position:absolute;top:0;left:0;width:5em;text-align:justify;'+
'text-justification:newspaper;'+
Modernizr._prefixes.join('hyphens:auto; ');
result = (span.offsetHeight != spanHeight || span.offsetWidth != spanWidth);
/* results and cleanup */
document.body.removeChild(div);
div.removeChild(span);
return result;
} catch(e) {
return false;
}
}
// for the softhyphens test
function test_hyphens(delimiter, testWidth) {
try {
/* create a div container and a span within that
* these have to be appended to document.body, otherwise some browsers can give false negative */
var div = document.createElement('div'),
span = document.createElement('span'),
divStyle = div.style,
spanSize = 0,
result = false,
result1 = false,
result2 = false,
firstChild = document.body.firstElementChild || document.body.firstChild;
divStyle.cssText = 'position:absolute;top:0;left:0;overflow:visible;width:1.25em;';
div.appendChild(span);
document.body.insertBefore(div, firstChild);
/* get height of unwrapped text */
span.innerHTML = 'mm';
spanSize = span.offsetHeight;
/* compare height w/ delimiter, to see if it wraps to new line */
span.innerHTML = 'm' + delimiter + 'm';
result1 = (span.offsetHeight > spanSize);
/* if we're testing the width too (i.e. for soft-hyphen, not zws),
* this is because tested Blackberry devices will wrap the text but not display the hyphen */
if (testWidth) {
/* get width of wrapped, non-hyphenated text */
span.innerHTML = 'm<br />m';
spanSize = span.offsetWidth;
/* compare width w/ wrapped w/ delimiter to see if hyphen is present */
span.innerHTML = 'm' + delimiter + 'm';
result2 = (span.offsetWidth > spanSize);
} else {
result2 = true;
}
/* results and cleanup */
if (result1 === true && result2 === true) { result = true; }
document.body.removeChild(div);
div.removeChild(span);
return result;
} catch(e) {
return false;
}
}
// testing if in-browser Find functionality will work on hyphenated text
function test_hyphens_find(delimiter) {
try {
/* create a dummy input for resetting selection location, and a div container
* these have to be appended to document.body, otherwise some browsers can give false negative
* div container gets the doubled testword, separated by the delimiter
* Note: giving a width to div gives false positive in iOS Safari */
var dummy = document.createElement('input'),
div = document.createElement('div'),
testword = 'lebowski',
result = false,
textrange,
firstChild = document.body.firstElementChild || document.body.firstChild;
div.innerHTML = testword + delimiter + testword;
document.body.insertBefore(div, firstChild);
document.body.insertBefore(dummy, div);
/* reset the selection to the dummy input element, i.e. BEFORE the div container
* stackoverflow.com/questions/499126/jquery-set-cursor-position-in-text-area */
if (dummy.setSelectionRange) {
dummy.focus();
dummy.setSelectionRange(0,0);
} else if (dummy.createTextRange) {
textrange = dummy.createTextRange();
textrange.collapse(true);
textrange.moveEnd('character', 0);
textrange.moveStart('character', 0);
textrange.select();
}
/* try to find the doubled testword, without the delimiter */
if (window.find) {
result = window.find(testword + testword);
} else {
try {
textrange = window.self.document.body.createTextRange();
result = textrange.findText(testword + testword);
} catch(e) {
result = false;
}
}
document.body.removeChild(div);
document.body.removeChild(dummy);
return result;
} catch(e) {
return false;
}
}
Modernizr.addTest("csshyphens", function() {
if (!Modernizr.testAllProps('hyphens')) return false;
/* Chrome lies about its hyphens support so we need a more robust test
crbug.com/107111
*/
try {
return test_hyphens_css();
} catch(e) {
return false;
}
});
Modernizr.addTest("softhyphens", function() {
try {
// use numeric entity instead of ­ in case it's XHTML
return test_hyphens('­', true) && test_hyphens('​', false);
} catch(e) {
return false;
}
});
Modernizr.addTest("softhyphensfind", function() {
try {
return test_hyphens_find('­') && test_hyphens_find('​');
} catch(e) {
return false;
}
});
})();
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/css-hyphens.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 2,158 |
```javascript
// developer.mozilla.org/en/CSS/pointer-events
// Test and project pages:
// ausi.github.com/Feature-detection-technique-for-pointer-events/
// github.com/ausi/Feature-detection-technique-for-pointer-events/wiki
// github.com/Modernizr/Modernizr/issues/80
Modernizr.addTest('pointerevents', function(){
var element = document.createElement('x'),
documentElement = document.documentElement,
getComputedStyle = window.getComputedStyle,
supports;
if(!('pointerEvents' in element.style)){
return false;
}
element.style.pointerEvents = 'auto';
element.style.pointerEvents = 'x';
documentElement.appendChild(element);
supports = getComputedStyle &&
getComputedStyle(element, '').pointerEvents === 'auto';
documentElement.removeChild(element);
return !!supports;
});
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/css-pointerevents.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 175 |
```javascript
Modernizr.addTest('mediaqueries', Modernizr.mq('only all'));
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/css-mediaqueries.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 18 |
```javascript
// speech input for inputs
// by @alrra
// `webkitSpeech` in elem
// doesn`t work correctly in all versions of Chromium based browsers.
// It can return false even if they have support for speech i.imgur.com/2Y40n.png
// Testing with 'onwebkitspeechchange' seems to fix this problem
// this detect only checks the webkit version because
// the speech attribute is likely to be deprecated in favor of a JavaScript API.
// path_to_url
// FIXME: add support for detecting the new spec'd behavior
Modernizr.addTest('speechinput', function(){
var elem = document.createElement('input');
return 'speech' in elem || 'onwebkitspeechchange' in elem;
});
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/forms-speechinput.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 160 |
```javascript
// testing for placeholder attribute in inputs and textareas
// re-using Modernizr.input if available
Modernizr.addTest('placeholder', function(){
return !!( 'placeholder' in ( Modernizr.input || document.createElement('input') ) &&
'placeholder' in ( Modernizr.textarea || document.createElement('textarea') )
);
});
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/forms-placeholder.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 73 |
```javascript
// Test for `srcdoc` attribute in iframes.
//
// Spec: path_to_url#attr-iframe-srcdoc
Modernizr.addTest('srcdoc', 'srcdoc' in document.createElement('iframe'));
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/iframe-srcdoc.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 45 |
```javascript
// Browser support test for <style scoped>
// path_to_url#attr-style-scoped
//
// by @alrra
Modernizr.addTest( 'stylescoped', 'scoped' in document.createElement('style') );
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/style-scoped.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 48 |
```javascript
// Method of allowing calculated values for length units, i.e. width: calc(100%-3em) path_to_url#search=calc
// By @calvein
Modernizr.addTest('csscalc', function() {
var prop = 'width:';
var value = 'calc(10px);';
var el = document.createElement('div');
el.style.cssText = prop + Modernizr._prefixes.join(value + prop);
return !!el.style.length;
});
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/css-calc.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 102 |
```javascript
// This implementation only tests support for interactive form validation.
// To check validation for a specific type or a specific other constraint,
// the test can be combined:
// - Modernizr.inputtypes.numer && Modernizr.formvalidation (browser supports rangeOverflow, typeMismatch etc. for type=number)
// - Modernizr.input.required && Modernizr.formvalidation (browser supports valueMissing)
//
(function(document, Modernizr){
Modernizr.formvalidationapi = false;
Modernizr.formvalidationmessage = false;
Modernizr.addTest('formvalidation', function() {
var form = document.createElement('form');
if ( !('checkValidity' in form) || !('addEventListener' in form) ) {
return false;
}
if ('reportValidity' in form) {
return true;
}
var invalidFired = false;
var input;
Modernizr.formvalidationapi = true;
// Prevent form from being submitted
form.addEventListener('submit', function(e) {
//Opera does not validate form, if submit is prevented
if ( !window.opera ) {
e.preventDefault();
}
e.stopPropagation();
}, false);
// Calling form.submit() doesn't trigger interactive validation,
// use a submit button instead
//older opera browsers need a name attribute
form.innerHTML = '<input name="modTest" required><button></button>';
Modernizr.testStyles('#modernizr form{position:absolute;top:-99999em}', function( node ) {
node.appendChild(form);
input = form.getElementsByTagName('input')[0];
// Record whether "invalid" event is fired
input.addEventListener('invalid', function(e) {
invalidFired = true;
e.preventDefault();
e.stopPropagation();
}, false);
//Opera does not fully support the validationMessage property
Modernizr.formvalidationmessage = !!input.validationMessage;
// Submit form by clicking submit button
form.getElementsByTagName('button')[0].click();
});
return invalidFired;
});
})(document, window.Modernizr);
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/forms-validation.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 433 |
```javascript
// Grab the WebGL extensions currently supported and add to the Modernizr.webgl object
// spec: www.khronos.org/registry/webgl/specs/latest/#5.13.14
// based on code from ilmari heikkinen
// code.google.com/p/graphics-detect/source/browse/js/detect.js
(function(){
if (!Modernizr.webgl) return;
var canvas, ctx, exts;
try {
canvas = document.createElement('canvas');
ctx = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
exts = ctx.getSupportedExtensions();
}
catch (e) {
return;
}
if (ctx === undefined) {
Modernizr.webgl = new Boolean(false);
}
else {
Modernizr.webgl = new Boolean(true);
}
for (var i = -1, len = exts.length; ++i < len; ){
Modernizr.webgl[exts[i]] = true;
}
// hack for addressing modernizr testsuite failures. sorry.
if (window.TEST && TEST.audvid){
TEST.audvid.push('webgl');
}
canvas = undefined;
})();
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/webgl-extensions.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 258 |
```javascript
/**
* file tests for the File API specification
* Tests for objects specific to the File API W3C specification without
* being redundant (don't bother testing for Blob since it is assumed
* to be the File object's prototype.
*
* Will fail in Safari 5 due to its lack of support for the standards
* defined FileReader object
*/
Modernizr.addTest('filereader', function () {
return !!(window.File && window.FileList && window.FileReader);
});
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/file-api.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 106 |
```javascript
// cors
// By Theodoor van Donge
Modernizr.addTest('cors', !!(window.XMLHttpRequest && 'withCredentials' in new XMLHttpRequest()));
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/cors.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 34 |
```javascript
// Requires a Modernizr build with `canvastext` included
// path_to_url#-canvas-canvastext
Modernizr.addTest('emoji', function() {
if (!Modernizr.canvastext) return false;
var node = document.createElement('canvas'),
ctx = node.getContext('2d');
ctx.textBaseline = 'top';
ctx.font = '32px Arial';
ctx.fillText('\ud83d\ude03', 0, 0); // "smiling face with open mouth" emoji
return ctx.getImageData(16, 16, 1, 1).data[0] !== 0;
});
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/emoji.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 140 |
```javascript
// determining low-bandwidth via navigator.connection
// There are two iterations of the navigator.connection interface:
// The first is present in Android 2.2+ and only in the Browser (not WebView)
// : docs.phonegap.com/en/1.2.0/phonegap_connection_connection.md.html#connection.type
// : davidbcalhoun.com/2010/using-navigator-connection-android
// The second is specced at dev.w3.org/2009/dap/netinfo/ and perhaps landing in WebKit
// : bugs.webkit.org/show_bug.cgi?id=73528
// unknown devices are assumed as fast
// for more rigorous network testing, consider boomerang.js: github.com/bluesmoon/boomerang/
Modernizr.addTest('lowbandwidth', function() {
var connection = navigator.connection || { type: 0 }; // polyfill
return connection.type == 3 || // connection.CELL_2G
connection.type == 4 || // connection.CELL_3G
/^[23]g$/.test(connection.type); // string value in new spec
});
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/network-connection.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 235 |
```javascript
//By Shi Chuan
//Part of Device Access aspect of HTML5, same category as geolocation
//W3C Editor's Draft at path_to_url
//Implementation by iOS Safari at path_to_url and path_to_url
//test for Device Motion Event support, returns boolean value true/false
Modernizr.addTest('devicemotion', ('DeviceMotionEvent' in window) );
//test for Device Orientation Event support, returns boolean value true/false
Modernizr.addTest('deviceorientation', ('DeviceOrientationEvent' in window) );
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/event-deviceorientation-motion.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 112 |
```javascript
// by alanhogan
// path_to_url
// path_to_url
Modernizr.testStyles(' #modernizr { display: run-in; } ', function(elem, rule){
var ret = (window.getComputedStyle ?
getComputedStyle(elem, null).getPropertyValue('display') :
elem.currentStyle['display']);
Modernizr.addTest('display-runin', ret == 'run-in');
});
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/css-displayrunin.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 86 |
```javascript
// Battery API
// path_to_url
// By: Paul Sayre
Modernizr.addTest('battery',
!!Modernizr.prefixed('battery', navigator)
);
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/battery-api.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 37 |
```javascript
// data uri test.
// path_to_url
// This test is asynchronous. Watch out.
// in IE7 in HTTPS this can cause a Mixed Content security popup.
// github.com/Modernizr/Modernizr/issues/362
// To avoid that you can create a new iframe and inject this.. perhaps..
(function(){
var datauri = new Image();
datauri.onerror = function() {
Modernizr.addTest('datauri', function () { return false; });
};
datauri.onload = function() {
Modernizr.addTest('datauri', function () { return (datauri.width == 1 && datauri.height == 1); });
};
datauri.src = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
})();
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/url-data-uri.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 180 |
```javascript
// async script
// By Theodoor van Donge
Modernizr.addTest('scriptasync', 'async' in document.createElement('script'));
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/script-async.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 31 |
```javascript
// -moz-user-select:none test.
// by ryan seddon
//path_to_url
Modernizr.addTest("userselect",function(){
return Modernizr.testAllProps("user-select");
});
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/css-userselect.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 43 |
```javascript
/*
Custom protocol handler support
path_to_url#custom-handlers
Added by @benschwarz
*/
Modernizr.addTest('customprotocolhandler', function () {
return !!navigator.registerProtocolHandler;
});
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/custom-protocol-handler.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 46 |
```javascript
// Notifications
// By Theodoor van Donge
// window.webkitNotifications is only used by Chrome
// path_to_url
// window.Notification only exist in the draft specs
// path_to_url#idl-if-Notification
Modernizr.addTest('notification', 'Notification' in window && 'permission' in window.Notification && 'requestPermission' in window.Notification);
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/notification.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 76 |
```javascript
// XML HTTP Request Level 2
// www.w3.org/TR/XMLHttpRequest2/
// Much more details at github.com/Modernizr/Modernizr/issues/385
// all three of these details report consistently across all target browsers:
// !!(window.ProgressEvent);
// !!(window.FormData);
// window.XMLHttpRequest && "withCredentials" in new XMLHttpRequest;
Modernizr.addTest('xhr2', 'FormData' in window);
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/network-xhr2.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 94 |
```javascript
// path_to_url
Modernizr.addTest('pointerlock',!!Modernizr.prefixed('pointerLockElement', document));
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/pointerlock-api.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 26 |
```javascript
// developer.mozilla.org/en/CSS/box-sizing
// github.com/Modernizr/Modernizr/issues/248
Modernizr.addTest("boxsizing",function(){
return Modernizr.testAllProps("boxSizing") && (document.documentMode === undefined || document.documentMode > 7);
});
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/css-boxsizing.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 65 |
```javascript
// by jussi-kalliokoski
// This test is asynchronous. Watch out.
// The test will potentially add garbage to console.
(function(){
try {
// we're avoiding using Modernizr._domPrefixes as the prefix capitalization on
// these guys are notoriously peculiar.
var BlobBuilder = window.MozBlobBuilder || window.WebKitBlobBuilder || window.MSBlobBuilder || window.OBlobBuilder || window.BlobBuilder;
var URL = window.MozURL || window.webkitURL || window.MSURL || window.OURL || window.URL;
var data = 'Modernizr',
blob,
bb,
worker,
url,
timeout,
scriptText = 'this.onmessage=function(e){postMessage(e.data)}';
try {
blob = new Blob([scriptText], {type:'text/javascript'});
} catch(e) {
// we'll fall back to the deprecated BlobBuilder
}
if (!blob) {
bb = new BlobBuilder();
bb.append(scriptText);
blob = bb.getBlob();
}
url = URL.createObjectURL(blob);
worker = new Worker(url);
worker.onmessage = function(e) {
Modernizr.addTest('blobworkers', data === e.data);
cleanup();
};
// Just in case...
worker.onerror = fail;
timeout = setTimeout(fail, 200);
worker.postMessage(data);
} catch (e) {
fail();
}
function fail() {
Modernizr.addTest('blobworkers', false);
cleanup();
}
function cleanup() {
if (url) {
URL.revokeObjectURL(url);
}
if (worker) {
worker.terminate();
}
if (timeout) {
clearTimeout(timeout);
}
}
}());
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/workers-blobworkers.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 380 |
```javascript
// contentEditable
// path_to_url#contenteditable
// this is known to false positive in some mobile browsers
// here is a whitelist of verified working browsers:
// path_to_url#L2083
Modernizr.addTest('contenteditable',
'contentEditable' in document.documentElement);
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/contenteditable.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 61 |
```javascript
// developer.mozilla.org/en/CSS/background-size
Modernizr.testStyles( '#modernizr{background-size:cover}', function( elem ) {
var style = window.getComputedStyle ?
window.getComputedStyle( elem, null )
: elem.currentStyle;
Modernizr.addTest( 'bgsizecover', style.backgroundSize == 'cover' );
});
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/css-backgroundsizecover.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 75 |
```javascript
// Animated PNG
// path_to_url
// By Addy Osmani
(function () {
if (!Modernizr.canvas) return false;
var image = new Image(),
canvas = document.createElement('canvas'),
ctx = canvas.getContext('2d');
image.onload = function () {
Modernizr.addTest('apng', function () {
if (typeof canvas.getContext == 'undefined') {
return false;
} else {
ctx.drawImage(image, 0, 0);
return ctx.getImageData(0, 0, 1, 1).data[3] === 0;
}
});
};
image.src = "data:image/png;base64,your_sha256_hashyour_sha256_hashAAEAAAAAAAAAAAD6A+gBAbNU+2sAAAARZmRBVAAAAAEImWNgYGBgAAAABQAB6MzFdgAAAABJRU5ErkJggg==";
}());
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/img-apng.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 204 |
```javascript
// Test for (experimental) Content Security Policy 1.1 support.
//
// This feature is still quite experimental, but is available now in Chrome 22.
// If the `SecurityPolicy` property is available, you can be sure the browser
// supports CSP. If it's not available, the browser still might support an
// earlier version of the CSP spec.
//
// Editor's Draft: path_to_url
Modernizr.addTest('contentsecuritypolicy', ('securityPolicy' in document || 'SecurityPolicy' in document));
``` | /content/code_sandbox/public/vendor/modernizr/feature-detects/contentsecuritypolicy.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 110 |
```javascript
!function(t,e){"function"==typeof define&&define.amd?define(["moment"],e):"object"==typeof exports?module.exports=e.call(t,require("moment")):t.Chart=e.call(t,t.moment)}(this,function(t){/*!
* Chart.js
* path_to_url
* Version: 2.0.0-beta2
*
* Released under the MIT license
* path_to_url
*/
/*!
* Chart.js
* path_to_url
* Version: 2.0.0-beta2
*
* Released under the MIT license
* path_to_url
*/
/*!
* Chart.js
* path_to_url
* Version: 2.0.0-beta2
*
* Released under the MIT license
* path_to_url
*/
/*!
* Chart.js
* path_to_url
* Version: 2.0.0-beta2
*
* Released under the MIT license
* path_to_url
*/
return!function e(t,i,a){function s(n,r){if(!i[n]){if(!t[n]){var h="function"==typeof require&&require;if(!r&&h)return h(n,!0);if(o)return o(n,!0);var l=new Error("Cannot find module '"+n+"'");throw l.code="MODULE_NOT_FOUND",l}var c=i[n]={exports:{}};t[n][0].call(c.exports,function(e){var i=t[n][1][e];return s(i?i:e)},c,c.exports,e,t,i,a)}return i[n].exports}for(var o="function"==typeof require&&require,n=0;n<a.length;n++)s(a[n]);return s}({1:[function(t,e,i){!function(){var i=t("color-convert"),a=t("color-string"),s=function(t){if(t instanceof s)return t;if(!(this instanceof s))return new s(t);if(this.values={rgb:[0,0,0],hsl:[0,0,0],hsv:[0,0,0],hwb:[0,0,0],cmyk:[0,0,0,0],alpha:1},"string"==typeof t){var e=a.getRgba(t);if(e)this.setValues("rgb",e);else if(e=a.getHsla(t))this.setValues("hsl",e);else{if(!(e=a.getHwb(t)))throw new Error('Unable to parse color from string "'+t+'"');this.setValues("hwb",e)}}else if("object"==typeof t){var e=t;if(void 0!==e.r||void 0!==e.red)this.setValues("rgb",e);else if(void 0!==e.l||void 0!==e.lightness)this.setValues("hsl",e);else if(void 0!==e.v||void 0!==e.value)this.setValues("hsv",e);else if(void 0!==e.w||void 0!==e.whiteness)this.setValues("hwb",e);else{if(void 0===e.c&&void 0===e.cyan)throw new Error("Unable to parse color from object "+JSON.stringify(t));this.setValues("cmyk",e)}}};s.prototype={rgb:function(t){return this.setSpace("rgb",arguments)},hsl:function(t){return this.setSpace("hsl",arguments)},hsv:function(t){return this.setSpace("hsv",arguments)},hwb:function(t){return this.setSpace("hwb",arguments)},cmyk:function(t){return this.setSpace("cmyk",arguments)},rgbArray:function(){return this.values.rgb},hslArray:function(){return this.values.hsl},hsvArray:function(){return this.values.hsv},hwbArray:function(){return 1!==this.values.alpha?this.values.hwb.concat([this.values.alpha]):this.values.hwb},cmykArray:function(){return this.values.cmyk},rgbaArray:function(){var t=this.values.rgb;return t.concat([this.values.alpha])},hslaArray:function(){var t=this.values.hsl;return t.concat([this.values.alpha])},alpha:function(t){return void 0===t?this.values.alpha:(this.setValues("alpha",t),this)},red:function(t){return this.setChannel("rgb",0,t)},green:function(t){return this.setChannel("rgb",1,t)},blue:function(t){return this.setChannel("rgb",2,t)},hue:function(t){return this.setChannel("hsl",0,t)},saturation:function(t){return this.setChannel("hsl",1,t)},lightness:function(t){return this.setChannel("hsl",2,t)},saturationv:function(t){return this.setChannel("hsv",1,t)},whiteness:function(t){return this.setChannel("hwb",1,t)},blackness:function(t){return this.setChannel("hwb",2,t)},value:function(t){return this.setChannel("hsv",2,t)},cyan:function(t){return this.setChannel("cmyk",0,t)},magenta:function(t){return this.setChannel("cmyk",1,t)},yellow:function(t){return this.setChannel("cmyk",2,t)},black:function(t){return this.setChannel("cmyk",3,t)},hexString:function(){return a.hexString(this.values.rgb)},rgbString:function(){return a.rgbString(this.values.rgb,this.values.alpha)},rgbaString:function(){return a.rgbaString(this.values.rgb,this.values.alpha)},percentString:function(){return a.percentString(this.values.rgb,this.values.alpha)},hslString:function(){return a.hslString(this.values.hsl,this.values.alpha)},hslaString:function(){return a.hslaString(this.values.hsl,this.values.alpha)},hwbString:function(){return a.hwbString(this.values.hwb,this.values.alpha)},keyword:function(){return a.keyword(this.values.rgb,this.values.alpha)},rgbNumber:function(){return this.values.rgb[0]<<16|this.values.rgb[1]<<8|this.values.rgb[2]},luminosity:function(){for(var t=this.values.rgb,e=[],i=0;i<t.length;i++){var a=t[i]/255;e[i]=.03928>=a?a/12.92:Math.pow((a+.055)/1.055,2.4)}return.2126*e[0]+.7152*e[1]+.0722*e[2]},contrast:function(t){var e=this.luminosity(),i=t.luminosity();return e>i?(e+.05)/(i+.05):(i+.05)/(e+.05)},level:function(t){var e=this.contrast(t);return e>=7.1?"AAA":e>=4.5?"AA":""},dark:function(){var t=this.values.rgb,e=(299*t[0]+587*t[1]+114*t[2])/1e3;return 128>e},light:function(){return!this.dark()},negate:function(){for(var t=[],e=0;3>e;e++)t[e]=255-this.values.rgb[e];return this.setValues("rgb",t),this},lighten:function(t){return this.values.hsl[2]+=this.values.hsl[2]*t,this.setValues("hsl",this.values.hsl),this},darken:function(t){return this.values.hsl[2]-=this.values.hsl[2]*t,this.setValues("hsl",this.values.hsl),this},saturate:function(t){return this.values.hsl[1]+=this.values.hsl[1]*t,this.setValues("hsl",this.values.hsl),this},desaturate:function(t){return this.values.hsl[1]-=this.values.hsl[1]*t,this.setValues("hsl",this.values.hsl),this},whiten:function(t){return this.values.hwb[1]+=this.values.hwb[1]*t,this.setValues("hwb",this.values.hwb),this},blacken:function(t){return this.values.hwb[2]+=this.values.hwb[2]*t,this.setValues("hwb",this.values.hwb),this},greyscale:function(){var t=this.values.rgb,e=.3*t[0]+.59*t[1]+.11*t[2];return this.setValues("rgb",[e,e,e]),this},clearer:function(t){return this.setValues("alpha",this.values.alpha-this.values.alpha*t),this},opaquer:function(t){return this.setValues("alpha",this.values.alpha+this.values.alpha*t),this},rotate:function(t){var e=this.values.hsl[0];return e=(e+t)%360,e=0>e?360+e:e,this.values.hsl[0]=e,this.setValues("hsl",this.values.hsl),this},mix:function(t,e){e=1-(null==e?.5:e);for(var i=2*e-1,a=this.alpha()-t.alpha(),s=((i*a==-1?i:(i+a)/(1+i*a))+1)/2,o=1-s,n=this.rgbArray(),r=t.rgbArray(),h=0;h<n.length;h++)n[h]=n[h]*s+r[h]*o;this.setValues("rgb",n);var l=this.alpha()*e+t.alpha()*(1-e);return this.setValues("alpha",l),this},toJSON:function(){return this.rgb()},clone:function(){return new s(this.rgb())}},s.prototype.getValues=function(t){for(var e={},i=0;i<t.length;i++)e[t.charAt(i)]=this.values[t][i];return 1!=this.values.alpha&&(e.a=this.values.alpha),e},s.prototype.setValues=function(t,e){var a={rgb:["red","green","blue"],hsl:["hue","saturation","lightness"],hsv:["hue","saturation","value"],hwb:["hue","whiteness","blackness"],cmyk:["cyan","magenta","yellow","black"]},s={rgb:[255,255,255],hsl:[360,100,100],hsv:[360,100,100],hwb:[360,100,100],cmyk:[100,100,100,100]},o=1;if("alpha"==t)o=e;else if(e.length)this.values[t]=e.slice(0,t.length),o=e[t.length];else if(void 0!==e[t.charAt(0)]){for(var n=0;n<t.length;n++)this.values[t][n]=e[t.charAt(n)];o=e.a}else if(void 0!==e[a[t][0]]){for(var r=a[t],n=0;n<t.length;n++)this.values[t][n]=e[r[n]];o=e.alpha}if(this.values.alpha=Math.max(0,Math.min(1,void 0!==o?o:this.values.alpha)),"alpha"!=t){for(var n=0;n<t.length;n++){var h=Math.max(0,Math.min(s[t][n],this.values[t][n]));this.values[t][n]=Math.round(h)}for(var l in a){l!=t&&(this.values[l]=i[t][l](this.values[t]));for(var n=0;n<l.length;n++){var h=Math.max(0,Math.min(s[l][n],this.values[l][n]));this.values[l][n]=Math.round(h)}}return!0}},s.prototype.setSpace=function(t,e){var i=e[0];return void 0===i?this.getValues(t):("number"==typeof i&&(i=Array.prototype.slice.call(e)),this.setValues(t,i),this)},s.prototype.setChannel=function(t,e,i){return void 0===i?this.values[t][e]:(this.values[t][e]=i,this.setValues(t,this.values[t]),this)},window.Color=e.exports=s}()},{"color-convert":3,"color-string":4}],2:[function(t,e,i){function a(t){var e,i,a,s=t[0]/255,o=t[1]/255,n=t[2]/255,r=Math.min(s,o,n),h=Math.max(s,o,n),l=h-r;return h==r?e=0:s==h?e=(o-n)/l:o==h?e=2+(n-s)/l:n==h&&(e=4+(s-o)/l),e=Math.min(60*e,360),0>e&&(e+=360),a=(r+h)/2,i=h==r?0:.5>=a?l/(h+r):l/(2-h-r),[e,100*i,100*a]}function s(t){var e,i,a,s=t[0],o=t[1],n=t[2],r=Math.min(s,o,n),h=Math.max(s,o,n),l=h-r;return i=0==h?0:l/h*1e3/10,h==r?e=0:s==h?e=(o-n)/l:o==h?e=2+(n-s)/l:n==h&&(e=4+(s-o)/l),e=Math.min(60*e,360),0>e&&(e+=360),a=h/255*1e3/10,[e,i,a]}function o(t){var e=t[0],i=t[1],s=t[2],o=a(t)[0],n=1/255*Math.min(e,Math.min(i,s)),s=1-1/255*Math.max(e,Math.max(i,s));return[o,100*n,100*s]}function n(t){var e,i,a,s,o=t[0]/255,n=t[1]/255,r=t[2]/255;return s=Math.min(1-o,1-n,1-r),e=(1-o-s)/(1-s)||0,i=(1-n-s)/(1-s)||0,a=(1-r-s)/(1-s)||0,[100*e,100*i,100*a,100*s]}function h(t){return G[JSON.stringify(t)]}function l(t){var e=t[0]/255,i=t[1]/255,a=t[2]/255;e=e>.04045?Math.pow((e+.055)/1.055,2.4):e/12.92,i=i>.04045?Math.pow((i+.055)/1.055,2.4):i/12.92,a=a>.04045?Math.pow((a+.055)/1.055,2.4):a/12.92;var s=.4124*e+.3576*i+.1805*a,o=.2126*e+.7152*i+.0722*a,n=.0193*e+.1192*i+.9505*a;return[100*s,100*o,100*n]}function c(t){var e,i,a,s=l(t),o=s[0],n=s[1],r=s[2];return o/=95.047,n/=100,r/=108.883,o=o>.008856?Math.pow(o,1/3):7.787*o+16/116,n=n>.008856?Math.pow(n,1/3):7.787*n+16/116,r=r>.008856?Math.pow(r,1/3):7.787*r+16/116,e=116*n-16,i=500*(o-n),a=200*(n-r),[e,i,a]}function d(t){return B(c(t))}function u(t){var e,i,a,s,o,n=t[0]/360,r=t[1]/100,h=t[2]/100;if(0==r)return o=255*h,[o,o,o];i=.5>h?h*(1+r):h+r-h*r,e=2*h-i,s=[0,0,0];for(var l=0;3>l;l++)a=n+1/3*-(l-1),0>a&&a++,a>1&&a--,o=1>6*a?e+6*(i-e)*a:1>2*a?i:2>3*a?e+(i-e)*(2/3-a)*6:e,s[l]=255*o;return s}function m(t){var e,i,a=t[0],s=t[1]/100,o=t[2]/100;return o*=2,s*=1>=o?o:2-o,i=(o+s)/2,e=2*s/(o+s),[a,100*e,100*i]}function f(t){return o(u(t))}function p(t){return n(u(t))}function x(t){return h(u(t))}function v(t){var e=t[0]/60,i=t[1]/100,a=t[2]/100,s=Math.floor(e)%6,o=e-Math.floor(e),n=255*a*(1-i),r=255*a*(1-i*o),h=255*a*(1-i*(1-o)),a=255*a;switch(s){case 0:return[a,h,n];case 1:return[r,a,n];case 2:return[n,a,h];case 3:return[n,r,a];case 4:return[h,n,a];case 5:return[a,n,r]}}function y(t){var e,i,a=t[0],s=t[1]/100,o=t[2]/100;return i=(2-s)*o,e=s*o,e/=1>=i?i:2-i,e=e||0,i/=2,[a,100*e,100*i]}function k(t){return o(v(t))}function C(t){return n(v(t))}function D(t){return h(v(t))}function S(t){var e,i,a,s,o=t[0]/360,n=t[1]/100,h=t[2]/100,l=n+h;switch(l>1&&(n/=l,h/=l),e=Math.floor(6*o),i=1-h,a=6*o-e,0!=(1&e)&&(a=1-a),s=n+a*(i-n),e){default:case 6:case 0:r=i,g=s,b=n;break;case 1:r=s,g=i,b=n;break;case 2:r=n,g=i,b=s;break;case 3:r=n,g=s,b=i;break;case 4:r=s,g=n,b=i;break;case 5:r=i,g=n,b=s}return[255*r,255*g,255*b]}function w(t){return a(S(t))}function _(t){return s(S(t))}function A(t){return n(S(t))}function M(t){return h(S(t))}function I(t){var e,i,a,s=t[0]/100,o=t[1]/100,n=t[2]/100,r=t[3]/100;return e=1-Math.min(1,s*(1-r)+r),i=1-Math.min(1,o*(1-r)+r),a=1-Math.min(1,n*(1-r)+r),[255*e,255*i,255*a]}function P(t){return a(I(t))}function F(t){return s(I(t))}function R(t){return o(I(t))}function T(t){return h(I(t))}function z(t){var e,i,a,s=t[0]/100,o=t[1]/100,n=t[2]/100;return e=3.2406*s+-1.5372*o+n*-.4986,i=s*-.9689+1.8758*o+.0415*n,a=.0557*s+o*-.204+1.057*n,e=e>.0031308?1.055*Math.pow(e,1/2.4)-.055:e=12.92*e,i=i>.0031308?1.055*Math.pow(i,1/2.4)-.055:i=12.92*i,a=a>.0031308?1.055*Math.pow(a,1/2.4)-.055:a=12.92*a,e=Math.min(Math.max(0,e),1),i=Math.min(Math.max(0,i),1),a=Math.min(Math.max(0,a),1),[255*e,255*i,255*a]}function W(t){var e,i,a,s=t[0],o=t[1],n=t[2];return s/=95.047,o/=100,n/=108.883,s=s>.008856?Math.pow(s,1/3):7.787*s+16/116,o=o>.008856?Math.pow(o,1/3):7.787*o+16/116,n=n>.008856?Math.pow(n,1/3):7.787*n+16/116,e=116*o-16,i=500*(s-o),a=200*(o-n),[e,i,a]}function L(t){return B(W(t))}function V(t){var e,i,a,s,o=t[0],n=t[1],r=t[2];return 8>=o?(i=100*o/903.3,s=7.787*(i/100)+16/116):(i=100*Math.pow((o+16)/116,3),s=Math.pow(i/100,1/3)),e=.008856>=e/95.047?e=95.047*(n/500+s-16/116)/7.787:95.047*Math.pow(n/500+s,3),a=.008859>=a/108.883?a=108.883*(s-r/200-16/116)/7.787:108.883*Math.pow(s-r/200,3),[e,i,a]}function B(t){var e,i,a,s=t[0],o=t[1],n=t[2];return e=Math.atan2(n,o),i=360*e/2/Math.PI,0>i&&(i+=360),a=Math.sqrt(o*o+n*n),[s,a,i]}function O(t){return z(V(t))}function N(t){var e,i,a,s=t[0],o=t[1],n=t[2];return a=n/360*2*Math.PI,e=o*Math.cos(a),i=o*Math.sin(a),[s,e,i]}function H(t){return V(N(t))}function E(t){return O(N(t))}function j(t){return Q[t]}function q(t){return a(j(t))}function U(t){return s(j(t))}function Y(t){return o(j(t))}function J(t){return n(j(t))}function Z(t){return c(j(t))}function X(t){return l(j(t))}e.exports={rgb2hsl:a,rgb2hsv:s,rgb2hwb:o,rgb2cmyk:n,rgb2keyword:h,rgb2xyz:l,rgb2lab:c,rgb2lch:d,hsl2rgb:u,hsl2hsv:m,hsl2hwb:f,hsl2cmyk:p,hsl2keyword:x,hsv2rgb:v,hsv2hsl:y,hsv2hwb:k,hsv2cmyk:C,hsv2keyword:D,hwb2rgb:S,hwb2hsl:w,hwb2hsv:_,hwb2cmyk:A,hwb2keyword:M,cmyk2rgb:I,cmyk2hsl:P,cmyk2hsv:F,cmyk2hwb:R,cmyk2keyword:T,keyword2rgb:j,keyword2hsl:q,keyword2hsv:U,keyword2hwb:Y,keyword2cmyk:J,keyword2lab:Z,keyword2xyz:X,xyz2rgb:z,xyz2lab:W,xyz2lch:L,lab2xyz:V,lab2rgb:O,lab2lch:B,lch2lab:N,lch2xyz:H,lch2rgb:E};var Q={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]},G={};for(var $ in Q)G[JSON.stringify(Q[$])]=$},{}],3:[function(t,e,i){var a=t("./conversions"),s=function(){return new l};for(var o in a){s[o+"Raw"]=function(t){return function(e){return"number"==typeof e&&(e=Array.prototype.slice.call(arguments)),a[t](e)}}(o);var n=/(\w+)2(\w+)/.exec(o),r=n[1],h=n[2];s[r]=s[r]||{},s[r][h]=s[o]=function(t){return function(e){"number"==typeof e&&(e=Array.prototype.slice.call(arguments));var i=a[t](e);if("string"==typeof i||void 0===i)return i;for(var s=0;s<i.length;s++)i[s]=Math.round(i[s]);return i}}(o)}var l=function(){this.convs={}};l.prototype.routeSpace=function(t,e){var i=e[0];return void 0===i?this.getValues(t):("number"==typeof i&&(i=Array.prototype.slice.call(e)),this.setValues(t,i))},l.prototype.setValues=function(t,e){return this.space=t,this.convs={},this.convs[t]=e,this},l.prototype.getValues=function(t){var e=this.convs[t];if(!e){var i=this.space,a=this.convs[i];e=s[i][t](a),this.convs[t]=e}return e},["rgb","hsl","hsv","cmyk","keyword"].forEach(function(t){l.prototype[t]=function(e){return this.routeSpace(t,arguments)}}),e.exports=s},{"./conversions":2}],4:[function(t,e,i){function a(t){if(t){var e=/^#([a-fA-F0-9]{3})$/,i=/^#([a-fA-F0-9]{6})$/,a=/^rgba?\(\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/,s=/^rgba?\(\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/,o=/(\w+)/,n=[0,0,0],r=1,h=t.match(e);if(h){h=h[1];for(var l=0;l<n.length;l++)n[l]=parseInt(h[l]+h[l],16)}else if(h=t.match(i)){h=h[1];for(var l=0;l<n.length;l++)n[l]=parseInt(h.slice(2*l,2*l+2),16)}else if(h=t.match(a)){for(var l=0;l<n.length;l++)n[l]=parseInt(h[l+1]);r=parseFloat(h[4])}else if(h=t.match(s)){for(var l=0;l<n.length;l++)n[l]=Math.round(2.55*parseFloat(h[l+1]));r=parseFloat(h[4])}else if(h=t.match(o)){if("transparent"==h[1])return[0,0,0,0];if(n=y[h[1]],!n)return}for(var l=0;l<n.length;l++)n[l]=x(n[l],0,255);return r=r||0==r?x(r,0,1):1,n[3]=r,n}}function s(t){if(t){var e=/^hsla?\(\s*([+-]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)/,i=t.match(e);if(i){var a=parseFloat(i[4]),s=x(parseInt(i[1]),0,360),o=x(parseFloat(i[2]),0,100),n=x(parseFloat(i[3]),0,100),r=x(isNaN(a)?1:a,0,1);return[s,o,n,r]}}}function o(t){if(t){var e=/^hwb\(\s*([+-]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)/,i=t.match(e);if(i){var a=parseFloat(i[4]),s=x(parseInt(i[1]),0,360),o=x(parseFloat(i[2]),0,100),n=x(parseFloat(i[3]),0,100),r=x(isNaN(a)?1:a,0,1);return[s,o,n,r]}}}function n(t){var e=a(t);return e&&e.slice(0,3)}function r(t){var e=s(t);return e&&e.slice(0,3)}function h(t){var e=a(t);return e?e[3]:(e=s(t))?e[3]:(e=o(t))?e[3]:void 0}function l(t){return"#"+v(t[0])+v(t[1])+v(t[2])}function c(t,e){return 1>e||t[3]&&t[3]<1?d(t,e):"rgb("+t[0]+", "+t[1]+", "+t[2]+")"}function d(t,e){return void 0===e&&(e=void 0!==t[3]?t[3]:1),"rgba("+t[0]+", "+t[1]+", "+t[2]+", "+e+")"}function u(t,e){if(1>e||t[3]&&t[3]<1)return g(t,e);var i=Math.round(t[0]/255*100),a=Math.round(t[1]/255*100),s=Math.round(t[2]/255*100);return"rgb("+i+"%, "+a+"%, "+s+"%)"}function g(t,e){var i=Math.round(t[0]/255*100),a=Math.round(t[1]/255*100),s=Math.round(t[2]/255*100);return"rgba("+i+"%, "+a+"%, "+s+"%, "+(e||t[3]||1)+")"}function m(t,e){return 1>e||t[3]&&t[3]<1?f(t,e):"hsl("+t[0]+", "+t[1]+"%, "+t[2]+"%)"}function f(t,e){return void 0===e&&(e=void 0!==t[3]?t[3]:1),"hsla("+t[0]+", "+t[1]+"%, "+t[2]+"%, "+e+")"}function p(t,e){return void 0===e&&(e=void 0!==t[3]?t[3]:1),"hwb("+t[0]+", "+t[1]+"%, "+t[2]+"%"+(void 0!==e&&1!==e?", "+e:"")+")"}function b(t){return k[t.slice(0,3)]}function x(t,e,i){return Math.min(Math.max(e,t),i)}function v(t){var e=t.toString(16).toUpperCase();return e.length<2?"0"+e:e}var y=t("color-name");e.exports={getRgba:a,getHsla:s,getRgb:n,getHsl:r,getHwb:o,getAlpha:h,hexString:l,rgbString:c,rgbaString:d,percentString:u,percentaString:g,hslString:m,hslaString:f,hwbString:p,keyword:b};var k={};for(var C in y)k[y[C]]=C},{"color-name":5}],5:[function(t,e,i){e.exports={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]}},{}]},{},[1]),function(){"use strict";var t=this,e=t.Chart,i=function(t,e){this.config=e,t.length&&t[0].getContext&&(t=t[0]),t.getContext&&(t=t.getContext("2d")),this.ctx=t,this.canvas=t.canvas,this.width=t.canvas.width||parseInt(i.helpers.getStyle(t.canvas,"width"))||i.helpers.getMaximumWidth(t.canvas),this.height=t.canvas.height||parseInt(i.helpers.getStyle(t.canvas,"height"))||i.helpers.getMaximumHeight(t.canvas),this.aspectRatio=this.width/this.height,(isNaN(this.aspectRatio)||isFinite(this.aspectRatio)===!1)&&(this.aspectRatio=void 0!==e.aspectRatio?e.aspectRatio:2),this.originalCanvasStyleWidth=t.canvas.style.width,this.originalCanvasStyleHeight=t.canvas.style.height,i.helpers.retinaScale(this),e&&(this.controller=new i.Controller(this));var a=this;return i.helpers.addResizeListener(t.canvas.parentNode,function(){a.controller&&a.controller.config.options.responsive&&a.controller.resize()}),this.controller?this.controller:this};i.defaults={global:{responsive:!0,responsiveAnimationDuration:0,maintainAspectRatio:!0,events:["mousemove","mouseout","click","touchstart","touchmove"],hover:{onHover:null,mode:"single",animationDuration:400},onClick:null,defaultColor:"rgba(0,0,0,0.1)",elements:{},legendCallback:function(t){var e=[];e.push('<ul class="'+t.id+'-legend">');for(var i=0;i<t.data.datasets.length;i++)e.push('<li><span style="background-color:'+t.data.datasets[i].backgroundColor+'">'),t.data.datasets[i].label&&e.push(t.data.datasets[i].label),e.push("</span></li>");return e.push("</ul>"),e.join("")}}},t.Chart=i,i.noConflict=function(){return t.Chart=e,i}}.call(this),function(){"use strict";var t=this,e=t.Chart,i=e.helpers={},a=i.each=function(t,e,i,a){var s=Array.prototype.slice.call(arguments,3);if(t)if(t.length===+t.length){var o;if(a)for(o=t.length-1;o>=0;o--)e.apply(i,[t[o],o].concat(s));else for(o=0;o<t.length;o++)e.apply(i,[t[o],o].concat(s))}else for(var n in t)e.apply(i,[t[n],n].concat(s))},s=i.clone=function(t){var e={};return a(t,function(a,o){t.hasOwnProperty(o)&&(i.isArray(a)?e[o]=a.slice(0):"object"==typeof a&&null!==a?e[o]=s(a):e[o]=a)}),e},o=i.extend=function(t){return a(Array.prototype.slice.call(arguments,1),function(e){a(e,function(i,a){e.hasOwnProperty(a)&&(t[a]=i)})}),t},n=(i.configMerge=function(t){var a=s(t);return i.each(Array.prototype.slice.call(arguments,1),function(t){i.each(t,function(s,o){if(t.hasOwnProperty(o))if("scales"===o)a[o]=i.scaleMerge(a.hasOwnProperty(o)?a[o]:{},s);else if("scale"===o)a[o]=i.configMerge(a.hasOwnProperty(o)?a[o]:{},e.scaleService.getScaleDefaults(s.type),s);else if(a.hasOwnProperty(o)&&i.isArray(a[o])&&i.isArray(s)){var n=a[o];i.each(s,function(t,e){e<n.length?"object"==typeof n[e]&&null!==n[e]&&"object"==typeof t&&null!==t?n[e]=i.configMerge(n[e],t):n[e]=t:n.push(t)})}else a.hasOwnProperty(o)&&"object"==typeof a[o]&&null!==a[o]&&"object"==typeof s?a[o]=i.configMerge(a[o],s):a[o]=s})}),a},i.extendDeep=function(t){function e(t){return i.each(arguments,function(a){a!==t&&i.each(a,function(i,a){t[a]&&t[a].constructor&&t[a].constructor===Object?e(t[a],i):t[a]=i})}),t}return e.apply(this,arguments)},i.scaleMerge=function(t,a){var o=s(t);return i.each(a,function(t,s){a.hasOwnProperty(s)&&("xAxes"===s||"yAxes"===s?o.hasOwnProperty(s)?i.each(t,function(t,a){a>=o[s].length||!o[s][a].type?o[s].push(i.configMerge(t.type?e.scaleService.getScaleDefaults(t.type):{},t)):t.type!==o[s][a].type?o[s][a]=i.configMerge(o[s][a],t.type?e.scaleService.getScaleDefaults(t.type):{},t):o[s][a]=i.configMerge(o[s][a],t)}):(o[s]=[],i.each(t,function(t){o[s].push(i.configMerge(t.type?e.scaleService.getScaleDefaults(t.type):{},t))})):o.hasOwnProperty(s)&&"object"==typeof o[s]&&null!==o[s]&&"object"==typeof t?o[s]=i.configMerge(o[s],t):o[s]=t)}),o},i.getValueAtIndexOrDefault=function(t,e,a){return void 0===t||null===t?a:i.isArray(t)?e<t.length?t[e]:a:t},i.getValueOrDefault=function(t,e){return void 0===t?e:t},i.indexOf=function(t,e){if(Array.prototype.indexOf)return t.indexOf(e);for(var i=0;i<t.length;i++)if(t[i]===e)return i;return-1},i.where=function(t,e){var a=[];return i.each(t,function(t){e(t)&&a.push(t)}),a},i.findNextWhere=function(t,e,i){(void 0===i||null===i)&&(i=-1);for(var a=i+1;a<t.length;a++){var s=t[a];if(e(s))return s}},i.findPreviousWhere=function(t,e,i){(void 0===i||null===i)&&(i=t.length);for(var a=i-1;a>=0;a--){var s=t[a];if(e(s))return s}},i.inherits=function(t){var e=this,i=t&&t.hasOwnProperty("constructor")?t.constructor:function(){return e.apply(this,arguments)},a=function(){this.constructor=i};return a.prototype=e.prototype,i.prototype=new a,i.extend=n,t&&o(i.prototype,t),i.__super__=e.prototype,i}),r=i.noop=function(){},h=(i.uid=function(){var t=0;return function(){return"chart-"+t++}}(),i.warn=function(t){console&&"function"==typeof console.warn&&console.warn(t)},i.isNumber=function(t){return!isNaN(parseFloat(t))&&isFinite(t)}),l=(i.max=function(t){return Math.max.apply(Math,t)},i.min=function(t){return Math.min.apply(Math,t)},i.sign=function(t){return Math.sign?Math.sign(t):(t=+t,0===t||isNaN(t)?t:t>0?1:-1)},i.log10=function(t){return Math.log10?Math.log10(t):Math.log(t)/Math.LN10},i.getDecimalPlaces=function(t){if(t%1!==0&&h(t)){var e=t.toString();if(e.indexOf("e-")<0)return e.split(".")[1].length;if(e.indexOf(".")<0)return parseInt(e.split("e-")[1]);var i=e.split(".")[1].split("e-");return i[0].length+parseInt(i[1])}return 0},i.toRadians=function(t){return t*(Math.PI/180)},i.toDegrees=function(t){return t*(180/Math.PI)},i.getAngleFromPoint=function(t,e){var i=e.x-t.x,a=e.y-t.y,s=Math.sqrt(i*i+a*a),o=Math.atan2(a,i);return o<-.5*Math.PI&&(o+=2*Math.PI),{angle:o,distance:s}},i.aliasPixel=function(t){return t%2===0?0:.5},i.splineCurve=function(t,e,i,a){var s=t.skip?e:t,o=e,n=i.skip?e:i,r=Math.sqrt(Math.pow(o.x-s.x,2)+Math.pow(o.y-s.y,2)),h=Math.sqrt(Math.pow(n.x-o.x,2)+Math.pow(n.y-o.y,2)),l=r/(r+h),c=h/(r+h);l=isNaN(l)?0:l,c=isNaN(c)?0:c;var d=a*l,u=a*c;return{previous:{x:o.x-d*(n.x-s.x),y:o.y-d*(n.y-s.y)},next:{x:o.x+u*(n.x-s.x),y:o.y+u*(n.y-s.y)}}},i.nextItem=function(t,e,i){return i?e>=t.length-1?t[0]:t[e+1]:e>=t.length-1?t[t.length-1]:t[e+1]},i.previousItem=function(t,e,i){return i?0>=e?t[t.length-1]:t[e-1]:0>=e?t[0]:t[e-1]},i.niceNum=function(t,e){var a,s=Math.floor(i.log10(t)),o=t/Math.pow(10,s);return a=e?1.5>o?1:3>o?2:7>o?5:10:1>=o?1:2>=o?2:5>=o?5:10,a*Math.pow(10,s)},i.easingEffects={linear:function(t){return t},easeInQuad:function(t){return t*t},easeOutQuad:function(t){return-1*t*(t-2)},easeInOutQuad:function(t){return(t/=.5)<1?.5*t*t:-0.5*(--t*(t-2)-1)},easeInCubic:function(t){return t*t*t},easeOutCubic:function(t){return 1*((t=t/1-1)*t*t+1)},easeInOutCubic:function(t){return(t/=.5)<1?.5*t*t*t:.5*((t-=2)*t*t+2)},easeInQuart:function(t){return t*t*t*t},easeOutQuart:function(t){return-1*((t=t/1-1)*t*t*t-1)},easeInOutQuart:function(t){return(t/=.5)<1?.5*t*t*t*t:-0.5*((t-=2)*t*t*t-2)},easeInQuint:function(t){return 1*(t/=1)*t*t*t*t},easeOutQuint:function(t){return 1*((t=t/1-1)*t*t*t*t+1)},easeInOutQuint:function(t){return(t/=.5)<1?.5*t*t*t*t*t:.5*((t-=2)*t*t*t*t+2)},easeInSine:function(t){return-1*Math.cos(t/1*(Math.PI/2))+1},easeOutSine:function(t){return 1*Math.sin(t/1*(Math.PI/2))},easeInOutSine:function(t){return-0.5*(Math.cos(Math.PI*t/1)-1)},easeInExpo:function(t){return 0===t?1:1*Math.pow(2,10*(t/1-1))},easeOutExpo:function(t){return 1===t?1:1*(-Math.pow(2,-10*t/1)+1)},easeInOutExpo:function(t){return 0===t?0:1===t?1:(t/=.5)<1?.5*Math.pow(2,10*(t-1)):.5*(-Math.pow(2,-10*--t)+2)},easeInCirc:function(t){return t>=1?t:-1*(Math.sqrt(1-(t/=1)*t)-1)},easeOutCirc:function(t){return 1*Math.sqrt(1-(t=t/1-1)*t)},easeInOutCirc:function(t){return(t/=.5)<1?-0.5*(Math.sqrt(1-t*t)-1):.5*(Math.sqrt(1-(t-=2)*t)+1)},easeInElastic:function(t){var e=1.70158,i=0,a=1;return 0===t?0:1==(t/=1)?1:(i||(i=.3),a<Math.abs(1)?(a=1,e=i/4):e=i/(2*Math.PI)*Math.asin(1/a),-(a*Math.pow(2,10*(t-=1))*Math.sin((1*t-e)*(2*Math.PI)/i)))},easeOutElastic:function(t){var e=1.70158,i=0,a=1;return 0===t?0:1==(t/=1)?1:(i||(i=.3),a<Math.abs(1)?(a=1,e=i/4):e=i/(2*Math.PI)*Math.asin(1/a),a*Math.pow(2,-10*t)*Math.sin((1*t-e)*(2*Math.PI)/i)+1)},easeInOutElastic:function(t){var e=1.70158,i=0,a=1;return 0===t?0:2==(t/=.5)?1:(i||(i=1*(.3*1.5)),a<Math.abs(1)?(a=1,e=i/4):e=i/(2*Math.PI)*Math.asin(1/a),1>t?-.5*(a*Math.pow(2,10*(t-=1))*Math.sin((1*t-e)*(2*Math.PI)/i)):a*Math.pow(2,-10*(t-=1))*Math.sin((1*t-e)*(2*Math.PI)/i)*.5+1)},easeInBack:function(t){var e=1.70158;return 1*(t/=1)*t*((e+1)*t-e)},easeOutBack:function(t){var e=1.70158;return 1*((t=t/1-1)*t*((e+1)*t+e)+1)},easeInOutBack:function(t){var e=1.70158;return(t/=.5)<1?.5*(t*t*(((e*=1.525)+1)*t-e)):.5*((t-=2)*t*(((e*=1.525)+1)*t+e)+2)},easeInBounce:function(t){return 1-l.easeOutBounce(1-t);
},easeOutBounce:function(t){return(t/=1)<1/2.75?1*(7.5625*t*t):2/2.75>t?1*(7.5625*(t-=1.5/2.75)*t+.75):2.5/2.75>t?1*(7.5625*(t-=2.25/2.75)*t+.9375):1*(7.5625*(t-=2.625/2.75)*t+.984375)},easeInOutBounce:function(t){return.5>t?.5*l.easeInBounce(2*t):.5*l.easeOutBounce(2*t-1)+.5}}),c=(i.requestAnimFrame=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(t){return window.setTimeout(t,1e3/60)}}(),i.cancelAnimFrame=function(){return window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.oCancelAnimationFrame||window.msCancelAnimationFrame||function(t){return window.clearTimeout(t,1e3/60)}}(),i.getRelativePosition=function(t,e){var i,a,s=t.originalEvent||t,o=t.currentTarget||t.srcElement,n=o.getBoundingClientRect();return s.touches&&s.touches.length>0?(i=s.touches[0].clientX,a=s.touches[0].clientY):(i=s.clientX,a=s.clientY),i=Math.round((i-n.left)/(n.right-n.left)*o.width/e.currentDevicePixelRatio),a=Math.round((a-n.top)/(n.bottom-n.top)*o.height/e.currentDevicePixelRatio),{x:i,y:a}},i.addEvent=function(t,e,i){t.addEventListener?t.addEventListener(e,i):t.attachEvent?t.attachEvent("on"+e,i):t["on"+e]=i}),d=i.removeEvent=function(t,e,i){t.removeEventListener?t.removeEventListener(e,i,!1):t.detachEvent?t.detachEvent("on"+e,i):t["on"+e]=r},u=(i.bindEvents=function(t,e,i){t.events||(t.events={}),a(e,function(e){t.events[e]=function(){i.apply(t,arguments)},c(t.chart.canvas,e,t.events[e])})},i.unbindEvents=function(t,e){a(e,function(e,i){d(t.chart.canvas,i,e)})},i.getConstraintWidth=function(t){var e,i=document.defaultView.getComputedStyle(t)["max-width"],a=document.defaultView.getComputedStyle(t.parentNode)["max-width"],s=null!==i&&"none"!==i,o=null!==a&&"none"!==a;return(s||o)&&(e=Math.min(s?parseInt(i,10):Number.POSITIVE_INFINITY,o?parseInt(a,10):Number.POSITIVE_INFINITY)),e}),g=i.getConstraintHeight=function(t){var e,i=document.defaultView.getComputedStyle(t)["max-height"],a=document.defaultView.getComputedStyle(t.parentNode)["max-height"],s=null!==i&&"none"!==i,o=null!==a&&"none"!==a;return(i||a)&&(e=Math.min(s?parseInt(i,10):Number.POSITIVE_INFINITY,o?parseInt(a,10):Number.POSITIVE_INFINITY)),e},m=(i.getMaximumWidth=function(t){var e=t.parentNode,i=parseInt(m(e,"padding-left"))+parseInt(m(e,"padding-right")),a=e.clientWidth-i,s=u(t);return void 0!==s&&(a=Math.min(a,s)),a},i.getMaximumHeight=function(t){var e=t.parentNode,i=parseInt(m(e,"padding-top"))+parseInt(m(e,"padding-bottom")),a=e.clientHeight-i,s=g(t);return void 0!==s&&(a=Math.min(a,s)),a},i.getStyle=function(t,e){return t.currentStyle?t.currentStyle[e]:document.defaultView.getComputedStyle(t,null).getPropertyValue(e)});i.getMaximumSize=i.getMaximumWidth,i.retinaScale=function(t){var e=t.ctx,i=t.canvas.width,a=t.canvas.height,s=t.currentDevicePixelRatio=window.devicePixelRatio||1;1!==s&&(e.canvas.height=a*s,e.canvas.width=i*s,e.scale(s,s),e.canvas.style.width=i+"px",e.canvas.style.height=a+"px",t.originalDevicePixelRatio=t.originalDevicePixelRatio||s)},i.clear=function(t){t.ctx.clearRect(0,0,t.width,t.height)},i.fontString=function(t,e,i){return e+" "+t+"px "+i},i.longestText=function(t,e,i){t.font=e;var s=0;return a(i,function(e){var i=t.measureText(e).width;s=i>s?i:s}),s},i.drawRoundedRectangle=function(t,e,i,a,s,o){t.beginPath(),t.moveTo(e+o,i),t.lineTo(e+a-o,i),t.quadraticCurveTo(e+a,i,e+a,i+o),t.lineTo(e+a,i+s-o),t.quadraticCurveTo(e+a,i+s,e+a-o,i+s),t.lineTo(e+o,i+s),t.quadraticCurveTo(e,i+s,e,i+s-o),t.lineTo(e,i+o),t.quadraticCurveTo(e,i,e+o,i),t.closePath()},i.color=function(e){return t.Color?t.Color(e):(console.log("Color.js not found!"),e)},i.addResizeListener=function(t,e){var i=document.createElement("iframe"),a="chartjs-hidden-iframe";i.classlist?i.classlist.add(a):i.setAttribute("class",a),i.style.width="100%",i.style.display="block",i.style.border=0,i.style.height=0,i.style.margin=0,i.style.position="absolute",i.style.left=0,i.style.right=0,i.style.top=0,i.style.bottom=0,t.insertBefore(i,t.firstChild);(i.contentWindow||i).onresize=function(){e&&e()}},i.removeResizeListener=function(t){var e=t.querySelector(".chartjs-hidden-iframe");e&&e.parentNode.removeChild(e)},i.isArray=function(t){return Array.isArray?Array.isArray(t):"[object Array]"===Object.prototype.toString.call(arg)},i.isDatasetVisible=function(t){return!t.hidden};i.callCallback=function(t,e,i){t&&"function"==typeof t.call&&t.apply(i,e)}}.call(this),function(){"use strict";var t=this,e=t.Chart,i=e.helpers;e.elements={},e.Element=function(t){i.extend(this,t),this.initialize.apply(this,arguments)},i.extend(e.Element.prototype,{initialize:function(){},pivot:function(){return this._view||(this._view=i.clone(this._model)),this._start=i.clone(this._view),this},transition:function(t){return this._view||(this._view=i.clone(this._model)),this._start||this.pivot(),i.each(this._model,function(e,a){if("_"!==a[0]&&this._model.hasOwnProperty(a))if(this._view[a])if(this._model[a]===this._view[a]);else if("string"==typeof e)try{var s=i.color(this._start[a]).mix(i.color(this._model[a]),t);this._view[a]=s.rgbString()}catch(o){this._view[a]=e}else if("number"==typeof e){var n=void 0!==this._start[a]&&isNaN(this._start[a])===!1?this._start[a]:0;this._view[a]=(this._model[a]-n)*t+n}else this._view[a]=e;else"number"==typeof e&&isNaN(this._view[a])===!1?this._view[a]=e*t:this._view[a]=e||null;else;},this),1===t&&delete this._start,this},tooltipPosition:function(){return{x:this._model.x,y:this._model.y}},hasValue:function(){return i.isNumber(this._model.x)&&i.isNumber(this._model.y)}}),e.Element.extend=i.inherits}.call(this),function(){"use strict";var t=this,e=t.Chart,i=e.helpers;e.defaults.global.animation={duration:1e3,easing:"easeOutQuart",onProgress:i.noop,onComplete:i.noop},e.Animation=e.Element.extend({currentStep:null,numSteps:60,easing:"",render:null,onAnimationProgress:null,onAnimationComplete:null}),e.animationService={frameDuration:17,animations:[],dropFrames:0,addAnimation:function(t,e,a,s){s||(t.animating=!0);for(var o=0;o<this.animations.length;++o)if(this.animations[o].chartInstance===t)return void(this.animations[o].animationObject=e);this.animations.push({chartInstance:t,animationObject:e}),1==this.animations.length&&i.requestAnimFrame.call(window,this.digestWrapper)},cancelAnimation:function(t){var e=i.findNextWhere(this.animations,function(e){return e.chartInstance===t});e&&(this.animations.splice(e,1),t.animating=!1)},digestWrapper:function(){e.animationService.startDigest.call(e.animationService)},startDigest:function(){var t=Date.now(),e=0;this.dropFrames>1&&(e=Math.floor(this.dropFrames),this.dropFrames=this.dropFrames%1);for(var a=0;a<this.animations.length;a++)null===this.animations[a].animationObject.currentStep&&(this.animations[a].animationObject.currentStep=0),this.animations[a].animationObject.currentStep+=1+e,this.animations[a].animationObject.currentStep>this.animations[a].animationObject.numSteps&&(this.animations[a].animationObject.currentStep=this.animations[a].animationObject.numSteps),this.animations[a].animationObject.render(this.animations[a].chartInstance,this.animations[a].animationObject),this.animations[a].animationObject.onAnimationProgress&&this.animations[a].animationObject.onAnimationProgress.call&&this.animations[a].animationObject.onAnimationProgress.call(this.animations[a].chartInstance,this.animations[a]),this.animations[a].animationObject.currentStep==this.animations[a].animationObject.numSteps&&(this.animations[a].animationObject.onAnimationComplete&&this.animations[a].animationObject.onAnimationComplete.call&&this.animations[a].animationObject.onAnimationComplete.call(this.animations[a].chartInstance,this.animations[a]),this.animations[a].chartInstance.animating=!1,this.animations.splice(a,1),a--);var s=Date.now(),o=(s-t)/this.frameDuration;this.dropFrames+=o,this.animations.length>0&&i.requestAnimFrame.call(window,this.digestWrapper)}}}.call(this),function(){"use strict";var t=this,e=t.Chart,i=e.helpers;e.types={},e.instances={},e.controllers={},e.Controller=function(t){return this.chart=t,this.config=t.config,this.options=this.config.options=i.configMerge(e.defaults.global,e.defaults[this.config.type],this.config.options||{}),this.id=i.uid(),Object.defineProperty(this,"data",{get:function(){return this.config.data}}),e.instances[this.id]=this,this.options.responsive&&this.resize(!0),this.initialize.call(this),this},i.extend(e.Controller.prototype,{initialize:function(){return this.bindEvents(),this.ensureScalesHaveIDs(),this.buildOrUpdateControllers(),this.buildScales(),this.buildSurroundingItems(),this.updateLayout(),this.resetElements(),this.initToolTip(),this.update(),this},clear:function(){return i.clear(this.chart),this},stop:function(){return e.animationService.cancelAnimation(this),this},resize:function(t){this.stop();var e=this.chart.canvas,a=i.getMaximumWidth(this.chart.canvas),s=this.options.maintainAspectRatio&&isNaN(this.chart.aspectRatio)===!1&&isFinite(this.chart.aspectRatio)&&0!==this.chart.aspectRatio?a/this.chart.aspectRatio:i.getMaximumHeight(this.chart.canvas);return e.width=this.chart.width=a,e.height=this.chart.height=s,i.retinaScale(this.chart),t||this.update(this.options.responsiveAnimationDuration),this},ensureScalesHaveIDs:function(){var t="x-axis-",e="y-axis-";this.options.scales&&(this.options.scales.xAxes&&this.options.scales.xAxes.length&&i.each(this.options.scales.xAxes,function(e,i){e.id=e.id||t+i},this),this.options.scales.yAxes&&this.options.scales.yAxes.length&&i.each(this.options.scales.yAxes,function(t,i){t.id=t.id||e+i},this))},buildScales:function(){if(this.scales={},this.options.scales&&(this.options.scales.xAxes&&this.options.scales.xAxes.length&&i.each(this.options.scales.xAxes,function(t,i){var a=e.scaleService.getScaleConstructor(t.type),s=new a({ctx:this.chart.ctx,options:t,chart:this,id:t.id});this.scales[s.id]=s},this),this.options.scales.yAxes&&this.options.scales.yAxes.length&&i.each(this.options.scales.yAxes,function(t,i){var a=e.scaleService.getScaleConstructor(t.type),s=new a({ctx:this.chart.ctx,options:t,chart:this,id:t.id});this.scales[s.id]=s},this)),this.options.scale){var t=e.scaleService.getScaleConstructor(this.options.scale.type),a=new t({ctx:this.chart.ctx,options:this.options.scale,chart:this});this.scale=a,this.scales.radialScale=a}e.scaleService.addScalesToLayout(this)},buildSurroundingItems:function(){this.options.title&&(this.titleBlock=new e.Title({ctx:this.chart.ctx,options:this.options.title,chart:this}),e.layoutService.addBox(this,this.titleBlock)),this.options.legend&&(this.legend=new e.Legend({ctx:this.chart.ctx,options:this.options.legend,chart:this}),e.layoutService.addBox(this,this.legend))},updateLayout:function(){e.layoutService.update(this,this.chart.width,this.chart.height)},buildOrUpdateControllers:function(t){var a=[];if(i.each(this.data.datasets,function(i,s){i.type||(i.type=this.config.type);var o=i.type;a.push(o),i.controller?i.controller.updateIndex(s):(i.controller=new e.controllers[o](this,s),t&&i.controller.reset())},this),a.length>1)for(var s=1;s<a.length;s++)if(a[s]!=a[s-1]){this.isCombo=!0;break}},resetElements:function(){i.each(this.data.datasets,function(t,e){t.controller.reset()},this)},update:function(t,a){this.tooltip._data=this.data,this.buildOrUpdateControllers(!0),e.layoutService.update(this,this.chart.width,this.chart.height),i.each(this.data.datasets,function(t,e){t.controller.buildOrUpdateElements()},this),i.each(this.data.datasets,function(t,e){t.controller.update()},this),this.render(t,a)},render:function(t,a){if(this.options.animation&&("undefined"!=typeof t&&0!==t||"undefined"==typeof t&&0!==this.options.animation.duration)){var s=new e.Animation;s.numSteps=(t||this.options.animation.duration)/16.66,s.easing=this.options.animation.easing,s.render=function(t,e){var a=i.easingEffects[e.easing],s=e.currentStep/e.numSteps,o=a(s);t.draw(o,s,e.currentStep)},s.onAnimationProgress=this.options.animation.onProgress,s.onAnimationComplete=this.options.animation.onComplete,e.animationService.addAnimation(this,s,t,a)}else this.draw(),this.options.animation&&this.options.animation.onComplete&&this.options.animation.onComplete.call&&this.options.animation.onComplete.call(this);return this},draw:function(t){var e=t||1;this.clear(),i.each(this.boxes,function(t){t.draw(this.chartArea)},this),this.scale&&this.scale.draw(),i.each(this.data.datasets,function(e,a){i.isDatasetVisible(e)&&e.controller.draw(t)},this),this.tooltip.transition(e).draw()},getElementAtEvent:function(t){var e=i.getRelativePosition(t,this.chart),a=[];return i.each(this.data.datasets,function(t,s){i.isDatasetVisible(t)&&i.each(t.metaData,function(t,i){return t.inRange(e.x,e.y)?(a.push(t),a):void 0},this)},this),a},getElementsAtEvent:function(t){var e=i.getRelativePosition(t,this.chart),a=[],s=function(){for(var t=0;t<this.data.datasets.length;t++)if(i.isDatasetVisible(this.data.datasets[t]))for(var a=0;a<this.data.datasets[t].metaData.length;a++)if(this.data.datasets[t].metaData[a].inRange(e.x,e.y))return this.data.datasets[t].metaData[a]}.call(this);return s?(i.each(this.data.datasets,function(t,e){i.isDatasetVisible(t)&&a.push(t.metaData[s._index])},this),a):a},getDatasetAtEvent:function(t){var e=this.getElementAtEvent(t);return e.length>0&&(e=this.data.datasets[e[0]._datasetIndex].metaData),e},generateLegend:function(){return this.options.legendCallback(this)},destroy:function(){this.clear(),i.unbindEvents(this,this.events),i.removeResizeListener(this.chart.canvas.parentNode);var t=this.chart.canvas;t.width=this.chart.width,t.height=this.chart.height,void 0!==this.chart.originalDevicePixelRatio&&this.chart.ctx.scale(1/this.chart.originalDevicePixelRatio,1/this.chart.originalDevicePixelRatio),t.style.width=this.chart.originalCanvasStyleWidth,t.style.height=this.chart.originalCanvasStyleHeight,delete e.instances[this.id]},toBase64Image:function(){return this.chart.canvas.toDataURL.apply(this.chart.canvas,arguments)},initToolTip:function(){this.tooltip=new e.Tooltip({_chart:this.chart,_chartInstance:this,_data:this.data,_options:this.options},this)},bindEvents:function(){i.bindEvents(this,this.options.events,function(t){this.eventHandler(t)})},eventHandler:function(t){if(this.lastActive=this.lastActive||[],this.lastTooltipActive=this.lastTooltipActive||[],"mouseout"==t.type)this.active=[],this.tooltipActive=[];else{var e=this,a=function(i){switch(i){case"single":return e.getElementAtEvent(t);case"label":return e.getElementsAtEvent(t);case"dataset":return e.getDatasetAtEvent(t);default:return t}};this.active=a(this.options.hover.mode),this.tooltipActive=a(this.options.tooltips.mode)}this.options.hover.onHover&&this.options.hover.onHover.call(this,this.active),("mouseup"==t.type||"click"==t.type)&&(this.options.onClick&&this.options.onClick.call(this,t,this.active),this.legend&&this.legend.handleEvent&&this.legend.handleEvent(t));if(this.lastActive.length)switch(this.options.hover.mode){case"single":this.data.datasets[this.lastActive[0]._datasetIndex].controller.removeHoverStyle(this.lastActive[0],this.lastActive[0]._datasetIndex,this.lastActive[0]._index);break;case"label":case"dataset":for(var s=0;s<this.lastActive.length;s++)this.lastActive[s]&&this.data.datasets[this.lastActive[s]._datasetIndex].controller.removeHoverStyle(this.lastActive[s],this.lastActive[s]._datasetIndex,this.lastActive[s]._index)}if(this.active.length&&this.options.hover.mode)switch(this.options.hover.mode){case"single":this.data.datasets[this.active[0]._datasetIndex].controller.setHoverStyle(this.active[0]);break;case"label":case"dataset":for(var o=0;o<this.active.length;o++)this.active[o]&&this.data.datasets[this.active[o]._datasetIndex].controller.setHoverStyle(this.active[o])}if((this.options.tooltips.enabled||this.options.tooltips.custom)&&(this.tooltip.initialize(),this.tooltip._active=this.tooltipActive,this.tooltip.update()),this.tooltip.pivot(),!this.animating){var n;i.each(this.active,function(t,e){t!==this.lastActive[e]&&(n=!0)},this),i.each(this.tooltipActive,function(t,e){t!==this.lastTooltipActive[e]&&(n=!0)},this),(this.lastActive.length!==this.active.length||this.lastTooltipActive.length!==this.tooltipActive.length||n)&&(this.stop(),(this.options.tooltips.enabled||this.options.tooltips.custom)&&this.tooltip.update(!0),this.render(this.options.hover.animationDuration,!0))}return this.lastActive=this.active,this.lastTooltipActive=this.tooltipActive,this}})}.call(this),function(){"use strict";var t=this,e=t.Chart,i=e.helpers;e.DatasetController=function(t,e){this.initialize.call(this,t,e)},i.extend(e.DatasetController.prototype,{initialize:function(t,e){this.chart=t,this.index=e,this.linkScales(),this.addElements()},updateIndex:function(t){this.index=t},linkScales:function(){this.getDataset().xAxisID||(this.getDataset().xAxisID=this.chart.options.scales.xAxes[0].id),this.getDataset().yAxisID||(this.getDataset().yAxisID=this.chart.options.scales.yAxes[0].id)},getDataset:function(){return this.chart.data.datasets[this.index]},getScaleForId:function(t){return this.chart.scales[t]},reset:function(){this.update(!0)},buildOrUpdateElements:function(){var t=this.getDataset().data.length,e=this.getDataset().metaData.length;if(e>t)this.getDataset().metaData.splice(t,e-t);else if(t>e)for(var i=e;t>i;++i)this.addElementAndReset(i)},addElements:i.noop,addElementAndReset:i.noop,draw:i.noop,removeHoverStyle:i.noop,setHoverStyle:i.noop,update:i.noop}),e.DatasetController.extend=i.inherits}.call(this),function(){"use strict";var t=this,e=t.Chart,i=e.helpers;e.layoutService={defaults:{},addBox:function(t,e){t.boxes||(t.boxes=[]),t.boxes.push(e)},removeBox:function(t,e){t.boxes&&t.boxes.splice(t.boxes.indexOf(e),1)},update:function(t,e,a){function s(t){var e,i=t.isHorizontal();i?(e=t.update(t.options.fullWidth?f:k,y),C-=e.height):(e=t.update(v,x),k-=e.width),D.push({horizontal:i,minSize:e,box:t})}function o(t){var e=i.findNextWhere(D,function(e){return e.box===t});if(e)if(t.isHorizontal()){var a={left:S,right:w,top:0,bottom:0};t.update(t.options.fullWidth?f:k,e.minSize.height,a)}else t.update(e.minSize.width,C)}function n(t){var e=i.findNextWhere(D,function(e){return e.box===t}),a={left:0,right:0,top:_,bottom:A};e&&t.update(e.minSize.width,C,a)}function r(t){t.isHorizontal()?(t.left=t.options.fullWidth?h:S,t.right=t.options.fullWidth?e-h:S+k,t.top=F,t.bottom=F+t.height,F=t.bottom):(t.left=P,t.right=P+t.width,t.top=_,t.bottom=_+C,P=t.right)}if(t){var h=e>30?5:2,l=a>30?5:2,c=i.where(t.boxes,function(t){return"left"==t.options.position}),d=i.where(t.boxes,function(t){return"right"==t.options.position}),u=i.where(t.boxes,function(t){return"top"==t.options.position}),g=i.where(t.boxes,function(t){return"bottom"==t.options.position}),m=i.where(t.boxes,function(t){return"chartArea"==t.options.position});u.sort(function(t,e){return(e.options.fullWidth?1:0)-(t.options.fullWidth?1:0)}),g.sort(function(t,e){return(t.options.fullWidth?1:0)-(e.options.fullWidth?1:0)});var f=e-2*h,p=a-2*l,b=f/2,x=p/2,v=(e-b)/(c.length+d.length),y=(a-x)/(u.length+g.length),k=f,C=p,D=[];i.each(c.concat(d,u,g),s);var S=h,w=h,_=l,A=l;i.each(c.concat(d),o),i.each(c,function(t){S+=t.width}),i.each(d,function(t){w+=t.width}),i.each(u.concat(g),o),i.each(u,function(t){_+=t.height}),i.each(g,function(t){A+=t.height}),i.each(c.concat(d),n),S=h,w=h,_=l,A=l,i.each(c,function(t){S+=t.width}),i.each(d,function(t){w+=t.width}),i.each(u,function(t){_+=t.height}),i.each(g,function(t){A+=t.height});var M=a-_-A,I=e-S-w;(I!==k||M!==C)&&(i.each(c,function(t){t.height=M}),i.each(d,function(t){t.height=M}),i.each(u,function(t){t.width=I}),i.each(g,function(t){t.width=I}),C=M,k=I);var P=h,F=l;i.each(c.concat(u),r),P+=k,F+=C,i.each(d,r),i.each(g,r),t.chartArea={left:S,top:_,right:S+k,bottom:_+C},i.each(m,function(e){e.left=t.chartArea.left,e.top=t.chartArea.top,e.right=t.chartArea.right,e.bottom=t.chartArea.bottom,e.update(k,C)})}}}}.call(this),function(){"use strict";var t=this,e=t.Chart,i=e.helpers;e.defaults.global.legend={display:!0,position:"top",fullWidth:!0,onClick:function(t,e){var i=this.chart.data.datasets[e.datasetIndex];i.hidden=!i.hidden,this.chart.update()},labels:{boxWidth:40,fontSize:12,fontStyle:"normal",fontColor:"#666",fontFamily:"Helvetica Neue",padding:10,generateLabels:function(t){return t.datasets.map(function(t,e){return{text:t.label,fillStyle:t.backgroundColor,hidden:t.hidden,lineCap:t.borderCapStyle,lineDash:t.borderDash,lineDashOffset:t.borderDashOffset,lineJoin:t.borderJoinStyle,lineWidth:t.borderWidth,strokeStyle:t.borderColor,datasetIndex:e}},this)}}},e.Legend=e.Element.extend({initialize:function(t){i.extend(this,t),this.legendHitBoxes=[],this.doughnutMode=!1},beforeUpdate:i.noop,update:function(t,e,i){return this.beforeUpdate(),this.maxWidth=t,this.maxHeight=e,this.margins=i,this.beforeSetDimensions(),this.setDimensions(),this.afterSetDimensions(),this.beforeBuildLabels(),this.buildLabels(),this.afterBuildLabels(),this.beforeFit(),this.fit(),this.afterFit(),this.afterUpdate(),this.minSize},afterUpdate:i.noop,beforeSetDimensions:i.noop,setDimensions:function(){this.isHorizontal()?(this.width=this.maxWidth,this.left=0,this.right=this.width):(this.height=this.maxHeight,this.top=0,this.bottom=this.height),this.paddingLeft=0,this.paddingTop=0,this.paddingRight=0,this.paddingBottom=0,this.minSize={width:0,height:0}},afterSetDimensions:i.noop,beforeBuildLabels:i.noop,buildLabels:function(){this.legendItems=this.options.labels.generateLabels.call(this,this.chart.data)},afterBuildLabels:i.noop,beforeFit:i.noop,fit:function(){var t=this.ctx,e=i.fontString(this.options.labels.fontSize,this.options.labels.fontStyle,this.options.labels.fontFamily);if(this.legendHitBoxes=[],this.isHorizontal()?this.minSize.width=this.maxWidth:this.minSize.width=this.options.display?10:0,this.isHorizontal()?this.minSize.height=this.options.display?10:0:this.minSize.height=this.maxHeight,this.options.display&&this.isHorizontal()){this.lineWidths=[0];var a=this.legendItems.length?this.options.labels.fontSize+this.options.labels.padding:0;t.textAlign="left",t.textBaseline="top",t.font=e,i.each(this.legendItems,function(e,i){var s=this.options.labels.boxWidth+this.options.labels.fontSize/2+t.measureText(e.text).width;this.lineWidths[this.lineWidths.length-1]+s>=this.width&&(a+=this.options.labels.fontSize+this.options.labels.padding,this.lineWidths[this.lineWidths.length]=this.left),this.legendHitBoxes[i]={left:0,top:0,width:s,height:this.options.labels.fontSize},this.lineWidths[this.lineWidths.length-1]+=s+this.options.labels.padding},this),this.minSize.height+=a}this.width=this.minSize.width,this.height=this.minSize.height},afterFit:i.noop,isHorizontal:function(){return"top"==this.options.position||"bottom"==this.options.position},draw:function(){if(this.options.display){var t=this.ctx,a={x:this.left+(this.width-this.lineWidths[0])/2,y:this.top+this.options.labels.padding,line:0},s=i.fontString(this.options.labels.fontSize,this.options.labels.fontStyle,this.options.labels.fontFamily);this.isHorizontal()&&(t.textAlign="left",t.textBaseline="top",t.lineWidth=.5,t.strokeStyle=this.options.labels.fontColor,t.fillStyle=this.options.labels.fontColor,t.font=s,i.each(this.legendItems,function(i,s){var o=t.measureText(i.text).width,n=this.options.labels.boxWidth+this.options.labels.fontSize/2+o;a.x+n>=this.width&&(a.y+=this.options.labels.fontSize+this.options.labels.padding,a.line++,a.x=this.left+(this.width-this.lineWidths[a.line])/2),t.save();var r=function(t,e){return void 0!==t?t:e};t.fillStyle=r(i.fillStyle,e.defaults.global.defaultColor),t.lineCap=r(i.lineCap,e.defaults.global.elements.line.borderCapStyle),t.lineDashOffset=r(i.lineDashOffset,e.defaults.global.elements.line.borderDashOffset),t.lineJoin=r(i.lineJoin,e.defaults.global.elements.line.borderJoinStyle),t.lineWidth=r(i.lineWidth,e.defaults.global.elements.line.borderWidth),t.strokeStyle=r(i.strokeStyle,e.defaults.global.defaultColor),t.setLineDash&&t.setLineDash(r(i.lineDash,e.defaults.global.elements.line.borderDash)),t.strokeRect(a.x,a.y,this.options.labels.boxWidth,this.options.labels.fontSize),t.fillRect(a.x,a.y,this.options.labels.boxWidth,this.options.labels.fontSize),t.restore(),this.legendHitBoxes[s].left=a.x,this.legendHitBoxes[s].top=a.y,t.fillText(i.text,this.options.labels.boxWidth+this.options.labels.fontSize/2+a.x,a.y),i.hidden&&(t.beginPath(),t.lineWidth=2,t.moveTo(this.options.labels.boxWidth+this.options.labels.fontSize/2+a.x,a.y+this.options.labels.fontSize/2),t.lineTo(this.options.labels.boxWidth+this.options.labels.fontSize/2+a.x+o,a.y+this.options.labels.fontSize/2),t.stroke()),a.x+=n+this.options.labels.padding},this))}},handleEvent:function(t){var e=i.getRelativePosition(t,this.chart.chart);if(e.x>=this.left&&e.x<=this.right&&e.y>=this.top&&e.y<=this.bottom)for(var a=0;a<this.legendHitBoxes.length;++a){var s=this.legendHitBoxes[a];if(e.x>=s.left&&e.x<=s.left+s.width&&e.y>=s.top&&e.y<=s.top+s.height){this.options.onClick&&this.options.onClick.call(this,t,this.legendItems[a]);break}}}})}.call(this),function(){"use strict";var t=this,e=t.Chart,i=e.helpers;e.defaults.scale={display:!0,gridLines:{display:!0,color:"rgba(0, 0, 0, 0.1)",lineWidth:1,drawOnChartArea:!0,drawTicks:!0,zeroLineWidth:1,zeroLineColor:"rgba(0,0,0,0.25)",offsetGridLines:!1},scaleLabel:{fontColor:"#666",fontFamily:"Helvetica Neue",fontSize:12,fontStyle:"normal",labelString:"",display:!1},ticks:{beginAtZero:!1,fontSize:12,fontStyle:"normal",fontColor:"#666",fontFamily:"Helvetica Neue",maxRotation:90,mirror:!1,padding:10,reverse:!1,display:!0,autoSkip:!0,autoSkipPadding:20,callback:function(t){return""+t}}},e.Scale=e.Element.extend({beforeUpdate:function(){i.callCallback(this.options.beforeUpdate,[this])},update:function(t,e,a){return this.beforeUpdate(),this.maxWidth=t,this.maxHeight=e,this.margins=i.extend({left:0,right:0,top:0,bottom:0},a),this.beforeSetDimensions(),this.setDimensions(),this.afterSetDimensions(),this.beforeDataLimits(),this.determineDataLimits(),this.afterDataLimits(),this.beforeBuildTicks(),this.buildTicks(),this.afterBuildTicks(),this.beforeTickToLabelConversion(),this.convertTicksToLabels(),this.afterTickToLabelConversion(),this.beforeCalculateTickRotation(),this.calculateTickRotation(),this.afterCalculateTickRotation(),this.beforeFit(),this.fit(),this.afterFit(),this.afterUpdate(),this.minSize},afterUpdate:function(){i.callCallback(this.options.afterUpdate,[this])},beforeSetDimensions:function(){i.callCallback(this.options.beforeSetDimensions,[this])},setDimensions:function(){this.isHorizontal()?(this.width=this.maxWidth,this.left=0,this.right=this.width):(this.height=this.maxHeight,this.top=0,this.bottom=this.height),this.paddingLeft=0,this.paddingTop=0,this.paddingRight=0,this.paddingBottom=0},afterSetDimensions:function(){i.callCallback(this.options.afterSetDimensions,[this])},beforeDataLimits:function(){i.callCallback(this.options.beforeDataLimits,[this])},determineDataLimits:i.noop,afterDataLimits:function(){i.callCallback(this.options.afterDataLimits,[this])},beforeBuildTicks:function(){i.callCallback(this.options.beforeBuildTicks,[this])},buildTicks:i.noop,afterBuildTicks:function(){i.callCallback(this.options.afterBuildTicks,[this])},beforeTickToLabelConversion:function(){i.callCallback(this.options.beforeTickToLabelConversion,[this])},convertTicksToLabels:function(){this.ticks=this.ticks.map(function(t,e,i){return this.options.ticks.userCallback?this.options.ticks.userCallback(t,e,i):this.options.ticks.callback(t,e,i)},this)},afterTickToLabelConversion:function(){i.callCallback(this.options.afterTickToLabelConversion,[this])},beforeCalculateTickRotation:function(){i.callCallback(this.options.beforeCalculateTickRotation,[this])},calculateTickRotation:function(){var t=i.fontString(this.options.ticks.fontSize,this.options.ticks.fontStyle,this.options.ticks.fontFamily);this.ctx.font=t;var e,a,s=this.ctx.measureText(this.ticks[0]).width,o=this.ctx.measureText(this.ticks[this.ticks.length-1]).width;if(this.paddingRight=o/2+3,this.paddingLeft=s/2+3,this.labelRotation=0,this.options.display&&this.isHorizontal()){var n,r,h=i.longestText(this.ctx,t,this.ticks);this.labelWidth=h;for(var l=this.getPixelForTick(1)-this.getPixelForTick(0)-6;this.labelWidth>l&&this.labelRotation<this.options.ticks.maxRotation;){if(n=Math.cos(i.toRadians(this.labelRotation)),r=Math.sin(i.toRadians(this.labelRotation)),e=n*s,a=n*o,e+this.options.ticks.fontSize/2>this.yLabelWidth&&(this.paddingLeft=e+this.options.ticks.fontSize/2),this.paddingRight=this.options.ticks.fontSize/2,r*h>this.maxHeight){this.labelRotation--;break}this.labelRotation++,this.labelWidth=n*h}}else this.labelWidth=0,this.paddingRight=0,this.paddingLeft=0;this.margins&&(this.paddingLeft-=this.margins.left,this.paddingRight-=this.margins.right,this.paddingLeft=Math.max(this.paddingLeft,0),this.paddingRight=Math.max(this.paddingRight,0))},afterCalculateTickRotation:function(){i.callCallback(this.options.afterCalculateTickRotation,[this])},beforeFit:function(){i.callCallback(this.options.beforeFit,[this])},fit:function(){if(this.minSize={width:0,height:0},this.isHorizontal()?this.minSize.width=this.isFullWidth()?this.maxWidth-this.margins.left-this.margins.right:this.maxWidth:this.minSize.width=this.options.gridLines.display&&this.options.display?10:0,this.isHorizontal()?this.minSize.height=this.options.gridLines.display&&this.options.display?10:0:this.minSize.height=this.maxHeight,this.options.scaleLabel.display&&(this.isHorizontal()?this.minSize.height+=1.5*this.options.scaleLabel.fontSize:this.minSize.width+=1.5*this.options.scaleLabel.fontSize),this.options.ticks.display&&this.options.display){var t=i.fontString(this.options.ticks.fontSize,this.options.ticks.fontStyle,this.options.ticks.fontFamily);if(this.isHorizontal()){this.longestLabelWidth=i.longestText(this.ctx,t,this.ticks);var e=Math.sin(i.toRadians(this.labelRotation))*this.longestLabelWidth+1.5*this.options.ticks.fontSize;this.minSize.height=Math.min(this.maxHeight,this.minSize.height+e),t=i.fontString(this.options.ticks.fontSize,this.options.ticks.fontStyle,this.options.ticks.fontFamily),this.ctx.font=t;var a=this.ctx.measureText(this.ticks[0]).width,s=this.ctx.measureText(this.ticks[this.ticks.length-1]).width,o=Math.cos(i.toRadians(this.labelRotation)),n=Math.sin(i.toRadians(this.labelRotation));this.paddingLeft=0!==this.labelRotation?o*a+3:a/2+3,this.paddingRight=0!==this.labelRotation?n*(this.options.ticks.fontSize/2)+3:s/2+3}else{var r=this.maxWidth-this.minSize.width,h=i.longestText(this.ctx,t,this.ticks);this.options.ticks.mirror||(h+=this.options.ticks.padding),r>h?this.minSize.width+=h:this.minSize.width=this.maxWidth,this.paddingTop=this.options.ticks.fontSize/2,this.paddingBottom=this.options.ticks.fontSize/2}}this.margins&&(this.paddingLeft-=this.margins.left,this.paddingTop-=this.margins.top,this.paddingRight-=this.margins.right,this.paddingBottom-=this.margins.bottom,this.paddingLeft=Math.max(this.paddingLeft,0),this.paddingTop=Math.max(this.paddingTop,0),this.paddingRight=Math.max(this.paddingRight,0),this.paddingBottom=Math.max(this.paddingBottom,0)),this.width=this.minSize.width,this.height=this.minSize.height},afterFit:function(){i.callCallback(this.options.afterFit,[this])},isHorizontal:function(){return"top"===this.options.position||"bottom"===this.options.position},isFullWidth:function(){return this.options.fullWidth},getRightValue:function a(t){return null===t||"undefined"==typeof t?NaN:"number"==typeof t&&isNaN(t)?NaN:"object"==typeof t?t instanceof Date?t:a(this.isHorizontal()?t.x:t.y):t},getLabelForIndex:i.noop,getPixelForValue:i.noop,getPixelForTick:function(t,e){if(this.isHorizontal()){var i=this.width-(this.paddingLeft+this.paddingRight),a=i/Math.max(this.ticks.length-(this.options.gridLines.offsetGridLines?0:1),1),s=a*t+this.paddingLeft;e&&(s+=a/2);var o=this.left+Math.round(s);
return o+=this.isFullWidth()?this.margins.left:0}var n=this.height-(this.paddingTop+this.paddingBottom);return this.top+t*(n/(this.ticks.length-1))},getPixelForDecimal:function(t){if(this.isHorizontal()){var e=this.width-(this.paddingLeft+this.paddingRight),i=e*t+this.paddingLeft,a=this.left+Math.round(i);return a+=this.isFullWidth()?this.margins.left:0}return this.top+t*this.height},draw:function(t){if(this.options.display){var e,a,s,o,n=0!==this.labelRotation,r=this.options.ticks.autoSkip;this.ctx.fillStyle=this.options.ticks.fontColor;var h=i.fontString(this.options.ticks.fontSize,this.options.ticks.fontStyle,this.options.ticks.fontFamily),l=Math.cos(i.toRadians(this.labelRotation)),c=Math.sin(i.toRadians(this.labelRotation)),d=this.longestLabelWidth*l;this.options.ticks.fontSize*c;if(this.isHorizontal()){e=!0;var u="bottom"===this.options.position?this.top:this.bottom-10,g="bottom"===this.options.position?this.top+10:this.bottom;a=!1,(d/2+this.options.ticks.autoSkipPadding)*this.ticks.length>this.width-(this.paddingLeft+this.paddingRight)&&(a=1+Math.floor((d/2+this.options.ticks.autoSkipPadding)*this.ticks.length/(this.width-(this.paddingLeft+this.paddingRight)))),r||(a=!1),i.each(this.ticks,function(s,o){if(!(a>1&&o%a>0||void 0===s||null===s)){var r=this.getPixelForTick(o),l=this.getPixelForTick(o,this.options.gridLines.offsetGridLines);this.options.gridLines.display&&(o===("undefined"!=typeof this.zeroLineIndex?this.zeroLineIndex:0)?(this.ctx.lineWidth=this.options.gridLines.zeroLineWidth,this.ctx.strokeStyle=this.options.gridLines.zeroLineColor,e=!0):e&&(this.ctx.lineWidth=this.options.gridLines.lineWidth,this.ctx.strokeStyle=this.options.gridLines.color,e=!1),r+=i.aliasPixel(this.ctx.lineWidth),this.ctx.beginPath(),this.options.gridLines.drawTicks&&(this.ctx.moveTo(r,u),this.ctx.lineTo(r,g)),this.options.gridLines.drawOnChartArea&&(this.ctx.moveTo(r,t.top),this.ctx.lineTo(r,t.bottom)),this.ctx.stroke()),this.options.ticks.display&&(this.ctx.save(),this.ctx.translate(l,n?this.top+12:"top"===this.options.position?this.bottom-10:this.top+10),this.ctx.rotate(-1*i.toRadians(this.labelRotation)),this.ctx.font=h,this.ctx.textAlign=n?"right":"center",this.ctx.textBaseline=n?"middle":"top"===this.options.position?"bottom":"top",this.ctx.fillText(s,0,0),this.ctx.restore())}},this),this.options.scaleLabel.display&&(this.ctx.textAlign="center",this.ctx.textBaseline="middle",this.ctx.fillStyle=this.options.scaleLabel.fontColor,this.ctx.font=i.fontString(this.options.scaleLabel.fontSize,this.options.scaleLabel.fontStyle,this.options.scaleLabel.fontFamily),s=this.left+(this.right-this.left)/2,o="bottom"===this.options.position?this.bottom-this.options.scaleLabel.fontSize/2:this.top+this.options.scaleLabel.fontSize/2,this.ctx.fillText(this.options.scaleLabel.labelString,s,o))}else{e=!0;var m="right"===this.options.position?this.left:this.right-5,f="right"===this.options.position?this.left+5:this.right;if(i.each(this.ticks,function(a,s){if(void 0!==a&&null!==a){var o=this.getPixelForTick(s);if(this.options.gridLines.display&&(s===("undefined"!=typeof this.zeroLineIndex?this.zeroLineIndex:0)?(this.ctx.lineWidth=this.options.gridLines.zeroLineWidth,this.ctx.strokeStyle=this.options.gridLines.zeroLineColor,e=!0):e&&(this.ctx.lineWidth=this.options.gridLines.lineWidth,this.ctx.strokeStyle=this.options.gridLines.color,e=!1),o+=i.aliasPixel(this.ctx.lineWidth),this.ctx.beginPath(),this.options.gridLines.drawTicks&&(this.ctx.moveTo(m,o),this.ctx.lineTo(f,o)),this.options.gridLines.drawOnChartArea&&(this.ctx.moveTo(t.left,o),this.ctx.lineTo(t.right,o)),this.ctx.stroke()),this.options.ticks.display){var n,r=this.getPixelForTick(s,this.options.gridLines.offsetGridLines);this.ctx.save(),"left"===this.options.position?this.options.ticks.mirror?(n=this.right+this.options.ticks.padding,this.ctx.textAlign="left"):(n=this.right-this.options.ticks.padding,this.ctx.textAlign="right"):this.options.ticks.mirror?(n=this.left-this.options.ticks.padding,this.ctx.textAlign="right"):(n=this.left+this.options.ticks.padding,this.ctx.textAlign="left"),this.ctx.translate(n,r),this.ctx.rotate(-1*i.toRadians(this.labelRotation)),this.ctx.font=h,this.ctx.textBaseline="middle",this.ctx.fillText(a,0,0),this.ctx.restore()}}},this),this.options.scaleLabel.display){s="left"===this.options.position?this.left+this.options.scaleLabel.fontSize/2:this.right-this.options.scaleLabel.fontSize/2,o=this.top+(this.bottom-this.top)/2;var p="left"===this.options.position?-.5*Math.PI:.5*Math.PI;this.ctx.save(),this.ctx.translate(s,o),this.ctx.rotate(p),this.ctx.textAlign="center",this.ctx.fillStyle=this.options.scaleLabel.fontColor,this.ctx.font=i.fontString(this.options.scaleLabel.fontSize,this.options.scaleLabel.fontStyle,this.options.scaleLabel.fontFamily),this.ctx.textBaseline="middle",this.ctx.fillText(this.options.scaleLabel.labelString,0,0),this.ctx.restore()}}}}})}.call(this),function(){"use strict";var t=this,e=t.Chart,i=e.helpers;e.scaleService={constructors:{},defaults:{},registerScaleType:function(t,e,a){this.constructors[t]=e,this.defaults[t]=i.clone(a)},getScaleConstructor:function(t){return this.constructors.hasOwnProperty(t)?this.constructors[t]:void 0},getScaleDefaults:function(t){return this.defaults.hasOwnProperty(t)?i.scaleMerge(e.defaults.scale,this.defaults[t]):{}},addScalesToLayout:function(t){i.each(t.scales,function(i){e.layoutService.addBox(t,i)})}}}.call(this),function(){"use strict";var t=this,e=t.Chart,i=e.helpers;e.defaults.global.title={display:!1,position:"top",fullWidth:!0,fontColor:"#666",fontFamily:"Helvetica Neue",fontSize:12,fontStyle:"bold",padding:10,text:""},e.Title=e.Element.extend({initialize:function(t){i.extend(this,t),this.options=i.configMerge(e.defaults.global.title,t.options),this.legendHitBoxes=[]},beforeUpdate:i.noop,update:function(t,e,i){return this.beforeUpdate(),this.maxWidth=t,this.maxHeight=e,this.margins=i,this.beforeSetDimensions(),this.setDimensions(),this.afterSetDimensions(),this.beforeBuildLabels(),this.buildLabels(),this.afterBuildLabels(),this.beforeFit(),this.fit(),this.afterFit(),this.afterUpdate(),this.minSize},afterUpdate:i.noop,beforeSetDimensions:i.noop,setDimensions:function(){this.isHorizontal()?(this.width=this.maxWidth,this.left=0,this.right=this.width):(this.height=this.maxHeight,this.top=0,this.bottom=this.height),this.paddingLeft=0,this.paddingTop=0,this.paddingRight=0,this.paddingBottom=0,this.minSize={width:0,height:0}},afterSetDimensions:i.noop,beforeBuildLabels:i.noop,buildLabels:i.noop,afterBuildLabels:i.noop,beforeFit:i.noop,fit:function(){this.ctx,i.fontString(this.options.fontSize,this.options.fontStyle,this.options.fontFamily);this.isHorizontal()?this.minSize.width=this.maxWidth:this.minSize.width=0,this.isHorizontal()?this.minSize.height=0:this.minSize.height=this.maxHeight,this.isHorizontal()&&this.options.display&&(this.minSize.height+=this.options.fontSize+2*this.options.padding),this.width=this.minSize.width,this.height=this.minSize.height},afterFit:i.noop,isHorizontal:function(){return"top"==this.options.position||"bottom"==this.options.position},draw:function(){if(this.options.display){var t,e,a=this.ctx;if(this.isHorizontal())this.options.display&&(a.textAlign="center",a.textBaseline="middle",a.fillStyle=this.options.fontColor,a.font=i.fontString(this.options.fontSize,this.options.fontStyle,this.options.fontFamily),t=this.left+(this.right-this.left)/2,e=this.top+(this.bottom-this.top)/2,a.fillText(this.options.text,t,e));else if(this.options.display){t="left"==this.options.position?this.left+this.options.fontSize/2:this.right-this.options.fontSize/2,e=this.top+(this.bottom-this.top)/2;var s="left"==this.options.position?-.5*Math.PI:.5*Math.PI;a.save(),a.translate(t,e),a.rotate(s),a.textAlign="center",a.fillStyle=this.options.fontColor,a.font=i.fontString(this.options.fontSize,this.options.fontStyle,this.options.fontFamily),a.textBaseline="middle",a.fillText(this.options.text,0,0),a.restore()}}}})}.call(this),function(){"use strict";function t(t,e){return e&&(a.isArray(e)?t=t.concat(e):t.push(e)),t}var e=this,i=e.Chart,a=i.helpers;i.defaults.global.tooltips={enabled:!0,custom:null,mode:"single",backgroundColor:"rgba(0,0,0,0.8)",titleFontFamily:"'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",titleFontSize:12,titleFontStyle:"bold",titleSpacing:2,titleMarginBottom:6,titleColor:"#fff",titleAlign:"left",bodyFontFamily:"'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",bodyFontSize:12,bodyFontStyle:"normal",bodySpacing:2,bodyColor:"#fff",bodyAlign:"left",footerFontFamily:"'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",footerFontSize:12,footerFontStyle:"bold",footerSpacing:2,footerMarginTop:6,footerColor:"#fff",footerAlign:"left",yPadding:6,xPadding:6,caretSize:5,cornerRadius:6,multiKeyBackground:"#fff",callbacks:{beforeTitle:a.noop,title:function(t,e){var i="";return t.length>0&&(t[0].xLabel?i=t[0].xLabel:e.labels.length>0&&t[0].index<e.labels.length&&(i=e.labels[t[0].index])),i},afterTitle:a.noop,beforeBody:a.noop,beforeLabel:a.noop,label:function(t,e){var i=e.datasets[t.datasetIndex].label||"";return i+": "+t.yLabel},afterLabel:a.noop,afterBody:a.noop,beforeFooter:a.noop,footer:a.noop,afterFooter:a.noop}},i.Tooltip=i.Element.extend({initialize:function(){var t=this._options;a.extend(this,{_model:{xPadding:t.tooltips.xPadding,yPadding:t.tooltips.yPadding,bodyColor:t.tooltips.bodyColor,_bodyFontFamily:t.tooltips.bodyFontFamily,_bodyFontStyle:t.tooltips.bodyFontStyle,_bodyAlign:t.tooltips.bodyAlign,bodyFontSize:t.tooltips.bodyFontSize,bodySpacing:t.tooltips.bodySpacing,titleColor:t.tooltips.titleColor,_titleFontFamily:t.tooltips.titleFontFamily,_titleFontStyle:t.tooltips.titleFontStyle,titleFontSize:t.tooltips.titleFontSize,_titleAlign:t.tooltips.titleAlign,titleSpacing:t.tooltips.titleSpacing,titleMarginBottom:t.tooltips.titleMarginBottom,footerColor:t.tooltips.footerColor,_footerFontFamily:t.tooltips.footerFontFamily,_footerFontStyle:t.tooltips.footerFontStyle,footerFontSize:t.tooltips.footerFontSize,_footerAlign:t.tooltips.footerAlign,footerSpacing:t.tooltips.footerSpacing,footerMarginTop:t.tooltips.footerMarginTop,caretSize:t.tooltips.caretSize,cornerRadius:t.tooltips.cornerRadius,backgroundColor:t.tooltips.backgroundColor,opacity:0,legendColorBackground:t.tooltips.multiKeyBackground}})},getTitle:function(){var e=this._options.tooltips.callbacks.beforeTitle.apply(this,arguments),i=this._options.tooltips.callbacks.title.apply(this,arguments),a=this._options.tooltips.callbacks.afterTitle.apply(this,arguments),s=[];return s=t(s,e),s=t(s,i),s=t(s,a)},getBeforeBody:function(){var t=this._options.tooltips.callbacks.beforeBody.apply(this,arguments);return a.isArray(t)?t:void 0!==t?[t]:[]},getBody:function(t,e){var i=[];return a.each(t,function(t){var a=this._options.tooltips.callbacks.beforeLabel.call(this,t,e)||"",s=this._options.tooltips.callbacks.label.call(this,t,e)||"",o=this._options.tooltips.callbacks.afterLabel.call(this,t,e)||"";i.push(a+s+o)},this),i},getAfterBody:function(){var t=this._options.tooltips.callbacks.afterBody.apply(this,arguments);return a.isArray(t)?t:void 0!==t?[t]:[]},getFooter:function(){var e=this._options.tooltips.callbacks.beforeFooter.apply(this,arguments),i=this._options.tooltips.callbacks.footer.apply(this,arguments),a=this._options.tooltips.callbacks.afterFooter.apply(this,arguments),s=[];return s=t(s,e),s=t(s,i),s=t(s,a)},getAveragePosition:function(t){if(!t.length)return!1;var e=[],i=[];a.each(t,function(t){if(t){var a=t.tooltipPosition();e.push(a.x),i.push(a.y)}});for(var s=0,o=0,n=0;n<e.length;n++)s+=e[n],o+=i[n];return{x:Math.round(s/e.length),y:Math.round(o/e.length)}},update:function(t){if(this._active.length){this._model.opacity=1;var e,i=this._active[0],s=[],o=[];if("single"===this._options.tooltips.mode){var n=i._yScale||i._scale;o.push({xLabel:i._xScale?i._xScale.getLabelForIndex(i._index,i._datasetIndex):"",yLabel:n?n.getLabelForIndex(i._index,i._datasetIndex):"",index:i._index,datasetIndex:i._datasetIndex}),e=this.getAveragePosition(this._active)}else a.each(this._data.datasets,function(t,e){if(a.isDatasetVisible(t)){var s=t.metaData[i._index];if(s){var n=i._yScale||i._scale;o.push({xLabel:s._xScale?s._xScale.getLabelForIndex(s._index,s._datasetIndex):"",yLabel:n?n.getLabelForIndex(s._index,s._datasetIndex):"",index:i._index,datasetIndex:e})}}}),a.each(this._active,function(t){t&&s.push({borderColor:t._view.borderColor,backgroundColor:t._view.backgroundColor})},this),e=this.getAveragePosition(this._active),e.y=this._active[0]._yScale.getPixelForDecimal(.5);a.extend(this._model,{title:this.getTitle(o,this._data),beforeBody:this.getBeforeBody(o,this._data),body:this.getBody(o,this._data),afterBody:this.getAfterBody(o,this._data),footer:this.getFooter(o,this._data)}),a.extend(this._model,{x:Math.round(e.x),y:Math.round(e.y),caretPadding:a.getValueOrDefault(e.padding,2),labelColors:s});var r=this.getTooltipSize(this._model);this.determineAlignment(r),a.extend(this._model,this.getBackgroundPoint(this._model,r))}else this._model.opacity=0;return t&&this._options.tooltips.custom&&this._options.tooltips.custom.call(this,this._model),this},getTooltipSize:function(t){var e=this._chart.ctx,i={height:2*t.yPadding,width:0},s=t.body.length+t.beforeBody.length+t.afterBody.length;return i.height+=t.title.length*t.titleFontSize,i.height+=(t.title.length-1)*t.titleSpacing,i.height+=t.title.length?t.titleMarginBottom:0,i.height+=s*t.bodyFontSize,i.height+=s?(s-1)*t.bodySpacing:0,i.height+=t.footer.length?t.footerMarginTop:0,i.height+=t.footer.length*t.footerFontSize,i.height+=t.footer.length?(t.footer.length-1)*t.footerSpacing:0,e.font=a.fontString(t.titleFontSize,t._titleFontStyle,t._titleFontFamily),a.each(t.title,function(t){i.width=Math.max(i.width,e.measureText(t).width)}),e.font=a.fontString(t.bodyFontSize,t._bodyFontStyle,t._bodyFontFamily),a.each(t.beforeBody.concat(t.afterBody),function(t){i.width=Math.max(i.width,e.measureText(t).width)},this),a.each(t.body,function(a){i.width=Math.max(i.width,e.measureText(a).width+("single"!==this._options.tooltips.mode?t.bodyFontSize+2:0))},this),e.font=a.fontString(t.footerFontSize,t._footerFontStyle,t._footerFontFamily),a.each(t.footer,function(t){i.width=Math.max(i.width,e.measureText(t).width)}),i.width+=2*t.xPadding,i},determineAlignment:function(t){this._model.xAlign=this._model.yAlign="center",this._model.y<t.height?this._model.yAlign="top":this._model.y>this._chart.height-t.height&&(this._model.yAlign="bottom");var e,i,a=this,s=(this._chartInstance.chartArea.left+this._chartInstance.chartArea.right)/2;"center"===this._model.yAlign?(e=function(t){return s>=t},i=function(t){return t>s}):(e=function(e){return e<=t.width/2},i=function(e){return e>=a._chart.width-t.width/2}),e(this._model.x)?this._model.xAlign="left":i(this._model.x)&&(this._model.xAlign="right")},getBackgroundPoint:function(t,e){var i={x:t.x,y:t.y};return"right"===t.xAlign?i.x-=e.width:"center"===t.xAlign&&(i.x-=e.width/2),"top"===t.yAlign?i.y+=t.caretPadding+t.caretSize:"bottom"===t.yAlign?i.y-=e.height+t.caretPadding+t.caretSize:i.y-=e.height/2,"center"==t.yAlign?"left"===t.xAlign?i.x+=t.caretPadding+t.caretSize:"right"===t.xAlign&&(i.x-=t.caretPadding+t.caretSize):"left"===t.xAlign?i.x-=t.cornerRadius+t.caretPadding:"right"===t.xAlign&&(i.x+=t.cornerRadius+t.caretPadding),i},drawCaret:function(t,e,i,s){var o,n,r,h,l,c,d=this._view,u=this._chart.ctx;"center"===d.yAlign?("left"===d.xAlign?(o=t.x,n=o-d.caretSize,r=o):(o=t.x+e.width,n=o+d.caretSize,r=o),l=t.y+e.height/2,h=l-d.caretSize,c=l+d.caretSize):("left"===d.xAlign?(o=t.x+d.cornerRadius,n=o+d.caretSize,r=n+d.caretSize):"right"===d.xAlign?(o=t.x+e.width-d.cornerRadius,n=o-d.caretSize,r=n-d.caretSize):(n=t.x+e.width/2,o=n-d.caretSize,r=n+d.caretSize),"top"===d.yAlign?(h=t.y,l=h-d.caretSize,c=h):(h=t.y+e.height,l=h+d.caretSize,c=h)),u.fillStyle=a.color(d.backgroundColor).alpha(i).rgbString(),u.beginPath(),u.moveTo(o,h),u.lineTo(n,l),u.lineTo(r,c),u.closePath(),u.fill()},drawTitle:function(t,e,i,s){e.title.length&&(i.textAlign=e._titleAlign,i.textBaseline="top",i.fillStyle=a.color(e.titleColor).alpha(s).rgbString(),i.font=a.fontString(e.titleFontSize,e._titleFontStyle,e._titleFontFamily),a.each(e.title,function(a,s){i.fillText(a,t.x,t.y),t.y+=e.titleFontSize+e.titleSpacing,s+1===e.title.length&&(t.y+=e.titleMarginBottom-e.titleSpacing)},this))},drawBody:function(t,e,i,s){i.textAlign=e._bodyAlign,i.textBaseline="top",i.fillStyle=a.color(e.bodyColor).alpha(s).rgbString(),i.font=a.fontString(e.bodyFontSize,e._bodyFontStyle,e._bodyFontFamily),a.each(e.beforeBody,function(a){i.fillText(a,t.x,t.y),t.y+=e.bodyFontSize+e.bodySpacing}),a.each(e.body,function(o,n){"single"!==this._options.tooltips.mode&&(i.fillStyle=a.color(e.legendColorBackground).alpha(s).rgbaString(),i.fillRect(t.x,t.y,e.bodyFontSize,e.bodyFontSize),i.strokeStyle=a.color(e.labelColors[n].borderColor).alpha(s).rgbaString(),i.strokeRect(t.x,t.y,e.bodyFontSize,e.bodyFontSize),i.fillStyle=a.color(e.labelColors[n].backgroundColor).alpha(s).rgbaString(),i.fillRect(t.x+1,t.y+1,e.bodyFontSize-2,e.bodyFontSize-2),i.fillStyle=a.color(e.bodyColor).alpha(s).rgbaString()),i.fillText(o,t.x+("single"!==this._options.tooltips.mode?e.bodyFontSize+2:0),t.y),t.y+=e.bodyFontSize+e.bodySpacing},this),a.each(e.afterBody,function(a){i.fillText(a,t.x,t.y),t.y+=e.bodyFontSize}),t.y-=e.bodySpacing},drawFooter:function(t,e,i,s){e.footer.length&&(t.y+=e.footerMarginTop,i.textAlign=e._footerAlign,i.textBaseline="top",i.fillStyle=a.color(e.footerColor).alpha(s).rgbString(),i.font=a.fontString(e.footerFontSize,e._footerFontStyle,e._footerFontFamily),a.each(e.footer,function(a){i.fillText(a,t.x,t.y),t.y+=e.footerFontSize+e.footerSpacing},this))},draw:function(){var t=this._chart.ctx,e=this._view;if(0!==e.opacity){var i=e.caretPadding,s=this.getTooltipSize(e),o={x:e.x,y:e.y},n=Math.abs(e.opacity<.001)?0:e.opacity;this._options.tooltips.enabled&&(t.fillStyle=a.color(e.backgroundColor).alpha(n).rgbString(),a.drawRoundedRectangle(t,o.x,o.y,s.width,s.height,e.cornerRadius),t.fill(),this.drawCaret(o,s,n,i),o.x+=e.xPadding,o.y+=e.yPadding,this.drawTitle(o,e,t,n),this.drawBody(o,e,t,n),this.drawFooter(o,e,t,n))}}})}.call(this),function(){"use strict";var t=this,e=t.Chart,i=e.helpers;e.defaults.bar={hover:{mode:"label"},scales:{xAxes:[{type:"category",categoryPercentage:.8,barPercentage:.9,gridLines:{offsetGridLines:!0}}],yAxes:[{type:"linear"}]}},e.controllers.bar=e.DatasetController.extend({initialize:function(t,i){e.DatasetController.prototype.initialize.call(this,t,i),this.getDataset().bar=!0},getBarCount:function(){var t=0;return i.each(this.chart.data.datasets,function(e){i.isDatasetVisible(e)&&e.bar&&++t},this),t},addElements:function(){this.getDataset().metaData=this.getDataset().metaData||[],i.each(this.getDataset().data,function(t,i){this.getDataset().metaData[i]=this.getDataset().metaData[i]||new e.elements.Rectangle({_chart:this.chart.chart,_datasetIndex:this.index,_index:i})},this)},addElementAndReset:function(t){this.getDataset().metaData=this.getDataset().metaData||[];var i=new e.elements.Rectangle({_chart:this.chart.chart,_datasetIndex:this.index,_index:t}),a=this.getBarCount();this.updateElement(i,t,!0,a),this.getDataset().metaData.splice(t,0,i)},update:function(t){var e=this.getBarCount();i.each(this.getDataset().metaData,function(i,a){this.updateElement(i,a,t,e)},this)},updateElement:function(t,e,a,s){var o,n=this.getScaleForId(this.getDataset().xAxisID),r=this.getScaleForId(this.getDataset().yAxisID);o=r.min<0&&r.max<0?r.getPixelForValue(r.max):r.min>0&&r.max>0?r.getPixelForValue(r.min):r.getPixelForValue(0),i.extend(t,{_chart:this.chart.chart,_xScale:n,_yScale:r,_datasetIndex:this.index,_index:e,_model:{x:this.calculateBarX(e,this.index),y:a?o:this.calculateBarY(e,this.index),label:this.chart.data.labels[e],datasetLabel:this.getDataset().label,base:this.calculateBarBase(this.index,e),width:this.calculateBarWidth(s),backgroundColor:t.custom&&t.custom.backgroundColor?t.custom.backgroundColor:i.getValueAtIndexOrDefault(this.getDataset().backgroundColor,e,this.chart.options.elements.rectangle.backgroundColor),borderColor:t.custom&&t.custom.borderColor?t.custom.borderColor:i.getValueAtIndexOrDefault(this.getDataset().borderColor,e,this.chart.options.elements.rectangle.borderColor),borderWidth:t.custom&&t.custom.borderWidth?t.custom.borderWidth:i.getValueAtIndexOrDefault(this.getDataset().borderWidth,e,this.chart.options.elements.rectangle.borderWidth)}}),t.pivot()},calculateBarBase:function(t,e){var a=(this.getScaleForId(this.getDataset().xAxisID),this.getScaleForId(this.getDataset().yAxisID)),s=0;if(a.options.stacked){var o=this.chart.data.datasets[t].data[e];if(0>o)for(var n=0;t>n;n++){var r=this.chart.data.datasets[n];i.isDatasetVisible(r)&&r.yAxisID===a.id&&(s+=r.data[e]<0?r.data[e]:0)}else for(var h=0;t>h;h++){var l=this.chart.data.datasets[h];i.isDatasetVisible(l)&&l.yAxisID===a.id&&(s+=l.data[e]>0?l.data[e]:0)}return a.getPixelForValue(s)}return s=a.getPixelForValue(a.min),a.beginAtZero||a.min<=0&&a.max>=0||a.min>=0&&a.max<=0?s=a.getPixelForValue(0,0):a.min<0&&a.max<0&&(s=a.getPixelForValue(a.max)),s},getRuler:function(){var t=this.getScaleForId(this.getDataset().xAxisID),e=(this.getScaleForId(this.getDataset().yAxisID),this.getBarCount()),i=function(){for(var e=t.getPixelForTick(1)-t.getPixelForTick(0),i=2;i<this.getDataset().data.length;i++)e=Math.min(t.getPixelForTick(i)-t.getPixelForTick(i-1),e);return e}.call(this),a=i*t.options.categoryPercentage,s=(i-i*t.options.categoryPercentage)/2,o=a/e,n=o*t.options.barPercentage,r=o-o*t.options.barPercentage;return{datasetCount:e,tickWidth:i,categoryWidth:a,categorySpacing:s,fullBarWidth:o,barWidth:n,barSpacing:r}},calculateBarWidth:function(){var t=this.getScaleForId(this.getDataset().xAxisID),e=this.getRuler();return t.options.stacked?e.categoryWidth:e.barWidth},getBarIndex:function(t){for(var e=0,a=0;t>a;++a)i.isDatasetVisible(this.chart.data.datasets[a])&&this.chart.data.datasets[a].bar&&++e;return e},calculateBarX:function(t,e){var i=(this.getScaleForId(this.getDataset().yAxisID),this.getScaleForId(this.getDataset().xAxisID)),a=this.getBarIndex(e),s=this.getRuler(),o=i.getPixelForValue(null,t,e,this.chart.isCombo);return o-=this.chart.isCombo?s.tickWidth/2:0,i.options.stacked?o+s.categoryWidth/2+s.categorySpacing:o+s.barWidth/2+s.categorySpacing+s.barWidth*a+s.barSpacing/2+s.barSpacing*a},calculateBarY:function(t,e){var a=(this.getScaleForId(this.getDataset().xAxisID),this.getScaleForId(this.getDataset().yAxisID)),s=this.getDataset().data[t];if(a.options.stacked){for(var o=0,n=0,r=0;e>r;r++){var h=this.chart.data.datasets[r];i.isDatasetVisible(h)&&(h.data[t]<0?n+=h.data[t]||0:o+=h.data[t]||0)}return 0>s?a.getPixelForValue(n+s):a.getPixelForValue(o+s)}return a.getPixelForValue(s)},draw:function(t){var e=t||1;i.each(this.getDataset().metaData,function(t,i){t.transition(e).draw()},this)},setHoverStyle:function(t){var e=this.chart.data.datasets[t._datasetIndex],a=t._index;t._model.backgroundColor=t.custom&&t.custom.hoverBackgroundColor?t.custom.hoverBackgroundColor:i.getValueAtIndexOrDefault(e.hoverBackgroundColor,a,i.color(t._model.backgroundColor).saturate(.5).darken(.1).rgbString()),t._model.borderColor=t.custom&&t.custom.hoverBorderColor?t.custom.hoverBorderColor:i.getValueAtIndexOrDefault(e.hoverBorderColor,a,i.color(t._model.borderColor).saturate(.5).darken(.1).rgbString()),t._model.borderWidth=t.custom&&t.custom.hoverBorderWidth?t.custom.hoverBorderWidth:i.getValueAtIndexOrDefault(e.hoverBorderWidth,a,t._model.borderWidth)},removeHoverStyle:function(t){var e=(this.chart.data.datasets[t._datasetIndex],t._index);t._model.backgroundColor=t.custom&&t.custom.backgroundColor?t.custom.backgroundColor:i.getValueAtIndexOrDefault(this.getDataset().backgroundColor,e,this.chart.options.elements.rectangle.backgroundColor),t._model.borderColor=t.custom&&t.custom.borderColor?t.custom.borderColor:i.getValueAtIndexOrDefault(this.getDataset().borderColor,e,this.chart.options.elements.rectangle.borderColor),t._model.borderWidth=t.custom&&t.custom.borderWidth?t.custom.borderWidth:i.getValueAtIndexOrDefault(this.getDataset().borderWidth,e,this.chart.options.elements.rectangle.borderWidth)}})}.call(this),function(){"use strict";var t=this,e=t.Chart,i=e.helpers;e.defaults.bubble={hover:{mode:"single"},scales:{xAxes:[{type:"linear",position:"bottom",id:"x-axis-0"}],yAxes:[{type:"linear",position:"left",id:"y-axis-0"}]},tooltips:{template:"(<%= value.x %>, <%= value.y %>, <%= value.r %>)",multiTemplate:"<%if (datasetLabel){%><%=datasetLabel%>: <%}%>(<%= value.x %>, <%= value.y %>, <%= value.r %>)"}},e.controllers.bubble=e.DatasetController.extend({addElements:function(){this.getDataset().metaData=this.getDataset().metaData||[],i.each(this.getDataset().data,function(t,i){this.getDataset().metaData[i]=this.getDataset().metaData[i]||new e.elements.Point({_chart:this.chart.chart,_datasetIndex:this.index,_index:i})},this)},addElementAndReset:function(t){this.getDataset().metaData=this.getDataset().metaData||[];var i=new e.elements.Point({_chart:this.chart.chart,_datasetIndex:this.index,_index:t});this.updateElement(i,t,!0),this.getDataset().metaData.splice(t,0,i)},update:function(t){var e,a=this.getDataset().metaData,s=this.getScaleForId(this.getDataset().yAxisID);this.getScaleForId(this.getDataset().xAxisID);e=s.min<0&&s.max<0?s.getPixelForValue(s.max):s.min>0&&s.max>0?s.getPixelForValue(s.min):s.getPixelForValue(0),i.each(a,function(e,i){this.updateElement(e,i,t)},this)},updateElement:function(t,e,a){var s,o=this.getScaleForId(this.getDataset().yAxisID),n=this.getScaleForId(this.getDataset().xAxisID);s=o.min<0&&o.max<0?o.getPixelForValue(o.max):o.min>0&&o.max>0?o.getPixelForValue(o.min):o.getPixelForValue(0),i.extend(t,{_chart:this.chart.chart,_xScale:n,_yScale:o,_datasetIndex:this.index,_index:e,_model:{x:a?n.getPixelForDecimal(.5):n.getPixelForValue(this.getDataset().data[e],e,this.index,this.chart.isCombo),y:a?s:o.getPixelForValue(this.getDataset().data[e],e,this.index),radius:a?0:t.custom&&t.custom.radius?t.custom.radius:this.getRadius(this.getDataset().data[e]),backgroundColor:t.custom&&t.custom.backgroundColor?t.custom.backgroundColor:i.getValueAtIndexOrDefault(this.getDataset().backgroundColor,e,this.chart.options.elements.point.backgroundColor),borderColor:t.custom&&t.custom.borderColor?t.custom.borderColor:i.getValueAtIndexOrDefault(this.getDataset().borderColor,e,this.chart.options.elements.point.borderColor),borderWidth:t.custom&&t.custom.borderWidth?t.custom.borderWidth:i.getValueAtIndexOrDefault(this.getDataset().borderWidth,e,this.chart.options.elements.point.borderWidth),hitRadius:t.custom&&t.custom.hitRadius?t.custom.hitRadius:i.getValueAtIndexOrDefault(this.getDataset().hitRadius,e,this.chart.options.elements.point.hitRadius)}}),t._model.skip=t.custom&&t.custom.skip?t.custom.skip:isNaN(t._model.x)||isNaN(t._model.y),t.pivot()},getRadius:function(t){return t.r||this.chart.options.elements.point.radius},draw:function(t){var e=t||1;i.each(this.getDataset().metaData,function(t,i){t.transition(e),t.draw()},this)},setHoverStyle:function(t){var e=this.chart.data.datasets[t._datasetIndex],a=t._index;t._model.radius=t.custom&&t.custom.hoverRadius?t.custom.hoverRadius:i.getValueAtIndexOrDefault(e.hoverRadius,a,this.chart.options.elements.point.hoverRadius)+this.getRadius(this.getDataset().data[t._index]),t._model.backgroundColor=t.custom&&t.custom.hoverBackgroundColor?t.custom.hoverBackgroundColor:i.getValueAtIndexOrDefault(e.hoverBackgroundColor,a,i.color(t._model.backgroundColor).saturate(.5).darken(.1).rgbString()),t._model.borderColor=t.custom&&t.custom.hoverBorderColor?t.custom.hoverBorderColor:i.getValueAtIndexOrDefault(e.hoverBorderColor,a,i.color(t._model.borderColor).saturate(.5).darken(.1).rgbString()),t._model.borderWidth=t.custom&&t.custom.hoverBorderWidth?t.custom.hoverBorderWidth:i.getValueAtIndexOrDefault(e.hoverBorderWidth,a,t._model.borderWidth)},removeHoverStyle:function(t){var e=(this.chart.data.datasets[t._datasetIndex],t._index);t._model.radius=t.custom&&t.custom.radius?t.custom.radius:this.getRadius(this.getDataset().data[t._index]),t._model.backgroundColor=t.custom&&t.custom.backgroundColor?t.custom.backgroundColor:i.getValueAtIndexOrDefault(this.getDataset().backgroundColor,e,this.chart.options.elements.point.backgroundColor),t._model.borderColor=t.custom&&t.custom.borderColor?t.custom.borderColor:i.getValueAtIndexOrDefault(this.getDataset().borderColor,e,this.chart.options.elements.point.borderColor),t._model.borderWidth=t.custom&&t.custom.borderWidth?t.custom.borderWidth:i.getValueAtIndexOrDefault(this.getDataset().borderWidth,e,this.chart.options.elements.point.borderWidth)}})}.call(this),function(){"use strict";var t=this,e=t.Chart,i=e.helpers;e.defaults.doughnut={animation:{animateRotate:!0,animateScale:!1},aspectRatio:1,hover:{mode:"single"},legendCallback:function(t){var e=[];if(e.push('<ul class="'+t.id+'-legend">'),t.data.datasets.length)for(var i=0;i<t.data.datasets[0].data.length;++i)e.push('<li><span style="background-color:'+t.data.datasets[0].backgroundColor[i]+'">'),t.data.labels[i]&&e.push(t.data.labels[i]),e.push("</span></li>");return e.push("</ul>"),e.join("")},legend:{labels:{generateLabels:function(t){return t.labels.map(function(e,i){return{text:e,fillStyle:t.datasets[0].backgroundColor[i],hidden:isNaN(t.datasets[0].data[i]),index:i}})}},onClick:function(t,e){i.each(this.chart.data.datasets,function(t){t.metaHiddenData=t.metaHiddenData||[];var i=e.index;isNaN(t.data[i])?isNaN(t.metaHiddenData[i])||(t.data[i]=t.metaHiddenData[i]):(t.metaHiddenData[i]=t.data[i],t.data[i]=NaN)}),this.chart.update()}},cutoutPercentage:50,tooltips:{callbacks:{title:function(){return""},label:function(t,e){return e.labels[t.index]+": "+e.datasets[t.datasetIndex].data[t.index]}}}},e.defaults.pie=i.clone(e.defaults.doughnut),i.extend(e.defaults.pie,{cutoutPercentage:0}),e.controllers.doughnut=e.controllers.pie=e.DatasetController.extend({linkScales:function(){},addElements:function(){this.getDataset().metaData=this.getDataset().metaData||[],i.each(this.getDataset().data,function(t,i){this.getDataset().metaData[i]=this.getDataset().metaData[i]||new e.elements.Arc({_chart:this.chart.chart,_datasetIndex:this.index,_index:i})},this)},addElementAndReset:function(t,a){this.getDataset().metaData=this.getDataset().metaData||[];var s=new e.elements.Arc({_chart:this.chart.chart,_datasetIndex:this.index,_index:t});a&&i.isArray(this.getDataset().backgroundColor)&&this.getDataset().backgroundColor.splice(t,0,a),this.updateElement(s,t,!0),this.getDataset().metaData.splice(t,0,s)},getVisibleDatasetCount:function(){return i.where(this.chart.data.datasets,function(t){return i.isDatasetVisible(t)}).length},getRingIndex:function(t){for(var e=0,a=0;t>a;++a)i.isDatasetVisible(this.chart.data.datasets[a])&&++e;return e},update:function(t){var e=Math.min(this.chart.chartArea.right-this.chart.chartArea.left,this.chart.chartArea.bottom-this.chart.chartArea.top);this.chart.outerRadius=Math.max(e/2-this.chart.options.elements.arc.borderWidth/2,0),this.chart.innerRadius=Math.max(this.chart.options.cutoutPercentage?this.chart.outerRadius/100*this.chart.options.cutoutPercentage:1,0),this.chart.radiusLength=(this.chart.outerRadius-this.chart.innerRadius)/this.getVisibleDatasetCount(),this.getDataset().total=0,i.each(this.getDataset().data,function(t){isNaN(t)||(this.getDataset().total+=Math.abs(t))},this),this.outerRadius=this.chart.outerRadius-this.chart.radiusLength*this.getRingIndex(this.index),this.innerRadius=this.outerRadius-this.chart.radiusLength,i.each(this.getDataset().metaData,function(e,i){this.updateElement(e,i,t)},this)},updateElement:function(t,e,a){var s=(this.chart.chartArea.left+this.chart.chartArea.right)/2,o=(this.chart.chartArea.top+this.chart.chartArea.bottom)/2,n={x:s,y:o,startAngle:Math.PI*-.5,endAngle:Math.PI*-.5,circumference:this.chart.options.animation.animateRotate?0:this.calculateCircumference(this.getDataset().data[e]),
outerRadius:this.chart.options.animation.animateScale?0:this.outerRadius,innerRadius:this.chart.options.animation.animateScale?0:this.innerRadius};i.extend(t,{_chart:this.chart.chart,_datasetIndex:this.index,_index:e,_model:a?n:{x:s,y:o,circumference:this.calculateCircumference(this.getDataset().data[e]),outerRadius:this.outerRadius,innerRadius:this.innerRadius,backgroundColor:t.custom&&t.custom.backgroundColor?t.custom.backgroundColor:i.getValueAtIndexOrDefault(this.getDataset().backgroundColor,e,this.chart.options.elements.arc.backgroundColor),hoverBackgroundColor:t.custom&&t.custom.hoverBackgroundColor?t.custom.hoverBackgroundColor:i.getValueAtIndexOrDefault(this.getDataset().hoverBackgroundColor,e,this.chart.options.elements.arc.hoverBackgroundColor),borderWidth:t.custom&&t.custom.borderWidth?t.custom.borderWidth:i.getValueAtIndexOrDefault(this.getDataset().borderWidth,e,this.chart.options.elements.arc.borderWidth),borderColor:t.custom&&t.custom.borderColor?t.custom.borderColor:i.getValueAtIndexOrDefault(this.getDataset().borderColor,e,this.chart.options.elements.arc.borderColor),label:i.getValueAtIndexOrDefault(this.getDataset().label,e,this.chart.data.labels[e])}}),a||(0===e?t._model.startAngle=Math.PI*-.5:t._model.startAngle=this.getDataset().metaData[e-1]._model.endAngle,t._model.endAngle=t._model.startAngle+t._model.circumference,e<this.getDataset().data.length-1&&(this.getDataset().metaData[e+1]._model.startAngle=t._model.endAngle)),t.pivot()},draw:function(t){var e=t||1;i.each(this.getDataset().metaData,function(t,i){t.transition(e).draw()},this)},setHoverStyle:function(t){var e=this.chart.data.datasets[t._datasetIndex],a=t._index;t._model.backgroundColor=t.custom&&t.custom.hoverBackgroundColor?t.custom.hoverBackgroundColor:i.getValueAtIndexOrDefault(e.hoverBackgroundColor,a,i.color(t._model.backgroundColor).saturate(.5).darken(.1).rgbString()),t._model.borderColor=t.custom&&t.custom.hoverBorderColor?t.custom.hoverBorderColor:i.getValueAtIndexOrDefault(e.hoverBorderColor,a,i.color(t._model.borderColor).saturate(.5).darken(.1).rgbString()),t._model.borderWidth=t.custom&&t.custom.hoverBorderWidth?t.custom.hoverBorderWidth:i.getValueAtIndexOrDefault(e.hoverBorderWidth,a,t._model.borderWidth)},removeHoverStyle:function(t){var e=(this.chart.data.datasets[t._datasetIndex],t._index);t._model.backgroundColor=t.custom&&t.custom.backgroundColor?t.custom.backgroundColor:i.getValueAtIndexOrDefault(this.getDataset().backgroundColor,e,this.chart.options.elements.arc.backgroundColor),t._model.borderColor=t.custom&&t.custom.borderColor?t.custom.borderColor:i.getValueAtIndexOrDefault(this.getDataset().borderColor,e,this.chart.options.elements.arc.borderColor),t._model.borderWidth=t.custom&&t.custom.borderWidth?t.custom.borderWidth:i.getValueAtIndexOrDefault(this.getDataset().borderWidth,e,this.chart.options.elements.arc.borderWidth)},calculateCircumference:function(t){return this.getDataset().total>0&&!isNaN(t)?1.999999*Math.PI*(t/this.getDataset().total):0}})}.call(this),function(){"use strict";var t=this,e=t.Chart,i=e.helpers;e.defaults.line={hover:{mode:"label"},scales:{xAxes:[{type:"category",id:"x-axis-0"}],yAxes:[{type:"linear",id:"y-axis-0"}]}},e.controllers.line=e.DatasetController.extend({addElements:function(){this.getDataset().metaData=this.getDataset().metaData||[],this.getDataset().metaDataset=this.getDataset().metaDataset||new e.elements.Line({_chart:this.chart.chart,_datasetIndex:this.index,_points:this.getDataset().metaData}),i.each(this.getDataset().data,function(t,i){this.getDataset().metaData[i]=this.getDataset().metaData[i]||new e.elements.Point({_chart:this.chart.chart,_datasetIndex:this.index,_index:i})},this)},addElementAndReset:function(t){this.getDataset().metaData=this.getDataset().metaData||[];var i=new e.elements.Point({_chart:this.chart.chart,_datasetIndex:this.index,_index:t});this.updateElement(i,t,!0),this.getDataset().metaData.splice(t,0,i),this.updateBezierControlPoints()},update:function(t){var e,a=this.getDataset().metaDataset,s=this.getDataset().metaData,o=this.getScaleForId(this.getDataset().yAxisID);this.getScaleForId(this.getDataset().xAxisID);e=o.min<0&&o.max<0?o.getPixelForValue(o.max):o.min>0&&o.max>0?o.getPixelForValue(o.min):o.getPixelForValue(0),i.extend(a,{_scale:o,_datasetIndex:this.index,_children:s,_model:{tension:a.custom&&a.custom.tension?a.custom.tension:i.getValueOrDefault(this.getDataset().tension,this.chart.options.elements.line.tension),backgroundColor:a.custom&&a.custom.backgroundColor?a.custom.backgroundColor:this.getDataset().backgroundColor||this.chart.options.elements.line.backgroundColor,borderWidth:a.custom&&a.custom.borderWidth?a.custom.borderWidth:this.getDataset().borderWidth||this.chart.options.elements.line.borderWidth,borderColor:a.custom&&a.custom.borderColor?a.custom.borderColor:this.getDataset().borderColor||this.chart.options.elements.line.borderColor,borderCapStyle:a.custom&&a.custom.borderCapStyle?a.custom.borderCapStyle:this.getDataset().borderCapStyle||this.chart.options.elements.line.borderCapStyle,borderDash:a.custom&&a.custom.borderDash?a.custom.borderDash:this.getDataset().borderDash||this.chart.options.elements.line.borderDash,borderDashOffset:a.custom&&a.custom.borderDashOffset?a.custom.borderDashOffset:this.getDataset().borderDashOffset||this.chart.options.elements.line.borderDashOffset,borderJoinStyle:a.custom&&a.custom.borderJoinStyle?a.custom.borderJoinStyle:this.getDataset().borderJoinStyle||this.chart.options.elements.line.borderJoinStyle,fill:a.custom&&a.custom.fill?a.custom.fill:void 0!==this.getDataset().fill?this.getDataset().fill:this.chart.options.elements.line.fill,scaleTop:o.top,scaleBottom:o.bottom,scaleZero:e}}),a.pivot(),i.each(s,function(e,i){this.updateElement(e,i,t)},this),this.updateBezierControlPoints()},getPointBackgroundColor:function(t,e){var a=this.chart.options.elements.point.backgroundColor,s=this.getDataset();return t.custom&&t.custom.backgroundColor?a=t.custom.backgroundColor:s.pointBackgroundColor?a=i.getValueAtIndexOrDefault(s.pointBackgroundColor,e,a):s.backgroundColor&&(a=s.backgroundColor),a},getPointBorderColor:function(t,e){var a=this.chart.options.elements.point.borderColor,s=this.getDataset();return t.custom&&t.custom.borderColor?a=t.custom.borderColor:s.pointBorderColor?a=i.getValueAtIndexOrDefault(this.getDataset().pointBorderColor,e,a):s.borderColor&&(a=s.borderColor),a},getPointBorderWidth:function(t,e){var a=this.chart.options.elements.point.borderWidth,s=this.getDataset();return t.custom&&void 0!==t.custom.borderWidth?a=t.custom.borderWidth:void 0!==s.pointBorderWidth?a=i.getValueAtIndexOrDefault(s.pointBorderWidth,e,a):void 0!==s.borderWidth&&(a=s.borderWidth),a},updateElement:function(t,e,a){var s,o=this.getScaleForId(this.getDataset().yAxisID),n=this.getScaleForId(this.getDataset().xAxisID);s=o.min<0&&o.max<0?o.getPixelForValue(o.max):o.min>0&&o.max>0?o.getPixelForValue(o.min):o.getPixelForValue(0),i.extend(t,{_chart:this.chart.chart,_xScale:n,_yScale:o,_datasetIndex:this.index,_index:e,_model:{x:n.getPixelForValue(this.getDataset().data[e],e,this.index,this.chart.isCombo),y:a?s:this.calculatePointY(this.getDataset().data[e],e,this.index,this.chart.isCombo),tension:t.custom&&t.custom.tension?t.custom.tension:i.getValueOrDefault(this.getDataset().tension,this.chart.options.elements.line.tension),radius:t.custom&&t.custom.radius?t.custom.radius:i.getValueAtIndexOrDefault(this.getDataset().radius,e,this.chart.options.elements.point.radius),backgroundColor:this.getPointBackgroundColor(t,e),borderColor:this.getPointBorderColor(t,e),borderWidth:this.getPointBorderWidth(t,e),hitRadius:t.custom&&t.custom.hitRadius?t.custom.hitRadius:i.getValueAtIndexOrDefault(this.getDataset().hitRadius,e,this.chart.options.elements.point.hitRadius)}}),t._model.skip=t.custom&&t.custom.skip?t.custom.skip:isNaN(t._model.x)||isNaN(t._model.y)},calculatePointY:function(t,e,a,s){var o=(this.getScaleForId(this.getDataset().xAxisID),this.getScaleForId(this.getDataset().yAxisID));if(o.options.stacked){for(var n=0,r=0,h=this.chart.data.datasets.length-1;h>a;h--){var l=this.chart.data.datasets[h];i.isDatasetVisible(l)&&(l.data[e]<0?r+=l.data[e]||0:n+=l.data[e]||0)}return 0>t?o.getPixelForValue(r+t):o.getPixelForValue(n+t)}return o.getPixelForValue(t)},updateBezierControlPoints:function(){i.each(this.getDataset().metaData,function(t,e){var a=i.splineCurve(i.previousItem(this.getDataset().metaData,e)._model,t._model,i.nextItem(this.getDataset().metaData,e)._model,t._model.tension);t._model.controlPointPreviousX=Math.max(Math.min(a.previous.x,this.chart.chartArea.right),this.chart.chartArea.left),t._model.controlPointPreviousY=Math.max(Math.min(a.previous.y,this.chart.chartArea.bottom),this.chart.chartArea.top),t._model.controlPointNextX=Math.max(Math.min(a.next.x,this.chart.chartArea.right),this.chart.chartArea.left),t._model.controlPointNextY=Math.max(Math.min(a.next.y,this.chart.chartArea.bottom),this.chart.chartArea.top),t.pivot()},this)},draw:function(t){var e=t||1;i.each(this.getDataset().metaData,function(t,i){t.transition(e)},this),this.getDataset().metaDataset.transition(e).draw(),i.each(this.getDataset().metaData,function(t){t.draw()})},setHoverStyle:function(t){var e=this.chart.data.datasets[t._datasetIndex],a=t._index;t._model.radius=t.custom&&t.custom.hoverRadius?t.custom.hoverRadius:i.getValueAtIndexOrDefault(e.pointHoverRadius,a,this.chart.options.elements.point.hoverRadius),t._model.backgroundColor=t.custom&&t.custom.hoverBackgroundColor?t.custom.hoverBackgroundColor:i.getValueAtIndexOrDefault(e.pointHoverBackgroundColor,a,i.color(t._model.backgroundColor).saturate(.5).darken(.1).rgbString()),t._model.borderColor=t.custom&&t.custom.hoverBorderColor?t.custom.hoverBorderColor:i.getValueAtIndexOrDefault(e.pointHoverBorderColor,a,i.color(t._model.borderColor).saturate(.5).darken(.1).rgbString()),t._model.borderWidth=t.custom&&t.custom.hoverBorderWidth?t.custom.hoverBorderWidth:i.getValueAtIndexOrDefault(e.pointHoverBorderWidth,a,t._model.borderWidth)},removeHoverStyle:function(t){var e=(this.chart.data.datasets[t._datasetIndex],t._index);t._model.radius=t.custom&&t.custom.radius?t.custom.radius:i.getValueAtIndexOrDefault(this.getDataset().radius,e,this.chart.options.elements.point.radius),t._model.backgroundColor=this.getPointBackgroundColor(t,e),t._model.borderColor=this.getPointBorderColor(t,e),t._model.borderWidth=this.getPointBorderWidth(t,e)}})}.call(this),function(){"use strict";var t=this,e=t.Chart,i=e.helpers;e.defaults.polarArea={scale:{type:"radialLinear",lineArc:!0},animateRotate:!0,animateScale:!0,aspectRatio:1,legendCallback:function(t){var e=[];if(e.push('<ul class="'+t.id+'-legend">'),t.data.datasets.length)for(var i=0;i<t.data.datasets[0].data.length;++i)e.push('<li><span style="background-color:'+t.data.datasets[0].backgroundColor[i]+'">'),t.data.labels[i]&&e.push(t.data.labels[i]),e.push("</span></li>");return e.push("</ul>"),e.join("")},legend:{labels:{generateLabels:function(t){return t.labels.map(function(e,i){return{text:e,fillStyle:t.datasets[0].backgroundColor[i],hidden:isNaN(t.datasets[0].data[i]),index:i}})}},onClick:function(t,e){i.each(this.chart.data.datasets,function(t){t.metaHiddenData=t.metaHiddenData||[];var i=e.index;isNaN(t.data[i])?isNaN(t.metaHiddenData[i])||(t.data[i]=t.metaHiddenData[i]):(t.metaHiddenData[i]=t.data[i],t.data[i]=NaN)}),this.chart.update()}},tooltips:{callbacks:{title:function(){return""},label:function(t,e){return e.labels[t.index]+": "+t.yLabel}}}},e.controllers.polarArea=e.DatasetController.extend({linkScales:function(){},addElements:function(){this.getDataset().metaData=this.getDataset().metaData||[],i.each(this.getDataset().data,function(t,i){this.getDataset().metaData[i]=this.getDataset().metaData[i]||new e.elements.Arc({_chart:this.chart.chart,_datasetIndex:this.index,_index:i})},this)},addElementAndReset:function(t){this.getDataset().metaData=this.getDataset().metaData||[];var i=new e.elements.Arc({_chart:this.chart.chart,_datasetIndex:this.index,_index:t});this.updateElement(i,t,!0),this.getDataset().metaData.splice(t,0,i)},getVisibleDatasetCount:function(){return i.where(this.chart.data.datasets,function(t){return i.isDatasetVisible(t)}).length},update:function(t){var e=Math.min(this.chart.chartArea.right-this.chart.chartArea.left,this.chart.chartArea.bottom-this.chart.chartArea.top);this.chart.outerRadius=Math.max((e-this.chart.options.elements.arc.borderWidth/2)/2,0),this.chart.innerRadius=Math.max(this.chart.options.cutoutPercentage?this.chart.outerRadius/100*this.chart.options.cutoutPercentage:1,0),this.chart.radiusLength=(this.chart.outerRadius-this.chart.innerRadius)/this.getVisibleDatasetCount(),this.getDataset().total=0,i.each(this.getDataset().data,function(t){this.getDataset().total+=Math.abs(t)},this),this.outerRadius=this.chart.outerRadius-this.chart.radiusLength*this.index,this.innerRadius=this.outerRadius-this.chart.radiusLength,i.each(this.getDataset().metaData,function(e,i){this.updateElement(e,i,t)},this)},updateElement:function(t,e,a){for(var s=this.calculateCircumference(this.getDataset().data[e]),o=(this.chart.chartArea.left+this.chart.chartArea.right)/2,n=(this.chart.chartArea.top+this.chart.chartArea.bottom)/2,r=0,h=0;e>h;++h)isNaN(this.getDataset().data[h])||++r;var l=-.5*Math.PI+s*r,c=l+s,d={x:o,y:n,innerRadius:0,outerRadius:this.chart.options.animateScale?0:this.chart.scale.getDistanceFromCenterForValue(this.getDataset().data[e]),startAngle:this.chart.options.animateRotate?Math.PI*-.5:l,endAngle:this.chart.options.animateRotate?Math.PI*-.5:c,backgroundColor:t.custom&&t.custom.backgroundColor?t.custom.backgroundColor:i.getValueAtIndexOrDefault(this.getDataset().backgroundColor,e,this.chart.options.elements.arc.backgroundColor),hoverBackgroundColor:t.custom&&t.custom.hoverBackgroundColor?t.custom.hoverBackgroundColor:i.getValueAtIndexOrDefault(this.getDataset().hoverBackgroundColor,e,this.chart.options.elements.arc.hoverBackgroundColor),borderWidth:t.custom&&t.custom.borderWidth?t.custom.borderWidth:i.getValueAtIndexOrDefault(this.getDataset().borderWidth,e,this.chart.options.elements.arc.borderWidth),borderColor:t.custom&&t.custom.borderColor?t.custom.borderColor:i.getValueAtIndexOrDefault(this.getDataset().borderColor,e,this.chart.options.elements.arc.borderColor),label:i.getValueAtIndexOrDefault(this.chart.data.labels,e,this.chart.data.labels[e])};i.extend(t,{_chart:this.chart.chart,_datasetIndex:this.index,_index:e,_scale:this.chart.scale,_model:a?d:{x:o,y:n,innerRadius:0,outerRadius:this.chart.scale.getDistanceFromCenterForValue(this.getDataset().data[e]),startAngle:l,endAngle:c,backgroundColor:t.custom&&t.custom.backgroundColor?t.custom.backgroundColor:i.getValueAtIndexOrDefault(this.getDataset().backgroundColor,e,this.chart.options.elements.arc.backgroundColor),hoverBackgroundColor:t.custom&&t.custom.hoverBackgroundColor?t.custom.hoverBackgroundColor:i.getValueAtIndexOrDefault(this.getDataset().hoverBackgroundColor,e,this.chart.options.elements.arc.hoverBackgroundColor),borderWidth:t.custom&&t.custom.borderWidth?t.custom.borderWidth:i.getValueAtIndexOrDefault(this.getDataset().borderWidth,e,this.chart.options.elements.arc.borderWidth),borderColor:t.custom&&t.custom.borderColor?t.custom.borderColor:i.getValueAtIndexOrDefault(this.getDataset().borderColor,e,this.chart.options.elements.arc.borderColor),label:i.getValueAtIndexOrDefault(this.chart.data.labels,e,this.chart.data.labels[e])}}),t.pivot()},draw:function(t){var e=t||1;i.each(this.getDataset().metaData,function(t,i){t.transition(e).draw()},this)},setHoverStyle:function(t){var e=this.chart.data.datasets[t._datasetIndex],a=t._index;t._model.backgroundColor=t.custom&&t.custom.hoverBackgroundColor?t.custom.hoverBackgroundColor:i.getValueAtIndexOrDefault(e.hoverBackgroundColor,a,i.color(t._model.backgroundColor).saturate(.5).darken(.1).rgbString()),t._model.borderColor=t.custom&&t.custom.hoverBorderColor?t.custom.hoverBorderColor:i.getValueAtIndexOrDefault(e.hoverBorderColor,a,i.color(t._model.borderColor).saturate(.5).darken(.1).rgbString()),t._model.borderWidth=t.custom&&t.custom.hoverBorderWidth?t.custom.hoverBorderWidth:i.getValueAtIndexOrDefault(e.borderWidth,a,t._model.borderWidth)},removeHoverStyle:function(t){var e=(this.chart.data.datasets[t._datasetIndex],t._index);t._model.backgroundColor=t.custom&&t.custom.backgroundColor?t.custom.backgroundColor:i.getValueAtIndexOrDefault(this.getDataset().backgroundColor,e,this.chart.options.elements.arc.backgroundColor),t._model.borderColor=t.custom&&t.custom.borderColor?t.custom.borderColor:i.getValueAtIndexOrDefault(this.getDataset().borderColor,e,this.chart.options.elements.arc.borderColor),t._model.borderWidth=t.custom&&t.custom.borderWidth?t.custom.borderWidth:i.getValueAtIndexOrDefault(this.getDataset().borderWidth,e,this.chart.options.elements.arc.borderWidth)},calculateCircumference:function(t){if(isNaN(t))return 0;var e=i.where(this.getDataset().data,function(t){return isNaN(t)}).length;return 2*Math.PI/(this.getDataset().data.length-e)}})}.call(this),function(){"use strict";var t=this,e=t.Chart,i=e.helpers;e.defaults.radar={scale:{type:"radialLinear"},elements:{line:{tension:0}}},e.controllers.radar=e.DatasetController.extend({linkScales:function(){},addElements:function(){this.getDataset().metaData=this.getDataset().metaData||[],this.getDataset().metaDataset=this.getDataset().metaDataset||new e.elements.Line({_chart:this.chart.chart,_datasetIndex:this.index,_points:this.getDataset().metaData,_loop:!0}),i.each(this.getDataset().data,function(t,i){this.getDataset().metaData[i]=this.getDataset().metaData[i]||new e.elements.Point({_chart:this.chart.chart,_datasetIndex:this.index,_index:i,_model:{x:0,y:0}})},this)},addElementAndReset:function(t){this.getDataset().metaData=this.getDataset().metaData||[];var i=new e.elements.Point({_chart:this.chart.chart,_datasetIndex:this.index,_index:t});this.updateElement(i,t,!0),this.getDataset().metaData.splice(t,0,i),this.updateBezierControlPoints()},update:function(t){var e,a=(this.getDataset().metaDataset,this.getDataset().metaData),s=this.chart.scale;e=s.min<0&&s.max<0?s.getPointPositionForValue(0,s.max):s.min>0&&s.max>0?s.getPointPositionForValue(0,s.min):s.getPointPositionForValue(0,0),i.extend(this.getDataset().metaDataset,{_datasetIndex:this.index,_children:this.getDataset().metaData,_model:{tension:i.getValueOrDefault(this.getDataset().tension,this.chart.options.elements.line.tension),backgroundColor:this.getDataset().backgroundColor||this.chart.options.elements.line.backgroundColor,borderWidth:this.getDataset().borderWidth||this.chart.options.elements.line.borderWidth,borderColor:this.getDataset().borderColor||this.chart.options.elements.line.borderColor,fill:void 0!==this.getDataset().fill?this.getDataset().fill:this.chart.options.elements.line.fill,scaleTop:s.top,scaleBottom:s.bottom,scaleZero:e}}),this.getDataset().metaDataset.pivot(),i.each(a,function(e,i){this.updateElement(e,i,t)},this),this.updateBezierControlPoints()},updateElement:function(t,e,a){var s=this.chart.scale.getPointPositionForValue(e,this.getDataset().data[e]);i.extend(t,{_datasetIndex:this.index,_index:e,_scale:this.chart.scale,_model:{x:a?this.chart.scale.xCenter:s.x,y:a?this.chart.scale.yCenter:s.y,tension:t.custom&&t.custom.tension?t.custom.tension:i.getValueOrDefault(this.getDataset().tension,this.chart.options.elements.line.tension),radius:t.custom&&t.custom.radius?t.custom.pointRadius:i.getValueAtIndexOrDefault(this.getDataset().pointRadius,e,this.chart.options.elements.point.radius),backgroundColor:t.custom&&t.custom.backgroundColor?t.custom.backgroundColor:i.getValueAtIndexOrDefault(this.getDataset().pointBackgroundColor,e,this.chart.options.elements.point.backgroundColor),borderColor:t.custom&&t.custom.borderColor?t.custom.borderColor:i.getValueAtIndexOrDefault(this.getDataset().pointBorderColor,e,this.chart.options.elements.point.borderColor),borderWidth:t.custom&&t.custom.borderWidth?t.custom.borderWidth:i.getValueAtIndexOrDefault(this.getDataset().pointBorderWidth,e,this.chart.options.elements.point.borderWidth),hitRadius:t.custom&&t.custom.hitRadius?t.custom.hitRadius:i.getValueAtIndexOrDefault(this.getDataset().hitRadius,e,this.chart.options.elements.point.hitRadius)}}),t._model.skip=t.custom&&t.custom.skip?t.custom.skip:isNaN(t._model.x)||isNaN(t._model.y)},updateBezierControlPoints:function(){i.each(this.getDataset().metaData,function(t,e){var a=i.splineCurve(i.previousItem(this.getDataset().metaData,e,!0)._model,t._model,i.nextItem(this.getDataset().metaData,e,!0)._model,t._model.tension);t._model.controlPointPreviousX=Math.max(Math.min(a.previous.x,this.chart.chartArea.right),this.chart.chartArea.left),t._model.controlPointPreviousY=Math.max(Math.min(a.previous.y,this.chart.chartArea.bottom),this.chart.chartArea.top),t._model.controlPointNextX=Math.max(Math.min(a.next.x,this.chart.chartArea.right),this.chart.chartArea.left),t._model.controlPointNextY=Math.max(Math.min(a.next.y,this.chart.chartArea.bottom),this.chart.chartArea.top),t.pivot()},this)},draw:function(t){var e=t||1;i.each(this.getDataset().metaData,function(t,i){t.transition(e)},this),this.getDataset().metaDataset.transition(e).draw(),i.each(this.getDataset().metaData,function(t){t.draw()})},setHoverStyle:function(t){var e=this.chart.data.datasets[t._datasetIndex],a=t._index;t._model.radius=t.custom&&t.custom.radius?t.custom.radius:i.getValueAtIndexOrDefault(e.pointHoverRadius,a,this.chart.options.elements.point.hoverRadius),t._model.backgroundColor=t.custom&&t.custom.hoverBackgroundColor?t.custom.hoverBackgroundColor:i.getValueAtIndexOrDefault(e.pointHoverBackgroundColor,a,i.color(t._model.backgroundColor).saturate(.5).darken(.1).rgbString()),t._model.borderColor=t.custom&&t.custom.hoverBorderColor?t.custom.hoverBorderColor:i.getValueAtIndexOrDefault(e.pointHoverBorderColor,a,i.color(t._model.borderColor).saturate(.5).darken(.1).rgbString()),t._model.borderWidth=t.custom&&t.custom.hoverBorderWidth?t.custom.hoverBorderWidth:i.getValueAtIndexOrDefault(e.pointBorderWidth,a,t._model.borderWidth)},removeHoverStyle:function(t){var e=(this.chart.data.datasets[t._datasetIndex],t._index);t._model.radius=t.custom&&t.custom.radius?t.custom.radius:i.getValueAtIndexOrDefault(this.getDataset().radius,e,this.chart.options.elements.point.radius),t._model.backgroundColor=t.custom&&t.custom.backgroundColor?t.custom.backgroundColor:i.getValueAtIndexOrDefault(this.getDataset().pointBackgroundColor,e,this.chart.options.elements.point.backgroundColor),t._model.borderColor=t.custom&&t.custom.borderColor?t.custom.borderColor:i.getValueAtIndexOrDefault(this.getDataset().pointBorderColor,e,this.chart.options.elements.point.borderColor),t._model.borderWidth=t.custom&&t.custom.borderWidth?t.custom.borderWidth:i.getValueAtIndexOrDefault(this.getDataset().pointBorderWidth,e,this.chart.options.elements.point.borderWidth)}})}.call(this),function(){"use strict";var t=this,e=t.Chart,i=(e.helpers,{position:"bottom"}),a=e.Scale.extend({buildTicks:function(t){this.ticks=this.chart.data.labels},getLabelForIndex:function(t,e){return this.ticks[t]},getPixelForValue:function(t,e,i,a){if(this.isHorizontal()){var s=this.width-(this.paddingLeft+this.paddingRight),o=s/Math.max(this.chart.data.labels.length-(this.options.gridLines.offsetGridLines?0:1),1),n=o*e+this.paddingLeft;return this.options.gridLines.offsetGridLines&&a&&(n+=o/2),this.left+Math.round(n)}var r=this.height-(this.paddingTop+this.paddingBottom),h=r/Math.max(this.chart.data.labels.length-(this.options.gridLines.offsetGridLines?0:1),1),l=h*e+this.paddingTop;return this.options.gridLines.offsetGridLines&&a&&(l+=h/2),this.top+Math.round(l)}});e.scaleService.registerScaleType("category",a,i)}.call(this),function(){"use strict";var t=this,e=t.Chart,i=e.helpers,a={position:"left",ticks:{callback:function(t,e,a){var s=a[1]-a[0];Math.abs(s)>1&&t!==Math.floor(t)&&(s=t-Math.floor(t));var o=i.log10(Math.abs(s)),n="";if(0!==t){var r=-1*Math.floor(o);r=Math.max(Math.min(r,20),0),n=t.toFixed(r)}else n="0";return n}}},s=e.Scale.extend({determineDataLimits:function(){if(this.min=null,this.max=null,this.options.stacked){var t={};i.each(this.chart.data.datasets,function(e){void 0===t[e.type]&&(t[e.type]={positiveValues:[],negativeValues:[]});var a=t[e.type].positiveValues,s=t[e.type].negativeValues;i.isDatasetVisible(e)&&(this.isHorizontal()?e.xAxisID===this.id:e.yAxisID===this.id)&&i.each(e.data,function(t,e){var i=+this.getRightValue(t);isNaN(i)||(a[e]=a[e]||0,s[e]=s[e]||0,this.options.relativePoints?a[e]=100:0>i?s[e]+=i:a[e]+=i)},this)},this),i.each(t,function(t){var e=t.positiveValues.concat(t.negativeValues),a=i.min(e),s=i.max(e);this.min=null===this.min?a:Math.min(this.min,a),this.max=null===this.max?s:Math.max(this.max,s)},this)}else i.each(this.chart.data.datasets,function(t){i.isDatasetVisible(t)&&(this.isHorizontal()?t.xAxisID===this.id:t.yAxisID===this.id)&&i.each(t.data,function(t,e){var i=+this.getRightValue(t);isNaN(i)||(null===this.min?this.min=i:i<this.min&&(this.min=i),null===this.max?this.max=i:i>this.max&&(this.max=i))},this)},this);if(this.options.ticks.beginAtZero){var e=i.sign(this.min),a=i.sign(this.max);0>e&&0>a?this.max=0:e>0&&a>0&&(this.min=0)}void 0!==this.options.ticks.min?this.min=this.options.ticks.min:void 0!==this.options.ticks.suggestedMin&&(this.min=Math.min(this.min,this.options.ticks.suggestedMin)),void 0!==this.options.ticks.max?this.max=this.options.ticks.max:void 0!==this.options.ticks.suggestedMax&&(this.max=Math.max(this.max,this.options.ticks.suggestedMax)),this.min===this.max&&(this.min--,this.max++)},buildTicks:function(){this.ticks=[];var t;t=this.isHorizontal()?Math.min(this.options.ticks.maxTicksLimit?this.options.ticks.maxTicksLimit:11,Math.ceil(this.width/50)):Math.min(this.options.ticks.maxTicksLimit?this.options.ticks.maxTicksLimit:11,Math.ceil(this.height/(2*this.options.ticks.fontSize))),t=Math.max(2,t);var e=i.niceNum(this.max-this.min,!1),a=i.niceNum(e/(t-1),!0),s=Math.floor(this.min/a)*a,o=Math.ceil(this.max/a)*a,n=Math.ceil((o-s)/a);this.ticks.push(void 0!==this.options.ticks.min?this.options.ticks.min:s);for(var r=1;n>r;++r)this.ticks.push(s+r*a);this.ticks.push(void 0!==this.options.ticks.max?this.options.ticks.max:o),("left"==this.options.position||"right"==this.options.position)&&this.ticks.reverse(),this.max=i.max(this.ticks),this.min=i.min(this.ticks),this.ticksAsNumbers=this.ticks.slice(),this.options.ticks.reverse?(this.ticks.reverse(),this.start=this.max,this.end=this.min):(this.start=this.min,this.end=this.max),this.zeroLineIndex=this.ticks.indexOf(0)},getLabelForIndex:function(t,e){return+this.getRightValue(this.chart.data.datasets[e].data[t])},getPixelForValue:function(t,e,i,a){var s,o=+this.getRightValue(t),n=this.end-this.start;if(this.isHorizontal()){var r=this.width-(this.paddingLeft+this.paddingRight);return s=this.left+r/n*(o-this.start),Math.round(s+this.paddingLeft)}var h=this.height-(this.paddingTop+this.paddingBottom);return s=this.bottom-this.paddingBottom-h/n*(o-this.start),Math.round(s)},getPixelForTick:function(t,e){return this.getPixelForValue(this.ticksAsNumbers[t],null,null,e)}});e.scaleService.registerScaleType("linear",s,a)}.call(this),function(){"use strict";var t=this,e=t.Chart,i=e.helpers,a={position:"left",ticks:{callback:function(t,i,a){var s=t/Math.pow(10,Math.floor(e.helpers.log10(t)));return 1===s||2===s||5===s||0===i||i===a.length-1?t.toExponential():""}}},s=e.Scale.extend({determineDataLimits:function(){if(this.min=null,this.max=null,this.options.stacked){var t={};i.each(this.chart.data.datasets,function(e){i.isDatasetVisible(e)&&(this.isHorizontal()?e.xAxisID===this.id:e.yAxisID===this.id)&&(void 0===t[e.type]&&(t[e.type]=[]),i.each(e.data,function(i,a){var s=t[e.type],o=+this.getRightValue(i);isNaN(o)||(s[a]=s[a]||0,this.options.relativePoints?s[a]=100:s[a]+=o)},this))},this),i.each(t,function(t){var e=i.min(t),a=i.max(t);this.min=null===this.min?e:Math.min(this.min,e),this.max=null===this.max?a:Math.max(this.max,a)},this)}else i.each(this.chart.data.datasets,function(t){i.isDatasetVisible(t)&&(this.isHorizontal()?t.xAxisID===this.id:t.yAxisID===this.id)&&i.each(t.data,function(t,e){var i=+this.getRightValue(t);isNaN(i)||(null===this.min?this.min=i:i<this.min&&(this.min=i),null===this.max?this.max=i:i>this.max&&(this.max=i))},this)},this);this.min=void 0!==this.options.ticks.min?this.options.ticks.min:this.min,this.max=void 0!==this.options.ticks.max?this.options.ticks.max:this.max,this.min===this.max&&(0!==this.min&&null!==this.min?(this.min=Math.pow(10,Math.floor(i.log10(this.min))-1),this.max=Math.pow(10,Math.floor(i.log10(this.max))+1)):(this.min=1,this.max=10))},buildTicks:function(){this.tickValues=[];for(var t=void 0!==this.options.ticks.min?this.options.ticks.min:Math.pow(10,Math.floor(i.log10(this.min)));t<this.max;){this.tickValues.push(t);var e=Math.floor(i.log10(t)),a=Math.floor(t/Math.pow(10,e))+1;10===a&&(a=1,++e),t=a*Math.pow(10,e)}var s=void 0!==this.options.ticks.max?this.options.ticks.max:t;this.tickValues.push(s),("left"==this.options.position||"right"==this.options.position)&&this.tickValues.reverse(),this.max=i.max(this.tickValues),this.min=i.min(this.tickValues),this.options.ticks.reverse?(this.tickValues.reverse(),this.start=this.max,this.end=this.min):(this.start=this.min,this.end=this.max),this.ticks=this.tickValues.slice()},getLabelForIndex:function(t,e){return+this.getRightValue(this.chart.data.datasets[e].data[t])},getPixelForTick:function(t,e){return this.getPixelForValue(this.tickValues[t],null,null,e)},getPixelForValue:function(t,e,a,s){var o,n=+this.getRightValue(t),r=i.log10(this.end)-i.log10(this.start);if(this.isHorizontal()){if(0!==n){var h=this.width-(this.paddingLeft+this.paddingRight);return o=this.left+h/r*(i.log10(n)-i.log10(this.start)),o+this.paddingLeft}o=this.left+this.paddingLeft}else{if(0!==n){var l=this.height-(this.paddingTop+this.paddingBottom);return this.bottom-this.paddingBottom-l/r*(i.log10(n)-i.log10(this.start))}o=this.top+this.paddingTop}}});e.scaleService.registerScaleType("logarithmic",s,a)}.call(this),function(){"use strict";var t=this,e=t.Chart,i=e.helpers,a={display:!0,animate:!0,lineArc:!1,position:"chartArea",angleLines:{display:!0,color:"rgba(0, 0, 0, 0.1)",lineWidth:1},ticks:{showLabelBackdrop:!0,backdropColor:"rgba(255,255,255,0.75)",backdropPaddingY:2,backdropPaddingX:2},pointLabels:{fontFamily:"'Arial'",fontStyle:"normal",fontSize:10,fontColor:"#666"}},s=e.Scale.extend({getValueCount:function(){return this.chart.data.labels.length},setDimensions:function(){this.width=this.maxWidth,this.height=this.maxHeight,this.xCenter=Math.round(this.width/2),this.yCenter=Math.round(this.height/2);var t=i.min([this.height,this.width]);this.drawingArea=this.options.display?t/2-(this.options.ticks.fontSize/2+this.options.ticks.backdropPaddingY):t/2},determineDataLimits:function(){if(this.min=null,this.max=null,i.each(this.chart.data.datasets,function(t){i.isDatasetVisible(t)&&i.each(t.data,function(t,e){var i=+this.getRightValue(t);isNaN(i)||(null===this.min?this.min=i:i<this.min&&(this.min=i),null===this.max?this.max=i:i>this.max&&(this.max=i))},this)},this),this.min===this.max&&(this.min--,this.max++),this.options.ticks.beginAtZero){var t=i.sign(this.min),e=i.sign(this.max);0>t&&0>e?this.max=0:t>0&&e>0&&(this.min=0)}},buildTicks:function(){this.ticks=[];var t=Math.min(this.options.ticks.maxTicksLimit?this.options.ticks.maxTicksLimit:11,Math.ceil(this.drawingArea/(1.5*this.options.ticks.fontSize)));t=Math.max(2,t);for(var e=i.niceNum(this.max-this.min,!1),a=i.niceNum(e/(t-1),!0),s=Math.floor(this.min/a)*a,o=Math.ceil(this.max/a)*a,n=s;o>=n;n+=a)this.ticks.push(n);this.max=i.max(this.ticks),this.min=i.min(this.ticks),this.options.ticks.reverse?(this.ticks.reverse(),this.start=this.max,this.end=this.min):(this.start=this.min,this.end=this.max),this.zeroLineIndex=this.ticks.indexOf(0)},getLabelForIndex:function(t,e){return+this.getRightValue(this.chart.data.datasets[e].data[t]);
},getCircumference:function(){return 2*Math.PI/this.getValueCount()},fit:function(){var t,e,a,s,o,n,r,h,l,c,d,u,g=i.min([this.height/2-this.options.pointLabels.fontSize-5,this.width/2]),m=this.width,f=0;for(this.ctx.font=i.fontString(this.options.pointLabels.fontSize,this.options.pointLabels.fontStyle,this.options.pointLabels.fontFamily),e=0;e<this.getValueCount();e++)t=this.getPointPosition(e,g),a=this.ctx.measureText(this.options.ticks.callback(this.chart.data.labels[e])).width+5,0===e||e===this.getValueCount()/2?(s=a/2,t.x+s>m&&(m=t.x+s,o=e),t.x-s<f&&(f=t.x-s,r=e)):e<this.getValueCount()/2?t.x+a>m&&(m=t.x+a,o=e):e>this.getValueCount()/2&&t.x-a<f&&(f=t.x-a,r=e);l=f,c=Math.ceil(m-this.width),n=this.getIndexAngle(o),h=this.getIndexAngle(r),d=c/Math.sin(n+Math.PI/2),u=l/Math.sin(h+Math.PI/2),d=i.isNumber(d)?d:0,u=i.isNumber(u)?u:0,this.drawingArea=Math.round(g-(u+d)/2),this.setCenterPoint(u,d)},setCenterPoint:function(t,e){var i=this.width-e-this.drawingArea,a=t+this.drawingArea;this.xCenter=Math.round((a+i)/2+this.left),this.yCenter=Math.round(this.height/2+this.top)},getIndexAngle:function(t){var e=2*Math.PI/this.getValueCount();return t*e-Math.PI/2},getDistanceFromCenterForValue:function(t){if(null===t)return 0;var e=this.drawingArea/(this.max-this.min);return this.options.reverse?(this.max-t)*e:(t-this.min)*e},getPointPosition:function(t,e){var i=this.getIndexAngle(t);return{x:Math.round(Math.cos(i)*e)+this.xCenter,y:Math.round(Math.sin(i)*e)+this.yCenter}},getPointPositionForValue:function(t,e){return this.getPointPosition(t,this.getDistanceFromCenterForValue(e))},draw:function(){if(this.options.display){var t=this.ctx;if(i.each(this.ticks,function(e,a){if(a>0||this.options.reverse){var s=this.getDistanceFromCenterForValue(this.ticks[a]),o=this.yCenter-s;if(this.options.gridLines.display)if(t.strokeStyle=this.options.gridLines.color,t.lineWidth=this.options.gridLines.lineWidth,this.options.lineArc)t.beginPath(),t.arc(this.xCenter,this.yCenter,s,0,2*Math.PI),t.closePath(),t.stroke();else{t.beginPath();for(var n=0;n<this.getValueCount();n++){var r=this.getPointPosition(n,this.getDistanceFromCenterForValue(this.ticks[a]));0===n?t.moveTo(r.x,r.y):t.lineTo(r.x,r.y)}t.closePath(),t.stroke()}if(this.options.ticks.display){if(t.font=i.fontString(this.options.ticks.fontSize,this.options.ticks.fontStyle,this.options.ticks.fontFamily),this.options.ticks.showLabelBackdrop){var h=t.measureText(e).width;t.fillStyle=this.options.ticks.backdropColor,t.fillRect(this.xCenter-h/2-this.options.ticks.backdropPaddingX,o-this.options.ticks.fontSize/2-this.options.ticks.backdropPaddingY,h+2*this.options.ticks.backdropPaddingX,this.options.ticks.fontSize+2*this.options.ticks.backdropPaddingY)}t.textAlign="center",t.textBaseline="middle",t.fillStyle=this.options.ticks.fontColor,t.fillText(e,this.xCenter,o)}}},this),!this.options.lineArc){t.lineWidth=this.options.angleLines.lineWidth,t.strokeStyle=this.options.angleLines.color;for(var e=this.getValueCount()-1;e>=0;e--){if(this.options.angleLines.display){var a=this.getPointPosition(e,this.getDistanceFromCenterForValue(this.options.reverse?this.min:this.max));t.beginPath(),t.moveTo(this.xCenter,this.yCenter),t.lineTo(a.x,a.y),t.stroke(),t.closePath()}var s=this.getPointPosition(e,this.getDistanceFromCenterForValue(this.options.reverse?this.min:this.max)+5);t.font=i.fontString(this.options.pointLabels.fontSize,this.options.pointLabels.fontStyle,this.options.pointLabels.fontFamily),t.fillStyle=this.options.pointLabels.fontColor;var o=this.chart.data.labels.length,n=this.chart.data.labels.length/2,r=n/2,h=r>e||e>o-r,l=e===r||e===o-r;0===e?t.textAlign="center":e===n?t.textAlign="center":n>e?t.textAlign="left":t.textAlign="right",l?t.textBaseline="middle":h?t.textBaseline="bottom":t.textBaseline="top",t.fillText(this.chart.data.labels[e],s.x,s.y)}}}}});e.scaleService.registerScaleType("radialLinear",s,a)}.call(this),function(t){"use strict";if(!t)return void console.warn("Chart.js - Moment.js could not be found! You must include it before Chart.js to use the time scale. Download at path_to_url");var e=this,i=e.Chart,a=i.helpers,s={units:[{name:"millisecond",steps:[1,2,5,10,20,50,100,250,500]},{name:"second",steps:[1,2,5,10,30]},{name:"minute",steps:[1,2,5,10,30]},{name:"hour",steps:[1,2,3,6,12]},{name:"day",steps:[1,2,5]},{name:"week",maxStep:4},{name:"month",maxStep:3},{name:"quarter",maxStep:4},{name:"year",maxStep:!1}]},o={position:"bottom",time:{format:!1,unit:!1,round:!1,displayFormat:!1,displayFormats:{millisecond:"SSS [ms]",second:"h:mm:ss a",minute:"h:mm:ss a",hour:"MMM D, hA",day:"ll",week:"ll",month:"MMM YYYY",quarter:"[Q]Q - YYYY",year:"YYYY"}}},n=i.Scale.extend({getLabelMoment:function(t,e){return this.labelMoments[t][e]},determineDataLimits:function(){this.labelMoments=[];var e=[];this.chart.data.labels&&this.chart.data.labels.length>0?(a.each(this.chart.data.labels,function(t,i){var a=this.parseTime(t);this.options.time.round&&a.startOf(this.options.time.round),e.push(a)},this),this.options.time.min?this.firstTick=this.parseTime(this.options.time.min):this.firstTick=t.min.call(this,e),this.options.time.max?this.lastTick=this.parseTime(this.options.time.max):this.lastTick=t.max.call(this,e)):(this.firstTick=null,this.lastTick=null),a.each(this.chart.data.datasets,function(i,s){var o=[];"object"==typeof i.data[0]?a.each(i.data,function(e,i){var a=this.parseTime(this.getRightValue(e));this.options.time.round&&a.startOf(this.options.time.round),o.push(a),this.firstTick=null!==this.firstTick?t.min(this.firstTick,a):a,this.lastTick=null!==this.lastTick?t.max(this.lastTick,a):a},this):o=e,this.labelMoments.push(o)},this),this.firstTick=(this.firstTick||t()).clone(),this.lastTick=(this.lastTick||t()).clone()},buildTicks:function(t){if(this.ticks=[],this.unitScale=1,this.options.time.unit)this.tickUnit=this.options.time.unit||"day",this.displayFormat=this.options.time.displayFormats[this.tickUnit],this.tickRange=Math.ceil(this.lastTick.diff(this.firstTick,this.tickUnit,!0));else{var e=this.width-(this.paddingLeft+this.paddingRight),i=e/(this.options.ticks.fontSize+10),o=this.options.time.round?0:2;this.tickUnit="millisecond",this.tickRange=Math.ceil(this.lastTick.diff(this.firstTick,this.tickUnit,!0)+o),this.displayFormat=this.options.time.displayFormats[this.tickUnit];for(var n=0,r=s.units[n];n<s.units.length;){if(this.unitScale=1,a.isArray(r.steps)&&Math.ceil(this.tickRange/i)<a.max(r.steps)){for(var h=0;h<r.steps.length;++h)if(r.steps[h]>Math.ceil(this.tickRange/i)){this.unitScale=r.steps[h];break}break}if(r.maxStep===!1||Math.ceil(this.tickRange/i)<r.maxStep){this.unitScale=Math.ceil(this.tickRange/i);break}++n,r=s.units[n],this.tickUnit=r.name,this.tickRange=Math.ceil(this.lastTick.diff(this.firstTick,this.tickUnit)+o),this.displayFormat=this.options.time.displayFormats[r.name]}}this.firstTick.startOf(this.tickUnit),this.lastTick.endOf(this.tickUnit),this.smallestLabelSeparation=this.width,a.each(this.chart.data.datasets,function(t,e){for(var i=1;i<this.labelMoments[e].length;i++)this.smallestLabelSeparation=Math.min(this.smallestLabelSeparation,this.labelMoments[e][i].diff(this.labelMoments[e][i-1],this.tickUnit,!0))},this),this.options.time.displayFormat&&(this.displayFormat=this.options.time.displayFormat);for(var l=0;l<=this.tickRange;++l)if(l%this.unitScale===0)this.ticks.push(this.firstTick.clone().add(l,this.tickUnit));else if(l===this.tickRange){this.tickRange=Math.ceil(this.tickRange/this.unitScale)*this.unitScale,this.ticks.push(this.firstTick.clone().add(this.tickRange,this.tickUnit)),this.lastTick=this.ticks[this.ticks.length-1].clone();break}},getLabelForIndex:function(t,e){var i=this.chart.data.labels&&t<this.chart.data.labels.length?this.chart.data.labels[t]:"";return"object"==typeof this.chart.data.datasets[e].data[0]&&(i=this.getRightValue(this.chart.data.datasets[e].data[t])),this.options.time.tooltipFormat&&(i=this.parseTime(i).format(this.options.time.tooltipFormat)),i},convertTicksToLabels:function(){this.ticks=this.ticks.map(function(t,e,i){var a=t.format(this.displayFormat);return this.options.ticks.userCallback?this.options.ticks.userCallback(a,e,i):a},this)},getPixelForValue:function(t,e,i,a){var s=this.getLabelMoment(i,e),o=s.diff(this.firstTick,this.tickUnit,!0),n=o/this.tickRange;if(this.isHorizontal()){var r=this.width-(this.paddingLeft+this.paddingRight),h=(r/Math.max(this.ticks.length-1,1),r*n+this.paddingLeft);return this.left+Math.round(h)}var l=this.height-(this.paddingTop+this.paddingBottom),c=(l/Math.max(this.ticks.length-1,1),l*n+this.paddingTop);return this.top+Math.round(c)},parseTime:function(e){return"function"==typeof e.getMonth||"number"==typeof e?t(e):e.isValid&&e.isValid()?e:"string"!=typeof this.options.time.format&&this.options.time.format.call?this.options.time.format(e):t(e,this.options.time.format)}});i.scaleService.registerScaleType("time",n,o)}.call(this,t),function(){"use strict";var t=this,e=t.Chart,i=e.helpers;e.defaults.global.elements.arc={backgroundColor:e.defaults.global.defaultColor,borderColor:"#fff",borderWidth:2},e.elements.Arc=e.Element.extend({inLabelRange:function(t){var e=this._view;return e?Math.pow(t-e.x,2)<Math.pow(e.radius+e.hoverRadius,2):!1},inRange:function(t,e){var a=this._view;if(a){var s=i.getAngleFromPoint(a,{x:t,y:e}),o=a.startAngle<-.5*Math.PI?a.startAngle+2*Math.PI:a.startAngle>1.5*Math.PI?a.startAngle-2*Math.PI:a.startAngle,n=a.endAngle<-.5*Math.PI?a.endAngle+2*Math.PI:a.endAngle>1.5*Math.PI?a.endAngle-2*Math.PI:a.endAngle,r=s.angle>=o&&s.angle<=n,h=s.distance>=a.innerRadius&&s.distance<=a.outerRadius;return r&&h}return!1},tooltipPosition:function(){var t=this._view,e=t.startAngle+(t.endAngle-t.startAngle)/2,i=(t.outerRadius-t.innerRadius)/2+t.innerRadius;return{x:t.x+Math.cos(e)*i,y:t.y+Math.sin(e)*i}},draw:function(){var t=this._chart.ctx,e=this._view;t.beginPath(),t.arc(e.x,e.y,e.outerRadius,e.startAngle,e.endAngle),t.arc(e.x,e.y,e.innerRadius,e.endAngle,e.startAngle,!0),t.closePath(),t.strokeStyle=e.borderColor,t.lineWidth=e.borderWidth,t.fillStyle=e.backgroundColor,t.fill(),t.lineJoin="bevel",e.borderWidth&&t.stroke()}})}.call(this),function(){"use strict";var t=this,e=t.Chart,i=e.helpers;e.defaults.global.elements.line={tension:.4,backgroundColor:e.defaults.global.defaultColor,borderWidth:3,borderColor:e.defaults.global.defaultColor,borderCapStyle:"butt",borderDash:[],borderDashOffset:0,borderJoinStyle:"miter",fill:!0},e.elements.Line=e.Element.extend({lineToNextPoint:function(t,e,i,a,s){var o=this._chart.ctx;e._view.skip?a.call(this,t,e,i):t._view.skip?s.call(this,t,e,i):0===e._view.tension?o.lineTo(e._view.x,e._view.y):o.bezierCurveTo(t._view.controlPointNextX,t._view.controlPointNextY,e._view.controlPointPreviousX,e._view.controlPointPreviousY,e._view.x,e._view.y)},draw:function(){function t(t){n._view.skip||r._view.skip?t&&o.lineTo(a._view.scaleZero.x,a._view.scaleZero.y):o.bezierCurveTo(r._view.controlPointNextX,r._view.controlPointNextY,n._view.controlPointPreviousX,n._view.controlPointPreviousY,n._view.x,n._view.y)}var a=this,s=this._view,o=this._chart.ctx,n=this._children[0],r=this._children[this._children.length-1];o.save(),this._children.length>0&&s.fill&&(o.beginPath(),i.each(this._children,function(t,e){var a=i.previousItem(this._children,e),n=i.nextItem(this._children,e);0===e?(this._loop?o.moveTo(s.scaleZero.x,s.scaleZero.y):o.moveTo(t._view.x,s.scaleZero),t._view.skip?this._loop||o.moveTo(n._view.x,this._view.scaleZero):o.lineTo(t._view.x,t._view.y)):this.lineToNextPoint(a,t,n,function(t,e,i){this._loop?o.lineTo(this._view.scaleZero.x,this._view.scaleZero.y):(o.lineTo(t._view.x,this._view.scaleZero),o.moveTo(i._view.x,this._view.scaleZero))},function(t,e){o.lineTo(e._view.x,e._view.y)})},this),this._loop?t(!0):(o.lineTo(this._children[this._children.length-1]._view.x,s.scaleZero),o.lineTo(this._children[0]._view.x,s.scaleZero)),o.fillStyle=s.backgroundColor||e.defaults.global.defaultColor,o.closePath(),o.fill()),o.lineCap=s.borderCapStyle||e.defaults.global.elements.line.borderCapStyle,o.setLineDash&&o.setLineDash(s.borderDash||e.defaults.global.elements.line.borderDash),o.lineDashOffset=s.borderDashOffset||e.defaults.global.elements.line.borderDashOffset,o.lineJoin=s.borderJoinStyle||e.defaults.global.elements.line.borderJoinStyle,o.lineWidth=s.borderWidth||e.defaults.global.elements.line.borderWidth,o.strokeStyle=s.borderColor||e.defaults.global.defaultColor,o.beginPath(),i.each(this._children,function(t,e){var a=i.previousItem(this._children,e),s=i.nextItem(this._children,e);0===e?o.moveTo(t._view.x,t._view.y):this.lineToNextPoint(a,t,s,function(t,e,i){o.moveTo(i._view.x,i._view.y)},function(t,e){o.moveTo(e._view.x,e._view.y)})},this),this._loop&&this._children.length>0&&t(),o.stroke(),o.restore()}})}.call(this),function(){"use strict";var t=this,e=t.Chart;e.helpers;e.defaults.global.elements.point={radius:3,backgroundColor:e.defaults.global.defaultColor,borderWidth:1,borderColor:e.defaults.global.defaultColor,hitRadius:1,hoverRadius:4,hoverBorderWidth:1},e.elements.Point=e.Element.extend({inRange:function(t,e){var i=this._view;if(i){var a=i.hitRadius+i.radius;return Math.pow(t-i.x,2)+Math.pow(e-i.y,2)<Math.pow(a,2)}return!1},inLabelRange:function(t){var e=this._view;return e?Math.pow(t-e.x,2)<Math.pow(e.radius+e.hitRadius,2):!1},tooltipPosition:function(){var t=this._view;return{x:t.x,y:t.y,padding:t.radius+t.borderWidth}},draw:function(){var t=this._view,i=this._chart.ctx;t.skip||(t.radius>0||t.borderWidth>0)&&(i.beginPath(),i.arc(t.x,t.y,t.radius||e.defaults.global.elements.point.radius,0,2*Math.PI),i.closePath(),i.strokeStyle=t.borderColor||e.defaults.global.defaultColor,i.lineWidth=t.borderWidth||e.defaults.global.elements.point.borderWidth,i.fillStyle=t.backgroundColor||e.defaults.global.defaultColor,i.fill(),i.stroke())}})}.call(this),function(){"use strict";var t=this,e=t.Chart;e.helpers;e.defaults.global.elements.rectangle={backgroundColor:e.defaults.global.defaultColor,borderWidth:0,borderColor:e.defaults.global.defaultColor},e.elements.Rectangle=e.Element.extend({draw:function(){var t=this._chart.ctx,e=this._view,i=e.width/2,a=e.x-i,s=e.x+i,o=e.base-(e.base-e.y),n=e.borderWidth/2;e.borderWidth&&(a+=n,s-=n,o+=n),t.beginPath(),t.fillStyle=e.backgroundColor,t.strokeStyle=e.borderColor,t.lineWidth=e.borderWidth,t.moveTo(a,e.base),t.lineTo(a,o),t.lineTo(s,o),t.lineTo(s,e.base),t.fill(),e.borderWidth&&t.stroke()},height:function(){var t=this._view;return t.base-t.y},inRange:function(t,e){var i=this._view,a=!1;return i&&(a=i.y<i.base?t>=i.x-i.width/2&&t<=i.x+i.width/2&&e>=i.y&&e<=i.base:t>=i.x-i.width/2&&t<=i.x+i.width/2&&e>=i.base&&e<=i.y),a},inLabelRange:function(t){var e=this._view;return e?t>=e.x-e.width/2&&t<=e.x+e.width/2:!1},tooltipPosition:function(){var t=this._view;return{x:t.x,y:t.y}}})}.call(this),function(){"use strict";var t=this,e=t.Chart;e.helpers;e.Bar=function(t,i){return i.type="bar",new e(t,i)}}.call(this),function(){"use strict";var t=this,e=t.Chart,i=(e.helpers,{hover:{mode:"single"},scales:{xAxes:[{type:"linear",position:"bottom",id:"x-axis-0"}],yAxes:[{type:"linear",position:"left",id:"y-axis-0"}]},tooltips:{callbacks:{title:function(t,e){return""},label:function(t,e){return"("+t.xLabel+", "+t.yLabel+")"}}}});e.defaults.bubble=i,e.Bubble=function(t,i){return i.type="bubble",new e(t,i)}}.call(this),function(){"use strict";var t=this,e=t.Chart;e.helpers;e.Doughnut=function(t,i){return i.type="doughnut",new e(t,i)}}.call(this),function(){"use strict";var t=this,e=t.Chart;e.helpers;e.Line=function(t,i){return i.type="line",new e(t,i)}}.call(this),function(){"use strict";var t=this,e=t.Chart;e.helpers;e.PolarArea=function(t,i){return i.type="polarArea",new e(t,i)}}.call(this),function(){"use strict";var t=this,e=t.Chart,i=e.helpers,a={aspectRatio:1};e.Radar=function(t,s){return s.options=i.configMerge(a,s.options),s.type="radar",new e(t,s)}}.call(this),function(){"use strict";var t=this,e=t.Chart,i=(e.helpers,{hover:{mode:"single"},scales:{xAxes:[{type:"linear",position:"bottom",id:"x-axis-1"}],yAxes:[{type:"linear",position:"left",id:"y-axis-1"}]},tooltips:{callbacks:{title:function(t,e){return""},label:function(t,e){return"("+t.xLabel+", "+t.yLabel+")"}}}});e.defaults.scatter=i,e.controllers.scatter=e.controllers.line,e.Scatter=function(t,i){return i.type="scatter",new e(t,i)}}.call(this),Chart});
``` | /content/code_sandbox/public/vendor/chartjs/Chart.min.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 41,341 |
```html
<!doctype html>
<html>
<head>
<title>Doughnut Chart</title>
<script src="../Chart.js"></script>
<script src="path_to_url"></script>
<style>
body {
padding: 0;
margin: 0;
}
#canvas-holder {
width: 30%;
}
</style>
</head>
<body>
<div id="canvas-holder" style="width:100%">
<canvas id="chart-area" />
</div>
<button id="randomizeData">Randomize Data</button>
<button id="addDataset">Add Dataset</button>
<button id="removeDataset">Remove Dataset</button>
<button id="addData">Add Data</button>
<button id="removeData">Remove Data</button>
<div>
<h3>Legend</h3>
<div id="legendContainer">
</div>
</div>
<script>
var randomScalingFactor = function() {
return Math.round(Math.random() * 100);
};
var randomColorFactor = function() {
return Math.round(Math.random() * 255);
};
var randomColor = function(opacity) {
return 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',' + (opacity || '.3') + ')';
};
var config = {
type: 'doughnut',
data: {
datasets: [{
data: [
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
],
backgroundColor: [
"#F7464A",
"#46BFBD",
"#FDB45C",
"#949FB1",
"#4D5360",
],
label: 'Dataset 1'
}, {
hidden: true,
data: [
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
],
backgroundColor: [
"#F7464A",
"#46BFBD",
"#FDB45C",
"#949FB1",
"#4D5360",
],
label: 'Dataset 2'
}, {
data: [
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
],
backgroundColor: [
"#F7464A",
"#46BFBD",
"#FDB45C",
"#949FB1",
"#4D5360",
],
label: 'Dataset 3'
}],
labels: [
"Red",
"Green",
"Yellow",
"Grey",
"Dark Grey"
]
},
options: {
responsive: true,
legend: {
position: 'top',
},
title: {
display: true,
text: 'Our Favorite Datasets'
}
}
};
function updateLegend() {
$legendContainer = $('#legendContainer');
$legendContainer.empty();
$legendContainer.append(window.myDoughnut.generateLegend());
}
window.onload = function() {
var ctx = document.getElementById("chart-area").getContext("2d");
window.myDoughnut = new Chart(ctx, config);
console.log(window.myDoughnut);
updateLegend();
};
$('#randomizeData').click(function() {
$.each(config.data.datasets, function(i, dataset) {
dataset.data = dataset.data.map(function() {
return randomScalingFactor();
});
dataset.backgroundColor = dataset.backgroundColor.map(function() {
return randomColor(0.7);
});
});
window.myDoughnut.update();
updateLegend();
});
$('#addDataset').click(function() {
var newDataset = {
backgroundColor: [],
data: [],
label: 'New dataset ' + config.data.datasets.length,
};
for (var index = 0; index < config.data.labels.length; ++index) {
newDataset.data.push(randomScalingFactor());
newDataset.backgroundColor.push(randomColor(0.7));
}
config.data.datasets.push(newDataset);
window.myDoughnut.update();
updateLegend();
});
$('#addData').click(function() {
if (config.data.datasets.length > 0) {
config.data.labels.push('data #' + config.data.labels.length);
$.each(config.data.datasets, function(index, dataset) {
dataset.data.push(randomScalingFactor());
dataset.backgroundColor.push(randomColor(0.7));
});
window.myDoughnut.update();
updateLegend();
}
});
$('#removeDataset').click(function() {
config.data.datasets.splice(0, 1);
window.myDoughnut.update();
updateLegend();
});
$('#removeData').click(function() {
config.data.labels.splice(-1, 1); // remove the label first
config.data.datasets.forEach(function(dataset, datasetIndex) {
dataset.data.pop();
dataset.backgroundColor.pop();
});
window.myDoughnut.update();
updateLegend();
});
</script>
</body>
</html>
``` | /content/code_sandbox/public/vendor/chartjs/samples/doughnut.html | html | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 1,106 |
```html
<!doctype html>
<html>
<head>
<title>Line Chart</title>
<script src="../Chart.js"></script>
<script src="../node_modules/jquery/dist/jquery.min.js"></script>
<style>
canvas {
-webkit-box-shadow: 0 0 20px 0 rgba(0, 0, 0, .5);
}
</style>
</head>
<body>
<div style="width:100%;">
<canvas id="canvas" style="width:100%;height:100%"></canvas>
</div>
<br>
<br>
<button id="randomizeData">Randomize Data</button>
<button id="changeDataObject">Change Data Object</button>
<button id="addDataset">Add Dataset</button>
<button id="removeDataset">Remove Dataset</button>
<button id="addData">Add Data</button>
<button id="removeData">Remove Data</button>
<div>
<h3>Legend</h3>
<div id="legendContainer">
</div>
</div>
<script>
var randomScalingFactor = function() {
return Math.round(Math.random() * 100);
//return 0;
};
var randomColorFactor = function() {
return Math.round(Math.random() * 255);
};
var randomColor = function(opacity) {
return 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',' + (opacity || '.3') + ')';
};
var config = {
type: 'line',
data: {
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [{
label: "My First dataset",
data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()],
fill: false,
borderDash: [5, 5],
}, {
hidden: true,
label: 'hidden dataset',
data: [],
}, {
label: "My Second dataset",
data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()],
}]
},
options: {
responsive: true,
tooltips: {
mode: 'label',
callbacks: {
// beforeTitle: function() {
// return '...beforeTitle';
// },
// afterTitle: function() {
// return '...afterTitle';
// },
// beforeBody: function() {
// return '...beforeBody';
// },
// afterBody: function() {
// return '...afterBody';
// },
// beforeFooter: function() {
// return '...beforeFooter';
// },
// footer: function() {
// return 'Footer';
// },
// afterFooter: function() {
// return '...afterFooter';
// },
}
},
hover: {
mode: 'dataset'
},
scales: {
xAxes: [{
display: true,
scaleLabel: {
show: true,
labelString: 'Month'
}
}],
yAxes: [{
display: true,
scaleLabel: {
show: true,
labelString: 'Value'
},
ticks: {
suggestedMin: -10,
suggestedMax: 250,
}
}]
}
}
};
$.each(config.data.datasets, function(i, dataset) {
dataset.borderColor = randomColor(0.4);
dataset.backgroundColor = randomColor(0.5);
dataset.pointBorderColor = randomColor(0.7);
dataset.pointBackgroundColor = randomColor(0.5);
dataset.pointBorderWidth = 1;
});
console.log(config.data);
window.onload = function() {
var ctx = document.getElementById("canvas").getContext("2d");
window.myLine = new Chart(ctx, config);
updateLegend();
};
function updateLegend() {
$legendContainer = $('#legendContainer');
$legendContainer.empty();
$legendContainer.append(window.myLine.generateLegend());
}
$('#randomizeData').click(function() {
$.each(config.data.datasets, function(i, dataset) {
dataset.data = dataset.data.map(function() {
return randomScalingFactor();
});
});
window.myLine.update();
updateLegend();
});
$('#changeDataObject').click(function() {
config.data = {
labels: ["July", "August", "September", "October", "November", "December"],
datasets: [{
label: "My First dataset",
data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()],
fill: false,
}, {
label: "My Second dataset",
fill: false,
data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()],
}]
};
$.each(config.data.datasets, function(i, dataset) {
dataset.borderColor = randomColor(0.4);
dataset.backgroundColor = randomColor(0.5);
dataset.pointBorderColor = randomColor(0.7);
dataset.pointBackgroundColor = randomColor(0.5);
dataset.pointBorderWidth = 1;
});
// Update the chart
window.myLine.update();
});
$('#addDataset').click(function() {
var newDataset = {
label: 'Dataset ' + config.data.datasets.length,
borderColor: randomColor(0.4),
backgroundColor: randomColor(0.5),
pointBorderColor: randomColor(0.7),
pointBackgroundColor: randomColor(0.5),
pointBorderWidth: 1,
data: [],
};
for (var index = 0; index < config.data.labels.length; ++index) {
newDataset.data.push(randomScalingFactor());
}
config.data.datasets.push(newDataset);
window.myLine.update();
updateLegend();
});
$('#addData').click(function() {
if (config.data.datasets.length > 0) {
config.data.labels.push('dataset #' + config.data.labels.length);
$.each(config.data.datasets, function(i, dataset) {
dataset.data.push(randomScalingFactor());
});
window.myLine.update();
updateLegend();
}
});
$('#removeDataset').click(function() {
config.data.datasets.splice(0, 1);
window.myLine.update();
updateLegend();
});
$('#removeData').click(function() {
config.data.labels.splice(-1, 1); // remove the label first
config.data.datasets.forEach(function(dataset, datasetIndex) {
dataset.data.pop();
});
window.myLine.update();
updateLegend();
});
</script>
</body>
</html>
``` | /content/code_sandbox/public/vendor/chartjs/samples/line.html | html | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 1,496 |
```html
<!doctype html>
<html>
<head>
<title>Radar Chart</title>
<script src="../Chart.js"></script>
<script src="path_to_url"></script>
</head>
<body>
<div style="width:100%">
<canvas id="canvas"></canvas>
</div>
<button id="randomizeData">Randomize Data</button>
<button id="addDataset">Add Dataset</button>
<button id="removeDataset">Remove Dataset</button>
<button id="addData">Add Data</button>
<button id="removeData">Remove Data</button>
<div>
<h3>Legend</h3>
<div id="legendContainer">
</div>
</div>
<script>
var randomScalingFactor = function() {
return Math.round(Math.random() * 100);
};
var randomColorFactor = function() {
return Math.round(Math.random() * 255);
};
var randomColor = function(opacity) {
return 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',' + (opacity || '.3') + ')';
};
var config = {
type: 'radar',
data: {
labels: ["Eating", "Drinking", "Sleeping", "Designing", "Coding", "Cycling", "Running"],
datasets: [{
label: "My First dataset",
backgroundColor: "rgba(220,220,220,0.2)",
pointBackgroundColor: "rgba(220,220,220,1)",
data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()]
}, {
label: 'Hidden dataset',
hidden: true,
data: [],
}, {
label: "My Second dataset",
backgroundColor: "rgba(151,187,205,0.2)",
pointBackgroundColor: "rgba(151,187,205,1)",
hoverPointBackgroundColor: "#fff",
pointHighlightStroke: "rgba(151,187,205,1)",
data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()]
},]
},
options: {
legend: {
position: 'top',
},
title: {
display: true,
text: 'Our 3 Favorite Datasets'
},
scale: {
reverse: false,
ticks: {
beginAtZero: true
}
}
}
};
function updateLegend() {
$legendContainer = $('#legendContainer');
$legendContainer.empty();
$legendContainer.append(window.myRadar.generateLegend());
}
window.onload = function() {
window.myRadar = new Chart(document.getElementById("canvas"), config);
updateLegend();
};
$('#randomizeData').click(function() {
$.each(config.data.datasets, function(i, dataset) {
dataset.data = dataset.data.map(function() {
return randomScalingFactor();
});
});
window.myRadar.update();
updateLegend();
});
$('#addDataset').click(function() {
var newDataset = {
label: 'Dataset ' + config.data.datasets.length,
borderColor: randomColor(0.4),
backgroundColor: randomColor(0.5),
pointBorderColor: randomColor(0.7),
pointBackgroundColor: randomColor(0.5),
pointBorderWidth: 1,
data: [],
};
for (var index = 0; index < config.data.labels.length; ++index) {
newDataset.data.push(randomScalingFactor());
}
config.data.datasets.push(newDataset);
window.myRadar.update();
updateLegend();
});
$('#addData').click(function() {
if (config.data.datasets.length > 0) {
config.data.labels.push('dataset #' + config.data.labels.length);
$.each(config.data.datasets, function (i, dataset) {
dataset.data.push(randomScalingFactor());
});
window.myRadar.update();
updateLegend();
}
});
$('#removeDataset').click(function() {
config.data.datasets.splice(0, 1);
window.myRadar.update();
updateLegend();
});
$('#removeData').click(function() {
config.data.labels.pop(); // remove the label first
$.each(config.data.datasets, function(i, dataset) {
dataset.data.pop();
});
window.myRadar.update();
updateLegend();
});
</script>
</body>
</html>
``` | /content/code_sandbox/public/vendor/chartjs/samples/radar.html | html | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 991 |
```html
<!doctype html>
<html>
<head>
<title>Bar Chart</title>
<script src="../node_modules/jquery/dist/jquery.min.js"></script>
<script src="../Chart.js"></script>
<style type="text/css">
canvas {
border: 1px solid red;
}
</style>
</head>
<body>
<div id="container" style="width: 50%; height: 25%;">
<canvas id="canvas" height="450" width="600"></canvas>
</div>
<button id="randomizeData">Randomize Data</button>
<button id="addDataset">Add Dataset</button>
<button id="removeDataset">Remove Dataset</button>
<button id="addData">Add Data</button>
<button id="removeData">Remove Data</button>
<button id="show">Show</button>
<div>
<h3>Legend</h3>
<div id="legendContainer">
</div>
</div>
<script>
var randomScalingFactor = function() {
return (Math.random() > 0.5 ? 1.0 : -1.0) * Math.round(Math.random() * 100);
};
var randomColorFactor = function() {
return Math.round(Math.random() * 255);
};
var randomColor = function() {
return 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',.7)';
};
var barChartData = {
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [{
label: 'Dataset 1',
backgroundColor: "rgba(220,220,220,0.5)",
data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()]
}, {
hidden: true,
label: 'Dataset 2',
backgroundColor: "rgba(151,187,205,0.5)",
data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()]
}, {
label: 'Dataset 3',
backgroundColor: "rgba(151,187,205,0.5)",
data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()]
}]
};
function updateLegend() {
$legendContainer = $('#legendContainer');
$legendContainer.empty();
$legendContainer.append(window.myBar.generateLegend());
}
window.onload = function() {
var ctx = document.getElementById("canvas").getContext("2d");
window.myBar = new Chart(ctx, {
type: 'bar',
data: barChartData,
options: {
responsive: true,
legend: {
position: 'top',
},
title: {
display: true,
text: 'Our 3 Favorite Datasets'
}
}
});
updateLegend();
};
$('#randomizeData').click(function() {
var zero = Math.random() < 0.2 ? true : false;
$.each(barChartData.datasets, function(i, dataset) {
dataset.backgroundColor = randomColor();
dataset.data = dataset.data.map(function() {
return zero ? 0.0 : randomScalingFactor();
});
});
window.myBar.update();
updateLegend();
});
$('#addDataset').click(function() {
var newDataset = {
label: 'Dataset ' + barChartData.datasets.length,
backgroundColor: randomColor(),
data: []
};
for (var index = 0; index < barChartData.labels.length; ++index) {
newDataset.data.push(randomScalingFactor());
}
barChartData.datasets.push(newDataset);
window.myBar.update();
updateLegend();
});
$('#addData').click(function() {
if (barChartData.datasets.length > 0) {
barChartData.labels.push('data #' + barChartData.labels.length);
for (var index = 0; index < barChartData.datasets.length; ++index) {
//window.myBar.addData(randomScalingFactor(), index);
barChartData.datasets[index].data.push(randomScalingFactor());
}
window.myBar.update();
updateLegend();
}
});
$('#removeDataset').click(function() {
barChartData.datasets.splice(0, 1);
window.myBar.update();
updateLegend();
});
$('#removeData').click(function() {
barChartData.labels.splice(-1, 1); // remove the label first
barChartData.datasets.forEach(function(dataset, datasetIndex) {
dataset.data.pop();
});
window.myBar.update();
updateLegend();
});
$('#show').click(function() {
document.getElementById('container').style.display = '';
});
</script>
</body>
</html>
``` | /content/code_sandbox/public/vendor/chartjs/samples/bar.html | html | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 1,068 |
```html
<!doctype html>
<html>
<head>
<title>Pie Chart</title>
<script src="../Chart.js"></script>
<script src="path_to_url"></script>
</head>
<body>
<div id="canvas-holder" style="width:50%">
<canvas id="chart-area" width="300" height="300" />
</div>
<button id="randomizeData">Randomize Data</button>
<button id="addDataset">Add Dataset</button>
<button id="removeDataset">Remove Dataset</button>
<script>
var randomScalingFactor = function() {
return Math.round(Math.random() * 100);
};
var randomColorFactor = function() {
return Math.round(Math.random() * 255);
};
var randomColor = function(opacity) {
return 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',' + (opacity || '.3') + ')';
};
var config = {
type: 'pie',
data: {
datasets: [{
data: [
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
],
backgroundColor: [
"#F7464A",
"#46BFBD",
"#FDB45C",
"#949FB1",
"#4D5360",
],
}, {
data: [
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
],
backgroundColor: [
"#F7464A",
"#46BFBD",
"#FDB45C",
"#949FB1",
"#4D5360",
],
}, {
data: [
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
],
backgroundColor: [
"#F7464A",
"#46BFBD",
"#FDB45C",
"#949FB1",
"#4D5360",
],
}],
labels: [
"Red",
"Green",
"Yellow",
"Grey",
"Dark Grey"
]
},
options: {
responsive: true
}
};
window.onload = function() {
var ctx = document.getElementById("chart-area").getContext("2d");
window.myPie = new Chart(ctx, config);
};
$('#randomizeData').click(function() {
$.each(config.data.datasets, function(i, piece) {
$.each(piece.data, function(j, value) {
config.data.datasets[i].data[j] = randomScalingFactor();
//config.data.datasets.backgroundColor[i] = 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',.7)';
});
});
window.myPie.update();
});
$('#addDataset').click(function() {
var newDataset = {
backgroundColor: [randomColor(0.7), randomColor(0.7), randomColor(0.7), randomColor(0.7), randomColor(0.7)],
data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()]
};
config.data.datasets.push(newDataset);
window.myPie.update();
});
$('#removeDataset').click(function() {
config.data.datasets.splice(0, 1);
window.myPie.update();
});
</script>
</body>
</html>
``` | /content/code_sandbox/public/vendor/chartjs/samples/pie.html | html | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 760 |
```javascript
;(function(root, factory) {
if (typeof define === 'function' && define.amd) {
define(['moment'], factory);
} else if (typeof exports === 'object') {
module.exports = factory.call(root,require('moment'));
} else {
root.Chart = factory.call(root,root.moment);
}
}(this, function(moment) {
!function e(r,t,n){function a(i,u){if(!t[i]){if(!r[i]){var l="function"==typeof require&&require;if(!u&&l)return l(i,!0);if(s)return s(i,!0);var h=new Error("Cannot find module '"+i+"'");throw h.code="MODULE_NOT_FOUND",h}var o=t[i]={exports:{}};r[i][0].call(o.exports,function(e){var t=r[i][1][e];return a(t?t:e)},o,o.exports,e,r,t,n)}return t[i].exports}for(var s="function"==typeof require&&require,i=0;i<n.length;i++)a(n[i]);return a}({1:[function(e,r,t){!function(){var t=e("color-convert"),n=e("color-string"),a=function(e){if(e instanceof a)return e;if(!(this instanceof a))return new a(e);if(this.values={rgb:[0,0,0],hsl:[0,0,0],hsv:[0,0,0],hwb:[0,0,0],cmyk:[0,0,0,0],alpha:1},"string"==typeof e){var r=n.getRgba(e);if(r)this.setValues("rgb",r);else if(r=n.getHsla(e))this.setValues("hsl",r);else{if(!(r=n.getHwb(e)))throw new Error('Unable to parse color from string "'+e+'"');this.setValues("hwb",r)}}else if("object"==typeof e){var r=e;if(void 0!==r.r||void 0!==r.red)this.setValues("rgb",r);else if(void 0!==r.l||void 0!==r.lightness)this.setValues("hsl",r);else if(void 0!==r.v||void 0!==r.value)this.setValues("hsv",r);else if(void 0!==r.w||void 0!==r.whiteness)this.setValues("hwb",r);else{if(void 0===r.c&&void 0===r.cyan)throw new Error("Unable to parse color from object "+JSON.stringify(e));this.setValues("cmyk",r)}}};a.prototype={rgb:function(e){return this.setSpace("rgb",arguments)},hsl:function(e){return this.setSpace("hsl",arguments)},hsv:function(e){return this.setSpace("hsv",arguments)},hwb:function(e){return this.setSpace("hwb",arguments)},cmyk:function(e){return this.setSpace("cmyk",arguments)},rgbArray:function(){return this.values.rgb},hslArray:function(){return this.values.hsl},hsvArray:function(){return this.values.hsv},hwbArray:function(){return 1!==this.values.alpha?this.values.hwb.concat([this.values.alpha]):this.values.hwb},cmykArray:function(){return this.values.cmyk},rgbaArray:function(){var e=this.values.rgb;return e.concat([this.values.alpha])},hslaArray:function(){var e=this.values.hsl;return e.concat([this.values.alpha])},alpha:function(e){return void 0===e?this.values.alpha:(this.setValues("alpha",e),this)},red:function(e){return this.setChannel("rgb",0,e)},green:function(e){return this.setChannel("rgb",1,e)},blue:function(e){return this.setChannel("rgb",2,e)},hue:function(e){return this.setChannel("hsl",0,e)},saturation:function(e){return this.setChannel("hsl",1,e)},lightness:function(e){return this.setChannel("hsl",2,e)},saturationv:function(e){return this.setChannel("hsv",1,e)},whiteness:function(e){return this.setChannel("hwb",1,e)},blackness:function(e){return this.setChannel("hwb",2,e)},value:function(e){return this.setChannel("hsv",2,e)},cyan:function(e){return this.setChannel("cmyk",0,e)},magenta:function(e){return this.setChannel("cmyk",1,e)},yellow:function(e){return this.setChannel("cmyk",2,e)},black:function(e){return this.setChannel("cmyk",3,e)},hexString:function(){return n.hexString(this.values.rgb)},rgbString:function(){return n.rgbString(this.values.rgb,this.values.alpha)},rgbaString:function(){return n.rgbaString(this.values.rgb,this.values.alpha)},percentString:function(){return n.percentString(this.values.rgb,this.values.alpha)},hslString:function(){return n.hslString(this.values.hsl,this.values.alpha)},hslaString:function(){return n.hslaString(this.values.hsl,this.values.alpha)},hwbString:function(){return n.hwbString(this.values.hwb,this.values.alpha)},keyword:function(){return n.keyword(this.values.rgb,this.values.alpha)},rgbNumber:function(){return this.values.rgb[0]<<16|this.values.rgb[1]<<8|this.values.rgb[2]},luminosity:function(){for(var e=this.values.rgb,r=[],t=0;t<e.length;t++){var n=e[t]/255;r[t]=.03928>=n?n/12.92:Math.pow((n+.055)/1.055,2.4)}return.2126*r[0]+.7152*r[1]+.0722*r[2]},contrast:function(e){var r=this.luminosity(),t=e.luminosity();return r>t?(r+.05)/(t+.05):(t+.05)/(r+.05)},level:function(e){var r=this.contrast(e);return r>=7.1?"AAA":r>=4.5?"AA":""},dark:function(){var e=this.values.rgb,r=(299*e[0]+587*e[1]+114*e[2])/1e3;return 128>r},light:function(){return!this.dark()},negate:function(){for(var e=[],r=0;3>r;r++)e[r]=255-this.values.rgb[r];return this.setValues("rgb",e),this},lighten:function(e){return this.values.hsl[2]+=this.values.hsl[2]*e,this.setValues("hsl",this.values.hsl),this},darken:function(e){return this.values.hsl[2]-=this.values.hsl[2]*e,this.setValues("hsl",this.values.hsl),this},saturate:function(e){return this.values.hsl[1]+=this.values.hsl[1]*e,this.setValues("hsl",this.values.hsl),this},desaturate:function(e){return this.values.hsl[1]-=this.values.hsl[1]*e,this.setValues("hsl",this.values.hsl),this},whiten:function(e){return this.values.hwb[1]+=this.values.hwb[1]*e,this.setValues("hwb",this.values.hwb),this},blacken:function(e){return this.values.hwb[2]+=this.values.hwb[2]*e,this.setValues("hwb",this.values.hwb),this},greyscale:function(){var e=this.values.rgb,r=.3*e[0]+.59*e[1]+.11*e[2];return this.setValues("rgb",[r,r,r]),this},clearer:function(e){return this.setValues("alpha",this.values.alpha-this.values.alpha*e),this},opaquer:function(e){return this.setValues("alpha",this.values.alpha+this.values.alpha*e),this},rotate:function(e){var r=this.values.hsl[0];return r=(r+e)%360,r=0>r?360+r:r,this.values.hsl[0]=r,this.setValues("hsl",this.values.hsl),this},mix:function(e,r){r=1-(null==r?.5:r);for(var t=2*r-1,n=this.alpha()-e.alpha(),a=((t*n==-1?t:(t+n)/(1+t*n))+1)/2,s=1-a,i=this.rgbArray(),u=e.rgbArray(),l=0;l<i.length;l++)i[l]=i[l]*a+u[l]*s;this.setValues("rgb",i);var h=this.alpha()*r+e.alpha()*(1-r);return this.setValues("alpha",h),this},toJSON:function(){return this.rgb()},clone:function(){return new a(this.rgb())}},a.prototype.getValues=function(e){for(var r={},t=0;t<e.length;t++)r[e.charAt(t)]=this.values[e][t];return 1!=this.values.alpha&&(r.a=this.values.alpha),r},a.prototype.setValues=function(e,r){var n={rgb:["red","green","blue"],hsl:["hue","saturation","lightness"],hsv:["hue","saturation","value"],hwb:["hue","whiteness","blackness"],cmyk:["cyan","magenta","yellow","black"]},a={rgb:[255,255,255],hsl:[360,100,100],hsv:[360,100,100],hwb:[360,100,100],cmyk:[100,100,100,100]},s=1;if("alpha"==e)s=r;else if(r.length)this.values[e]=r.slice(0,e.length),s=r[e.length];else if(void 0!==r[e.charAt(0)]){for(var i=0;i<e.length;i++)this.values[e][i]=r[e.charAt(i)];s=r.a}else if(void 0!==r[n[e][0]]){for(var u=n[e],i=0;i<e.length;i++)this.values[e][i]=r[u[i]];s=r.alpha}if(this.values.alpha=Math.max(0,Math.min(1,void 0!==s?s:this.values.alpha)),"alpha"!=e){for(var i=0;i<e.length;i++){var l=Math.max(0,Math.min(a[e][i],this.values[e][i]));this.values[e][i]=Math.round(l)}for(var h in n){h!=e&&(this.values[h]=t[e][h](this.values[e]));for(var i=0;i<h.length;i++){var l=Math.max(0,Math.min(a[h][i],this.values[h][i]));this.values[h][i]=Math.round(l)}}return!0}},a.prototype.setSpace=function(e,r){var t=r[0];return void 0===t?this.getValues(e):("number"==typeof t&&(t=Array.prototype.slice.call(r)),this.setValues(e,t),this)},a.prototype.setChannel=function(e,r,t){return void 0===t?this.values[e][r]:(this.values[e][r]=t,this.setValues(e,this.values[e]),this)},window.Color=r.exports=a}()},{"color-convert":3,"color-string":4}],2:[function(e,t,n){function a(e){var r,t,n,a=e[0]/255,s=e[1]/255,i=e[2]/255,u=Math.min(a,s,i),l=Math.max(a,s,i),h=l-u;return l==u?r=0:a==l?r=(s-i)/h:s==l?r=2+(i-a)/h:i==l&&(r=4+(a-s)/h),r=Math.min(60*r,360),0>r&&(r+=360),n=(u+l)/2,t=l==u?0:.5>=n?h/(l+u):h/(2-l-u),[r,100*t,100*n]}function s(e){var r,t,n,a=e[0],s=e[1],i=e[2],u=Math.min(a,s,i),l=Math.max(a,s,i),h=l-u;return t=0==l?0:h/l*1e3/10,l==u?r=0:a==l?r=(s-i)/h:s==l?r=2+(i-a)/h:i==l&&(r=4+(a-s)/h),r=Math.min(60*r,360),0>r&&(r+=360),n=l/255*1e3/10,[r,t,n]}function i(e){var r=e[0],t=e[1],n=e[2],s=a(e)[0],i=1/255*Math.min(r,Math.min(t,n)),n=1-1/255*Math.max(r,Math.max(t,n));return[s,100*i,100*n]}function u(e){var r,t,n,a,s=e[0]/255,i=e[1]/255,u=e[2]/255;return a=Math.min(1-s,1-i,1-u),r=(1-s-a)/(1-a)||0,t=(1-i-a)/(1-a)||0,n=(1-u-a)/(1-a)||0,[100*r,100*t,100*n,100*a]}function l(e){return X[JSON.stringify(e)]}function h(e){var r=e[0]/255,t=e[1]/255,n=e[2]/255;r=r>.04045?Math.pow((r+.055)/1.055,2.4):r/12.92,t=t>.04045?Math.pow((t+.055)/1.055,2.4):t/12.92,n=n>.04045?Math.pow((n+.055)/1.055,2.4):n/12.92;var a=.4124*r+.3576*t+.1805*n,s=.2126*r+.7152*t+.0722*n,i=.0193*r+.1192*t+.9505*n;return[100*a,100*s,100*i]}function o(e){var r,t,n,a=h(e),s=a[0],i=a[1],u=a[2];return s/=95.047,i/=100,u/=108.883,s=s>.008856?Math.pow(s,1/3):7.787*s+16/116,i=i>.008856?Math.pow(i,1/3):7.787*i+16/116,u=u>.008856?Math.pow(u,1/3):7.787*u+16/116,r=116*i-16,t=500*(s-i),n=200*(i-u),[r,t,n]}function c(e){return J(o(e))}function v(e){var r,t,n,a,s,i=e[0]/360,u=e[1]/100,l=e[2]/100;if(0==u)return s=255*l,[s,s,s];t=.5>l?l*(1+u):l+u-l*u,r=2*l-t,a=[0,0,0];for(var h=0;3>h;h++)n=i+1/3*-(h-1),0>n&&n++,n>1&&n--,s=1>6*n?r+6*(t-r)*n:1>2*n?t:2>3*n?r+(t-r)*(2/3-n)*6:r,a[h]=255*s;return a}function f(e){var r,t,n=e[0],a=e[1]/100,s=e[2]/100;return s*=2,a*=1>=s?s:2-s,t=(s+a)/2,r=2*a/(s+a),[n,100*r,100*t]}function d(e){return i(v(e))}function p(e){return u(v(e))}function m(e){return l(v(e))}function y(e){var r=e[0]/60,t=e[1]/100,n=e[2]/100,a=Math.floor(r)%6,s=r-Math.floor(r),i=255*n*(1-t),u=255*n*(1-t*s),l=255*n*(1-t*(1-s)),n=255*n;switch(a){case 0:return[n,l,i];case 1:return[u,n,i];case 2:return[i,n,l];case 3:return[i,u,n];case 4:return[l,i,n];case 5:return[n,i,u]}}function w(e){var r,t,n=e[0],a=e[1]/100,s=e[2]/100;return t=(2-a)*s,r=a*s,r/=1>=t?t:2-t,r=r||0,t/=2,[n,100*r,100*t]}function k(e){return i(y(e))}function M(e){return u(y(e))}function S(e){return l(y(e))}function x(e){var t,n,a,s,i=e[0]/360,u=e[1]/100,l=e[2]/100,h=u+l;switch(h>1&&(u/=h,l/=h),t=Math.floor(6*i),n=1-l,a=6*i-t,0!=(1&t)&&(a=1-a),s=u+a*(n-u),t){default:case 6:case 0:r=n,g=s,b=u;break;case 1:r=s,g=n,b=u;break;case 2:r=u,g=n,b=s;break;case 3:r=u,g=s,b=n;break;case 4:r=s,g=u,b=n;break;case 5:r=n,g=u,b=s}return[255*r,255*g,255*b]}function V(e){return a(x(e))}function q(e){return s(x(e))}function A(e){return u(x(e))}function C(e){return l(x(e))}function F(e){var r,t,n,a=e[0]/100,s=e[1]/100,i=e[2]/100,u=e[3]/100;return r=1-Math.min(1,a*(1-u)+u),t=1-Math.min(1,s*(1-u)+u),n=1-Math.min(1,i*(1-u)+u),[255*r,255*t,255*n]}function N(e){return a(F(e))}function z(e){return s(F(e))}function I(e){return i(F(e))}function O(e){return l(F(e))}function E(e){var r,t,n,a=e[0]/100,s=e[1]/100,i=e[2]/100;return r=3.2406*a+-1.5372*s+i*-.4986,t=a*-.9689+1.8758*s+.0415*i,n=.0557*a+s*-.204+1.057*i,r=r>.0031308?1.055*Math.pow(r,1/2.4)-.055:r=12.92*r,t=t>.0031308?1.055*Math.pow(t,1/2.4)-.055:t=12.92*t,n=n>.0031308?1.055*Math.pow(n,1/2.4)-.055:n=12.92*n,r=Math.min(Math.max(0,r),1),t=Math.min(Math.max(0,t),1),n=Math.min(Math.max(0,n),1),[255*r,255*t,255*n]}function H(e){var r,t,n,a=e[0],s=e[1],i=e[2];return a/=95.047,s/=100,i/=108.883,a=a>.008856?Math.pow(a,1/3):7.787*a+16/116,s=s>.008856?Math.pow(s,1/3):7.787*s+16/116,i=i>.008856?Math.pow(i,1/3):7.787*i+16/116,r=116*s-16,t=500*(a-s),n=200*(s-i),[r,t,n]}function U(e){return J(H(e))}function j(e){var r,t,n,a,s=e[0],i=e[1],u=e[2];return 8>=s?(t=100*s/903.3,a=7.787*(t/100)+16/116):(t=100*Math.pow((s+16)/116,3),a=Math.pow(t/100,1/3)),r=.008856>=r/95.047?r=95.047*(i/500+a-16/116)/7.787:95.047*Math.pow(i/500+a,3),n=.008859>=n/108.883?n=108.883*(a-u/200-16/116)/7.787:108.883*Math.pow(a-u/200,3),[r,t,n]}function J(e){var r,t,n,a=e[0],s=e[1],i=e[2];return r=Math.atan2(i,s),t=360*r/2/Math.PI,0>t&&(t+=360),n=Math.sqrt(s*s+i*i),[a,n,t]}function R(e){return E(j(e))}function $(e){var r,t,n,a=e[0],s=e[1],i=e[2];return n=i/360*2*Math.PI,r=s*Math.cos(n),t=s*Math.sin(n),[a,r,t]}function D(e){return j($(e))}function P(e){return R($(e))}function _(e){return W[e]}function L(e){return a(_(e))}function T(e){return s(_(e))}function B(e){return i(_(e))}function G(e){return u(_(e))}function K(e){return o(_(e))}function Q(e){return h(_(e))}t.exports={rgb2hsl:a,rgb2hsv:s,rgb2hwb:i,rgb2cmyk:u,rgb2keyword:l,rgb2xyz:h,rgb2lab:o,rgb2lch:c,hsl2rgb:v,hsl2hsv:f,hsl2hwb:d,hsl2cmyk:p,hsl2keyword:m,hsv2rgb:y,hsv2hsl:w,hsv2hwb:k,hsv2cmyk:M,hsv2keyword:S,hwb2rgb:x,hwb2hsl:V,hwb2hsv:q,hwb2cmyk:A,hwb2keyword:C,cmyk2rgb:F,cmyk2hsl:N,cmyk2hsv:z,cmyk2hwb:I,cmyk2keyword:O,keyword2rgb:_,keyword2hsl:L,keyword2hsv:T,keyword2hwb:B,keyword2cmyk:G,keyword2lab:K,keyword2xyz:Q,xyz2rgb:E,xyz2lab:H,xyz2lch:U,lab2xyz:j,lab2rgb:R,lab2lch:J,lch2lab:$,lch2xyz:D,lch2rgb:P};var W={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]},X={};for(var Y in W)X[JSON.stringify(W[Y])]=Y},{}],3:[function(e,r,t){var n=e("./conversions"),a=function(){return new h};for(var s in n){a[s+"Raw"]=function(e){return function(r){return"number"==typeof r&&(r=Array.prototype.slice.call(arguments)),n[e](r)}}(s);var i=/(\w+)2(\w+)/.exec(s),u=i[1],l=i[2];a[u]=a[u]||{},a[u][l]=a[s]=function(e){return function(r){"number"==typeof r&&(r=Array.prototype.slice.call(arguments));var t=n[e](r);if("string"==typeof t||void 0===t)return t;for(var a=0;a<t.length;a++)t[a]=Math.round(t[a]);return t}}(s)}var h=function(){this.convs={}};h.prototype.routeSpace=function(e,r){var t=r[0];return void 0===t?this.getValues(e):("number"==typeof t&&(t=Array.prototype.slice.call(r)),this.setValues(e,t))},h.prototype.setValues=function(e,r){return this.space=e,this.convs={},this.convs[e]=r,this},h.prototype.getValues=function(e){var r=this.convs[e];if(!r){var t=this.space,n=this.convs[t];r=a[t][e](n),this.convs[e]=r}return r},["rgb","hsl","hsv","cmyk","keyword"].forEach(function(e){h.prototype[e]=function(r){return this.routeSpace(e,arguments)}}),r.exports=a},{"./conversions":2}],4:[function(e,r,t){function n(e){if(e){var r=/^#([a-fA-F0-9]{3})$/,t=/^#([a-fA-F0-9]{6})$/,n=/^rgba?\(\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/,a=/^rgba?\(\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/,s=/(\w+)/,i=[0,0,0],u=1,l=e.match(r);if(l){l=l[1];for(var h=0;h<i.length;h++)i[h]=parseInt(l[h]+l[h],16)}else if(l=e.match(t)){l=l[1];for(var h=0;h<i.length;h++)i[h]=parseInt(l.slice(2*h,2*h+2),16)}else if(l=e.match(n)){for(var h=0;h<i.length;h++)i[h]=parseInt(l[h+1]);u=parseFloat(l[4])}else if(l=e.match(a)){for(var h=0;h<i.length;h++)i[h]=Math.round(2.55*parseFloat(l[h+1]));u=parseFloat(l[4])}else if(l=e.match(s)){if("transparent"==l[1])return[0,0,0,0];if(i=w[l[1]],!i)return}for(var h=0;h<i.length;h++)i[h]=m(i[h],0,255);return u=u||0==u?m(u,0,1):1,i[3]=u,i}}function a(e){if(e){var r=/^hsla?\(\s*([+-]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)/,t=e.match(r);if(t){var n=parseFloat(t[4]),a=m(parseInt(t[1]),0,360),s=m(parseFloat(t[2]),0,100),i=m(parseFloat(t[3]),0,100),u=m(isNaN(n)?1:n,0,1);return[a,s,i,u]}}}function s(e){if(e){var r=/^hwb\(\s*([+-]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)/,t=e.match(r);if(t){var n=parseFloat(t[4]),a=m(parseInt(t[1]),0,360),s=m(parseFloat(t[2]),0,100),i=m(parseFloat(t[3]),0,100),u=m(isNaN(n)?1:n,0,1);return[a,s,i,u]}}}function i(e){var r=n(e);return r&&r.slice(0,3)}function u(e){var r=a(e);return r&&r.slice(0,3)}function l(e){var r=n(e);return r?r[3]:(r=a(e))?r[3]:(r=s(e))?r[3]:void 0}function h(e){return"#"+y(e[0])+y(e[1])+y(e[2])}function o(e,r){return 1>r||e[3]&&e[3]<1?c(e,r):"rgb("+e[0]+", "+e[1]+", "+e[2]+")"}function c(e,r){return void 0===r&&(r=void 0!==e[3]?e[3]:1),"rgba("+e[0]+", "+e[1]+", "+e[2]+", "+r+")"}function g(e,r){if(1>r||e[3]&&e[3]<1)return v(e,r);var t=Math.round(e[0]/255*100),n=Math.round(e[1]/255*100),a=Math.round(e[2]/255*100);return"rgb("+t+"%, "+n+"%, "+a+"%)"}function v(e,r){var t=Math.round(e[0]/255*100),n=Math.round(e[1]/255*100),a=Math.round(e[2]/255*100);return"rgba("+t+"%, "+n+"%, "+a+"%, "+(r||e[3]||1)+")"}function f(e,r){return 1>r||e[3]&&e[3]<1?d(e,r):"hsl("+e[0]+", "+e[1]+"%, "+e[2]+"%)"}function d(e,r){return void 0===r&&(r=void 0!==e[3]?e[3]:1),"hsla("+e[0]+", "+e[1]+"%, "+e[2]+"%, "+r+")"}function b(e,r){return void 0===r&&(r=void 0!==e[3]?e[3]:1),"hwb("+e[0]+", "+e[1]+"%, "+e[2]+"%"+(void 0!==r&&1!==r?", "+r:"")+")"}function p(e){return k[e.slice(0,3)]}function m(e,r,t){return Math.min(Math.max(r,e),t)}function y(e){var r=e.toString(16).toUpperCase();return r.length<2?"0"+r:r}var w=e("color-name");r.exports={getRgba:n,getHsla:a,getRgb:i,getHsl:u,getHwb:s,getAlpha:l,hexString:h,rgbString:o,rgbaString:c,percentString:g,percentaString:v,hslString:f,hslaString:d,hwbString:b,keyword:p};var k={};for(var M in w)k[w[M]]=M},{"color-name":5}],5:[function(e,r,t){r.exports={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]}},{}]},{},[1]);
/*!
* Chart.js
* path_to_url
* Version: 2.0.0-beta2
*
* Released under the MIT license
* path_to_url
*/
(function() {
"use strict";
//Declare root variable - window in the browser, global on the server
var root = this,
previous = root.Chart;
//Occupy the global variable of Chart, and create a simple base class
var Chart = function(context, config) {
this.config = config;
// Support a jQuery'd canvas element
if (context.length && context[0].getContext) {
context = context[0];
}
// Support a canvas domnode
if (context.getContext) {
context = context.getContext("2d");
}
this.ctx = context;
this.canvas = context.canvas;
// Figure out what the size of the chart will be.
// If the canvas has a specified width and height, we use those else
// we look to see if the canvas node has a CSS width and height.
// If there is still no height, fill the parent container
this.width = context.canvas.width || parseInt(Chart.helpers.getStyle(context.canvas, 'width')) || Chart.helpers.getMaximumWidth(context.canvas);
this.height = context.canvas.height || parseInt(Chart.helpers.getStyle(context.canvas, 'height')) || Chart.helpers.getMaximumHeight(context.canvas);
this.aspectRatio = this.width / this.height;
if (isNaN(this.aspectRatio) || isFinite(this.aspectRatio) === false) {
// If the canvas has no size, try and figure out what the aspect ratio will be.
// Some charts prefer square canvases (pie, radar, etc). If that is specified, use that
// else use the canvas default ratio of 2
this.aspectRatio = config.aspectRatio !== undefined ? config.aspectRatio : 2;
}
// Store the original style of the element so we can set it back
this.originalCanvasStyleWidth = context.canvas.style.width;
this.originalCanvasStyleHeight = context.canvas.style.height;
// High pixel density displays - multiply the size of the canvas height/width by the device pixel ratio, then scale.
Chart.helpers.retinaScale(this);
if (config) {
this.controller = new Chart.Controller(this);
}
// Always bind this so that if the responsive state changes we still work
var _this = this;
Chart.helpers.addResizeListener(context.canvas.parentNode, function() {
if (_this.controller && _this.controller.config.options.responsive) {
_this.controller.resize();
}
});
return this.controller ? this.controller : this;
};
//Globally expose the defaults to allow for user updating/changing
Chart.defaults = {
global: {
responsive: true,
responsiveAnimationDuration: 0,
maintainAspectRatio: true,
events: ["mousemove", "mouseout", "click", "touchstart", "touchmove"],
hover: {
onHover: null,
mode: 'single',
animationDuration: 400,
},
onClick: null,
defaultColor: 'rgba(0,0,0,0.1)',
// Element defaults defined in element extensions
elements: {},
// Legend callback string
legendCallback: function(chart) {
var text = [];
text.push('<ul class="' + chart.id + '-legend">');
for (var i = 0; i < chart.data.datasets.length; i++) {
text.push('<li><span style="background-color:' + chart.data.datasets[i].backgroundColor + '">');
if (chart.data.datasets[i].label) {
text.push(chart.data.datasets[i].label);
}
text.push('</span></li>');
}
text.push('</ul>');
return text.join("");
}
},
};
root.Chart = Chart;
Chart.noConflict = function() {
root.Chart = previous;
return Chart;
};
}).call(this);
(function() {
"use strict";
//Declare root variable - window in the browser, global on the server
var root = this,
Chart = root.Chart;
//Global Chart helpers object for utility methods and classes
var helpers = Chart.helpers = {};
//-- Basic js utility methods
var each = helpers.each = function(loopable, callback, self, reverse) {
var additionalArgs = Array.prototype.slice.call(arguments, 3);
// Check to see if null or undefined firstly.
if (loopable) {
if (loopable.length === +loopable.length) {
var i;
if (reverse) {
for (i = loopable.length - 1; i >= 0; i--) {
callback.apply(self, [loopable[i], i].concat(additionalArgs));
}
} else {
for (i = 0; i < loopable.length; i++) {
callback.apply(self, [loopable[i], i].concat(additionalArgs));
}
}
} else {
for (var item in loopable) {
callback.apply(self, [loopable[item], item].concat(additionalArgs));
}
}
}
},
clone = helpers.clone = function(obj) {
var objClone = {};
each(obj, function(value, key) {
if (obj.hasOwnProperty(key)) {
if (helpers.isArray(value)) {
objClone[key] = value.slice(0);
} else if (typeof value === 'object' && value !== null) {
objClone[key] = clone(value);
} else {
objClone[key] = value;
}
}
});
return objClone;
},
extend = helpers.extend = function(base) {
each(Array.prototype.slice.call(arguments, 1), function(extensionObject) {
each(extensionObject, function(value, key) {
if (extensionObject.hasOwnProperty(key)) {
base[key] = value;
}
});
});
return base;
},
// Need a special merge function to chart configs since they are now grouped
configMerge = helpers.configMerge = function(_base) {
var base = clone(_base);
helpers.each(Array.prototype.slice.call(arguments, 1), function(extension) {
helpers.each(extension, function(value, key) {
if (extension.hasOwnProperty(key)) {
if (key === 'scales') {
// Scale config merging is complex. Add out own function here for that
base[key] = helpers.scaleMerge(base.hasOwnProperty(key) ? base[key] : {}, value);
} else if (key === 'scale') {
// Used in polar area & radar charts since there is only one scale
base[key] = helpers.configMerge(base.hasOwnProperty(key) ? base[key] : {}, Chart.scaleService.getScaleDefaults(value.type), value);
} else if (base.hasOwnProperty(key) && helpers.isArray(base[key]) && helpers.isArray(value)) {
// In this case we have an array of objects replacing another array. Rather than doing a strict replace,
// merge. This allows easy scale option merging
var baseArray = base[key];
helpers.each(value, function(valueObj, index) {
if (index < baseArray.length) {
if (typeof baseArray[index] == 'object' && baseArray[index] !== null && typeof valueObj == 'object' && valueObj !== null) {
// Two objects are coming together. Do a merge of them.
baseArray[index] = helpers.configMerge(baseArray[index], valueObj);
} else {
// Just overwrite in this case since there is nothing to merge
baseArray[index] = valueObj;
}
} else {
baseArray.push(valueObj); // nothing to merge
}
});
} else if (base.hasOwnProperty(key) && typeof base[key] == "object" && base[key] !== null && typeof value == "object") {
// If we are overwriting an object with an object, do a merge of the properties.
base[key] = helpers.configMerge(base[key], value);
} else {
// can just overwrite the value in this case
base[key] = value;
}
}
});
});
return base;
},
extendDeep = helpers.extendDeep = function(_base) {
return _extendDeep.apply(this, arguments);
function _extendDeep(dst) {
helpers.each(arguments, function(obj) {
if (obj !== dst) {
helpers.each(obj, function(value, key) {
if (dst[key] && dst[key].constructor && dst[key].constructor === Object) {
_extendDeep(dst[key], value);
} else {
dst[key] = value;
}
});
}
});
return dst;
}
},
scaleMerge = helpers.scaleMerge = function(_base, extension) {
var base = clone(_base);
helpers.each(extension, function(value, key) {
if (extension.hasOwnProperty(key)) {
if (key === 'xAxes' || key === 'yAxes') {
// These properties are arrays of items
if (base.hasOwnProperty(key)) {
helpers.each(value, function(valueObj, index) {
if (index >= base[key].length || !base[key][index].type) {
base[key].push(helpers.configMerge(valueObj.type ? Chart.scaleService.getScaleDefaults(valueObj.type) : {}, valueObj));
} else if (valueObj.type !== base[key][index].type) {
// Type changed. Bring in the new defaults before we bring in valueObj so that valueObj can override the correct scale defaults
base[key][index] = helpers.configMerge(base[key][index], valueObj.type ? Chart.scaleService.getScaleDefaults(valueObj.type) : {}, valueObj);
} else {
// Type is the same
base[key][index] = helpers.configMerge(base[key][index], valueObj);
}
});
} else {
base[key] = [];
helpers.each(value, function(valueObj) {
base[key].push(helpers.configMerge(valueObj.type ? Chart.scaleService.getScaleDefaults(valueObj.type) : {}, valueObj));
});
}
} else if (base.hasOwnProperty(key) && typeof base[key] == "object" && base[key] !== null && typeof value == "object") {
// If we are overwriting an object with an object, do a merge of the properties.
base[key] = helpers.configMerge(base[key], value);
} else {
// can just overwrite the value in this case
base[key] = value;
}
}
});
return base;
},
getValueAtIndexOrDefault = helpers.getValueAtIndexOrDefault = function(value, index, defaultValue) {
if (value === undefined || value === null) {
return defaultValue;
}
if (helpers.isArray(value)) {
return index < value.length ? value[index] : defaultValue;
}
return value;
},
getValueOrDefault = helpers.getValueOrDefault = function(value, defaultValue) {
return value === undefined ? defaultValue : value;
},
indexOf = helpers.indexOf = function(arrayToSearch, item) {
if (Array.prototype.indexOf) {
return arrayToSearch.indexOf(item);
} else {
for (var i = 0; i < arrayToSearch.length; i++) {
if (arrayToSearch[i] === item) return i;
}
return -1;
}
},
where = helpers.where = function(collection, filterCallback) {
var filtered = [];
helpers.each(collection, function(item) {
if (filterCallback(item)) {
filtered.push(item);
}
});
return filtered;
},
findNextWhere = helpers.findNextWhere = function(arrayToSearch, filterCallback, startIndex) {
// Default to start of the array
if (startIndex === undefined || startIndex === null) {
startIndex = -1;
}
for (var i = startIndex + 1; i < arrayToSearch.length; i++) {
var currentItem = arrayToSearch[i];
if (filterCallback(currentItem)) {
return currentItem;
}
}
},
findPreviousWhere = helpers.findPreviousWhere = function(arrayToSearch, filterCallback, startIndex) {
// Default to end of the array
if (startIndex === undefined || startIndex === null) {
startIndex = arrayToSearch.length;
}
for (var i = startIndex - 1; i >= 0; i--) {
var currentItem = arrayToSearch[i];
if (filterCallback(currentItem)) {
return currentItem;
}
}
},
inherits = helpers.inherits = function(extensions) {
//Basic javascript inheritance based on the model created in Backbone.js
var parent = this;
var ChartElement = (extensions && extensions.hasOwnProperty("constructor")) ? extensions.constructor : function() {
return parent.apply(this, arguments);
};
var Surrogate = function() {
this.constructor = ChartElement;
};
Surrogate.prototype = parent.prototype;
ChartElement.prototype = new Surrogate();
ChartElement.extend = inherits;
if (extensions) extend(ChartElement.prototype, extensions);
ChartElement.__super__ = parent.prototype;
return ChartElement;
},
noop = helpers.noop = function() {},
uid = helpers.uid = (function() {
var id = 0;
return function() {
return "chart-" + id++;
};
})(),
warn = helpers.warn = function(str) {
//Method for warning of errors
if (console && typeof console.warn === "function") {
console.warn(str);
}
},
//-- Math methods
isNumber = helpers.isNumber = function(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
},
max = helpers.max = function(array) {
return Math.max.apply(Math, array);
},
min = helpers.min = function(array) {
return Math.min.apply(Math, array);
},
sign = helpers.sign = function(x) {
if (Math.sign) {
return Math.sign(x);
} else {
x = +x; // convert to a number
if (x === 0 || isNaN(x)) {
return x;
}
return x > 0 ? 1 : -1;
}
},
log10 = helpers.log10 = function(x) {
if (Math.log10) {
return Math.log10(x);
} else {
return Math.log(x) / Math.LN10;
}
},
getDecimalPlaces = helpers.getDecimalPlaces = function(num) {
if (num % 1 !== 0 && isNumber(num)) {
var s = num.toString();
if (s.indexOf("e-") < 0) {
// no exponent, e.g. 0.01
return s.split(".")[1].length;
} else if (s.indexOf(".") < 0) {
// no decimal point, e.g. 1e-9
return parseInt(s.split("e-")[1]);
} else {
// exponent and decimal point, e.g. 1.23e-9
var parts = s.split(".")[1].split("e-");
return parts[0].length + parseInt(parts[1]);
}
} else {
return 0;
}
},
toRadians = helpers.toRadians = function(degrees) {
return degrees * (Math.PI / 180);
},
toDegrees = helpers.toDegrees = function(radians) {
return radians * (180 / Math.PI);
},
// Gets the angle from vertical upright to the point about a centre.
getAngleFromPoint = helpers.getAngleFromPoint = function(centrePoint, anglePoint) {
var distanceFromXCenter = anglePoint.x - centrePoint.x,
distanceFromYCenter = anglePoint.y - centrePoint.y,
radialDistanceFromCenter = Math.sqrt(distanceFromXCenter * distanceFromXCenter + distanceFromYCenter * distanceFromYCenter);
var angle = Math.atan2(distanceFromYCenter, distanceFromXCenter);
if (angle < (-0.5 * Math.PI)) {
angle += 2.0 * Math.PI; // make sure the returned angle is in the range of (-PI/2, 3PI/2]
}
return {
angle: angle,
distance: radialDistanceFromCenter
};
},
aliasPixel = helpers.aliasPixel = function(pixelWidth) {
return (pixelWidth % 2 === 0) ? 0 : 0.5;
},
splineCurve = helpers.splineCurve = function(firstPoint, middlePoint, afterPoint, t) {
//Props to Rob Spencer at scaled innovation for his post on splining between points
//path_to_url
// This function must also respect "skipped" points
var previous = firstPoint.skip ? middlePoint : firstPoint,
current = middlePoint,
next = afterPoint.skip ? middlePoint : afterPoint;
var d01 = Math.sqrt(Math.pow(current.x - previous.x, 2) + Math.pow(current.y - previous.y, 2));
var d12 = Math.sqrt(Math.pow(next.x - current.x, 2) + Math.pow(next.y - current.y, 2));
var s01 = d01 / (d01 + d12);
var s12 = d12 / (d01 + d12);
// If all points are the same, s01 & s02 will be inf
s01 = isNaN(s01) ? 0 : s01;
s12 = isNaN(s12) ? 0 : s12;
var fa = t * s01; // scaling factor for triangle Ta
var fb = t * s12;
return {
previous: {
x: current.x - fa * (next.x - previous.x),
y: current.y - fa * (next.y - previous.y)
},
next: {
x: current.x + fb * (next.x - previous.x),
y: current.y + fb * (next.y - previous.y)
}
};
},
nextItem = helpers.nextItem = function(collection, index, loop) {
if (loop) {
return index >= collection.length - 1 ? collection[0] : collection[index + 1];
}
return index >= collection.length - 1 ? collection[collection.length - 1] : collection[index + 1];
},
previousItem = helpers.previousItem = function(collection, index, loop) {
if (loop) {
return index <= 0 ? collection[collection.length - 1] : collection[index - 1];
}
return index <= 0 ? collection[0] : collection[index - 1];
},
// Implementation of the nice number algorithm used in determining where axis labels will go
niceNum = helpers.niceNum = function(range, round) {
var exponent = Math.floor(helpers.log10(range));
var fraction = range / Math.pow(10, exponent);
var niceFraction;
if (round) {
if (fraction < 1.5) {
niceFraction = 1;
} else if (fraction < 3) {
niceFraction = 2;
} else if (fraction < 7) {
niceFraction = 5;
} else {
niceFraction = 10;
}
} else {
if (fraction <= 1.0) {
niceFraction = 1;
} else if (fraction <= 2) {
niceFraction = 2;
} else if (fraction <= 5) {
niceFraction = 5;
} else {
niceFraction = 10;
}
}
return niceFraction * Math.pow(10, exponent);
},
//Easing functions adapted from Robert Penner's easing equations
//path_to_url
easingEffects = helpers.easingEffects = {
linear: function(t) {
return t;
},
easeInQuad: function(t) {
return t * t;
},
easeOutQuad: function(t) {
return -1 * t * (t - 2);
},
easeInOutQuad: function(t) {
if ((t /= 1 / 2) < 1) {
return 1 / 2 * t * t;
}
return -1 / 2 * ((--t) * (t - 2) - 1);
},
easeInCubic: function(t) {
return t * t * t;
},
easeOutCubic: function(t) {
return 1 * ((t = t / 1 - 1) * t * t + 1);
},
easeInOutCubic: function(t) {
if ((t /= 1 / 2) < 1) {
return 1 / 2 * t * t * t;
}
return 1 / 2 * ((t -= 2) * t * t + 2);
},
easeInQuart: function(t) {
return t * t * t * t;
},
easeOutQuart: function(t) {
return -1 * ((t = t / 1 - 1) * t * t * t - 1);
},
easeInOutQuart: function(t) {
if ((t /= 1 / 2) < 1) {
return 1 / 2 * t * t * t * t;
}
return -1 / 2 * ((t -= 2) * t * t * t - 2);
},
easeInQuint: function(t) {
return 1 * (t /= 1) * t * t * t * t;
},
easeOutQuint: function(t) {
return 1 * ((t = t / 1 - 1) * t * t * t * t + 1);
},
easeInOutQuint: function(t) {
if ((t /= 1 / 2) < 1) {
return 1 / 2 * t * t * t * t * t;
}
return 1 / 2 * ((t -= 2) * t * t * t * t + 2);
},
easeInSine: function(t) {
return -1 * Math.cos(t / 1 * (Math.PI / 2)) + 1;
},
easeOutSine: function(t) {
return 1 * Math.sin(t / 1 * (Math.PI / 2));
},
easeInOutSine: function(t) {
return -1 / 2 * (Math.cos(Math.PI * t / 1) - 1);
},
easeInExpo: function(t) {
return (t === 0) ? 1 : 1 * Math.pow(2, 10 * (t / 1 - 1));
},
easeOutExpo: function(t) {
return (t === 1) ? 1 : 1 * (-Math.pow(2, -10 * t / 1) + 1);
},
easeInOutExpo: function(t) {
if (t === 0) {
return 0;
}
if (t === 1) {
return 1;
}
if ((t /= 1 / 2) < 1) {
return 1 / 2 * Math.pow(2, 10 * (t - 1));
}
return 1 / 2 * (-Math.pow(2, -10 * --t) + 2);
},
easeInCirc: function(t) {
if (t >= 1) {
return t;
}
return -1 * (Math.sqrt(1 - (t /= 1) * t) - 1);
},
easeOutCirc: function(t) {
return 1 * Math.sqrt(1 - (t = t / 1 - 1) * t);
},
easeInOutCirc: function(t) {
if ((t /= 1 / 2) < 1) {
return -1 / 2 * (Math.sqrt(1 - t * t) - 1);
}
return 1 / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1);
},
easeInElastic: function(t) {
var s = 1.70158;
var p = 0;
var a = 1;
if (t === 0) {
return 0;
}
if ((t /= 1) == 1) {
return 1;
}
if (!p) {
p = 1 * 0.3;
}
if (a < Math.abs(1)) {
a = 1;
s = p / 4;
} else {
s = p / (2 * Math.PI) * Math.asin(1 / a);
}
return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p));
},
easeOutElastic: function(t) {
var s = 1.70158;
var p = 0;
var a = 1;
if (t === 0) {
return 0;
}
if ((t /= 1) == 1) {
return 1;
}
if (!p) {
p = 1 * 0.3;
}
if (a < Math.abs(1)) {
a = 1;
s = p / 4;
} else {
s = p / (2 * Math.PI) * Math.asin(1 / a);
}
return a * Math.pow(2, -10 * t) * Math.sin((t * 1 - s) * (2 * Math.PI) / p) + 1;
},
easeInOutElastic: function(t) {
var s = 1.70158;
var p = 0;
var a = 1;
if (t === 0) {
return 0;
}
if ((t /= 1 / 2) == 2) {
return 1;
}
if (!p) {
p = 1 * (0.3 * 1.5);
}
if (a < Math.abs(1)) {
a = 1;
s = p / 4;
} else {
s = p / (2 * Math.PI) * Math.asin(1 / a);
}
if (t < 1) {
return -0.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p));
}
return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p) * 0.5 + 1;
},
easeInBack: function(t) {
var s = 1.70158;
return 1 * (t /= 1) * t * ((s + 1) * t - s);
},
easeOutBack: function(t) {
var s = 1.70158;
return 1 * ((t = t / 1 - 1) * t * ((s + 1) * t + s) + 1);
},
easeInOutBack: function(t) {
var s = 1.70158;
if ((t /= 1 / 2) < 1) {
return 1 / 2 * (t * t * (((s *= (1.525)) + 1) * t - s));
}
return 1 / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2);
},
easeInBounce: function(t) {
return 1 - easingEffects.easeOutBounce(1 - t);
},
easeOutBounce: function(t) {
if ((t /= 1) < (1 / 2.75)) {
return 1 * (7.5625 * t * t);
} else if (t < (2 / 2.75)) {
return 1 * (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75);
} else if (t < (2.5 / 2.75)) {
return 1 * (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375);
} else {
return 1 * (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375);
}
},
easeInOutBounce: function(t) {
if (t < 1 / 2) {
return easingEffects.easeInBounce(t * 2) * 0.5;
}
return easingEffects.easeOutBounce(t * 2 - 1) * 0.5 + 1 * 0.5;
}
},
//Request animation polyfill - path_to_url
requestAnimFrame = helpers.requestAnimFrame = (function() {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(callback) {
return window.setTimeout(callback, 1000 / 60);
};
})(),
cancelAnimFrame = helpers.cancelAnimFrame = (function() {
return window.cancelAnimationFrame ||
window.webkitCancelAnimationFrame ||
window.mozCancelAnimationFrame ||
window.oCancelAnimationFrame ||
window.msCancelAnimationFrame ||
function(callback) {
return window.clearTimeout(callback, 1000 / 60);
};
})(),
//-- DOM methods
getRelativePosition = helpers.getRelativePosition = function(evt, chart) {
var mouseX, mouseY;
var e = evt.originalEvent || evt,
canvas = evt.currentTarget || evt.srcElement,
boundingRect = canvas.getBoundingClientRect();
if (e.touches && e.touches.length > 0) {
mouseX = e.touches[0].clientX;
mouseY = e.touches[0].clientY;
} else {
mouseX = e.clientX;
mouseY = e.clientY;
}
// Scale mouse coordinates into canvas coordinates
// by following the pattern laid out by 'jerryj' in the comments of
// path_to_url
// We divide by the current device pixel ratio, because the canvas is scaled up by that amount in each direction. However
// the backend model is in unscaled coordinates. Since we are going to deal with our model coordinates, we go back here
mouseX = Math.round((mouseX - boundingRect.left) / (boundingRect.right - boundingRect.left) * canvas.width / chart.currentDevicePixelRatio);
mouseY = Math.round((mouseY - boundingRect.top) / (boundingRect.bottom - boundingRect.top) * canvas.height / chart.currentDevicePixelRatio);
return {
x: mouseX,
y: mouseY
};
},
addEvent = helpers.addEvent = function(node, eventType, method) {
if (node.addEventListener) {
node.addEventListener(eventType, method);
} else if (node.attachEvent) {
node.attachEvent("on" + eventType, method);
} else {
node["on" + eventType] = method;
}
},
removeEvent = helpers.removeEvent = function(node, eventType, handler) {
if (node.removeEventListener) {
node.removeEventListener(eventType, handler, false);
} else if (node.detachEvent) {
node.detachEvent("on" + eventType, handler);
} else {
node["on" + eventType] = noop;
}
},
bindEvents = helpers.bindEvents = function(chartInstance, arrayOfEvents, handler) {
// Create the events object if it's not already present
if (!chartInstance.events) chartInstance.events = {};
each(arrayOfEvents, function(eventName) {
chartInstance.events[eventName] = function() {
handler.apply(chartInstance, arguments);
};
addEvent(chartInstance.chart.canvas, eventName, chartInstance.events[eventName]);
});
},
unbindEvents = helpers.unbindEvents = function(chartInstance, arrayOfEvents) {
each(arrayOfEvents, function(handler, eventName) {
removeEvent(chartInstance.chart.canvas, eventName, handler);
});
},
getConstraintWidth = helpers.getConstraintWidth = function(domNode) { // returns Number or undefined if no constraint
var constrainedWidth;
var constrainedWNode = document.defaultView.getComputedStyle(domNode)['max-width'];
var constrainedWContainer = document.defaultView.getComputedStyle(domNode.parentNode)['max-width'];
var hasCWNode = constrainedWNode !== null && constrainedWNode !== "none";
var hasCWContainer = constrainedWContainer !== null && constrainedWContainer !== "none";
if (hasCWNode || hasCWContainer) {
constrainedWidth = Math.min((hasCWNode ? parseInt(constrainedWNode, 10) : Number.POSITIVE_INFINITY), (hasCWContainer ? parseInt(constrainedWContainer, 10) : Number.POSITIVE_INFINITY));
}
return constrainedWidth;
},
getConstraintHeight = helpers.getConstraintHeight = function(domNode) { // returns Number or undefined if no constraint
var constrainedHeight;
var constrainedHNode = document.defaultView.getComputedStyle(domNode)['max-height'];
var constrainedHContainer = document.defaultView.getComputedStyle(domNode.parentNode)['max-height'];
var hasCHNode = constrainedHNode !== null && constrainedHNode !== "none";
var hasCHContainer = constrainedHContainer !== null && constrainedHContainer !== "none";
if (constrainedHNode || constrainedHContainer) {
constrainedHeight = Math.min((hasCHNode ? parseInt(constrainedHNode, 10) : Number.POSITIVE_INFINITY), (hasCHContainer ? parseInt(constrainedHContainer, 10) : Number.POSITIVE_INFINITY));
}
return constrainedHeight;
},
getMaximumWidth = helpers.getMaximumWidth = function(domNode) {
var container = domNode.parentNode;
var padding = parseInt(getStyle(container, 'padding-left')) + parseInt(getStyle(container, 'padding-right'));
var w = container.clientWidth - padding;
var cw = getConstraintWidth(domNode);
if (cw !== undefined) {
w = Math.min(w, cw);
}
return w;
},
getMaximumHeight = helpers.getMaximumHeight = function(domNode) {
var container = domNode.parentNode;
var padding = parseInt(getStyle(container, 'padding-top')) + parseInt(getStyle(container, 'padding-bottom'));
var h = container.clientHeight - padding;
var ch = getConstraintHeight(domNode);
if (ch !== undefined) {
h = Math.min(h, ch);
}
return h;
},
getStyle = helpers.getStyle = function(el, property) {
return el.currentStyle ?
el.currentStyle[property] :
document.defaultView.getComputedStyle(el, null).getPropertyValue(property);
},
getMaximumSize = helpers.getMaximumSize = helpers.getMaximumWidth, // legacy support
retinaScale = helpers.retinaScale = function(chart) {
var ctx = chart.ctx;
var width = chart.canvas.width;
var height = chart.canvas.height;
var pixelRatio = chart.currentDevicePixelRatio = window.devicePixelRatio || 1;
if (pixelRatio !== 1) {
ctx.canvas.height = height * pixelRatio;
ctx.canvas.width = width * pixelRatio;
ctx.scale(pixelRatio, pixelRatio);
ctx.canvas.style.width = width + 'px';
ctx.canvas.style.height = height + 'px';
// Store the device pixel ratio so that we can go backwards in `destroy`.
// The devicePixelRatio changes with zoom, so there are no guarantees that it is the same
// when destroy is called
chart.originalDevicePixelRatio = chart.originalDevicePixelRatio || pixelRatio;
}
},
//-- Canvas methods
clear = helpers.clear = function(chart) {
chart.ctx.clearRect(0, 0, chart.width, chart.height);
},
fontString = helpers.fontString = function(pixelSize, fontStyle, fontFamily) {
return fontStyle + " " + pixelSize + "px " + fontFamily;
},
longestText = helpers.longestText = function(ctx, font, arrayOfStrings) {
ctx.font = font;
var longest = 0;
each(arrayOfStrings, function(string) {
var textWidth = ctx.measureText(string).width;
longest = (textWidth > longest) ? textWidth : longest;
});
return longest;
},
drawRoundedRectangle = helpers.drawRoundedRectangle = function(ctx, x, y, width, height, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.lineTo(x + width - radius, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
ctx.lineTo(x + width, y + height - radius);
ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
ctx.lineTo(x + radius, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
ctx.lineTo(x, y + radius);
ctx.quadraticCurveTo(x, y, x + radius, y);
ctx.closePath();
},
color = helpers.color = function(color) {
if (!root.Color) {
console.log('Color.js not found!');
return color;
}
return root.Color(color);
},
addResizeListener = helpers.addResizeListener = function(node, callback) {
// Hide an iframe before the node
var hiddenIframe = document.createElement('iframe');
var hiddenIframeClass = 'chartjs-hidden-iframe';
if (hiddenIframe.classlist) {
// can use classlist
hiddenIframe.classlist.add(hiddenIframeClass);
} else {
hiddenIframe.setAttribute('class', hiddenIframeClass);
}
// Set the style
hiddenIframe.style.width = '100%';
hiddenIframe.style.display = 'block';
hiddenIframe.style.border = 0;
hiddenIframe.style.height = 0;
hiddenIframe.style.margin = 0;
hiddenIframe.style.position = 'absolute';
hiddenIframe.style.left = 0;
hiddenIframe.style.right = 0;
hiddenIframe.style.top = 0;
hiddenIframe.style.bottom = 0;
// Insert the iframe so that contentWindow is available
node.insertBefore(hiddenIframe, node.firstChild);
var timer = 0;
(hiddenIframe.contentWindow || hiddenIframe).onresize = function() {
if (callback) {
callback();
}
};
},
removeResizeListener = helpers.removeResizeListener = function(node) {
var hiddenIframe = node.querySelector('.chartjs-hidden-iframe');
// Remove the resize detect iframe
if (hiddenIframe) {
hiddenIframe.parentNode.removeChild(hiddenIframe);
}
},
isArray = helpers.isArray = function(obj) {
if (!Array.isArray) {
return Object.prototype.toString.call(arg) === '[object Array]';
}
return Array.isArray(obj);
},
isDatasetVisible = helpers.isDatasetVisible = function(dataset) {
return !dataset.hidden;
};
helpers.callCallback = function(fn, args, _tArg) {
if (fn && typeof fn.call === 'function') {
fn.apply(_tArg, args);
}
}
}).call(this);
(function() {
"use strict";
//Declare root variable - window in the browser, global on the server
var root = this,
Chart = root.Chart,
helpers = Chart.helpers;
Chart.elements = {};
Chart.Element = function(configuration) {
helpers.extend(this, configuration);
this.initialize.apply(this, arguments);
};
helpers.extend(Chart.Element.prototype, {
initialize: function() {},
pivot: function() {
if (!this._view) {
this._view = helpers.clone(this._model);
}
this._start = helpers.clone(this._view);
return this;
},
transition: function(ease) {
if (!this._view) {
this._view = helpers.clone(this._model);
}
if (!this._start) {
this.pivot();
}
helpers.each(this._model, function(value, key) {
if (key[0] === '_' || !this._model.hasOwnProperty(key)) {
// Only non-underscored properties
}
// Init if doesn't exist
else if (!this._view[key]) {
if (typeof value === 'number' && isNaN(this._view[key]) === false) {
this._view[key] = value * ease;
} else {
this._view[key] = value || null;
}
}
// No unnecessary computations
else if (this._model[key] === this._view[key]) {
// It's the same! Woohoo!
}
// Color transitions if possible
else if (typeof value === 'string') {
try {
var color = helpers.color(this._start[key]).mix(helpers.color(this._model[key]), ease);
this._view[key] = color.rgbString();
} catch (err) {
this._view[key] = value;
}
}
// Number transitions
else if (typeof value === 'number') {
var startVal = this._start[key] !== undefined && isNaN(this._start[key]) === false ? this._start[key] : 0;
this._view[key] = ((this._model[key] - startVal) * ease) + startVal;
}
// Everything else
else {
this._view[key] = value;
}
}, this);
if (ease === 1) {
delete this._start;
}
return this;
},
tooltipPosition: function() {
return {
x: this._model.x,
y: this._model.y
};
},
hasValue: function() {
return helpers.isNumber(this._model.x) && helpers.isNumber(this._model.y);
}
});
Chart.Element.extend = helpers.inherits;
}).call(this);
(function() {
"use strict";
var root = this,
Chart = root.Chart,
helpers = Chart.helpers;
Chart.defaults.global.animation = {
duration: 1000,
easing: "easeOutQuart",
onProgress: helpers.noop,
onComplete: helpers.noop,
};
Chart.Animation = Chart.Element.extend({
currentStep: null, // the current animation step
numSteps: 60, // default number of steps
easing: "", // the easing to use for this animation
render: null, // render function used by the animation service
onAnimationProgress: null, // user specified callback to fire on each step of the animation
onAnimationComplete: null, // user specified callback to fire when the animation finishes
});
Chart.animationService = {
frameDuration: 17,
animations: [],
dropFrames: 0,
addAnimation: function(chartInstance, animationObject, duration, lazy) {
if (!lazy) {
chartInstance.animating = true;
}
for (var index = 0; index < this.animations.length; ++index) {
if (this.animations[index].chartInstance === chartInstance) {
// replacing an in progress animation
this.animations[index].animationObject = animationObject;
return;
}
}
this.animations.push({
chartInstance: chartInstance,
animationObject: animationObject
});
// If there are no animations queued, manually kickstart a digest, for lack of a better word
if (this.animations.length == 1) {
helpers.requestAnimFrame.call(window, this.digestWrapper);
}
},
// Cancel the animation for a given chart instance
cancelAnimation: function(chartInstance) {
var index = helpers.findNextWhere(this.animations, function(animationWrapper) {
return animationWrapper.chartInstance === chartInstance;
});
if (index) {
this.animations.splice(index, 1);
chartInstance.animating = false;
}
},
// calls startDigest with the proper context
digestWrapper: function() {
Chart.animationService.startDigest.call(Chart.animationService);
},
startDigest: function() {
var startTime = Date.now();
var framesToDrop = 0;
if (this.dropFrames > 1) {
framesToDrop = Math.floor(this.dropFrames);
this.dropFrames = this.dropFrames % 1;
}
for (var i = 0; i < this.animations.length; i++) {
if (this.animations[i].animationObject.currentStep === null) {
this.animations[i].animationObject.currentStep = 0;
}
this.animations[i].animationObject.currentStep += 1 + framesToDrop;
if (this.animations[i].animationObject.currentStep > this.animations[i].animationObject.numSteps) {
this.animations[i].animationObject.currentStep = this.animations[i].animationObject.numSteps;
}
this.animations[i].animationObject.render(this.animations[i].chartInstance, this.animations[i].animationObject);
if (this.animations[i].animationObject.onAnimationProgress && this.animations[i].animationObject.onAnimationProgress.call) {
this.animations[i].animationObject.onAnimationProgress.call(this.animations[i].chartInstance, this.animations[i]);
}
if (this.animations[i].animationObject.currentStep == this.animations[i].animationObject.numSteps) {
if (this.animations[i].animationObject.onAnimationComplete && this.animations[i].animationObject.onAnimationComplete.call) {
this.animations[i].animationObject.onAnimationComplete.call(this.animations[i].chartInstance, this.animations[i]);
}
// executed the last frame. Remove the animation.
this.animations[i].chartInstance.animating = false;
this.animations.splice(i, 1);
// Keep the index in place to offset the splice
i--;
}
}
var endTime = Date.now();
var dropFrames = (endTime - startTime) / this.frameDuration;
this.dropFrames += dropFrames;
// Do we have more stuff to animate?
if (this.animations.length > 0) {
helpers.requestAnimFrame.call(window, this.digestWrapper);
}
}
};
}).call(this);
(function() {
"use strict";
//Declare root variable - window in the browser, global on the server
var root = this,
Chart = root.Chart,
helpers = Chart.helpers;
//Create a dictionary of chart types, to allow for extension of existing types
Chart.types = {};
//Store a reference to each instance - allowing us to globally resize chart instances on window resize.
//Destroy method on the chart will remove the instance of the chart from this reference.
Chart.instances = {};
// Controllers available for dataset visualization eg. bar, line, slice, etc.
Chart.controllers = {};
// The main controller of a chart
Chart.Controller = function(instance) {
this.chart = instance;
this.config = instance.config;
this.options = this.config.options = helpers.configMerge(Chart.defaults.global, Chart.defaults[this.config.type], this.config.options || {});
this.id = helpers.uid();
Object.defineProperty(this, 'data', {
get: function() {
return this.config.data;
},
});
//Add the chart instance to the global namespace
Chart.instances[this.id] = this;
if (this.options.responsive) {
// Silent resize before chart draws
this.resize(true);
}
this.initialize.call(this);
return this;
};
helpers.extend(Chart.Controller.prototype, {
initialize: function initialize() {
// TODO
// If BeforeInit(this) doesn't return false, proceed
this.bindEvents();
// Make sure controllers are built first so that each dataset is bound to an axis before the scales
// are built
this.ensureScalesHaveIDs();
this.buildOrUpdateControllers();
this.buildScales();
this.buildSurroundingItems();
this.updateLayout();
this.resetElements();
this.initToolTip();
this.update();
// TODO
// If AfterInit(this) doesn't return false, proceed
return this;
},
clear: function clear() {
helpers.clear(this.chart);
return this;
},
stop: function stop() {
// Stops any current animation loop occuring
Chart.animationService.cancelAnimation(this);
return this;
},
resize: function resize(silent) {
this.stop();
var canvas = this.chart.canvas;
var newWidth = helpers.getMaximumWidth(this.chart.canvas);
var newHeight = (this.options.maintainAspectRatio && isNaN(this.chart.aspectRatio) === false && isFinite(this.chart.aspectRatio) && this.chart.aspectRatio !== 0) ? newWidth / this.chart.aspectRatio : helpers.getMaximumHeight(this.chart.canvas);
canvas.width = this.chart.width = newWidth;
canvas.height = this.chart.height = newHeight;
helpers.retinaScale(this.chart);
if (!silent) {
this.update(this.options.responsiveAnimationDuration);
}
return this;
},
ensureScalesHaveIDs: function ensureScalesHaveIDs() {
var defaultXAxisID = 'x-axis-';
var defaultYAxisID = 'y-axis-';
if (this.options.scales) {
if (this.options.scales.xAxes && this.options.scales.xAxes.length) {
helpers.each(this.options.scales.xAxes, function(xAxisOptions, index) {
xAxisOptions.id = xAxisOptions.id || (defaultXAxisID + index);
}, this);
}
if (this.options.scales.yAxes && this.options.scales.yAxes.length) {
// Build the y axes
helpers.each(this.options.scales.yAxes, function(yAxisOptions, index) {
yAxisOptions.id = yAxisOptions.id || (defaultYAxisID + index);
}, this);
}
}
},
buildScales: function buildScales() {
// Map of scale ID to scale object so we can lookup later
this.scales = {};
// Build the x axes
if (this.options.scales) {
if (this.options.scales.xAxes && this.options.scales.xAxes.length) {
helpers.each(this.options.scales.xAxes, function(xAxisOptions, index) {
var ScaleClass = Chart.scaleService.getScaleConstructor(xAxisOptions.type);
var scale = new ScaleClass({
ctx: this.chart.ctx,
options: xAxisOptions,
chart: this,
id: xAxisOptions.id,
});
this.scales[scale.id] = scale;
}, this);
}
if (this.options.scales.yAxes && this.options.scales.yAxes.length) {
// Build the y axes
helpers.each(this.options.scales.yAxes, function(yAxisOptions, index) {
var ScaleClass = Chart.scaleService.getScaleConstructor(yAxisOptions.type);
var scale = new ScaleClass({
ctx: this.chart.ctx,
options: yAxisOptions,
chart: this,
id: yAxisOptions.id,
});
this.scales[scale.id] = scale;
}, this);
}
}
if (this.options.scale) {
// Build radial axes
var ScaleClass = Chart.scaleService.getScaleConstructor(this.options.scale.type);
var scale = new ScaleClass({
ctx: this.chart.ctx,
options: this.options.scale,
chart: this,
});
this.scale = scale;
this.scales.radialScale = scale;
}
Chart.scaleService.addScalesToLayout(this);
},
buildSurroundingItems: function() {
if (this.options.title) {
this.titleBlock = new Chart.Title({
ctx: this.chart.ctx,
options: this.options.title,
chart: this
});
Chart.layoutService.addBox(this, this.titleBlock);
}
if (this.options.legend) {
this.legend = new Chart.Legend({
ctx: this.chart.ctx,
options: this.options.legend,
chart: this,
});
Chart.layoutService.addBox(this, this.legend);
}
},
updateLayout: function() {
Chart.layoutService.update(this, this.chart.width, this.chart.height);
},
buildOrUpdateControllers: function buildOrUpdateControllers(resetNewControllers) {
var types = [];
helpers.each(this.data.datasets, function(dataset, datasetIndex) {
if (!dataset.type) {
dataset.type = this.config.type;
}
var type = dataset.type;
types.push(type);
if (dataset.controller) {
dataset.controller.updateIndex(datasetIndex);
} else {
dataset.controller = new Chart.controllers[type](this, datasetIndex);
if (resetNewControllers) {
dataset.controller.reset();
}
}
}, this);
if (types.length > 1) {
for (var i = 1; i < types.length; i++) {
if (types[i] != types[i - 1]) {
this.isCombo = true;
break;
}
}
}
},
resetElements: function resetElements() {
helpers.each(this.data.datasets, function(dataset, datasetIndex) {
dataset.controller.reset();
}, this);
},
update: function update(animationDuration, lazy) {
// In case the entire data object changed
this.tooltip._data = this.data;
// Make sure dataset controllers are updated and new controllers are reset
this.buildOrUpdateControllers(true);
Chart.layoutService.update(this, this.chart.width, this.chart.height);
// Make sure all dataset controllers have correct meta data counts
helpers.each(this.data.datasets, function(dataset, datasetIndex) {
dataset.controller.buildOrUpdateElements();
}, this);
// This will loop through any data and do the appropriate element update for the type
helpers.each(this.data.datasets, function(dataset, datasetIndex) {
dataset.controller.update();
}, this);
this.render(animationDuration, lazy);
},
render: function render(duration, lazy) {
if (this.options.animation && ((typeof duration !== 'undefined' && duration !== 0) || (typeof duration == 'undefined' && this.options.animation.duration !== 0))) {
var animation = new Chart.Animation();
animation.numSteps = (duration || this.options.animation.duration) / 16.66; //60 fps
animation.easing = this.options.animation.easing;
// render function
animation.render = function(chartInstance, animationObject) {
var easingFunction = helpers.easingEffects[animationObject.easing];
var stepDecimal = animationObject.currentStep / animationObject.numSteps;
var easeDecimal = easingFunction(stepDecimal);
chartInstance.draw(easeDecimal, stepDecimal, animationObject.currentStep);
};
// user events
animation.onAnimationProgress = this.options.animation.onProgress;
animation.onAnimationComplete = this.options.animation.onComplete;
Chart.animationService.addAnimation(this, animation, duration, lazy);
} else {
this.draw();
if (this.options.animation && this.options.animation.onComplete && this.options.animation.onComplete.call) {
this.options.animation.onComplete.call(this);
}
}
return this;
},
draw: function(ease) {
var easingDecimal = ease || 1;
this.clear();
// Draw all the scales
helpers.each(this.boxes, function(box) {
box.draw(this.chartArea);
}, this);
if (this.scale) {
this.scale.draw();
}
// Draw each dataset via its respective controller (reversed to support proper line stacking)
helpers.each(this.data.datasets, function(dataset, datasetIndex) {
if (helpers.isDatasetVisible(dataset)) {
dataset.controller.draw(ease);
}
}, this);
// Finally draw the tooltip
this.tooltip.transition(easingDecimal).draw();
},
// Get the single element that was clicked on
// @return : An object containing the dataset index and element index of the matching element. Also contains the rectangle that was draw
getElementAtEvent: function(e) {
var eventPosition = helpers.getRelativePosition(e, this.chart);
var elementsArray = [];
helpers.each(this.data.datasets, function(dataset, datasetIndex) {
if (helpers.isDatasetVisible(dataset)) {
helpers.each(dataset.metaData, function(element, index) {
if (element.inRange(eventPosition.x, eventPosition.y)) {
elementsArray.push(element);
return elementsArray;
}
}, this);
}
}, this);
return elementsArray;
},
getElementsAtEvent: function(e) {
var eventPosition = helpers.getRelativePosition(e, this.chart);
var elementsArray = [];
var found = (function(){
for (var i = 0; i < this.data.datasets.length; i++) {
if (helpers.isDatasetVisible(this.data.datasets[i])) {
for (var j = 0; j < this.data.datasets[i].metaData.length; j++) {
if (this.data.datasets[i].metaData[j].inRange(eventPosition.x, eventPosition.y)) {
return this.data.datasets[i].metaData[j];
}
}
}
}
}).call(this);
if(!found){
return elementsArray;
}
helpers.each(this.data.datasets, function(dataset, dsIndex){
if(helpers.isDatasetVisible(dataset)){
elementsArray.push(dataset.metaData[found._index]);
}
}, this);
return elementsArray;
},
getDatasetAtEvent: function(e) {
var elementsArray = this.getElementAtEvent(e);
if (elementsArray.length > 0) {
elementsArray = this.data.datasets[elementsArray[0]._datasetIndex].metaData;
}
return elementsArray;
},
generateLegend: function generateLegend() {
return this.options.legendCallback(this);
},
destroy: function destroy() {
this.clear();
helpers.unbindEvents(this, this.events);
helpers.removeResizeListener(this.chart.canvas.parentNode);
// Reset canvas height/width attributes
var canvas = this.chart.canvas;
canvas.width = this.chart.width;
canvas.height = this.chart.height;
// if we scaled the canvas in response to a devicePixelRatio !== 1, we need to undo that transform here
if (this.chart.originalDevicePixelRatio !== undefined) {
this.chart.ctx.scale(1 / this.chart.originalDevicePixelRatio, 1 / this.chart.originalDevicePixelRatio);
}
// Reset to the old style since it may have been changed by the device pixel ratio changes
canvas.style.width = this.chart.originalCanvasStyleWidth;
canvas.style.height = this.chart.originalCanvasStyleHeight;
delete Chart.instances[this.id];
},
toBase64Image: function toBase64Image() {
return this.chart.canvas.toDataURL.apply(this.chart.canvas, arguments);
},
initToolTip: function initToolTip() {
this.tooltip = new Chart.Tooltip({
_chart: this.chart,
_chartInstance: this,
_data: this.data,
_options: this.options,
}, this);
},
bindEvents: function bindEvents() {
helpers.bindEvents(this, this.options.events, function(evt) {
this.eventHandler(evt);
});
},
eventHandler: function eventHandler(e) {
this.lastActive = this.lastActive || [];
this.lastTooltipActive = this.lastTooltipActive || [];
// Find Active Elements for hover and tooltips
if (e.type == 'mouseout') {
this.active = [];
this.tooltipActive = [];
} else {
var _this = this;
var getItemsForMode = function(mode) {
switch (mode) {
case 'single':
return _this.getElementAtEvent(e);
case 'label':
return _this.getElementsAtEvent(e);
case 'dataset':
return _this.getDatasetAtEvent(e);
default:
return e;
}
};
this.active = getItemsForMode(this.options.hover.mode);
this.tooltipActive = getItemsForMode(this.options.tooltips.mode);
}
// On Hover hook
if (this.options.hover.onHover) {
this.options.hover.onHover.call(this, this.active);
}
if (e.type == 'mouseup' || e.type == 'click') {
if (this.options.onClick) {
this.options.onClick.call(this, e, this.active);
}
if (this.legend && this.legend.handleEvent) {
this.legend.handleEvent(e);
}
}
var dataset;
var index;
// Remove styling for last active (even if it may still be active)
if (this.lastActive.length) {
switch (this.options.hover.mode) {
case 'single':
this.data.datasets[this.lastActive[0]._datasetIndex].controller.removeHoverStyle(this.lastActive[0], this.lastActive[0]._datasetIndex, this.lastActive[0]._index);
break;
case 'label':
case 'dataset':
for (var i = 0; i < this.lastActive.length; i++) {
if (this.lastActive[i])
this.data.datasets[this.lastActive[i]._datasetIndex].controller.removeHoverStyle(this.lastActive[i], this.lastActive[i]._datasetIndex, this.lastActive[i]._index);
}
break;
default:
// Don't change anything
}
}
// Built in hover styling
if (this.active.length && this.options.hover.mode) {
switch (this.options.hover.mode) {
case 'single':
this.data.datasets[this.active[0]._datasetIndex].controller.setHoverStyle(this.active[0]);
break;
case 'label':
case 'dataset':
for (var j = 0; j < this.active.length; j++) {
if (this.active[j])
this.data.datasets[this.active[j]._datasetIndex].controller.setHoverStyle(this.active[j]);
}
break;
default:
// Don't change anything
}
}
// Built in Tooltips
if (this.options.tooltips.enabled || this.options.tooltips.custom) {
// The usual updates
this.tooltip.initialize();
this.tooltip._active = this.tooltipActive;
this.tooltip.update();
}
// Hover animations
this.tooltip.pivot();
if (!this.animating) {
var changed;
helpers.each(this.active, function(element, index) {
if (element !== this.lastActive[index]) {
changed = true;
}
}, this);
helpers.each(this.tooltipActive, function(element, index) {
if (element !== this.lastTooltipActive[index]) {
changed = true;
}
}, this);
// If entering, leaving, or changing elements, animate the change via pivot
if ((this.lastActive.length !== this.active.length) ||
(this.lastTooltipActive.length !== this.tooltipActive.length) ||
changed) {
this.stop();
if (this.options.tooltips.enabled || this.options.tooltips.custom) {
this.tooltip.update(true);
}
// We only need to render at this point. Updating will cause scales to be recomputed generating flicker & using more
// memory than necessary.
this.render(this.options.hover.animationDuration, true);
}
}
// Remember Last Actives
this.lastActive = this.active;
this.lastTooltipActive = this.tooltipActive;
return this;
},
});
}).call(this);
(function() {
"use strict";
//Declare root variable - window in the browser, global on the server
var root = this,
Chart = root.Chart,
helpers = Chart.helpers;
// Base class for all dataset controllers (line, bar, etc)
Chart.DatasetController = function(chart, datasetIndex) {
this.initialize.call(this, chart, datasetIndex);
};
helpers.extend(Chart.DatasetController.prototype, {
initialize: function(chart, datasetIndex) {
this.chart = chart;
this.index = datasetIndex;
this.linkScales();
this.addElements();
},
updateIndex: function(datasetIndex) {
this.index = datasetIndex;
},
linkScales: function() {
if (!this.getDataset().xAxisID) {
this.getDataset().xAxisID = this.chart.options.scales.xAxes[0].id;
}
if (!this.getDataset().yAxisID) {
this.getDataset().yAxisID = this.chart.options.scales.yAxes[0].id;
}
},
getDataset: function() {
return this.chart.data.datasets[this.index];
},
getScaleForId: function(scaleID) {
return this.chart.scales[scaleID];
},
reset: function() {
this.update(true);
},
buildOrUpdateElements: function buildOrUpdateElements() {
// Handle the number of data points changing
var numData = this.getDataset().data.length;
var numMetaData = this.getDataset().metaData.length;
// Make sure that we handle number of datapoints changing
if (numData < numMetaData) {
// Remove excess bars for data points that have been removed
this.getDataset().metaData.splice(numData, numMetaData - numData);
} else if (numData > numMetaData) {
// Add new elements
for (var index = numMetaData; index < numData; ++index) {
this.addElementAndReset(index);
}
}
},
// Controllers should implement the following
addElements: helpers.noop,
addElementAndReset: helpers.noop,
draw: helpers.noop,
removeHoverStyle: helpers.noop,
setHoverStyle: helpers.noop,
update: helpers.noop,
});
Chart.DatasetController.extend = helpers.inherits;
}).call(this);
(function() {
"use strict";
var root = this,
Chart = root.Chart,
helpers = Chart.helpers;
// The layout service is ver self explanatory. It's responsible for the layout within a chart.
// Scales, Legends and Plugins all rely on the layout service and can easily register to be placed anywhere they need
// It is this service's responsibility of carrying out that layout.
Chart.layoutService = {
defaults: {},
// Register a box to a chartInstance. A box is simply a reference to an object that requires layout. eg. Scales, Legend, Plugins.
addBox: function(chartInstance, box) {
if (!chartInstance.boxes) {
chartInstance.boxes = [];
}
chartInstance.boxes.push(box);
},
removeBox: function(chartInstance, box) {
if (!chartInstance.boxes) {
return;
}
chartInstance.boxes.splice(chartInstance.boxes.indexOf(box), 1);
},
// The most important function
update: function(chartInstance, width, height) {
if (!chartInstance) {
return;
}
var xPadding = width > 30 ? 5 : 2;
var yPadding = height > 30 ? 5 : 2;
var leftBoxes = helpers.where(chartInstance.boxes, function(box) {
return box.options.position == "left";
});
var rightBoxes = helpers.where(chartInstance.boxes, function(box) {
return box.options.position == "right";
});
var topBoxes = helpers.where(chartInstance.boxes, function(box) {
return box.options.position == "top";
});
var bottomBoxes = helpers.where(chartInstance.boxes, function(box) {
return box.options.position == "bottom";
});
// Boxes that overlay the chartarea such as the radialLinear scale
var chartAreaBoxes = helpers.where(chartInstance.boxes, function(box) {
return box.options.position == "chartArea";
});
function fullWidthSorter(a, b) {
}
// Ensure that full width boxes are at the very top / bottom
topBoxes.sort(function(a, b) {
return (b.options.fullWidth ? 1 : 0) - (a.options.fullWidth ? 1 : 0);
});
bottomBoxes.sort(function(a, b) {
return (a.options.fullWidth ? 1 : 0) - (b.options.fullWidth ? 1 : 0);
});
// Essentially we now have any number of boxes on each of the 4 sides.
// Our canvas looks like the following.
// The areas L1 and L2 are the left axes. R1 is the right axis, T1 is the top axis and
// B1 is the bottom axis
// There are also 4 quadrant-like locations (left to right instead of clockwise) reserved for chart overlays
// These locations are single-box locations only, when trying to register a chartArea location that is already taken,
// an error will be thrown.
//
// |----------------------------------------------------|
// | T1 (Full Width) |
// |----------------------------------------------------|
// | | | T2 | |
// | |----|-------------------------------------|----|
// | | | C1 | | C2 | |
// | | |----| |----| |
// | | | | |
// | L1 | L2 | ChartArea (C0) | R1 |
// | | | | |
// | | |----| |----| |
// | | | C3 | | C4 | |
// | |----|-------------------------------------|----|
// | | | B1 | |
// |----------------------------------------------------|
// | B2 (Full Width) |
// |----------------------------------------------------|
//
// What we do to find the best sizing, we do the following
// 1. Determine the minimum size of the chart area.
// 2. Split the remaining width equally between each vertical axis
// 3. Split the remaining height equally between each horizontal axis
// 4. Give each layout the maximum size it can be. The layout will return it's minimum size
// 5. Adjust the sizes of each axis based on it's minimum reported size.
// 6. Refit each axis
// 7. Position each axis in the final location
// 8. Tell the chart the final location of the chart area
// 9. Tell any axes that overlay the chart area the positions of the chart area
// Step 1
var chartWidth = width - (2 * xPadding);
var chartHeight = height - (2 * yPadding);
var chartAreaWidth = chartWidth / 2; // min 50%
var chartAreaHeight = chartHeight / 2; // min 50%
// Step 2
var verticalBoxWidth = (width - chartAreaWidth) / (leftBoxes.length + rightBoxes.length);
// Step 3
var horizontalBoxHeight = (height - chartAreaHeight) / (topBoxes.length + bottomBoxes.length);
// Step 4
var maxChartAreaWidth = chartWidth;
var maxChartAreaHeight = chartHeight;
var minBoxSizes = [];
helpers.each(leftBoxes.concat(rightBoxes, topBoxes, bottomBoxes), getMinimumBoxSize);
function getMinimumBoxSize(box) {
var minSize;
var isHorizontal = box.isHorizontal();
if (isHorizontal) {
minSize = box.update(box.options.fullWidth ? chartWidth : maxChartAreaWidth, horizontalBoxHeight);
maxChartAreaHeight -= minSize.height;
} else {
minSize = box.update(verticalBoxWidth, chartAreaHeight);
maxChartAreaWidth -= minSize.width;
}
minBoxSizes.push({
horizontal: isHorizontal,
minSize: minSize,
box: box,
});
}
// At this point, maxChartAreaHeight and maxChartAreaWidth are the size the chart area could
// be if the axes are drawn at their minimum sizes.
// Steps 5 & 6
var totalLeftBoxesWidth = xPadding;
var totalRightBoxesWidth = xPadding;
var totalTopBoxesHeight = yPadding;
var totalBottomBoxesHeight = yPadding;
// Update, and calculate the left and right margins for the horizontal boxes
helpers.each(leftBoxes.concat(rightBoxes), fitBox);
helpers.each(leftBoxes, function(box) {
totalLeftBoxesWidth += box.width;
});
helpers.each(rightBoxes, function(box) {
totalRightBoxesWidth += box.width;
});
// Set the Left and Right margins for the horizontal boxes
helpers.each(topBoxes.concat(bottomBoxes), fitBox);
// Function to fit a box
function fitBox(box) {
var minBoxSize = helpers.findNextWhere(minBoxSizes, function(minBoxSize) {
return minBoxSize.box === box;
});
if (minBoxSize) {
if (box.isHorizontal()) {
var scaleMargin = {
left: totalLeftBoxesWidth,
right: totalRightBoxesWidth,
top: 0,
bottom: 0,
};
box.update(box.options.fullWidth ? chartWidth : maxChartAreaWidth, minBoxSize.minSize.height, scaleMargin);
} else {
box.update(minBoxSize.minSize.width, maxChartAreaHeight);
}
}
}
// Figure out how much margin is on the top and bottom of the vertical boxes
helpers.each(topBoxes, function(box) {
totalTopBoxesHeight += box.height;
});
helpers.each(bottomBoxes, function(box) {
totalBottomBoxesHeight += box.height;
});
// Let the left layout know the final margin
helpers.each(leftBoxes.concat(rightBoxes), finalFitVerticalBox);
function finalFitVerticalBox(box) {
var minBoxSize = helpers.findNextWhere(minBoxSizes, function(minBoxSize) {
return minBoxSize.box === box;
});
var scaleMargin = {
left: 0,
right: 0,
top: totalTopBoxesHeight,
bottom: totalBottomBoxesHeight
};
if (minBoxSize) {
box.update(minBoxSize.minSize.width, maxChartAreaHeight, scaleMargin);
}
}
// Recalculate because the size of each layout might have changed slightly due to the margins (label rotation for instance)
totalLeftBoxesWidth = xPadding;
totalRightBoxesWidth = xPadding;
totalTopBoxesHeight = yPadding;
totalBottomBoxesHeight = yPadding;
helpers.each(leftBoxes, function(box) {
totalLeftBoxesWidth += box.width;
});
helpers.each(rightBoxes, function(box) {
totalRightBoxesWidth += box.width;
});
helpers.each(topBoxes, function(box) {
totalTopBoxesHeight += box.height;
});
helpers.each(bottomBoxes, function(box) {
totalBottomBoxesHeight += box.height;
});
// Figure out if our chart area changed. This would occur if the dataset layout label rotation
// changed due to the application of the margins in step 6. Since we can only get bigger, this is safe to do
// without calling `fit` again
var newMaxChartAreaHeight = height - totalTopBoxesHeight - totalBottomBoxesHeight;
var newMaxChartAreaWidth = width - totalLeftBoxesWidth - totalRightBoxesWidth;
if (newMaxChartAreaWidth !== maxChartAreaWidth || newMaxChartAreaHeight !== maxChartAreaHeight) {
helpers.each(leftBoxes, function(box) {
box.height = newMaxChartAreaHeight;
});
helpers.each(rightBoxes, function(box) {
box.height = newMaxChartAreaHeight;
});
helpers.each(topBoxes, function(box) {
box.width = newMaxChartAreaWidth;
});
helpers.each(bottomBoxes, function(box) {
box.width = newMaxChartAreaWidth;
});
maxChartAreaHeight = newMaxChartAreaHeight;
maxChartAreaWidth = newMaxChartAreaWidth;
}
// Step 7 - Position the boxes
var left = xPadding;
var top = yPadding;
var right = 0;
var bottom = 0;
helpers.each(leftBoxes.concat(topBoxes), placeBox);
// Account for chart width and height
left += maxChartAreaWidth;
top += maxChartAreaHeight;
helpers.each(rightBoxes, placeBox);
helpers.each(bottomBoxes, placeBox);
function placeBox(box) {
if (box.isHorizontal()) {
box.left = box.options.fullWidth ? xPadding : totalLeftBoxesWidth;
box.right = box.options.fullWidth ? width - xPadding : totalLeftBoxesWidth + maxChartAreaWidth;
box.top = top;
box.bottom = top + box.height;
// Move to next point
top = box.bottom;
} else {
box.left = left;
box.right = left + box.width;
box.top = totalTopBoxesHeight;
box.bottom = totalTopBoxesHeight + maxChartAreaHeight;
// Move to next point
left = box.right;
}
}
// Step 8
chartInstance.chartArea = {
left: totalLeftBoxesWidth,
top: totalTopBoxesHeight,
right: totalLeftBoxesWidth + maxChartAreaWidth,
bottom: totalTopBoxesHeight + maxChartAreaHeight,
};
// Step 9
helpers.each(chartAreaBoxes, function(box) {
box.left = chartInstance.chartArea.left;
box.top = chartInstance.chartArea.top;
box.right = chartInstance.chartArea.right;
box.bottom = chartInstance.chartArea.bottom;
box.update(maxChartAreaWidth, maxChartAreaHeight);
});
}
};
}).call(this);
(function() {
"use strict";
var root = this,
Chart = root.Chart,
helpers = Chart.helpers;
Chart.defaults.global.legend = {
display: true,
position: 'top',
fullWidth: true, // marks that this box should take the full width of the canvas (pushing down other boxes)
// a callback that will handle
onClick: function(e, legendItem) {
var dataset = this.chart.data.datasets[legendItem.datasetIndex];
dataset.hidden = !dataset.hidden;
// We hid a dataset ... rerender the chart
this.chart.update();
},
labels: {
boxWidth: 40,
fontSize: 12,
fontStyle: "normal",
fontColor: "#666",
fontFamily: "Helvetica Neue",
padding: 10,
// Generates labels shown in the legend
// Valid properties to return:
// text : text to display
// fillStyle : fill of coloured box
// strokeStyle: stroke of coloured box
// hidden : if this legend item refers to a hidden item
// lineCap : cap style for line
// lineDash
// lineDashOffset :
// lineJoin :
// lineWidth :
generateLabels: function(data) {
return data.datasets.map(function(dataset, i) {
return {
text: dataset.label,
fillStyle: dataset.backgroundColor,
hidden: dataset.hidden,
lineCap: dataset.borderCapStyle,
lineDash: dataset.borderDash,
lineDashOffset: dataset.borderDashOffset,
lineJoin: dataset.borderJoinStyle,
lineWidth: dataset.borderWidth,
strokeStyle: dataset.borderColor,
// Below is extra data used for toggling the datasets
datasetIndex: i
};
}, this);
}
},
};
Chart.Legend = Chart.Element.extend({
initialize: function(config) {
helpers.extend(this, config);
// Contains hit boxes for each dataset (in dataset order)
this.legendHitBoxes = [];
// Are we in doughnut mode which has a different data type
this.doughnutMode = false;
},
// These methods are ordered by lifecyle. Utilities then follow.
// Any function defined here is inherited by all legend types.
// Any function can be extended by the legend type
beforeUpdate: helpers.noop,
update: function(maxWidth, maxHeight, margins) {
// Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
this.beforeUpdate();
// Absorb the master measurements
this.maxWidth = maxWidth;
this.maxHeight = maxHeight;
this.margins = margins;
// Dimensions
this.beforeSetDimensions();
this.setDimensions();
this.afterSetDimensions();
// Labels
this.beforeBuildLabels();
this.buildLabels();
this.afterBuildLabels();
// Fit
this.beforeFit();
this.fit();
this.afterFit();
//
this.afterUpdate();
return this.minSize;
},
afterUpdate: helpers.noop,
//
beforeSetDimensions: helpers.noop,
setDimensions: function() {
// Set the unconstrained dimension before label rotation
if (this.isHorizontal()) {
// Reset position before calculating rotation
this.width = this.maxWidth;
this.left = 0;
this.right = this.width;
} else {
this.height = this.maxHeight;
// Reset position before calculating rotation
this.top = 0;
this.bottom = this.height;
}
// Reset padding
this.paddingLeft = 0;
this.paddingTop = 0;
this.paddingRight = 0;
this.paddingBottom = 0;
// Reset minSize
this.minSize = {
width: 0,
height: 0,
};
},
afterSetDimensions: helpers.noop,
//
beforeBuildLabels: helpers.noop,
buildLabels: function() {
this.legendItems = this.options.labels.generateLabels.call(this, this.chart.data);
},
afterBuildLabels: helpers.noop,
//
beforeFit: helpers.noop,
fit: function() {
var ctx = this.ctx;
var labelFont = helpers.fontString(this.options.labels.fontSize, this.options.labels.fontStyle, this.options.labels.fontFamily);
// Reset hit boxes
this.legendHitBoxes = [];
// Width
if (this.isHorizontal()) {
this.minSize.width = this.maxWidth; // fill all the width
} else {
this.minSize.width = this.options.display ? 10 : 0;
}
// height
if (this.isHorizontal()) {
this.minSize.height = this.options.display ? 10 : 0;
} else {
this.minSize.height = this.maxHeight; // fill all the height
}
// Increase sizes here
if (this.options.display) {
if (this.isHorizontal()) {
// Labels
// Width of each line of legend boxes. Labels wrap onto multiple lines when there are too many to fit on one
this.lineWidths = [0];
var totalHeight = this.legendItems.length ? this.options.labels.fontSize + (this.options.labels.padding) : 0;
ctx.textAlign = "left";
ctx.textBaseline = 'top';
ctx.font = labelFont;
helpers.each(this.legendItems, function(legendItem, i) {
var width = this.options.labels.boxWidth + (this.options.labels.fontSize / 2) + ctx.measureText(legendItem.text).width;
if (this.lineWidths[this.lineWidths.length - 1] + width >= this.width) {
totalHeight += this.options.labels.fontSize + (this.options.labels.padding);
this.lineWidths[this.lineWidths.length] = this.left;
}
// Store the hitbox width and height here. Final position will be updated in `draw`
this.legendHitBoxes[i] = {
left: 0,
top: 0,
width: width,
height: this.options.labels.fontSize,
};
this.lineWidths[this.lineWidths.length - 1] += width + this.options.labels.padding;
}, this);
this.minSize.height += totalHeight;
} else {
// TODO vertical
}
}
this.width = this.minSize.width;
this.height = this.minSize.height;
},
afterFit: helpers.noop,
// Shared Methods
isHorizontal: function() {
return this.options.position == "top" || this.options.position == "bottom";
},
// Actualy draw the legend on the canvas
draw: function() {
if (this.options.display) {
var ctx = this.ctx;
var cursor = {
x: this.left + ((this.width - this.lineWidths[0]) / 2),
y: this.top + this.options.labels.padding,
line: 0,
};
var labelFont = helpers.fontString(this.options.labels.fontSize, this.options.labels.fontStyle, this.options.labels.fontFamily);
// Horizontal
if (this.isHorizontal()) {
// Labels
ctx.textAlign = "left";
ctx.textBaseline = 'top';
ctx.lineWidth = 0.5;
ctx.strokeStyle = this.options.labels.fontColor; // for strikethrough effect
ctx.fillStyle = this.options.labels.fontColor; // render in correct colour
ctx.font = labelFont;
helpers.each(this.legendItems, function(legendItem, i) {
var textWidth = ctx.measureText(legendItem.text).width;
var width = this.options.labels.boxWidth + (this.options.labels.fontSize / 2) + textWidth;
if (cursor.x + width >= this.width) {
cursor.y += this.options.labels.fontSize + (this.options.labels.padding);
cursor.line++;
cursor.x = this.left + ((this.width - this.lineWidths[cursor.line]) / 2);
}
// Set the ctx for the box
ctx.save();
var itemOrDefault = function(item, defaulVal) {
return item !== undefined ? item : defaulVal;
};
ctx.fillStyle = itemOrDefault(legendItem.fillStyle, Chart.defaults.global.defaultColor);
ctx.lineCap = itemOrDefault(legendItem.lineCap, Chart.defaults.global.elements.line.borderCapStyle);
ctx.lineDashOffset = itemOrDefault(legendItem.lineDashOffset, Chart.defaults.global.elements.line.borderDashOffset);
ctx.lineJoin = itemOrDefault(legendItem.lineJoin, Chart.defaults.global.elements.line.borderJoinStyle);
ctx.lineWidth = itemOrDefault(legendItem.lineWidth, Chart.defaults.global.elements.line.borderWidth);
ctx.strokeStyle = itemOrDefault(legendItem.strokeStyle, Chart.defaults.global.defaultColor);
if (ctx.setLineDash) {
// IE 9 and 10 do not support line dash
ctx.setLineDash(itemOrDefault(legendItem.lineDash, Chart.defaults.global.elements.line.borderDash));
}
// Draw the box
ctx.strokeRect(cursor.x, cursor.y, this.options.labels.boxWidth, this.options.labels.fontSize);
ctx.fillRect(cursor.x, cursor.y, this.options.labels.boxWidth, this.options.labels.fontSize);
ctx.restore();
this.legendHitBoxes[i].left = cursor.x;
this.legendHitBoxes[i].top = cursor.y;
// Fill the actual label
ctx.fillText(legendItem.text, this.options.labels.boxWidth + (this.options.labels.fontSize / 2) + cursor.x, cursor.y);
if (legendItem.hidden) {
// Strikethrough the text if hidden
ctx.beginPath();
ctx.lineWidth = 2;
ctx.moveTo(this.options.labels.boxWidth + (this.options.labels.fontSize / 2) + cursor.x, cursor.y + (this.options.labels.fontSize / 2));
ctx.lineTo(this.options.labels.boxWidth + (this.options.labels.fontSize / 2) + cursor.x + textWidth, cursor.y + (this.options.labels.fontSize / 2));
ctx.stroke();
}
cursor.x += width + (this.options.labels.padding);
}, this);
} else {
}
}
},
// Handle an event
handleEvent: function(e) {
var position = helpers.getRelativePosition(e, this.chart.chart);
if (position.x >= this.left && position.x <= this.right && position.y >= this.top && position.y <= this.bottom) {
// See if we are touching one of the dataset boxes
for (var i = 0; i < this.legendHitBoxes.length; ++i) {
var hitBox = this.legendHitBoxes[i];
if (position.x >= hitBox.left && position.x <= hitBox.left + hitBox.width && position.y >= hitBox.top && position.y <= hitBox.top + hitBox.height) {
// Touching an element
if (this.options.onClick) {
this.options.onClick.call(this, e, this.legendItems[i]);
}
break;
}
}
}
}
});
}).call(this);
(function() {
"use strict";
var root = this,
Chart = root.Chart,
helpers = Chart.helpers;
Chart.defaults.scale = {
display: true,
// grid line settings
gridLines: {
display: true,
color: "rgba(0, 0, 0, 0.1)",
lineWidth: 1,
drawOnChartArea: true,
drawTicks: true,
zeroLineWidth: 1,
zeroLineColor: "rgba(0,0,0,0.25)",
offsetGridLines: false,
},
// scale label
scaleLabel: {
fontColor: '#666',
fontFamily: 'Helvetica Neue',
fontSize: 12,
fontStyle: 'normal',
// actual label
labelString: '',
// display property
display: false,
},
// label settings
ticks: {
beginAtZero: false,
fontSize: 12,
fontStyle: "normal",
fontColor: "#666",
fontFamily: "Helvetica Neue",
maxRotation: 90,
mirror: false,
padding: 10,
reverse: false,
display: true,
autoSkip: true,
autoSkipPadding: 20,
callback: function(value) {
return '' + value;
},
},
};
Chart.Scale = Chart.Element.extend({
// These methods are ordered by lifecyle. Utilities then follow.
// Any function defined here is inherited by all scale types.
// Any function can be extended by the scale type
beforeUpdate: function() {
helpers.callCallback(this.options.beforeUpdate, [this]);
},
update: function(maxWidth, maxHeight, margins) {
// Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
this.beforeUpdate();
// Absorb the master measurements
this.maxWidth = maxWidth;
this.maxHeight = maxHeight;
this.margins = helpers.extend({
left: 0,
right: 0,
top: 0,
bottom: 0
}, margins);
// Dimensions
this.beforeSetDimensions();
this.setDimensions();
this.afterSetDimensions();
// Data min/max
this.beforeDataLimits();
this.determineDataLimits();
this.afterDataLimits();
// Ticks
this.beforeBuildTicks();
this.buildTicks();
this.afterBuildTicks();
this.beforeTickToLabelConversion();
this.convertTicksToLabels();
this.afterTickToLabelConversion();
// Tick Rotation
this.beforeCalculateTickRotation();
this.calculateTickRotation();
this.afterCalculateTickRotation();
// Fit
this.beforeFit();
this.fit();
this.afterFit();
//
this.afterUpdate();
return this.minSize;
},
afterUpdate: function() {
helpers.callCallback(this.options.afterUpdate, [this]);
},
//
beforeSetDimensions: function() {
helpers.callCallback(this.options.beforeSetDimensions, [this]);
},
setDimensions: function() {
// Set the unconstrained dimension before label rotation
if (this.isHorizontal()) {
// Reset position before calculating rotation
this.width = this.maxWidth;
this.left = 0;
this.right = this.width;
} else {
this.height = this.maxHeight;
// Reset position before calculating rotation
this.top = 0;
this.bottom = this.height;
}
// Reset padding
this.paddingLeft = 0;
this.paddingTop = 0;
this.paddingRight = 0;
this.paddingBottom = 0;
},
afterSetDimensions: function() {
helpers.callCallback(this.options.afterSetDimensions, [this]);
},
// Data limits
beforeDataLimits: function() {
helpers.callCallback(this.options.beforeDataLimits, [this]);
},
determineDataLimits: helpers.noop,
afterDataLimits: function() {
helpers.callCallback(this.options.afterDataLimits, [this]);
},
//
beforeBuildTicks: function() {
helpers.callCallback(this.options.beforeBuildTicks, [this]);
},
buildTicks: helpers.noop,
afterBuildTicks: function() {
helpers.callCallback(this.options.afterBuildTicks, [this]);
},
beforeTickToLabelConversion: function() {
helpers.callCallback(this.options.beforeTickToLabelConversion, [this]);
},
convertTicksToLabels: function() {
// Convert ticks to strings
this.ticks = this.ticks.map(function(numericalTick, index, ticks) {
if (this.options.ticks.userCallback) {
return this.options.ticks.userCallback(numericalTick, index, ticks);
}
return this.options.ticks.callback(numericalTick, index, ticks);
},
this);
},
afterTickToLabelConversion: function() {
helpers.callCallback(this.options.afterTickToLabelConversion, [this]);
},
//
beforeCalculateTickRotation: function() {
helpers.callCallback(this.options.beforeCalculateTickRotation, [this]);
},
calculateTickRotation: function() {
//Get the width of each grid by calculating the difference
//between x offsets between 0 and 1.
var labelFont = helpers.fontString(this.options.ticks.fontSize, this.options.ticks.fontStyle, this.options.ticks.fontFamily);
this.ctx.font = labelFont;
var firstWidth = this.ctx.measureText(this.ticks[0]).width;
var lastWidth = this.ctx.measureText(this.ticks[this.ticks.length - 1]).width;
var firstRotated;
var lastRotated;
this.paddingRight = lastWidth / 2 + 3;
this.paddingLeft = firstWidth / 2 + 3;
this.labelRotation = 0;
if (this.options.display && this.isHorizontal()) {
var originalLabelWidth = helpers.longestText(this.ctx, labelFont, this.ticks);
var cosRotation;
var sinRotation;
this.labelWidth = originalLabelWidth;
// Allow 3 pixels x2 padding either side for label readability
// only the index matters for a dataset scale, but we want a consistent interface between scales
var tickWidth = this.getPixelForTick(1) - this.getPixelForTick(0) - 6;
//Max label rotation can be set or default to 90 - also act as a loop counter
while (this.labelWidth > tickWidth && this.labelRotation < this.options.ticks.maxRotation) {
cosRotation = Math.cos(helpers.toRadians(this.labelRotation));
sinRotation = Math.sin(helpers.toRadians(this.labelRotation));
firstRotated = cosRotation * firstWidth;
lastRotated = cosRotation * lastWidth;
// We're right aligning the text now.
if (firstRotated + this.options.ticks.fontSize / 2 > this.yLabelWidth) {
this.paddingLeft = firstRotated + this.options.ticks.fontSize / 2;
}
this.paddingRight = this.options.ticks.fontSize / 2;
if (sinRotation * originalLabelWidth > this.maxHeight) {
// go back one step
this.labelRotation--;
break;
}
this.labelRotation++;
this.labelWidth = cosRotation * originalLabelWidth;
}
} else {
this.labelWidth = 0;
this.paddingRight = 0;
this.paddingLeft = 0;
}
if (this.margins) {
this.paddingLeft -= this.margins.left;
this.paddingRight -= this.margins.right;
this.paddingLeft = Math.max(this.paddingLeft, 0);
this.paddingRight = Math.max(this.paddingRight, 0);
}
},
afterCalculateTickRotation: function() {
helpers.callCallback(this.options.afterCalculateTickRotation, [this]);
},
//
beforeFit: function() {
helpers.callCallback(this.options.beforeFit, [this]);
},
fit: function() {
this.minSize = {
width: 0,
height: 0,
};
// Width
if (this.isHorizontal()) {
// subtract the margins to line up with the chartArea if we are a full width scale
this.minSize.width = this.isFullWidth() ? this.maxWidth - this.margins.left - this.margins.right : this.maxWidth;
} else {
this.minSize.width = this.options.gridLines.display && this.options.display ? 10 : 0;
}
// height
if (this.isHorizontal()) {
this.minSize.height = this.options.gridLines.display && this.options.display ? 10 : 0;
} else {
this.minSize.height = this.maxHeight; // fill all the height
}
// Are we showing a title for the scale?
if (this.options.scaleLabel.display) {
if (this.isHorizontal()) {
this.minSize.height += (this.options.scaleLabel.fontSize * 1.5);
} else {
this.minSize.width += (this.options.scaleLabel.fontSize * 1.5);
}
}
if (this.options.ticks.display && this.options.display) {
// Don't bother fitting the ticks if we are not showing them
var labelFont = helpers.fontString(this.options.ticks.fontSize,
this.options.ticks.fontStyle, this.options.ticks.fontFamily);
if (this.isHorizontal()) {
// A horizontal axis is more constrained by the height.
this.longestLabelWidth = helpers.longestText(this.ctx, labelFont, this.ticks);
// TODO - improve this calculation
var labelHeight = (Math.sin(helpers.toRadians(this.labelRotation)) * this.longestLabelWidth) + 1.5 * this.options.ticks.fontSize;
this.minSize.height = Math.min(this.maxHeight, this.minSize.height + labelHeight);
labelFont = helpers.fontString(this.options.ticks.fontSize, this.options.ticks.fontStyle, this.options.ticks.fontFamily);
this.ctx.font = labelFont;
var firstLabelWidth = this.ctx.measureText(this.ticks[0]).width;
var lastLabelWidth = this.ctx.measureText(this.ticks[this.ticks.length - 1]).width;
// Ensure that our ticks are always inside the canvas. When rotated, ticks are right aligned which means that the right padding is dominated
// by the font height
var cosRotation = Math.cos(helpers.toRadians(this.labelRotation));
var sinRotation = Math.sin(helpers.toRadians(this.labelRotation));
this.paddingLeft = this.labelRotation !== 0 ? (cosRotation * firstLabelWidth) + 3 : firstLabelWidth / 2 + 3; // add 3 px to move away from canvas edges
this.paddingRight = this.labelRotation !== 0 ? (sinRotation * (this.options.ticks.fontSize / 2)) + 3 : lastLabelWidth / 2 + 3; // when rotated
} else {
// A vertical axis is more constrained by the width. Labels are the dominant factor here, so get that length first
var maxLabelWidth = this.maxWidth - this.minSize.width;
var largestTextWidth = helpers.longestText(this.ctx, labelFont, this.ticks);
// Account for padding
if (!this.options.ticks.mirror) {
largestTextWidth += this.options.ticks.padding;
}
if (largestTextWidth < maxLabelWidth) {
// We don't need all the room
this.minSize.width += largestTextWidth;
} else {
// Expand to max size
this.minSize.width = this.maxWidth;
}
this.paddingTop = this.options.ticks.fontSize / 2;
this.paddingBottom = this.options.ticks.fontSize / 2;
}
}
if (this.margins) {
this.paddingLeft -= this.margins.left;
this.paddingTop -= this.margins.top;
this.paddingRight -= this.margins.right;
this.paddingBottom -= this.margins.bottom;
this.paddingLeft = Math.max(this.paddingLeft, 0);
this.paddingTop = Math.max(this.paddingTop, 0);
this.paddingRight = Math.max(this.paddingRight, 0);
this.paddingBottom = Math.max(this.paddingBottom, 0);
}
this.width = this.minSize.width;
this.height = this.minSize.height;
},
afterFit: function() {
helpers.callCallback(this.options.afterFit, [this]);
},
// Shared Methods
isHorizontal: function() {
return this.options.position === "top" || this.options.position === "bottom";
},
isFullWidth: function() {
return (this.options.fullWidth);
},
// Get the correct value. NaN bad inputs, If the value type is object get the x or y based on whether we are horizontal or not
getRightValue: function getRightValue(rawValue) {
// Null and undefined values first
if (rawValue === null || typeof(rawValue) === 'undefined') {
return NaN;
}
// isNaN(object) returns true, so make sure NaN is checking for a number
if (typeof(rawValue) === 'number' && isNaN(rawValue)) {
return NaN;
}
// If it is in fact an object, dive in one more level
if (typeof(rawValue) === "object") {
if (rawValue instanceof Date) {
return rawValue;
} else {
return getRightValue(this.isHorizontal() ? rawValue.x : rawValue.y);
}
}
// Value is good, return it
return rawValue;
},
// Used to get the value to display in the tooltip for the data at the given index
// function getLabelForIndex(index, datasetIndex)
getLabelForIndex: helpers.noop,
// Used to get data value locations. Value can either be an index or a numerical value
getPixelForValue: helpers.noop,
// Used for tick location, should
getPixelForTick: function(index, includeOffset) {
if (this.isHorizontal()) {
var innerWidth = this.width - (this.paddingLeft + this.paddingRight);
var tickWidth = innerWidth / Math.max((this.ticks.length - ((this.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
var pixel = (tickWidth * index) + this.paddingLeft;
if (includeOffset) {
pixel += tickWidth / 2;
}
var finalVal = this.left + Math.round(pixel);
finalVal += this.isFullWidth() ? this.margins.left : 0;
return finalVal;
} else {
var innerHeight = this.height - (this.paddingTop + this.paddingBottom);
return this.top + (index * (innerHeight / (this.ticks.length - 1)));
}
},
// Utility for getting the pixel location of a percentage of scale
getPixelForDecimal: function(decimal/*, includeOffset*/) {
if (this.isHorizontal()) {
var innerWidth = this.width - (this.paddingLeft + this.paddingRight);
var valueOffset = (innerWidth * decimal) + this.paddingLeft;
var finalVal = this.left + Math.round(valueOffset);
finalVal += this.isFullWidth() ? this.margins.left : 0;
return finalVal;
} else {
return this.top + (decimal * this.height);
}
},
// Actualy draw the scale on the canvas
// @param {rectangle} chartArea : the area of the chart to draw full grid lines on
draw: function(chartArea) {
if (this.options.display) {
var setContextLineSettings;
var isRotated = this.labelRotation !== 0;
var skipRatio;
var scaleLabelX;
var scaleLabelY;
var useAutoskipper = this.options.ticks.autoSkip;
// Make sure we draw text in the correct color and font
this.ctx.fillStyle = this.options.ticks.fontColor;
var labelFont = helpers.fontString(this.options.ticks.fontSize, this.options.ticks.fontStyle, this.options.ticks.fontFamily);
var cosRotation = Math.cos(helpers.toRadians(this.labelRotation));
var sinRotation = Math.sin(helpers.toRadians(this.labelRotation));
var longestRotatedLabel = this.longestLabelWidth * cosRotation;
var rotatedLabelHeight = this.options.ticks.fontSize * sinRotation;
if (this.isHorizontal()) {
setContextLineSettings = true;
var yTickStart = this.options.position === "bottom" ? this.top : this.bottom - 10;
var yTickEnd = this.options.position === "bottom" ? this.top + 10 : this.bottom;
skipRatio = false;
if (((longestRotatedLabel / 2) + this.options.ticks.autoSkipPadding) * this.ticks.length > (this.width - (this.paddingLeft + this.paddingRight))) {
skipRatio = 1 + Math.floor((((longestRotatedLabel / 2) + this.options.ticks.autoSkipPadding) * this.ticks.length) / (this.width - (this.paddingLeft + this.paddingRight)));
}
if (!useAutoskipper) {
skipRatio = false;
}
helpers.each(this.ticks, function(label, index) {
// Blank ticks
if ((skipRatio > 1 && index % skipRatio > 0) || (label === undefined || label === null)) {
return;
}
var xLineValue = this.getPixelForTick(index); // xvalues for grid lines
var xLabelValue = this.getPixelForTick(index, this.options.gridLines.offsetGridLines); // x values for ticks (need to consider offsetLabel option)
if (this.options.gridLines.display) {
if (index === (typeof this.zeroLineIndex !== 'undefined' ? this.zeroLineIndex : 0)) {
// Draw the first index specially
this.ctx.lineWidth = this.options.gridLines.zeroLineWidth;
this.ctx.strokeStyle = this.options.gridLines.zeroLineColor;
setContextLineSettings = true; // reset next time
} else if (setContextLineSettings) {
this.ctx.lineWidth = this.options.gridLines.lineWidth;
this.ctx.strokeStyle = this.options.gridLines.color;
setContextLineSettings = false;
}
xLineValue += helpers.aliasPixel(this.ctx.lineWidth);
// Draw the label area
this.ctx.beginPath();
if (this.options.gridLines.drawTicks) {
this.ctx.moveTo(xLineValue, yTickStart);
this.ctx.lineTo(xLineValue, yTickEnd);
}
// Draw the chart area
if (this.options.gridLines.drawOnChartArea) {
this.ctx.moveTo(xLineValue, chartArea.top);
this.ctx.lineTo(xLineValue, chartArea.bottom);
}
// Need to stroke in the loop because we are potentially changing line widths & colours
this.ctx.stroke();
}
if (this.options.ticks.display) {
this.ctx.save();
this.ctx.translate(xLabelValue, (isRotated) ? this.top + 12 : this.options.position === "top" ? this.bottom - 10 : this.top + 10);
this.ctx.rotate(helpers.toRadians(this.labelRotation) * -1);
this.ctx.font = labelFont;
this.ctx.textAlign = (isRotated) ? "right" : "center";
this.ctx.textBaseline = (isRotated) ? "middle" : this.options.position === "top" ? "bottom" : "top";
this.ctx.fillText(label, 0, 0);
this.ctx.restore();
}
}, this);
if (this.options.scaleLabel.display) {
// Draw the scale label
this.ctx.textAlign = "center";
this.ctx.textBaseline = 'middle';
this.ctx.fillStyle = this.options.scaleLabel.fontColor; // render in correct colour
this.ctx.font = helpers.fontString(this.options.scaleLabel.fontSize, this.options.scaleLabel.fontStyle, this.options.scaleLabel.fontFamily);
scaleLabelX = this.left + ((this.right - this.left) / 2); // midpoint of the width
scaleLabelY = this.options.position === 'bottom' ? this.bottom - (this.options.scaleLabel.fontSize / 2) : this.top + (this.options.scaleLabel.fontSize / 2);
this.ctx.fillText(this.options.scaleLabel.labelString, scaleLabelX, scaleLabelY);
}
} else {
setContextLineSettings = true;
var xTickStart = this.options.position === "right" ? this.left : this.right - 5;
var xTickEnd = this.options.position === "right" ? this.left + 5 : this.right;
helpers.each(this.ticks, function(label, index) {
// If the callback returned a null or undefined value, do not draw this line
if (label === undefined || label === null) {
return;
}
var yLineValue = this.getPixelForTick(index); // xvalues for grid lines
if (this.options.gridLines.display) {
if (index === (typeof this.zeroLineIndex !== 'undefined' ? this.zeroLineIndex : 0)) {
// Draw the first index specially
this.ctx.lineWidth = this.options.gridLines.zeroLineWidth;
this.ctx.strokeStyle = this.options.gridLines.zeroLineColor;
setContextLineSettings = true; // reset next time
} else if (setContextLineSettings) {
this.ctx.lineWidth = this.options.gridLines.lineWidth;
this.ctx.strokeStyle = this.options.gridLines.color;
setContextLineSettings = false;
}
yLineValue += helpers.aliasPixel(this.ctx.lineWidth);
// Draw the label area
this.ctx.beginPath();
if (this.options.gridLines.drawTicks) {
this.ctx.moveTo(xTickStart, yLineValue);
this.ctx.lineTo(xTickEnd, yLineValue);
}
// Draw the chart area
if (this.options.gridLines.drawOnChartArea) {
this.ctx.moveTo(chartArea.left, yLineValue);
this.ctx.lineTo(chartArea.right, yLineValue);
}
// Need to stroke in the loop because we are potentially changing line widths & colours
this.ctx.stroke();
}
if (this.options.ticks.display) {
var xLabelValue;
var yLabelValue = this.getPixelForTick(index, this.options.gridLines.offsetGridLines); // x values for ticks (need to consider offsetLabel option)
this.ctx.save();
if (this.options.position === "left") {
if (this.options.ticks.mirror) {
xLabelValue = this.right + this.options.ticks.padding;
this.ctx.textAlign = "left";
} else {
xLabelValue = this.right - this.options.ticks.padding;
this.ctx.textAlign = "right";
}
} else {
// right side
if (this.options.ticks.mirror) {
xLabelValue = this.left - this.options.ticks.padding;
this.ctx.textAlign = "right";
} else {
xLabelValue = this.left + this.options.ticks.padding;
this.ctx.textAlign = "left";
}
}
this.ctx.translate(xLabelValue, yLabelValue);
this.ctx.rotate(helpers.toRadians(this.labelRotation) * -1);
this.ctx.font = labelFont;
this.ctx.textBaseline = "middle";
this.ctx.fillText(label, 0, 0);
this.ctx.restore();
}
}, this);
if (this.options.scaleLabel.display) {
// Draw the scale label
scaleLabelX = this.options.position === 'left' ? this.left + (this.options.scaleLabel.fontSize / 2) : this.right - (this.options.scaleLabel.fontSize / 2);
scaleLabelY = this.top + ((this.bottom - this.top) / 2);
var rotation = this.options.position === 'left' ? -0.5 * Math.PI : 0.5 * Math.PI;
this.ctx.save();
this.ctx.translate(scaleLabelX, scaleLabelY);
this.ctx.rotate(rotation);
this.ctx.textAlign = "center";
this.ctx.fillStyle = this.options.scaleLabel.fontColor; // render in correct colour
this.ctx.font = helpers.fontString(this.options.scaleLabel.fontSize, this.options.scaleLabel.fontStyle, this.options.scaleLabel.fontFamily);
this.ctx.textBaseline = 'middle';
this.ctx.fillText(this.options.scaleLabel.labelString, 0, 0);
this.ctx.restore();
}
}
}
}
});
}).call(this);
(function() {
"use strict";
var root = this,
Chart = root.Chart,
helpers = Chart.helpers;
Chart.scaleService = {
// Scale registration object. Extensions can register new scale types (such as log or DB scales) and then
// use the new chart options to grab the correct scale
constructors: {},
// Use a registration function so that we can move to an ES6 map when we no longer need to support
// old browsers
// Scale config defaults
defaults: {},
registerScaleType: function(type, scaleConstructor, defaults) {
this.constructors[type] = scaleConstructor;
this.defaults[type] = helpers.clone(defaults);
},
getScaleConstructor: function(type) {
return this.constructors.hasOwnProperty(type) ? this.constructors[type] : undefined;
},
getScaleDefaults: function(type) {
// Return the scale defaults merged with the global settings so that we always use the latest ones
return this.defaults.hasOwnProperty(type) ? helpers.scaleMerge(Chart.defaults.scale, this.defaults[type]) : {};
},
addScalesToLayout: function(chartInstance) {
// Adds each scale to the chart.boxes array to be sized accordingly
helpers.each(chartInstance.scales, function(scale) {
Chart.layoutService.addBox(chartInstance, scale);
});
},
};
}).call(this);
(function() {
"use strict";
var root = this,
Chart = root.Chart,
helpers = Chart.helpers;
Chart.defaults.global.title = {
display: false,
position: 'top',
fullWidth: true, // marks that this box should take the full width of the canvas (pushing down other boxes)
fontColor: '#666',
fontFamily: 'Helvetica Neue',
fontSize: 12,
fontStyle: 'bold',
padding: 10,
// actual title
text: '',
};
Chart.Title = Chart.Element.extend({
initialize: function(config) {
helpers.extend(this, config);
this.options = helpers.configMerge(Chart.defaults.global.title, config.options);
// Contains hit boxes for each dataset (in dataset order)
this.legendHitBoxes = [];
},
// These methods are ordered by lifecyle. Utilities then follow.
beforeUpdate: helpers.noop,
update: function(maxWidth, maxHeight, margins) {
// Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
this.beforeUpdate();
// Absorb the master measurements
this.maxWidth = maxWidth;
this.maxHeight = maxHeight;
this.margins = margins;
// Dimensions
this.beforeSetDimensions();
this.setDimensions();
this.afterSetDimensions();
// Labels
this.beforeBuildLabels();
this.buildLabels();
this.afterBuildLabels();
// Fit
this.beforeFit();
this.fit();
this.afterFit();
//
this.afterUpdate();
return this.minSize;
},
afterUpdate: helpers.noop,
//
beforeSetDimensions: helpers.noop,
setDimensions: function() {
// Set the unconstrained dimension before label rotation
if (this.isHorizontal()) {
// Reset position before calculating rotation
this.width = this.maxWidth;
this.left = 0;
this.right = this.width;
} else {
this.height = this.maxHeight;
// Reset position before calculating rotation
this.top = 0;
this.bottom = this.height;
}
// Reset padding
this.paddingLeft = 0;
this.paddingTop = 0;
this.paddingRight = 0;
this.paddingBottom = 0;
// Reset minSize
this.minSize = {
width: 0,
height: 0,
};
},
afterSetDimensions: helpers.noop,
//
beforeBuildLabels: helpers.noop,
buildLabels: helpers.noop,
afterBuildLabels: helpers.noop,
//
beforeFit: helpers.noop,
fit: function() {
var ctx = this.ctx;
var titleFont = helpers.fontString(this.options.fontSize, this.options.fontStyle, this.options.fontFamily);
// Width
if (this.isHorizontal()) {
this.minSize.width = this.maxWidth; // fill all the width
} else {
this.minSize.width = 0;
}
// height
if (this.isHorizontal()) {
this.minSize.height = 0;
} else {
this.minSize.height = this.maxHeight; // fill all the height
}
// Increase sizes here
if (this.isHorizontal()) {
// Title
if (this.options.display) {
this.minSize.height += this.options.fontSize + (this.options.padding * 2);
}
} else {
// TODO vertical
}
this.width = this.minSize.width;
this.height = this.minSize.height;
},
afterFit: helpers.noop,
// Shared Methods
isHorizontal: function() {
return this.options.position == "top" || this.options.position == "bottom";
},
// Actualy draw the title block on the canvas
draw: function() {
if (this.options.display) {
var ctx = this.ctx;
var titleX, titleY;
// Horizontal
if (this.isHorizontal()) {
// Title
if (this.options.display) {
ctx.textAlign = "center";
ctx.textBaseline = 'middle';
ctx.fillStyle = this.options.fontColor; // render in correct colour
ctx.font = helpers.fontString(this.options.fontSize, this.options.fontStyle, this.options.fontFamily);
titleX = this.left + ((this.right - this.left) / 2); // midpoint of the width
titleY = this.top + ((this.bottom - this.top) / 2); // midpoint of the height
ctx.fillText(this.options.text, titleX, titleY);
}
} else {
// Title
if (this.options.display) {
titleX = this.options.position == 'left' ? this.left + (this.options.fontSize / 2) : this.right - (this.options.fontSize / 2);
titleY = this.top + ((this.bottom - this.top) / 2);
var rotation = this.options.position == 'left' ? -0.5 * Math.PI : 0.5 * Math.PI;
ctx.save();
ctx.translate(titleX, titleY);
ctx.rotate(rotation);
ctx.textAlign = "center";
ctx.fillStyle = this.options.fontColor; // render in correct colour
ctx.font = helpers.fontString(this.options.fontSize, this.options.fontStyle, this.options.fontFamily);
ctx.textBaseline = 'middle';
ctx.fillText(this.options.text, 0, 0);
ctx.restore();
}
}
}
}
});
}).call(this);
(function() {
"use strict";
var root = this,
Chart = root.Chart,
helpers = Chart.helpers;
Chart.defaults.global.tooltips = {
enabled: true,
custom: null,
mode: 'single',
backgroundColor: "rgba(0,0,0,0.8)",
titleFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
titleFontSize: 12,
titleFontStyle: "bold",
titleSpacing: 2,
titleMarginBottom: 6,
titleColor: "#fff",
titleAlign: "left",
bodyFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
bodyFontSize: 12,
bodyFontStyle: "normal",
bodySpacing: 2,
bodyColor: "#fff",
bodyAlign: "left",
footerFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
footerFontSize: 12,
footerFontStyle: "bold",
footerSpacing: 2,
footerMarginTop: 6,
footerColor: "#fff",
footerAlign: "left",
yPadding: 6,
xPadding: 6,
caretSize: 5,
cornerRadius: 6,
multiKeyBackground: '#fff',
callbacks: {
// Args are: (tooltipItems, data)
beforeTitle: helpers.noop,
title: function(tooltipItems, data) {
// Pick first xLabel for now
var title = '';
if (tooltipItems.length > 0) {
if (tooltipItems[0].xLabel) {
title = tooltipItems[0].xLabel;
} else if (data.labels.length > 0 && tooltipItems[0].index < data.labels.length) {
title = data.labels[tooltipItems[0].index];
}
}
return title;
},
afterTitle: helpers.noop,
// Args are: (tooltipItems, data)
beforeBody: helpers.noop,
// Args are: (tooltipItem, data)
beforeLabel: helpers.noop,
label: function(tooltipItem, data) {
var datasetLabel = data.datasets[tooltipItem.datasetIndex].label || '';
return datasetLabel + ': ' + tooltipItem.yLabel;
},
afterLabel: helpers.noop,
// Args are: (tooltipItems, data)
afterBody: helpers.noop,
// Args are: (tooltipItems, data)
beforeFooter: helpers.noop,
footer: helpers.noop,
afterFooter: helpers.noop,
},
};
// Helper to push or concat based on if the 2nd parameter is an array or not
function pushOrConcat(base, toPush) {
if (toPush) {
if (helpers.isArray(toPush)) {
base = base.concat(toPush);
} else {
base.push(toPush);
}
}
return base;
}
Chart.Tooltip = Chart.Element.extend({
initialize: function() {
var options = this._options;
helpers.extend(this, {
_model: {
// Positioning
xPadding: options.tooltips.xPadding,
yPadding: options.tooltips.yPadding,
// Body
bodyColor: options.tooltips.bodyColor,
_bodyFontFamily: options.tooltips.bodyFontFamily,
_bodyFontStyle: options.tooltips.bodyFontStyle,
_bodyAlign: options.tooltips.bodyAlign,
bodyFontSize: options.tooltips.bodyFontSize,
bodySpacing: options.tooltips.bodySpacing,
// Title
titleColor: options.tooltips.titleColor,
_titleFontFamily: options.tooltips.titleFontFamily,
_titleFontStyle: options.tooltips.titleFontStyle,
titleFontSize: options.tooltips.titleFontSize,
_titleAlign: options.tooltips.titleAlign,
titleSpacing: options.tooltips.titleSpacing,
titleMarginBottom: options.tooltips.titleMarginBottom,
// Footer
footerColor: options.tooltips.footerColor,
_footerFontFamily: options.tooltips.footerFontFamily,
_footerFontStyle: options.tooltips.footerFontStyle,
footerFontSize: options.tooltips.footerFontSize,
_footerAlign: options.tooltips.footerAlign,
footerSpacing: options.tooltips.footerSpacing,
footerMarginTop: options.tooltips.footerMarginTop,
// Appearance
caretSize: options.tooltips.caretSize,
cornerRadius: options.tooltips.cornerRadius,
backgroundColor: options.tooltips.backgroundColor,
opacity: 0,
legendColorBackground: options.tooltips.multiKeyBackground,
},
});
},
// Get the title
// Args are: (tooltipItem, data)
getTitle: function() {
var beforeTitle = this._options.tooltips.callbacks.beforeTitle.apply(this, arguments),
title = this._options.tooltips.callbacks.title.apply(this, arguments),
afterTitle = this._options.tooltips.callbacks.afterTitle.apply(this, arguments);
var lines = [];
lines = pushOrConcat(lines, beforeTitle);
lines = pushOrConcat(lines, title);
lines = pushOrConcat(lines, afterTitle);
return lines;
},
// Args are: (tooltipItem, data)
getBeforeBody: function() {
var lines = this._options.tooltips.callbacks.beforeBody.apply(this, arguments);
return helpers.isArray(lines) ? lines : lines !== undefined ? [lines] : [];
},
// Args are: (tooltipItem, data)
getBody: function(tooltipItems, data) {
var lines = [];
helpers.each(tooltipItems, function(bodyItem) {
var beforeLabel = this._options.tooltips.callbacks.beforeLabel.call(this, bodyItem, data) || '';
var bodyLabel = this._options.tooltips.callbacks.label.call(this, bodyItem, data) || '';
var afterLabel = this._options.tooltips.callbacks.afterLabel.call(this, bodyItem, data) || '';
lines.push(beforeLabel + bodyLabel + afterLabel);
}, this);
return lines;
},
// Args are: (tooltipItem, data)
getAfterBody: function() {
var lines = this._options.tooltips.callbacks.afterBody.apply(this, arguments);
return helpers.isArray(lines) ? lines : lines !== undefined ? [lines] : [];
},
// Get the footer and beforeFooter and afterFooter lines
// Args are: (tooltipItem, data)
getFooter: function() {
var beforeFooter = this._options.tooltips.callbacks.beforeFooter.apply(this, arguments);
var footer = this._options.tooltips.callbacks.footer.apply(this, arguments);
var afterFooter = this._options.tooltips.callbacks.afterFooter.apply(this, arguments);
var lines = [];
lines = pushOrConcat(lines, beforeFooter);
lines = pushOrConcat(lines, footer);
lines = pushOrConcat(lines, afterFooter);
return lines;
},
getAveragePosition: function(elements){
if(!elements.length){
return false;
}
var xPositions = [];
var yPositions = [];
helpers.each(elements, function(el){
if(el) {
var pos = el.tooltipPosition();
xPositions.push(pos.x);
yPositions.push(pos.y);
}
});
var x = 0, y = 0;
for (var i = 0; i < xPositions.length; i++) {
x += xPositions[i];
y += yPositions[i];
}
return {
x: Math.round(x / xPositions.length),
y: Math.round(y / xPositions.length)
};
},
update: function(changed) {
if (this._active.length){
this._model.opacity = 1;
var element = this._active[0],
labelColors = [],
tooltipPosition;
var tooltipItems = [];
if (this._options.tooltips.mode === 'single') {
var yScale = element._yScale || element._scale; // handle radar || polarArea charts
tooltipItems.push({
xLabel: element._xScale ? element._xScale.getLabelForIndex(element._index, element._datasetIndex) : '',
yLabel: yScale ? yScale.getLabelForIndex(element._index, element._datasetIndex) : '',
index: element._index,
datasetIndex: element._datasetIndex,
});
tooltipPosition = this.getAveragePosition(this._active);
} else {
helpers.each(this._data.datasets, function(dataset, datasetIndex) {
if (!helpers.isDatasetVisible(dataset)) {
return;
}
var currentElement = dataset.metaData[element._index];
if (currentElement) {
var yScale = element._yScale || element._scale; // handle radar || polarArea charts
tooltipItems.push({
xLabel: currentElement._xScale ? currentElement._xScale.getLabelForIndex(currentElement._index, currentElement._datasetIndex) : '',
yLabel: yScale ? yScale.getLabelForIndex(currentElement._index, currentElement._datasetIndex) : '',
index: element._index,
datasetIndex: datasetIndex,
});
}
});
helpers.each(this._active, function(active) {
if (active) {
labelColors.push({
borderColor: active._view.borderColor,
backgroundColor: active._view.backgroundColor
});
}
}, this);
tooltipPosition = this.getAveragePosition(this._active);
tooltipPosition.y = this._active[0]._yScale.getPixelForDecimal(0.5);
}
// Build the Text Lines
helpers.extend(this._model, {
title: this.getTitle(tooltipItems, this._data),
beforeBody: this.getBeforeBody(tooltipItems, this._data),
body: this.getBody(tooltipItems, this._data),
afterBody: this.getAfterBody(tooltipItems, this._data),
footer: this.getFooter(tooltipItems, this._data),
});
helpers.extend(this._model, {
x: Math.round(tooltipPosition.x),
y: Math.round(tooltipPosition.y),
caretPadding: helpers.getValueOrDefault(tooltipPosition.padding, 2),
labelColors: labelColors,
});
// We need to determine alignment of
var tooltipSize = this.getTooltipSize(this._model);
this.determineAlignment(tooltipSize); // Smart Tooltip placement to stay on the canvas
helpers.extend(this._model, this.getBackgroundPoint(this._model, tooltipSize));
}
else{
this._model.opacity = 0;
}
if (changed && this._options.tooltips.custom) {
this._options.tooltips.custom.call(this, this._model);
}
return this;
},
getTooltipSize: function getTooltipSize(vm) {
var ctx = this._chart.ctx;
var size = {
height: vm.yPadding * 2, // Tooltip Padding
width: 0
};
var combinedBodyLength = vm.body.length + vm.beforeBody.length + vm.afterBody.length;
size.height += vm.title.length * vm.titleFontSize; // Title Lines
size.height += (vm.title.length - 1) * vm.titleSpacing; // Title Line Spacing
size.height += vm.title.length ? vm.titleMarginBottom : 0; // Title's bottom Margin
size.height += combinedBodyLength * vm.bodyFontSize; // Body Lines
size.height += combinedBodyLength ? (combinedBodyLength - 1) * vm.bodySpacing : 0; // Body Line Spacing
size.height += vm.footer.length ? vm.footerMarginTop : 0; // Footer Margin
size.height += vm.footer.length * (vm.footerFontSize); // Footer Lines
size.height += vm.footer.length ? (vm.footer.length - 1) * vm.footerSpacing : 0; // Footer Line Spacing
// Width
ctx.font = helpers.fontString(vm.titleFontSize, vm._titleFontStyle, vm._titleFontFamily);
helpers.each(vm.title, function(line) {
size.width = Math.max(size.width, ctx.measureText(line).width);
});
ctx.font = helpers.fontString(vm.bodyFontSize, vm._bodyFontStyle, vm._bodyFontFamily);
helpers.each(vm.beforeBody.concat(vm.afterBody), function(line) {
size.width = Math.max(size.width, ctx.measureText(line).width);
}, this);
helpers.each(vm.body, function(line) {
size.width = Math.max(size.width, ctx.measureText(line).width + (this._options.tooltips.mode !== 'single' ? (vm.bodyFontSize + 2) : 0));
}, this);
ctx.font = helpers.fontString(vm.footerFontSize, vm._footerFontStyle, vm._footerFontFamily);
helpers.each(vm.footer, function(line) {
size.width = Math.max(size.width, ctx.measureText(line).width);
});
size.width += 2 * vm.xPadding;
return size;
},
determineAlignment: function determineAlignment(size) {
this._model.xAlign = this._model.yAlign = "center";
if (this._model.y < size.height) {
this._model.yAlign = 'top';
} else if (this._model.y > (this._chart.height - size.height)) {
this._model.yAlign = 'bottom';
}
var lf, rf;
var _this = this;
var midX = (this._chartInstance.chartArea.left + this._chartInstance.chartArea.right) / 2;
if (this._model.yAlign === 'center') {
lf = function(x) { return x <= midX; };
rf = function(x) { return x > midX; };
} else {
lf = function(x) { return x <= (size.width / 2); };
rf = function(x) { return x >= (_this._chart.width - (size.width / 2)); };
}
if (lf(this._model.x)) {
this._model.xAlign = 'left';
} else if (rf(this._model.x)) {
this._model.xAlign = 'right';
}
},
getBackgroundPoint: function getBackgroundPoint(vm, size) {
// Background Position
var pt = {
x: vm.x,
y: vm.y
};
if (vm.xAlign === 'right') {
pt.x -= size.width;
} else if (vm.xAlign === 'center') {
pt.x -= (size.width / 2);
}
if (vm.yAlign === 'top') {
pt.y += vm.caretPadding + vm.caretSize;
} else if (vm.yAlign === 'bottom') {
pt.y -= size.height + vm.caretPadding + vm.caretSize;
} else {
pt.y -= (size.height / 2);
}
if (vm.yAlign == 'center') {
if (vm.xAlign === 'left') {
pt.x += vm.caretPadding + vm.caretSize;
} else if (vm.xAlign === 'right') {
pt.x -= vm.caretPadding + vm.caretSize;
}
} else {
if (vm.xAlign === 'left') {
pt.x -= vm.cornerRadius + vm.caretPadding;
} else if (vm.xAlign === 'right') {
pt.x += vm.cornerRadius + vm.caretPadding;
}
}
return pt;
},
drawCaret: function drawCaret(tooltipPoint, size, opacity, caretPadding) {
var vm = this._view;
var ctx = this._chart.ctx;
var x1, x2, x3;
var y1, y2, y3;
if (vm.yAlign === 'center') {
// Left or right side
if (vm.xAlign === 'left') {
x1 = tooltipPoint.x;
x2 = x1 - vm.caretSize;
x3 = x1;
} else {
x1 = tooltipPoint.x + size.width;
x2 = x1 + vm.caretSize;
x3 = x1;
}
y2 = tooltipPoint.y + (size.height / 2);
y1 = y2 - vm.caretSize;
y3 = y2 + vm.caretSize;
} else {
if (vm.xAlign === 'left') {
x1 = tooltipPoint.x + vm.cornerRadius;
x2 = x1 + vm.caretSize;
x3 = x2 + vm.caretSize;
} else if (vm.xAlign === 'right') {
x1 = tooltipPoint.x + size.width - vm.cornerRadius;
x2 = x1 - vm.caretSize;
x3 = x2 - vm.caretSize;
} else {
x2 = tooltipPoint.x + (size.width / 2);
x1 = x2 - vm.caretSize;
x3 = x2 + vm.caretSize;
}
if (vm.yAlign === 'top') {
y1 = tooltipPoint.y;
y2 = y1 - vm.caretSize;
y3 = y1;
} else {
y1 = tooltipPoint.y + size.height;
y2 = y1 + vm.caretSize;
y3 = y1;
}
}
ctx.fillStyle = helpers.color(vm.backgroundColor).alpha(opacity).rgbString();
ctx.beginPath();
ctx.moveTo(x1, y1);
ctx.lineTo(x2, y2);
ctx.lineTo(x3, y3);
ctx.closePath();
ctx.fill();
},
drawTitle: function drawTitle(pt, vm, ctx, opacity) {
if (vm.title.length) {
ctx.textAlign = vm._titleAlign;
ctx.textBaseline = "top";
ctx.fillStyle = helpers.color(vm.titleColor).alpha(opacity).rgbString();
ctx.font = helpers.fontString(vm.titleFontSize, vm._titleFontStyle, vm._titleFontFamily);
helpers.each(vm.title, function(title, i) {
ctx.fillText(title, pt.x, pt.y);
pt.y += vm.titleFontSize + vm.titleSpacing; // Line Height and spacing
if (i + 1 === vm.title.length) {
pt.y += vm.titleMarginBottom - vm.titleSpacing; // If Last, add margin, remove spacing
}
}, this);
}
},
drawBody: function drawBody(pt, vm, ctx, opacity) {
ctx.textAlign = vm._bodyAlign;
ctx.textBaseline = "top";
ctx.fillStyle = helpers.color(vm.bodyColor).alpha(opacity).rgbString();
ctx.font = helpers.fontString(vm.bodyFontSize, vm._bodyFontStyle, vm._bodyFontFamily);
// Before Body
helpers.each(vm.beforeBody, function(beforeBody) {
ctx.fillText(beforeBody, pt.x, pt.y);
pt.y += vm.bodyFontSize + vm.bodySpacing;
});
helpers.each(vm.body, function(body, i) {
// Draw Legend-like boxes if needed
if (this._options.tooltips.mode !== 'single') {
// Fill a white rect so that colours merge nicely if the opacity is < 1
ctx.fillStyle = helpers.color(vm.legendColorBackground).alpha(opacity).rgbaString();
ctx.fillRect(pt.x, pt.y, vm.bodyFontSize, vm.bodyFontSize);
// Border
ctx.strokeStyle = helpers.color(vm.labelColors[i].borderColor).alpha(opacity).rgbaString();
ctx.strokeRect(pt.x, pt.y, vm.bodyFontSize, vm.bodyFontSize);
// Inner square
ctx.fillStyle = helpers.color(vm.labelColors[i].backgroundColor).alpha(opacity).rgbaString();
ctx.fillRect(pt.x + 1, pt.y + 1, vm.bodyFontSize - 2, vm.bodyFontSize - 2);
ctx.fillStyle = helpers.color(vm.bodyColor).alpha(opacity).rgbaString(); // Return fill style for text
}
// Body Line
ctx.fillText(body, pt.x + (this._options.tooltips.mode !== 'single' ? (vm.bodyFontSize + 2) : 0), pt.y);
pt.y += vm.bodyFontSize + vm.bodySpacing;
}, this);
// After Body
helpers.each(vm.afterBody, function(afterBody) {
ctx.fillText(afterBody, pt.x, pt.y);
pt.y += vm.bodyFontSize;
});
pt.y -= vm.bodySpacing; // Remove last body spacing
},
drawFooter: function drawFooter(pt, vm, ctx, opacity) {
if (vm.footer.length) {
pt.y += vm.footerMarginTop;
ctx.textAlign = vm._footerAlign;
ctx.textBaseline = "top";
ctx.fillStyle = helpers.color(vm.footerColor).alpha(opacity).rgbString();
ctx.font = helpers.fontString(vm.footerFontSize, vm._footerFontStyle, vm._footerFontFamily);
helpers.each(vm.footer, function(footer) {
ctx.fillText(footer, pt.x, pt.y);
pt.y += vm.footerFontSize + vm.footerSpacing;
}, this);
}
},
draw: function draw() {
var ctx = this._chart.ctx;
var vm = this._view;
if (vm.opacity === 0) {
return;
}
var caretPadding = vm.caretPadding;
var tooltipSize = this.getTooltipSize(vm);
var pt = {
x: vm.x,
y: vm.y
};
// IE11/Edge does not like very small opacities, so snap to 0
var opacity = Math.abs(vm.opacity < 1e-3) ? 0 : vm.opacity;
if (this._options.tooltips.enabled) {
// Draw Background
ctx.fillStyle = helpers.color(vm.backgroundColor).alpha(opacity).rgbString();
helpers.drawRoundedRectangle(ctx, pt.x, pt.y, tooltipSize.width, tooltipSize.height, vm.cornerRadius);
ctx.fill();
// Draw Caret
this.drawCaret(pt, tooltipSize, opacity, caretPadding);
// Draw Title, Body, and Footer
pt.x += vm.xPadding;
pt.y += vm.yPadding;
// Titles
this.drawTitle(pt, vm, ctx, opacity);
// Body
this.drawBody(pt, vm, ctx, opacity);
// Footer
this.drawFooter(pt, vm, ctx, opacity);
}
}
});
}).call(this);
(function() {
"use strict";
var root = this,
Chart = root.Chart,
helpers = Chart.helpers;
Chart.defaults.bar = {
hover: {
mode: "label"
},
scales: {
xAxes: [{
type: "category",
// Specific to Bar Controller
categoryPercentage: 0.8,
barPercentage: 0.9,
// grid line settings
gridLines: {
offsetGridLines: true,
},
}],
yAxes: [{
type: "linear",
}],
},
};
Chart.controllers.bar = Chart.DatasetController.extend({
initialize: function(chart, datasetIndex) {
Chart.DatasetController.prototype.initialize.call(this, chart, datasetIndex);
// Use this to indicate that this is a bar dataset.
this.getDataset().bar = true;
},
// Get the number of datasets that display bars. We use this to correctly calculate the bar width
getBarCount: function getBarCount() {
var barCount = 0;
helpers.each(this.chart.data.datasets, function(dataset) {
if (helpers.isDatasetVisible(dataset) && dataset.bar) {
++barCount;
}
}, this);
return barCount;
},
addElements: function() {
this.getDataset().metaData = this.getDataset().metaData || [];
helpers.each(this.getDataset().data, function(value, index) {
this.getDataset().metaData[index] = this.getDataset().metaData[index] || new Chart.elements.Rectangle({
_chart: this.chart.chart,
_datasetIndex: this.index,
_index: index,
});
}, this);
},
addElementAndReset: function(index) {
this.getDataset().metaData = this.getDataset().metaData || [];
var rectangle = new Chart.elements.Rectangle({
_chart: this.chart.chart,
_datasetIndex: this.index,
_index: index,
});
var numBars = this.getBarCount();
this.updateElement(rectangle, index, true, numBars);
this.getDataset().metaData.splice(index, 0, rectangle);
},
update: function update(reset) {
var numBars = this.getBarCount();
helpers.each(this.getDataset().metaData, function(rectangle, index) {
this.updateElement(rectangle, index, reset, numBars);
}, this);
},
updateElement: function updateElement(rectangle, index, reset, numBars) {
var xScale = this.getScaleForId(this.getDataset().xAxisID);
var yScale = this.getScaleForId(this.getDataset().yAxisID);
var yScalePoint;
if (yScale.min < 0 && yScale.max < 0) {
// all less than 0. use the top
yScalePoint = yScale.getPixelForValue(yScale.max);
} else if (yScale.min > 0 && yScale.max > 0) {
yScalePoint = yScale.getPixelForValue(yScale.min);
} else {
yScalePoint = yScale.getPixelForValue(0);
}
helpers.extend(rectangle, {
// Utility
_chart: this.chart.chart,
_xScale: xScale,
_yScale: yScale,
_datasetIndex: this.index,
_index: index,
// Desired view properties
_model: {
x: this.calculateBarX(index, this.index),
y: reset ? yScalePoint : this.calculateBarY(index, this.index),
// Tooltip
label: this.chart.data.labels[index],
datasetLabel: this.getDataset().label,
// Appearance
base: this.calculateBarBase(this.index, index),
width: this.calculateBarWidth(numBars),
backgroundColor: rectangle.custom && rectangle.custom.backgroundColor ? rectangle.custom.backgroundColor : helpers.getValueAtIndexOrDefault(this.getDataset().backgroundColor, index, this.chart.options.elements.rectangle.backgroundColor),
borderColor: rectangle.custom && rectangle.custom.borderColor ? rectangle.custom.borderColor : helpers.getValueAtIndexOrDefault(this.getDataset().borderColor, index, this.chart.options.elements.rectangle.borderColor),
borderWidth: rectangle.custom && rectangle.custom.borderWidth ? rectangle.custom.borderWidth : helpers.getValueAtIndexOrDefault(this.getDataset().borderWidth, index, this.chart.options.elements.rectangle.borderWidth),
},
});
rectangle.pivot();
},
calculateBarBase: function(datasetIndex, index) {
var xScale = this.getScaleForId(this.getDataset().xAxisID);
var yScale = this.getScaleForId(this.getDataset().yAxisID);
var base = 0;
if (yScale.options.stacked) {
var value = this.chart.data.datasets[datasetIndex].data[index];
if (value < 0) {
for (var i = 0; i < datasetIndex; i++) {
var negDS = this.chart.data.datasets[i];
if (helpers.isDatasetVisible(negDS) && negDS.yAxisID === yScale.id) {
base += negDS.data[index] < 0 ? negDS.data[index] : 0;
}
}
} else {
for (var j = 0; j < datasetIndex; j++) {
var posDS = this.chart.data.datasets[j];
if (helpers.isDatasetVisible(posDS) && posDS.yAxisID === yScale.id) {
base += posDS.data[index] > 0 ? posDS.data[index] : 0;
}
}
}
return yScale.getPixelForValue(base);
}
base = yScale.getPixelForValue(yScale.min);
if (yScale.beginAtZero || ((yScale.min <= 0 && yScale.max >= 0) || (yScale.min >= 0 && yScale.max <= 0))) {
base = yScale.getPixelForValue(0, 0);
//base += yScale.options.gridLines.lineWidth;
} else if (yScale.min < 0 && yScale.max < 0) {
// All values are negative. Use the top as the base
base = yScale.getPixelForValue(yScale.max);
}
return base;
},
getRuler: function() {
var xScale = this.getScaleForId(this.getDataset().xAxisID);
var yScale = this.getScaleForId(this.getDataset().yAxisID);
var datasetCount = this.getBarCount();
var tickWidth = (function() {
var min = xScale.getPixelForTick(1) - xScale.getPixelForTick(0);
for (var i = 2; i < this.getDataset().data.length; i++) {
min = Math.min(xScale.getPixelForTick(i) - xScale.getPixelForTick(i - 1), min);
}
return min;
}).call(this);
var categoryWidth = tickWidth * xScale.options.categoryPercentage;
var categorySpacing = (tickWidth - (tickWidth * xScale.options.categoryPercentage)) / 2;
var fullBarWidth = categoryWidth / datasetCount;
var barWidth = fullBarWidth * xScale.options.barPercentage;
var barSpacing = fullBarWidth - (fullBarWidth * xScale.options.barPercentage);
return {
datasetCount: datasetCount,
tickWidth: tickWidth,
categoryWidth: categoryWidth,
categorySpacing: categorySpacing,
fullBarWidth: fullBarWidth,
barWidth: barWidth,
barSpacing: barSpacing,
};
},
calculateBarWidth: function() {
var xScale = this.getScaleForId(this.getDataset().xAxisID);
var ruler = this.getRuler();
if (xScale.options.stacked) {
return ruler.categoryWidth;
}
return ruler.barWidth;
},
// Get bar index from the given dataset index accounting for the fact that not all bars are visible
getBarIndex: function(datasetIndex) {
var barIndex = 0;
for (var j = 0; j < datasetIndex; ++j) {
if (helpers.isDatasetVisible(this.chart.data.datasets[j]) && this.chart.data.datasets[j].bar) {
++barIndex;
}
}
return barIndex;
},
calculateBarX: function(index, datasetIndex) {
var yScale = this.getScaleForId(this.getDataset().yAxisID);
var xScale = this.getScaleForId(this.getDataset().xAxisID);
var barIndex = this.getBarIndex(datasetIndex);
var ruler = this.getRuler();
var leftTick = xScale.getPixelForValue(null, index, datasetIndex, this.chart.isCombo);
leftTick -= this.chart.isCombo ? (ruler.tickWidth / 2) : 0;
if (xScale.options.stacked) {
return leftTick + (ruler.categoryWidth / 2) + ruler.categorySpacing;
}
return leftTick +
(ruler.barWidth / 2) +
ruler.categorySpacing +
(ruler.barWidth * barIndex) +
(ruler.barSpacing / 2) +
(ruler.barSpacing * barIndex);
},
calculateBarY: function(index, datasetIndex) {
var xScale = this.getScaleForId(this.getDataset().xAxisID);
var yScale = this.getScaleForId(this.getDataset().yAxisID);
var value = this.getDataset().data[index];
if (yScale.options.stacked) {
var sumPos = 0,
sumNeg = 0;
for (var i = 0; i < datasetIndex; i++) {
var ds = this.chart.data.datasets[i];
if (helpers.isDatasetVisible(ds)) {
if (ds.data[index] < 0) {
sumNeg += ds.data[index] || 0;
} else {
sumPos += ds.data[index] || 0;
}
}
}
if (value < 0) {
return yScale.getPixelForValue(sumNeg + value);
} else {
return yScale.getPixelForValue(sumPos + value);
}
return yScale.getPixelForValue(value);
}
return yScale.getPixelForValue(value);
},
draw: function(ease) {
var easingDecimal = ease || 1;
helpers.each(this.getDataset().metaData, function(rectangle, index) {
rectangle.transition(easingDecimal).draw();
}, this);
},
setHoverStyle: function(rectangle) {
var dataset = this.chart.data.datasets[rectangle._datasetIndex];
var index = rectangle._index;
rectangle._model.backgroundColor = rectangle.custom && rectangle.custom.hoverBackgroundColor ? rectangle.custom.hoverBackgroundColor : helpers.getValueAtIndexOrDefault(dataset.hoverBackgroundColor, index, helpers.color(rectangle._model.backgroundColor).saturate(0.5).darken(0.1).rgbString());
rectangle._model.borderColor = rectangle.custom && rectangle.custom.hoverBorderColor ? rectangle.custom.hoverBorderColor : helpers.getValueAtIndexOrDefault(dataset.hoverBorderColor, index, helpers.color(rectangle._model.borderColor).saturate(0.5).darken(0.1).rgbString());
rectangle._model.borderWidth = rectangle.custom && rectangle.custom.hoverBorderWidth ? rectangle.custom.hoverBorderWidth : helpers.getValueAtIndexOrDefault(dataset.hoverBorderWidth, index, rectangle._model.borderWidth);
},
removeHoverStyle: function(rectangle) {
var dataset = this.chart.data.datasets[rectangle._datasetIndex];
var index = rectangle._index;
rectangle._model.backgroundColor = rectangle.custom && rectangle.custom.backgroundColor ? rectangle.custom.backgroundColor : helpers.getValueAtIndexOrDefault(this.getDataset().backgroundColor, index, this.chart.options.elements.rectangle.backgroundColor);
rectangle._model.borderColor = rectangle.custom && rectangle.custom.borderColor ? rectangle.custom.borderColor : helpers.getValueAtIndexOrDefault(this.getDataset().borderColor, index, this.chart.options.elements.rectangle.borderColor);
rectangle._model.borderWidth = rectangle.custom && rectangle.custom.borderWidth ? rectangle.custom.borderWidth : helpers.getValueAtIndexOrDefault(this.getDataset().borderWidth, index, this.chart.options.elements.rectangle.borderWidth);
}
});
}).call(this);
(function() {
"use strict";
var root = this,
Chart = root.Chart,
helpers = Chart.helpers;
Chart.defaults.bubble = {
hover: {
mode: "single"
},
scales: {
xAxes: [{
type: "linear", // bubble should probably use a linear scale by default
position: "bottom",
id: "x-axis-0", // need an ID so datasets can reference the scale
}],
yAxes: [{
type: "linear",
position: "left",
id: "y-axis-0",
}],
},
tooltips: {
template: "(<%= value.x %>, <%= value.y %>, <%= value.r %>)",
multiTemplate: "<%if (datasetLabel){%><%=datasetLabel%>: <%}%>(<%= value.x %>, <%= value.y %>, <%= value.r %>)",
},
};
Chart.controllers.bubble = Chart.DatasetController.extend({
addElements: function() {
this.getDataset().metaData = this.getDataset().metaData || [];
helpers.each(this.getDataset().data, function(value, index) {
this.getDataset().metaData[index] = this.getDataset().metaData[index] || new Chart.elements.Point({
_chart: this.chart.chart,
_datasetIndex: this.index,
_index: index,
});
}, this);
},
addElementAndReset: function(index) {
this.getDataset().metaData = this.getDataset().metaData || [];
var point = new Chart.elements.Point({
_chart: this.chart.chart,
_datasetIndex: this.index,
_index: index,
});
// Reset the point
this.updateElement(point, index, true);
// Add to the points array
this.getDataset().metaData.splice(index, 0, point);
},
update: function update(reset) {
var points = this.getDataset().metaData;
var yScale = this.getScaleForId(this.getDataset().yAxisID);
var xScale = this.getScaleForId(this.getDataset().xAxisID);
var scaleBase;
if (yScale.min < 0 && yScale.max < 0) {
scaleBase = yScale.getPixelForValue(yScale.max);
} else if (yScale.min > 0 && yScale.max > 0) {
scaleBase = yScale.getPixelForValue(yScale.min);
} else {
scaleBase = yScale.getPixelForValue(0);
}
// Update Points
helpers.each(points, function(point, index) {
this.updateElement(point, index, reset);
}, this);
},
updateElement: function(point, index, reset) {
var yScale = this.getScaleForId(this.getDataset().yAxisID);
var xScale = this.getScaleForId(this.getDataset().xAxisID);
var scaleBase;
if (yScale.min < 0 && yScale.max < 0) {
scaleBase = yScale.getPixelForValue(yScale.max);
} else if (yScale.min > 0 && yScale.max > 0) {
scaleBase = yScale.getPixelForValue(yScale.min);
} else {
scaleBase = yScale.getPixelForValue(0);
}
helpers.extend(point, {
// Utility
_chart: this.chart.chart,
_xScale: xScale,
_yScale: yScale,
_datasetIndex: this.index,
_index: index,
// Desired view properties
_model: {
x: reset ? xScale.getPixelForDecimal(0.5) : xScale.getPixelForValue(this.getDataset().data[index], index, this.index, this.chart.isCombo),
y: reset ? scaleBase : yScale.getPixelForValue(this.getDataset().data[index], index, this.index),
// Appearance
radius: reset ? 0 : point.custom && point.custom.radius ? point.custom.radius : this.getRadius(this.getDataset().data[index]),
backgroundColor: point.custom && point.custom.backgroundColor ? point.custom.backgroundColor : helpers.getValueAtIndexOrDefault(this.getDataset().backgroundColor, index, this.chart.options.elements.point.backgroundColor),
borderColor: point.custom && point.custom.borderColor ? point.custom.borderColor : helpers.getValueAtIndexOrDefault(this.getDataset().borderColor, index, this.chart.options.elements.point.borderColor),
borderWidth: point.custom && point.custom.borderWidth ? point.custom.borderWidth : helpers.getValueAtIndexOrDefault(this.getDataset().borderWidth, index, this.chart.options.elements.point.borderWidth),
// Tooltip
hitRadius: point.custom && point.custom.hitRadius ? point.custom.hitRadius : helpers.getValueAtIndexOrDefault(this.getDataset().hitRadius, index, this.chart.options.elements.point.hitRadius),
},
});
point._model.skip = point.custom && point.custom.skip ? point.custom.skip : (isNaN(point._model.x) || isNaN(point._model.y));
point.pivot();
},
getRadius: function(value) {
return value.r || this.chart.options.elements.point.radius;
},
draw: function(ease) {
var easingDecimal = ease || 1;
// Transition and Draw the Points
helpers.each(this.getDataset().metaData, function(point, index) {
point.transition(easingDecimal);
point.draw();
}, this);
},
setHoverStyle: function(point) {
// Point
var dataset = this.chart.data.datasets[point._datasetIndex];
var index = point._index;
point._model.radius = point.custom && point.custom.hoverRadius ? point.custom.hoverRadius : (helpers.getValueAtIndexOrDefault(dataset.hoverRadius, index, this.chart.options.elements.point.hoverRadius)) + this.getRadius(this.getDataset().data[point._index]);
point._model.backgroundColor = point.custom && point.custom.hoverBackgroundColor ? point.custom.hoverBackgroundColor : helpers.getValueAtIndexOrDefault(dataset.hoverBackgroundColor, index, helpers.color(point._model.backgroundColor).saturate(0.5).darken(0.1).rgbString());
point._model.borderColor = point.custom && point.custom.hoverBorderColor ? point.custom.hoverBorderColor : helpers.getValueAtIndexOrDefault(dataset.hoverBorderColor, index, helpers.color(point._model.borderColor).saturate(0.5).darken(0.1).rgbString());
point._model.borderWidth = point.custom && point.custom.hoverBorderWidth ? point.custom.hoverBorderWidth : helpers.getValueAtIndexOrDefault(dataset.hoverBorderWidth, index, point._model.borderWidth);
},
removeHoverStyle: function(point) {
var dataset = this.chart.data.datasets[point._datasetIndex];
var index = point._index;
point._model.radius = point.custom && point.custom.radius ? point.custom.radius : this.getRadius(this.getDataset().data[point._index]);
point._model.backgroundColor = point.custom && point.custom.backgroundColor ? point.custom.backgroundColor : helpers.getValueAtIndexOrDefault(this.getDataset().backgroundColor, index, this.chart.options.elements.point.backgroundColor);
point._model.borderColor = point.custom && point.custom.borderColor ? point.custom.borderColor : helpers.getValueAtIndexOrDefault(this.getDataset().borderColor, index, this.chart.options.elements.point.borderColor);
point._model.borderWidth = point.custom && point.custom.borderWidth ? point.custom.borderWidth : helpers.getValueAtIndexOrDefault(this.getDataset().borderWidth, index, this.chart.options.elements.point.borderWidth);
}
});
}).call(this);
(function() {
"use strict";
var root = this,
Chart = root.Chart,
//Cache a local reference to Chart.helpers
helpers = Chart.helpers;
Chart.defaults.doughnut = {
animation: {
//Boolean - Whether we animate the rotation of the Doughnut
animateRotate: true,
//Boolean - Whether we animate scaling the Doughnut from the centre
animateScale: false,
},
aspectRatio: 1,
hover: {
mode: 'single'
},
legendCallback: function(chart) {
var text = [];
text.push('<ul class="' + chart.id + '-legend">');
if (chart.data.datasets.length) {
for (var i = 0; i < chart.data.datasets[0].data.length; ++i) {
text.push('<li><span style="background-color:' + chart.data.datasets[0].backgroundColor[i] + '">');
if (chart.data.labels[i]) {
text.push(chart.data.labels[i]);
}
text.push('</span></li>');
}
}
text.push('</ul>');
return text.join("");
},
legend: {
labels: {
generateLabels: function(data) {
return data.labels.map(function(label, i) {
return {
text: label,
fillStyle: data.datasets[0].backgroundColor[i],
hidden: isNaN(data.datasets[0].data[i]),
// Extra data used for toggling the correct item
index: i
};
});
}
},
onClick: function(e, legendItem) {
helpers.each(this.chart.data.datasets, function(dataset) {
dataset.metaHiddenData = dataset.metaHiddenData || [];
var idx = legendItem.index;
if (!isNaN(dataset.data[idx])) {
dataset.metaHiddenData[idx] = dataset.data[idx];
dataset.data[idx] = NaN;
} else if (!isNaN(dataset.metaHiddenData[idx])) {
dataset.data[idx] = dataset.metaHiddenData[idx];
}
});
this.chart.update();
}
},
//The percentage of the chart that we cut out of the middle.
cutoutPercentage: 50,
// Need to override these to give a nice default
tooltips: {
callbacks: {
title: function() { return '';},
label: function(tooltipItem, data) {
return data.labels[tooltipItem.index] + ': ' + data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
}
}
}
};
Chart.defaults.pie = helpers.clone(Chart.defaults.doughnut);
helpers.extend(Chart.defaults.pie, {
cutoutPercentage: 0
});
Chart.controllers.doughnut = Chart.controllers.pie = Chart.DatasetController.extend({
linkScales: function() {
// no scales for doughnut
},
addElements: function() {
this.getDataset().metaData = this.getDataset().metaData || [];
helpers.each(this.getDataset().data, function(value, index) {
this.getDataset().metaData[index] = this.getDataset().metaData[index] || new Chart.elements.Arc({
_chart: this.chart.chart,
_datasetIndex: this.index,
_index: index,
});
}, this);
},
addElementAndReset: function(index, colorForNewElement) {
this.getDataset().metaData = this.getDataset().metaData || [];
var arc = new Chart.elements.Arc({
_chart: this.chart.chart,
_datasetIndex: this.index,
_index: index,
});
if (colorForNewElement && helpers.isArray(this.getDataset().backgroundColor)) {
this.getDataset().backgroundColor.splice(index, 0, colorForNewElement);
}
// Reset the point
this.updateElement(arc, index, true);
// Add to the points array
this.getDataset().metaData.splice(index, 0, arc);
},
getVisibleDatasetCount: function getVisibleDatasetCount() {
return helpers.where(this.chart.data.datasets, function(ds) { return helpers.isDatasetVisible(ds); }).length;
},
// Get index of the dataset in relation to the visible datasets. This allows determining the inner and outer radius correctly
getRingIndex: function getRingIndex(datasetIndex) {
var ringIndex = 0;
for (var j = 0; j < datasetIndex; ++j) {
if (helpers.isDatasetVisible(this.chart.data.datasets[j])) {
++ringIndex;
}
}
return ringIndex;
},
update: function update(reset) {
var minSize = Math.min(this.chart.chartArea.right - this.chart.chartArea.left, this.chart.chartArea.bottom - this.chart.chartArea.top);
this.chart.outerRadius = Math.max((minSize / 2) - this.chart.options.elements.arc.borderWidth / 2, 0);
this.chart.innerRadius = Math.max(this.chart.options.cutoutPercentage ? (this.chart.outerRadius / 100) * (this.chart.options.cutoutPercentage) : 1, 0);
this.chart.radiusLength = (this.chart.outerRadius - this.chart.innerRadius) / this.getVisibleDatasetCount();
this.getDataset().total = 0;
helpers.each(this.getDataset().data, function(value) {
if (!isNaN(value)) {
this.getDataset().total += Math.abs(value);
}
}, this);
this.outerRadius = this.chart.outerRadius - (this.chart.radiusLength * this.getRingIndex(this.index));
this.innerRadius = this.outerRadius - this.chart.radiusLength;
helpers.each(this.getDataset().metaData, function(arc, index) {
this.updateElement(arc, index, reset);
}, this);
},
updateElement: function(arc, index, reset) {
var centerX = (this.chart.chartArea.left + this.chart.chartArea.right) / 2;
var centerY = (this.chart.chartArea.top + this.chart.chartArea.bottom) / 2;
var resetModel = {
x: centerX,
y: centerY,
startAngle: Math.PI * -0.5, // use - PI / 2 instead of 3PI / 2 to make animations better. It means that we never deal with overflow during the transition function
endAngle: Math.PI * -0.5,
circumference: (this.chart.options.animation.animateRotate) ? 0 : this.calculateCircumference(this.getDataset().data[index]),
outerRadius: (this.chart.options.animation.animateScale) ? 0 : this.outerRadius,
innerRadius: (this.chart.options.animation.animateScale) ? 0 : this.innerRadius
};
helpers.extend(arc, {
// Utility
_chart: this.chart.chart,
_datasetIndex: this.index,
_index: index,
// Desired view properties
_model: reset ? resetModel : {
x: centerX,
y: centerY,
circumference: this.calculateCircumference(this.getDataset().data[index]),
outerRadius: this.outerRadius,
innerRadius: this.innerRadius,
backgroundColor: arc.custom && arc.custom.backgroundColor ? arc.custom.backgroundColor : helpers.getValueAtIndexOrDefault(this.getDataset().backgroundColor, index, this.chart.options.elements.arc.backgroundColor),
hoverBackgroundColor: arc.custom && arc.custom.hoverBackgroundColor ? arc.custom.hoverBackgroundColor : helpers.getValueAtIndexOrDefault(this.getDataset().hoverBackgroundColor, index, this.chart.options.elements.arc.hoverBackgroundColor),
borderWidth: arc.custom && arc.custom.borderWidth ? arc.custom.borderWidth : helpers.getValueAtIndexOrDefault(this.getDataset().borderWidth, index, this.chart.options.elements.arc.borderWidth),
borderColor: arc.custom && arc.custom.borderColor ? arc.custom.borderColor : helpers.getValueAtIndexOrDefault(this.getDataset().borderColor, index, this.chart.options.elements.arc.borderColor),
label: helpers.getValueAtIndexOrDefault(this.getDataset().label, index, this.chart.data.labels[index])
},
});
if (!reset) {
if (index === 0) {
arc._model.startAngle = Math.PI * -0.5; // use - PI / 2 instead of 3PI / 2 to make animations better. It means that we never deal with overflow during the transition function
} else {
arc._model.startAngle = this.getDataset().metaData[index - 1]._model.endAngle;
}
arc._model.endAngle = arc._model.startAngle + arc._model.circumference;
//Check to see if it's the last arc, if not get the next and update its start angle
if (index < this.getDataset().data.length - 1) {
this.getDataset().metaData[index + 1]._model.startAngle = arc._model.endAngle;
}
}
arc.pivot();
},
draw: function(ease) {
var easingDecimal = ease || 1;
helpers.each(this.getDataset().metaData, function(arc, index) {
arc.transition(easingDecimal).draw();
}, this);
},
setHoverStyle: function(arc) {
var dataset = this.chart.data.datasets[arc._datasetIndex];
var index = arc._index;
arc._model.backgroundColor = arc.custom && arc.custom.hoverBackgroundColor ? arc.custom.hoverBackgroundColor : helpers.getValueAtIndexOrDefault(dataset.hoverBackgroundColor, index, helpers.color(arc._model.backgroundColor).saturate(0.5).darken(0.1).rgbString());
arc._model.borderColor = arc.custom && arc.custom.hoverBorderColor ? arc.custom.hoverBorderColor : helpers.getValueAtIndexOrDefault(dataset.hoverBorderColor, index, helpers.color(arc._model.borderColor).saturate(0.5).darken(0.1).rgbString());
arc._model.borderWidth = arc.custom && arc.custom.hoverBorderWidth ? arc.custom.hoverBorderWidth : helpers.getValueAtIndexOrDefault(dataset.hoverBorderWidth, index, arc._model.borderWidth);
},
removeHoverStyle: function(arc) {
var dataset = this.chart.data.datasets[arc._datasetIndex];
var index = arc._index;
arc._model.backgroundColor = arc.custom && arc.custom.backgroundColor ? arc.custom.backgroundColor : helpers.getValueAtIndexOrDefault(this.getDataset().backgroundColor, index, this.chart.options.elements.arc.backgroundColor);
arc._model.borderColor = arc.custom && arc.custom.borderColor ? arc.custom.borderColor : helpers.getValueAtIndexOrDefault(this.getDataset().borderColor, index, this.chart.options.elements.arc.borderColor);
arc._model.borderWidth = arc.custom && arc.custom.borderWidth ? arc.custom.borderWidth : helpers.getValueAtIndexOrDefault(this.getDataset().borderWidth, index, this.chart.options.elements.arc.borderWidth);
},
calculateCircumference: function(value) {
if (this.getDataset().total > 0 && !isNaN(value)) {
return (Math.PI * 1.999999) * (value / this.getDataset().total);
} else {
return 0;
}
},
});
}).call(this);
(function() {
"use strict";
var root = this,
Chart = root.Chart,
helpers = Chart.helpers;
Chart.defaults.line = {
hover: {
mode: "label"
},
scales: {
xAxes: [{
type: "category",
id: 'x-axis-0'
}],
yAxes: [{
type: "linear",
id: 'y-axis-0'
}],
},
};
Chart.controllers.line = Chart.DatasetController.extend({
addElements: function() {
this.getDataset().metaData = this.getDataset().metaData || [];
this.getDataset().metaDataset = this.getDataset().metaDataset || new Chart.elements.Line({
_chart: this.chart.chart,
_datasetIndex: this.index,
_points: this.getDataset().metaData,
});
helpers.each(this.getDataset().data, function(value, index) {
this.getDataset().metaData[index] = this.getDataset().metaData[index] || new Chart.elements.Point({
_chart: this.chart.chart,
_datasetIndex: this.index,
_index: index,
});
}, this);
},
addElementAndReset: function(index) {
this.getDataset().metaData = this.getDataset().metaData || [];
var point = new Chart.elements.Point({
_chart: this.chart.chart,
_datasetIndex: this.index,
_index: index,
});
// Reset the point
this.updateElement(point, index, true);
// Add to the points array
this.getDataset().metaData.splice(index, 0, point);
// Make sure bezier control points are updated
this.updateBezierControlPoints();
},
update: function update(reset) {
var line = this.getDataset().metaDataset;
var points = this.getDataset().metaData;
var yScale = this.getScaleForId(this.getDataset().yAxisID);
var xScale = this.getScaleForId(this.getDataset().xAxisID);
var scaleBase;
if (yScale.min < 0 && yScale.max < 0) {
scaleBase = yScale.getPixelForValue(yScale.max);
} else if (yScale.min > 0 && yScale.max > 0) {
scaleBase = yScale.getPixelForValue(yScale.min);
} else {
scaleBase = yScale.getPixelForValue(0);
}
// Update Line
helpers.extend(line, {
// Utility
_scale: yScale,
_datasetIndex: this.index,
// Data
_children: points,
// Model
_model: {
// Appearance
tension: line.custom && line.custom.tension ? line.custom.tension : helpers.getValueOrDefault(this.getDataset().tension, this.chart.options.elements.line.tension),
backgroundColor: line.custom && line.custom.backgroundColor ? line.custom.backgroundColor : (this.getDataset().backgroundColor || this.chart.options.elements.line.backgroundColor),
borderWidth: line.custom && line.custom.borderWidth ? line.custom.borderWidth : (this.getDataset().borderWidth || this.chart.options.elements.line.borderWidth),
borderColor: line.custom && line.custom.borderColor ? line.custom.borderColor : (this.getDataset().borderColor || this.chart.options.elements.line.borderColor),
borderCapStyle: line.custom && line.custom.borderCapStyle ? line.custom.borderCapStyle : (this.getDataset().borderCapStyle || this.chart.options.elements.line.borderCapStyle),
borderDash: line.custom && line.custom.borderDash ? line.custom.borderDash : (this.getDataset().borderDash || this.chart.options.elements.line.borderDash),
borderDashOffset: line.custom && line.custom.borderDashOffset ? line.custom.borderDashOffset : (this.getDataset().borderDashOffset || this.chart.options.elements.line.borderDashOffset),
borderJoinStyle: line.custom && line.custom.borderJoinStyle ? line.custom.borderJoinStyle : (this.getDataset().borderJoinStyle || this.chart.options.elements.line.borderJoinStyle),
fill: line.custom && line.custom.fill ? line.custom.fill : (this.getDataset().fill !== undefined ? this.getDataset().fill : this.chart.options.elements.line.fill),
// Scale
scaleTop: yScale.top,
scaleBottom: yScale.bottom,
scaleZero: scaleBase,
},
});
line.pivot();
// Update Points
helpers.each(points, function(point, index) {
this.updateElement(point, index, reset);
}, this);
this.updateBezierControlPoints();
},
getPointBackgroundColor: function(point, index) {
var backgroundColor = this.chart.options.elements.point.backgroundColor;
var dataset = this.getDataset();
if (point.custom && point.custom.backgroundColor) {
backgroundColor = point.custom.backgroundColor;
} else if (dataset.pointBackgroundColor) {
backgroundColor = helpers.getValueAtIndexOrDefault(dataset.pointBackgroundColor, index, backgroundColor);
} else if (dataset.backgroundColor) {
backgroundColor = dataset.backgroundColor;
}
return backgroundColor;
},
getPointBorderColor: function(point, index) {
var borderColor = this.chart.options.elements.point.borderColor;
var dataset = this.getDataset();
if (point.custom && point.custom.borderColor) {
borderColor = point.custom.borderColor;
} else if (dataset.pointBorderColor) {
borderColor = helpers.getValueAtIndexOrDefault(this.getDataset().pointBorderColor, index, borderColor);
} else if (dataset.borderColor) {
borderColor = dataset.borderColor;
}
return borderColor;
},
getPointBorderWidth: function(point, index) {
var borderWidth = this.chart.options.elements.point.borderWidth;
var dataset = this.getDataset();
if (point.custom && point.custom.borderWidth !== undefined) {
borderWidth = point.custom.borderWidth;
} else if (dataset.pointBorderWidth !== undefined) {
borderWidth = helpers.getValueAtIndexOrDefault(dataset.pointBorderWidth, index, borderWidth);
} else if (dataset.borderWidth !== undefined) {
borderWidth = dataset.borderWidth;
}
return borderWidth;
},
updateElement: function(point, index, reset) {
var yScale = this.getScaleForId(this.getDataset().yAxisID);
var xScale = this.getScaleForId(this.getDataset().xAxisID);
var scaleBase;
if (yScale.min < 0 && yScale.max < 0) {
scaleBase = yScale.getPixelForValue(yScale.max);
} else if (yScale.min > 0 && yScale.max > 0) {
scaleBase = yScale.getPixelForValue(yScale.min);
} else {
scaleBase = yScale.getPixelForValue(0);
}
helpers.extend(point, {
// Utility
_chart: this.chart.chart,
_xScale: xScale,
_yScale: yScale,
_datasetIndex: this.index,
_index: index,
// Desired view properties
_model: {
x: xScale.getPixelForValue(this.getDataset().data[index], index, this.index, this.chart.isCombo),
y: reset ? scaleBase : this.calculatePointY(this.getDataset().data[index], index, this.index, this.chart.isCombo),
// Appearance
tension: point.custom && point.custom.tension ? point.custom.tension : helpers.getValueOrDefault(this.getDataset().tension, this.chart.options.elements.line.tension),
radius: point.custom && point.custom.radius ? point.custom.radius : helpers.getValueAtIndexOrDefault(this.getDataset().radius, index, this.chart.options.elements.point.radius),
backgroundColor: this.getPointBackgroundColor(point, index),
borderColor: this.getPointBorderColor(point, index),
borderWidth: this.getPointBorderWidth(point, index),
// Tooltip
hitRadius: point.custom && point.custom.hitRadius ? point.custom.hitRadius : helpers.getValueAtIndexOrDefault(this.getDataset().hitRadius, index, this.chart.options.elements.point.hitRadius),
},
});
point._model.skip = point.custom && point.custom.skip ? point.custom.skip : (isNaN(point._model.x) || isNaN(point._model.y));
},
calculatePointY: function(value, index, datasetIndex, isCombo) {
var xScale = this.getScaleForId(this.getDataset().xAxisID);
var yScale = this.getScaleForId(this.getDataset().yAxisID);
if (yScale.options.stacked) {
var sumPos = 0,
sumNeg = 0;
for (var i = this.chart.data.datasets.length - 1; i > datasetIndex; i--) {
var ds = this.chart.data.datasets[i];
if (helpers.isDatasetVisible(ds)) {
if (ds.data[index] < 0) {
sumNeg += ds.data[index] || 0;
} else {
sumPos += ds.data[index] || 0;
}
}
}
if (value < 0) {
return yScale.getPixelForValue(sumNeg + value);
} else {
return yScale.getPixelForValue(sumPos + value);
}
return yScale.getPixelForValue(value);
}
return yScale.getPixelForValue(value);
},
updateBezierControlPoints: function() {
// Update bezier control points
helpers.each(this.getDataset().metaData, function(point, index) {
var controlPoints = helpers.splineCurve(
helpers.previousItem(this.getDataset().metaData, index)._model,
point._model,
helpers.nextItem(this.getDataset().metaData, index)._model,
point._model.tension
);
// Prevent the bezier going outside of the bounds of the graph
point._model.controlPointPreviousX = Math.max(Math.min(controlPoints.previous.x, this.chart.chartArea.right), this.chart.chartArea.left);
point._model.controlPointPreviousY = Math.max(Math.min(controlPoints.previous.y, this.chart.chartArea.bottom), this.chart.chartArea.top);
point._model.controlPointNextX = Math.max(Math.min(controlPoints.next.x, this.chart.chartArea.right), this.chart.chartArea.left);
point._model.controlPointNextY = Math.max(Math.min(controlPoints.next.y, this.chart.chartArea.bottom), this.chart.chartArea.top);
// Now pivot the point for animation
point.pivot();
}, this);
},
draw: function(ease) {
var easingDecimal = ease || 1;
// Transition Point Locations
helpers.each(this.getDataset().metaData, function(point, index) {
point.transition(easingDecimal);
}, this);
// Transition and Draw the line
this.getDataset().metaDataset.transition(easingDecimal).draw();
// Draw the points
helpers.each(this.getDataset().metaData, function(point) {
point.draw();
});
},
setHoverStyle: function(point) {
// Point
var dataset = this.chart.data.datasets[point._datasetIndex];
var index = point._index;
point._model.radius = point.custom && point.custom.hoverRadius ? point.custom.hoverRadius : helpers.getValueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius);
point._model.backgroundColor = point.custom && point.custom.hoverBackgroundColor ? point.custom.hoverBackgroundColor : helpers.getValueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.color(point._model.backgroundColor).saturate(0.5).darken(0.1).rgbString());
point._model.borderColor = point.custom && point.custom.hoverBorderColor ? point.custom.hoverBorderColor : helpers.getValueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.color(point._model.borderColor).saturate(0.5).darken(0.1).rgbString());
point._model.borderWidth = point.custom && point.custom.hoverBorderWidth ? point.custom.hoverBorderWidth : helpers.getValueAtIndexOrDefault(dataset.pointHoverBorderWidth, index, point._model.borderWidth);
},
removeHoverStyle: function(point) {
var dataset = this.chart.data.datasets[point._datasetIndex];
var index = point._index;
point._model.radius = point.custom && point.custom.radius ? point.custom.radius : helpers.getValueAtIndexOrDefault(this.getDataset().radius, index, this.chart.options.elements.point.radius);
point._model.backgroundColor = this.getPointBackgroundColor(point, index);
point._model.borderColor = this.getPointBorderColor(point, index);
point._model.borderWidth = this.getPointBorderWidth(point, index);
}
});
}).call(this);
(function() {
"use strict";
var root = this,
Chart = root.Chart,
//Cache a local reference to Chart.helpers
helpers = Chart.helpers;
Chart.defaults.polarArea = {
scale: {
type: "radialLinear",
lineArc: true, // so that lines are circular
},
//Boolean - Whether to animate the rotation of the chart
animateRotate: true,
animateScale: true,
aspectRatio: 1,
legendCallback: function(chart) {
var text = [];
text.push('<ul class="' + chart.id + '-legend">');
if (chart.data.datasets.length) {
for (var i = 0; i < chart.data.datasets[0].data.length; ++i) {
text.push('<li><span style="background-color:' + chart.data.datasets[0].backgroundColor[i] + '">');
if (chart.data.labels[i]) {
text.push(chart.data.labels[i]);
}
text.push('</span></li>');
}
}
text.push('</ul>');
return text.join("");
},
legend: {
labels: {
generateLabels: function(data) {
return data.labels.map(function(label, i) {
return {
text: label,
fillStyle: data.datasets[0].backgroundColor[i],
hidden: isNaN(data.datasets[0].data[i]),
// Extra data used for toggling the correct item
index: i
};
});
}
},
onClick: function(e, legendItem) {
helpers.each(this.chart.data.datasets, function(dataset) {
dataset.metaHiddenData = dataset.metaHiddenData || [];
var idx = legendItem.index;
if (!isNaN(dataset.data[idx])) {
dataset.metaHiddenData[idx] = dataset.data[idx];
dataset.data[idx] = NaN;
} else if (!isNaN(dataset.metaHiddenData[idx])) {
dataset.data[idx] = dataset.metaHiddenData[idx];
}
});
this.chart.update();
}
},
// Need to override these to give a nice default
tooltips: {
callbacks: {
title: function() { return ''; },
label: function(tooltipItem, data) {
return data.labels[tooltipItem.index] + ': ' + tooltipItem.yLabel;
}
}
}
};
Chart.controllers.polarArea = Chart.DatasetController.extend({
linkScales: function() {
// no scales for doughnut
},
addElements: function() {
this.getDataset().metaData = this.getDataset().metaData || [];
helpers.each(this.getDataset().data, function(value, index) {
this.getDataset().metaData[index] = this.getDataset().metaData[index] || new Chart.elements.Arc({
_chart: this.chart.chart,
_datasetIndex: this.index,
_index: index,
});
}, this);
},
addElementAndReset: function(index) {
this.getDataset().metaData = this.getDataset().metaData || [];
var arc = new Chart.elements.Arc({
_chart: this.chart.chart,
_datasetIndex: this.index,
_index: index,
});
// Reset the point
this.updateElement(arc, index, true);
// Add to the points array
this.getDataset().metaData.splice(index, 0, arc);
},
getVisibleDatasetCount: function getVisibleDatasetCount() {
return helpers.where(this.chart.data.datasets, function(ds) { return helpers.isDatasetVisible(ds); }).length;
},
update: function update(reset) {
var minSize = Math.min(this.chart.chartArea.right - this.chart.chartArea.left, this.chart.chartArea.bottom - this.chart.chartArea.top);
this.chart.outerRadius = Math.max((minSize - this.chart.options.elements.arc.borderWidth / 2) / 2, 0);
this.chart.innerRadius = Math.max(this.chart.options.cutoutPercentage ? (this.chart.outerRadius / 100) * (this.chart.options.cutoutPercentage) : 1, 0);
this.chart.radiusLength = (this.chart.outerRadius - this.chart.innerRadius) / this.getVisibleDatasetCount();
this.getDataset().total = 0;
helpers.each(this.getDataset().data, function(value) {
this.getDataset().total += Math.abs(value);
}, this);
this.outerRadius = this.chart.outerRadius - (this.chart.radiusLength * this.index);
this.innerRadius = this.outerRadius - this.chart.radiusLength;
helpers.each(this.getDataset().metaData, function(arc, index) {
this.updateElement(arc, index, reset);
}, this);
},
updateElement: function(arc, index, reset) {
var circumference = this.calculateCircumference(this.getDataset().data[index]);
var centerX = (this.chart.chartArea.left + this.chart.chartArea.right) / 2;
var centerY = (this.chart.chartArea.top + this.chart.chartArea.bottom) / 2;
// If there is NaN data before us, we need to calculate the starting angle correctly.
// We could be way more efficient here, but its unlikely that the polar area chart will have a lot of data
var notNullIndex = 0;
for (var i = 0; i < index; ++i) {
if (!isNaN(this.getDataset().data[i])) {
++notNullIndex;
}
}
var startAngle = (-0.5 * Math.PI) + (circumference * notNullIndex);
var endAngle = startAngle + circumference;
var resetModel = {
x: centerX,
y: centerY,
innerRadius: 0,
outerRadius: this.chart.options.animateScale ? 0 : this.chart.scale.getDistanceFromCenterForValue(this.getDataset().data[index]),
startAngle: this.chart.options.animateRotate ? Math.PI * -0.5 : startAngle,
endAngle: this.chart.options.animateRotate ? Math.PI * -0.5 : endAngle,
backgroundColor: arc.custom && arc.custom.backgroundColor ? arc.custom.backgroundColor : helpers.getValueAtIndexOrDefault(this.getDataset().backgroundColor, index, this.chart.options.elements.arc.backgroundColor),
hoverBackgroundColor: arc.custom && arc.custom.hoverBackgroundColor ? arc.custom.hoverBackgroundColor : helpers.getValueAtIndexOrDefault(this.getDataset().hoverBackgroundColor, index, this.chart.options.elements.arc.hoverBackgroundColor),
borderWidth: arc.custom && arc.custom.borderWidth ? arc.custom.borderWidth : helpers.getValueAtIndexOrDefault(this.getDataset().borderWidth, index, this.chart.options.elements.arc.borderWidth),
borderColor: arc.custom && arc.custom.borderColor ? arc.custom.borderColor : helpers.getValueAtIndexOrDefault(this.getDataset().borderColor, index, this.chart.options.elements.arc.borderColor),
label: helpers.getValueAtIndexOrDefault(this.chart.data.labels, index, this.chart.data.labels[index])
};
helpers.extend(arc, {
// Utility
_chart: this.chart.chart,
_datasetIndex: this.index,
_index: index,
_scale: this.chart.scale,
// Desired view properties
_model: reset ? resetModel : {
x: centerX,
y: centerY,
innerRadius: 0,
outerRadius: this.chart.scale.getDistanceFromCenterForValue(this.getDataset().data[index]),
startAngle: startAngle,
endAngle: endAngle,
backgroundColor: arc.custom && arc.custom.backgroundColor ? arc.custom.backgroundColor : helpers.getValueAtIndexOrDefault(this.getDataset().backgroundColor, index, this.chart.options.elements.arc.backgroundColor),
hoverBackgroundColor: arc.custom && arc.custom.hoverBackgroundColor ? arc.custom.hoverBackgroundColor : helpers.getValueAtIndexOrDefault(this.getDataset().hoverBackgroundColor, index, this.chart.options.elements.arc.hoverBackgroundColor),
borderWidth: arc.custom && arc.custom.borderWidth ? arc.custom.borderWidth : helpers.getValueAtIndexOrDefault(this.getDataset().borderWidth, index, this.chart.options.elements.arc.borderWidth),
borderColor: arc.custom && arc.custom.borderColor ? arc.custom.borderColor : helpers.getValueAtIndexOrDefault(this.getDataset().borderColor, index, this.chart.options.elements.arc.borderColor),
label: helpers.getValueAtIndexOrDefault(this.chart.data.labels, index, this.chart.data.labels[index])
},
});
arc.pivot();
},
draw: function(ease) {
var easingDecimal = ease || 1;
helpers.each(this.getDataset().metaData, function(arc, index) {
arc.transition(easingDecimal).draw();
}, this);
},
setHoverStyle: function(arc) {
var dataset = this.chart.data.datasets[arc._datasetIndex];
var index = arc._index;
arc._model.backgroundColor = arc.custom && arc.custom.hoverBackgroundColor ? arc.custom.hoverBackgroundColor : helpers.getValueAtIndexOrDefault(dataset.hoverBackgroundColor, index, helpers.color(arc._model.backgroundColor).saturate(0.5).darken(0.1).rgbString());
arc._model.borderColor = arc.custom && arc.custom.hoverBorderColor ? arc.custom.hoverBorderColor : helpers.getValueAtIndexOrDefault(dataset.hoverBorderColor, index, helpers.color(arc._model.borderColor).saturate(0.5).darken(0.1).rgbString());
arc._model.borderWidth = arc.custom && arc.custom.hoverBorderWidth ? arc.custom.hoverBorderWidth : helpers.getValueAtIndexOrDefault(dataset.borderWidth, index, arc._model.borderWidth);
},
removeHoverStyle: function(arc) {
var dataset = this.chart.data.datasets[arc._datasetIndex];
var index = arc._index;
arc._model.backgroundColor = arc.custom && arc.custom.backgroundColor ? arc.custom.backgroundColor : helpers.getValueAtIndexOrDefault(this.getDataset().backgroundColor, index, this.chart.options.elements.arc.backgroundColor);
arc._model.borderColor = arc.custom && arc.custom.borderColor ? arc.custom.borderColor : helpers.getValueAtIndexOrDefault(this.getDataset().borderColor, index, this.chart.options.elements.arc.borderColor);
arc._model.borderWidth = arc.custom && arc.custom.borderWidth ? arc.custom.borderWidth : helpers.getValueAtIndexOrDefault(this.getDataset().borderWidth, index, this.chart.options.elements.arc.borderWidth);
},
calculateCircumference: function(value) {
if (isNaN(value)) {
return 0;
} else {
// Count the number of NaN values
var numNaN = helpers.where(this.getDataset().data, function(data) {
return isNaN(data);
}).length;
return (2 * Math.PI) / (this.getDataset().data.length - numNaN);
}
}
});
}).call(this);
(function() {
"use strict";
var root = this,
Chart = root.Chart,
helpers = Chart.helpers;
Chart.defaults.radar = {
scale: {
type: "radialLinear",
},
elements: {
line: {
tension: 0, // no bezier in radar
}
},
};
Chart.controllers.radar = Chart.DatasetController.extend({
linkScales: function() {
// No need. Single scale only
},
addElements: function() {
this.getDataset().metaData = this.getDataset().metaData || [];
this.getDataset().metaDataset = this.getDataset().metaDataset || new Chart.elements.Line({
_chart: this.chart.chart,
_datasetIndex: this.index,
_points: this.getDataset().metaData,
_loop: true
});
helpers.each(this.getDataset().data, function(value, index) {
this.getDataset().metaData[index] = this.getDataset().metaData[index] || new Chart.elements.Point({
_chart: this.chart.chart,
_datasetIndex: this.index,
_index: index,
_model: {
x: 0, //xScale.getPixelForValue(null, index, true),
y: 0, //this.chartArea.bottom,
},
});
}, this);
},
addElementAndReset: function(index) {
this.getDataset().metaData = this.getDataset().metaData || [];
var point = new Chart.elements.Point({
_chart: this.chart.chart,
_datasetIndex: this.index,
_index: index,
});
// Reset the point
this.updateElement(point, index, true);
// Add to the points array
this.getDataset().metaData.splice(index, 0, point);
// Make sure bezier control points are updated
this.updateBezierControlPoints();
},
update: function update(reset) {
var line = this.getDataset().metaDataset;
var points = this.getDataset().metaData;
var scale = this.chart.scale;
var scaleBase;
if (scale.min < 0 && scale.max < 0) {
scaleBase = scale.getPointPositionForValue(0, scale.max);
} else if (scale.min > 0 && scale.max > 0) {
scaleBase = scale.getPointPositionForValue(0, scale.min);
} else {
scaleBase = scale.getPointPositionForValue(0, 0);
}
helpers.extend(this.getDataset().metaDataset, {
// Utility
_datasetIndex: this.index,
// Data
_children: this.getDataset().metaData,
// Model
_model: {
// Appearance
tension: helpers.getValueOrDefault(this.getDataset().tension, this.chart.options.elements.line.tension),
backgroundColor: this.getDataset().backgroundColor || this.chart.options.elements.line.backgroundColor,
borderWidth: this.getDataset().borderWidth || this.chart.options.elements.line.borderWidth,
borderColor: this.getDataset().borderColor || this.chart.options.elements.line.borderColor,
fill: this.getDataset().fill !== undefined ? this.getDataset().fill : this.chart.options.elements.line.fill, // use the value from the this.getDataset() if it was provided. else fall back to the default
// Scale
scaleTop: scale.top,
scaleBottom: scale.bottom,
scaleZero: scaleBase,
},
});
this.getDataset().metaDataset.pivot();
// Update Points
helpers.each(points, function(point, index) {
this.updateElement(point, index, reset);
}, this);
// Update bezier control points
this.updateBezierControlPoints();
},
updateElement: function(point, index, reset) {
var pointPosition = this.chart.scale.getPointPositionForValue(index, this.getDataset().data[index]);
helpers.extend(point, {
// Utility
_datasetIndex: this.index,
_index: index,
_scale: this.chart.scale,
// Desired view properties
_model: {
x: reset ? this.chart.scale.xCenter : pointPosition.x, // value not used in dataset scale, but we want a consistent API between scales
y: reset ? this.chart.scale.yCenter : pointPosition.y,
// Appearance
tension: point.custom && point.custom.tension ? point.custom.tension : helpers.getValueOrDefault(this.getDataset().tension, this.chart.options.elements.line.tension),
radius: point.custom && point.custom.radius ? point.custom.pointRadius : helpers.getValueAtIndexOrDefault(this.getDataset().pointRadius, index, this.chart.options.elements.point.radius),
backgroundColor: point.custom && point.custom.backgroundColor ? point.custom.backgroundColor : helpers.getValueAtIndexOrDefault(this.getDataset().pointBackgroundColor, index, this.chart.options.elements.point.backgroundColor),
borderColor: point.custom && point.custom.borderColor ? point.custom.borderColor : helpers.getValueAtIndexOrDefault(this.getDataset().pointBorderColor, index, this.chart.options.elements.point.borderColor),
borderWidth: point.custom && point.custom.borderWidth ? point.custom.borderWidth : helpers.getValueAtIndexOrDefault(this.getDataset().pointBorderWidth, index, this.chart.options.elements.point.borderWidth),
// Tooltip
hitRadius: point.custom && point.custom.hitRadius ? point.custom.hitRadius : helpers.getValueAtIndexOrDefault(this.getDataset().hitRadius, index, this.chart.options.elements.point.hitRadius),
},
});
point._model.skip = point.custom && point.custom.skip ? point.custom.skip : (isNaN(point._model.x) || isNaN(point._model.y));
},
updateBezierControlPoints: function() {
helpers.each(this.getDataset().metaData, function(point, index) {
var controlPoints = helpers.splineCurve(
helpers.previousItem(this.getDataset().metaData, index, true)._model,
point._model,
helpers.nextItem(this.getDataset().metaData, index, true)._model,
point._model.tension
);
// Prevent the bezier going outside of the bounds of the graph
point._model.controlPointPreviousX = Math.max(Math.min(controlPoints.previous.x, this.chart.chartArea.right), this.chart.chartArea.left);
point._model.controlPointPreviousY = Math.max(Math.min(controlPoints.previous.y, this.chart.chartArea.bottom), this.chart.chartArea.top);
point._model.controlPointNextX = Math.max(Math.min(controlPoints.next.x, this.chart.chartArea.right), this.chart.chartArea.left);
point._model.controlPointNextY = Math.max(Math.min(controlPoints.next.y, this.chart.chartArea.bottom), this.chart.chartArea.top);
// Now pivot the point for animation
point.pivot();
}, this);
},
draw: function(ease) {
var easingDecimal = ease || 1;
// Transition Point Locations
helpers.each(this.getDataset().metaData, function(point, index) {
point.transition(easingDecimal);
}, this);
// Transition and Draw the line
this.getDataset().metaDataset.transition(easingDecimal).draw();
// Draw the points
helpers.each(this.getDataset().metaData, function(point) {
point.draw();
});
},
setHoverStyle: function(point) {
// Point
var dataset = this.chart.data.datasets[point._datasetIndex];
var index = point._index;
point._model.radius = point.custom && point.custom.radius ? point.custom.radius : helpers.getValueAtIndexOrDefault(dataset.pointHoverRadius, index, this.chart.options.elements.point.hoverRadius);
point._model.backgroundColor = point.custom && point.custom.hoverBackgroundColor ? point.custom.hoverBackgroundColor : helpers.getValueAtIndexOrDefault(dataset.pointHoverBackgroundColor, index, helpers.color(point._model.backgroundColor).saturate(0.5).darken(0.1).rgbString());
point._model.borderColor = point.custom && point.custom.hoverBorderColor ? point.custom.hoverBorderColor : helpers.getValueAtIndexOrDefault(dataset.pointHoverBorderColor, index, helpers.color(point._model.borderColor).saturate(0.5).darken(0.1).rgbString());
point._model.borderWidth = point.custom && point.custom.hoverBorderWidth ? point.custom.hoverBorderWidth : helpers.getValueAtIndexOrDefault(dataset.pointBorderWidth, index, point._model.borderWidth);
},
removeHoverStyle: function(point) {
var dataset = this.chart.data.datasets[point._datasetIndex];
var index = point._index;
point._model.radius = point.custom && point.custom.radius ? point.custom.radius : helpers.getValueAtIndexOrDefault(this.getDataset().radius, index, this.chart.options.elements.point.radius);
point._model.backgroundColor = point.custom && point.custom.backgroundColor ? point.custom.backgroundColor : helpers.getValueAtIndexOrDefault(this.getDataset().pointBackgroundColor, index, this.chart.options.elements.point.backgroundColor);
point._model.borderColor = point.custom && point.custom.borderColor ? point.custom.borderColor : helpers.getValueAtIndexOrDefault(this.getDataset().pointBorderColor, index, this.chart.options.elements.point.borderColor);
point._model.borderWidth = point.custom && point.custom.borderWidth ? point.custom.borderWidth : helpers.getValueAtIndexOrDefault(this.getDataset().pointBorderWidth, index, this.chart.options.elements.point.borderWidth);
}
});
}).call(this);
(function() {
"use strict";
var root = this,
Chart = root.Chart,
helpers = Chart.helpers;
// Default config for a category scale
var defaultConfig = {
position: "bottom",
};
var DatasetScale = Chart.Scale.extend({
buildTicks: function(index) {
this.ticks = this.chart.data.labels;
},
getLabelForIndex: function(index, datasetIndex) {
return this.ticks[index];
},
// Used to get data value locations. Value can either be an index or a numerical value
getPixelForValue: function(value, index, datasetIndex, includeOffset) {
if (this.isHorizontal()) {
var innerWidth = this.width - (this.paddingLeft + this.paddingRight);
var valueWidth = innerWidth / Math.max((this.chart.data.labels.length - ((this.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
var widthOffset = (valueWidth * index) + this.paddingLeft;
if (this.options.gridLines.offsetGridLines && includeOffset) {
widthOffset += (valueWidth / 2);
}
return this.left + Math.round(widthOffset);
} else {
var innerHeight = this.height - (this.paddingTop + this.paddingBottom);
var valueHeight = innerHeight / Math.max((this.chart.data.labels.length - ((this.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
var heightOffset = (valueHeight * index) + this.paddingTop;
if (this.options.gridLines.offsetGridLines && includeOffset) {
heightOffset += (valueHeight / 2);
}
return this.top + Math.round(heightOffset);
}
},
});
Chart.scaleService.registerScaleType("category", DatasetScale, defaultConfig);
}).call(this);
(function() {
"use strict";
var root = this,
Chart = root.Chart,
helpers = Chart.helpers;
var defaultConfig = {
position: "left",
ticks: {
callback: function(tickValue, index, ticks) {
var delta = ticks[1] - ticks[0];
// If we have a number like 2.5 as the delta, figure out how many decimal places we need
if (Math.abs(delta) > 1) {
if (tickValue !== Math.floor(tickValue)) {
// not an integer
delta = tickValue - Math.floor(tickValue);
}
}
var logDelta = helpers.log10(Math.abs(delta));
var tickString = '';
if (tickValue !== 0) {
var numDecimal = -1 * Math.floor(logDelta);
numDecimal = Math.max(Math.min(numDecimal, 20), 0); // toFixed has a max of 20 decimal places
tickString = tickValue.toFixed(numDecimal);
} else {
tickString = '0'; // never show decimal places for 0
}
return tickString;
}
}
};
var LinearScale = Chart.Scale.extend({
determineDataLimits: function() {
// First Calculate the range
this.min = null;
this.max = null;
if (this.options.stacked) {
var valuesPerType = {};
helpers.each(this.chart.data.datasets, function(dataset) {
if (valuesPerType[dataset.type] === undefined) {
valuesPerType[dataset.type] = {
positiveValues: [],
negativeValues: [],
};
}
// Store these per type
var positiveValues = valuesPerType[dataset.type].positiveValues;
var negativeValues = valuesPerType[dataset.type].negativeValues;
if (helpers.isDatasetVisible(dataset) && (this.isHorizontal() ? dataset.xAxisID === this.id : dataset.yAxisID === this.id)) {
helpers.each(dataset.data, function(rawValue, index) {
var value = +this.getRightValue(rawValue);
if (isNaN(value)) {
return;
}
positiveValues[index] = positiveValues[index] || 0;
negativeValues[index] = negativeValues[index] || 0;
if (this.options.relativePoints) {
positiveValues[index] = 100;
} else {
if (value < 0) {
negativeValues[index] += value;
} else {
positiveValues[index] += value;
}
}
}, this);
}
}, this);
helpers.each(valuesPerType, function(valuesForType) {
var values = valuesForType.positiveValues.concat(valuesForType.negativeValues);
var minVal = helpers.min(values);
var maxVal = helpers.max(values);
this.min = this.min === null ? minVal : Math.min(this.min, minVal);
this.max = this.max === null ? maxVal : Math.max(this.max, maxVal);
}, this);
} else {
helpers.each(this.chart.data.datasets, function(dataset) {
if (helpers.isDatasetVisible(dataset) && (this.isHorizontal() ? dataset.xAxisID === this.id : dataset.yAxisID === this.id)) {
helpers.each(dataset.data, function(rawValue, index) {
var value = +this.getRightValue(rawValue);
if (isNaN(value)) {
return;
}
if (this.min === null) {
this.min = value;
} else if (value < this.min) {
this.min = value;
}
if (this.max === null) {
this.max = value;
} else if (value > this.max) {
this.max = value;
}
}, this);
}
}, this);
}
// If we are forcing it to begin at 0, but 0 will already be rendered on the chart,
// do nothing since that would make the chart weird. If the user really wants a weird chart
// axis, they can manually override it
if (this.options.ticks.beginAtZero) {
var minSign = helpers.sign(this.min);
var maxSign = helpers.sign(this.max);
if (minSign < 0 && maxSign < 0) {
// move the top up to 0
this.max = 0;
} else if (minSign > 0 && maxSign > 0) {
// move the botttom down to 0
this.min = 0;
}
}
if (this.options.ticks.min !== undefined) {
this.min = this.options.ticks.min;
} else if (this.options.ticks.suggestedMin !== undefined) {
this.min = Math.min(this.min, this.options.ticks.suggestedMin);
}
if (this.options.ticks.max !== undefined) {
this.max = this.options.ticks.max;
} else if (this.options.ticks.suggestedMax !== undefined) {
this.max = Math.max(this.max, this.options.ticks.suggestedMax);
}
if (this.min === this.max) {
this.min--;
this.max++;
}
},
buildTicks: function() {
// Then calulate the ticks
this.ticks = [];
// Figure out what the max number of ticks we can support it is based on the size of
// the axis area. For now, we say that the minimum tick spacing in pixels must be 50
// We also limit the maximum number of ticks to 11 which gives a nice 10 squares on
// the graph
var maxTicks;
if (this.isHorizontal()) {
maxTicks = Math.min(this.options.ticks.maxTicksLimit ? this.options.ticks.maxTicksLimit : 11,
Math.ceil(this.width / 50));
} else {
// The factor of 2 used to scale the font size has been experimentally determined.
maxTicks = Math.min(this.options.ticks.maxTicksLimit ? this.options.ticks.maxTicksLimit : 11,
Math.ceil(this.height / (2 * this.options.ticks.fontSize)));
}
// Make sure we always have at least 2 ticks
maxTicks = Math.max(2, maxTicks);
// To get a "nice" value for the tick spacing, we will use the appropriately named
// "nice number" algorithm. See path_to_url
// for details.
var niceRange = helpers.niceNum(this.max - this.min, false);
var spacing = helpers.niceNum(niceRange / (maxTicks - 1), true);
var niceMin = Math.floor(this.min / spacing) * spacing;
var niceMax = Math.ceil(this.max / spacing) * spacing;
var numSpaces = Math.ceil((niceMax - niceMin) / spacing);
// Put the values into the ticks array
this.ticks.push(this.options.ticks.min !== undefined ? this.options.ticks.min : niceMin);
for (var j = 1; j < numSpaces; ++j) {
this.ticks.push(niceMin + (j * spacing));
}
this.ticks.push(this.options.ticks.max !== undefined ? this.options.ticks.max : niceMax);
if (this.options.position == "left" || this.options.position == "right") {
// We are in a vertical orientation. The top value is the highest. So reverse the array
this.ticks.reverse();
}
// At this point, we need to update our max and min given the tick values since we have expanded the
// range of the scale
this.max = helpers.max(this.ticks);
this.min = helpers.min(this.ticks);
this.ticksAsNumbers = this.ticks.slice();
if (this.options.ticks.reverse) {
this.ticks.reverse();
this.start = this.max;
this.end = this.min;
} else {
this.start = this.min;
this.end = this.max;
}
this.zeroLineIndex = this.ticks.indexOf(0);
},
getLabelForIndex: function(index, datasetIndex) {
return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
},
// Utils
getPixelForValue: function(value, index, datasetIndex, includeOffset) {
// This must be called after fit has been run so that
// this.left, this.top, this.right, and this.bottom have been defined
var rightValue = +this.getRightValue(value);
var pixel;
var range = this.end - this.start;
if (this.isHorizontal()) {
var innerWidth = this.width - (this.paddingLeft + this.paddingRight);
pixel = this.left + (innerWidth / range * (rightValue - this.start));
return Math.round(pixel + this.paddingLeft);
} else {
var innerHeight = this.height - (this.paddingTop + this.paddingBottom);
pixel = (this.bottom - this.paddingBottom) - (innerHeight / range * (rightValue - this.start));
return Math.round(pixel);
}
},
getPixelForTick: function(index, includeOffset) {
return this.getPixelForValue(this.ticksAsNumbers[index], null, null, includeOffset);
},
});
Chart.scaleService.registerScaleType("linear", LinearScale, defaultConfig);
}).call(this);
(function() {
"use strict";
var root = this,
Chart = root.Chart,
helpers = Chart.helpers;
var defaultConfig = {
position: "left",
// label settings
ticks: {
callback: function(value, index, arr) {
var remain = value / (Math.pow(10, Math.floor(Chart.helpers.log10(value))));
if (remain === 1 || remain === 2 || remain === 5 || index === 0 || index === arr.length - 1) {
return value.toExponential();
} else {
return '';
}
}
}
};
var LogarithmicScale = Chart.Scale.extend({
determineDataLimits: function() {
// Calculate Range
this.min = null;
this.max = null;
if (this.options.stacked) {
var valuesPerType = {};
helpers.each(this.chart.data.datasets, function(dataset) {
if (helpers.isDatasetVisible(dataset) && (this.isHorizontal() ? dataset.xAxisID === this.id : dataset.yAxisID === this.id)) {
if (valuesPerType[dataset.type] === undefined) {
valuesPerType[dataset.type] = [];
}
helpers.each(dataset.data, function(rawValue, index) {
var values = valuesPerType[dataset.type];
var value = +this.getRightValue(rawValue);
if (isNaN(value)) {
return;
}
values[index] = values[index] || 0;
if (this.options.relativePoints) {
values[index] = 100;
} else {
// Don't need to split positive and negative since the log scale can't handle a 0 crossing
values[index] += value;
}
}, this);
}
}, this);
helpers.each(valuesPerType, function(valuesForType) {
var minVal = helpers.min(valuesForType);
var maxVal = helpers.max(valuesForType);
this.min = this.min === null ? minVal : Math.min(this.min, minVal);
this.max = this.max === null ? maxVal : Math.max(this.max, maxVal);
}, this);
} else {
helpers.each(this.chart.data.datasets, function(dataset) {
if (helpers.isDatasetVisible(dataset) && (this.isHorizontal() ? dataset.xAxisID === this.id : dataset.yAxisID === this.id)) {
helpers.each(dataset.data, function(rawValue, index) {
var value = +this.getRightValue(rawValue);
if (isNaN(value)) {
return;
}
if (this.min === null) {
this.min = value;
} else if (value < this.min) {
this.min = value;
}
if (this.max === null) {
this.max = value;
} else if (value > this.max) {
this.max = value;
}
}, this);
}
}, this);
}
this.min = this.options.ticks.min !== undefined ? this.options.ticks.min : this.min;
this.max = this.options.ticks.max !== undefined ? this.options.ticks.max : this.max;
if (this.min === this.max) {
if (this.min !== 0 && this.min !== null) {
this.min = Math.pow(10, Math.floor(helpers.log10(this.min)) - 1);
this.max = Math.pow(10, Math.floor(helpers.log10(this.max)) + 1);
} else {
this.min = 1;
this.max = 10;
}
}
},
buildTicks: function() {
// Reset the ticks array. Later on, we will draw a grid line at these positions
// The array simply contains the numerical value of the spots where ticks will be
this.tickValues = [];
// Figure out what the max number of ticks we can support it is based on the size of
// the axis area. For now, we say that the minimum tick spacing in pixels must be 50
// We also limit the maximum number of ticks to 11 which gives a nice 10 squares on
// the graph
var tickVal = this.options.ticks.min !== undefined ? this.options.ticks.min : Math.pow(10, Math.floor(helpers.log10(this.min)));
while (tickVal < this.max) {
this.tickValues.push(tickVal);
var exp = Math.floor(helpers.log10(tickVal));
var significand = Math.floor(tickVal / Math.pow(10, exp)) + 1;
if (significand === 10) {
significand = 1;
++exp;
}
tickVal = significand * Math.pow(10, exp);
}
var lastTick = this.options.ticks.max !== undefined ? this.options.ticks.max : tickVal;
this.tickValues.push(lastTick);
if (this.options.position == "left" || this.options.position == "right") {
// We are in a vertical orientation. The top value is the highest. So reverse the array
this.tickValues.reverse();
}
// At this point, we need to update our max and min given the tick values since we have expanded the
// range of the scale
this.max = helpers.max(this.tickValues);
this.min = helpers.min(this.tickValues);
if (this.options.ticks.reverse) {
this.tickValues.reverse();
this.start = this.max;
this.end = this.min;
} else {
this.start = this.min;
this.end = this.max;
}
this.ticks = this.tickValues.slice();
},
// Get the correct tooltip label
getLabelForIndex: function(index, datasetIndex) {
return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
},
getPixelForTick: function(index, includeOffset) {
return this.getPixelForValue(this.tickValues[index], null, null, includeOffset);
},
getPixelForValue: function(value, index, datasetIndex, includeOffset) {
var pixel;
var newVal = +this.getRightValue(value);
var range = helpers.log10(this.end) - helpers.log10(this.start);
if (this.isHorizontal()) {
if (newVal === 0) {
pixel = this.left + this.paddingLeft;
} else {
var innerWidth = this.width - (this.paddingLeft + this.paddingRight);
pixel = this.left + (innerWidth / range * (helpers.log10(newVal) - helpers.log10(this.start)));
return pixel + this.paddingLeft;
}
} else {
// Bottom - top since pixels increase downard on a screen
if (newVal === 0) {
pixel = this.top + this.paddingTop;
} else {
var innerHeight = this.height - (this.paddingTop + this.paddingBottom);
return (this.bottom - this.paddingBottom) - (innerHeight / range * (helpers.log10(newVal) - helpers.log10(this.start)));
}
}
},
});
Chart.scaleService.registerScaleType("logarithmic", LogarithmicScale, defaultConfig);
}).call(this);
(function() {
"use strict";
var root = this,
Chart = root.Chart,
helpers = Chart.helpers;
var defaultConfig = {
display: true,
//Boolean - Whether to animate scaling the chart from the centre
animate: true,
lineArc: false,
position: "chartArea",
angleLines: {
display: true,
color: "rgba(0, 0, 0, 0.1)",
lineWidth: 1
},
// label settings
ticks: {
//Boolean - Show a backdrop to the scale label
showLabelBackdrop: true,
//String - The colour of the label backdrop
backdropColor: "rgba(255,255,255,0.75)",
//Number - The backdrop padding above & below the label in pixels
backdropPaddingY: 2,
//Number - The backdrop padding to the side of the label in pixels
backdropPaddingX: 2,
},
pointLabels: {
//String - Point label font declaration
fontFamily: "'Arial'",
//String - Point label font weight
fontStyle: "normal",
//Number - Point label font size in pixels
fontSize: 10,
//String - Point label font colour
fontColor: "#666",
},
};
var LinearRadialScale = Chart.Scale.extend({
getValueCount: function() {
return this.chart.data.labels.length;
},
setDimensions: function() {
// Set the unconstrained dimension before label rotation
this.width = this.maxWidth;
this.height = this.maxHeight;
this.xCenter = Math.round(this.width / 2);
this.yCenter = Math.round(this.height / 2);
var minSize = helpers.min([this.height, this.width]);
this.drawingArea = (this.options.display) ? (minSize / 2) - (this.options.ticks.fontSize / 2 + this.options.ticks.backdropPaddingY) : (minSize / 2);
},
determineDataLimits: function() {
this.min = null;
this.max = null;
helpers.each(this.chart.data.datasets, function(dataset) {
if (helpers.isDatasetVisible(dataset)) {
helpers.each(dataset.data, function(rawValue, index) {
var value = +this.getRightValue(rawValue);
if (isNaN(value)) {
return;
}
if (this.min === null) {
this.min = value;
} else if (value < this.min) {
this.min = value;
}
if (this.max === null) {
this.max = value;
} else if (value > this.max) {
this.max = value;
}
}, this);
}
}, this);
if (this.min === this.max) {
this.min--;
this.max++;
}
// If we are forcing it to begin at 0, but 0 will already be rendered on the chart,
// do nothing since that would make the chart weird. If the user really wants a weird chart
// axis, they can manually override it
if (this.options.ticks.beginAtZero) {
var minSign = helpers.sign(this.min);
var maxSign = helpers.sign(this.max);
if (minSign < 0 && maxSign < 0) {
// move the top up to 0
this.max = 0;
} else if (minSign > 0 && maxSign > 0) {
// move the botttom down to 0
this.min = 0;
}
}
},
buildTicks: function() {
this.ticks = [];
// Figure out what the max number of ticks we can support it is based on the size of
// the axis area. For now, we say that the minimum tick spacing in pixels must be 50
// We also limit the maximum number of ticks to 11 which gives a nice 10 squares on
// the graph
var maxTicks = Math.min(this.options.ticks.maxTicksLimit ? this.options.ticks.maxTicksLimit : 11,
Math.ceil(this.drawingArea / (1.5 * this.options.ticks.fontSize)));
maxTicks = Math.max(2, maxTicks); // Make sure we always have at least 2 ticks
// To get a "nice" value for the tick spacing, we will use the appropriately named
// "nice number" algorithm. See path_to_url
// for details.
var niceRange = helpers.niceNum(this.max - this.min, false);
var spacing = helpers.niceNum(niceRange / (maxTicks - 1), true);
var niceMin = Math.floor(this.min / spacing) * spacing;
var niceMax = Math.ceil(this.max / spacing) * spacing;
// Put the values into the ticks array
for (var j = niceMin; j <= niceMax; j += spacing) {
this.ticks.push(j);
}
// At this point, we need to update our max and min given the tick values since we have expanded the
// range of the scale
this.max = helpers.max(this.ticks);
this.min = helpers.min(this.ticks);
if (this.options.ticks.reverse) {
this.ticks.reverse();
this.start = this.max;
this.end = this.min;
} else {
this.start = this.min;
this.end = this.max;
}
this.zeroLineIndex = this.ticks.indexOf(0);
},
getLabelForIndex: function(index, datasetIndex) {
return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
},
getCircumference: function() {
return ((Math.PI * 2) / this.getValueCount());
},
fit: function() {
/*
* Right, this is really confusing and there is a lot of maths going on here
* The gist of the problem is here: path_to_url
*
* Reaction: path_to_url
*
* Solution:
*
* We assume the radius of the polygon is half the size of the canvas at first
* at each index we check if the text overlaps.
*
* Where it does, we store that angle and that index.
*
* After finding the largest index and angle we calculate how much we need to remove
* from the shape radius to move the point inwards by that x.
*
* We average the left and right distances to get the maximum shape radius that can fit in the box
* along with labels.
*
* Once we have that, we can find the centre point for the chart, by taking the x text protrusion
* on each side, removing that from the size, halving it and adding the left x protrusion width.
*
* This will mean we have a shape fitted to the canvas, as large as it can be with the labels
* and position it in the most space efficient manner
*
* path_to_url
*/
// Get maximum radius of the polygon. Either half the height (minus the text width) or half the width.
// Use this to calculate the offset + change. - Make sure L/R protrusion is at least 0 to stop issues with centre points
var largestPossibleRadius = helpers.min([(this.height / 2 - this.options.pointLabels.fontSize - 5), this.width / 2]),
pointPosition,
i,
textWidth,
halfTextWidth,
furthestRight = this.width,
furthestRightIndex,
furthestRightAngle,
furthestLeft = 0,
furthestLeftIndex,
furthestLeftAngle,
xProtrusionLeft,
xProtrusionRight,
radiusReductionRight,
radiusReductionLeft,
maxWidthRadius;
this.ctx.font = helpers.fontString(this.options.pointLabels.fontSize, this.options.pointLabels.fontStyle, this.options.pointLabels.fontFamily);
for (i = 0; i < this.getValueCount(); i++) {
// 5px to space the text slightly out - similar to what we do in the draw function.
pointPosition = this.getPointPosition(i, largestPossibleRadius);
textWidth = this.ctx.measureText(this.options.ticks.callback(this.chart.data.labels[i])).width + 5;
if (i === 0 || i === this.getValueCount() / 2) {
// If we're at index zero, or exactly the middle, we're at exactly the top/bottom
// of the radar chart, so text will be aligned centrally, so we'll half it and compare
// w/left and right text sizes
halfTextWidth = textWidth / 2;
if (pointPosition.x + halfTextWidth > furthestRight) {
furthestRight = pointPosition.x + halfTextWidth;
furthestRightIndex = i;
}
if (pointPosition.x - halfTextWidth < furthestLeft) {
furthestLeft = pointPosition.x - halfTextWidth;
furthestLeftIndex = i;
}
} else if (i < this.getValueCount() / 2) {
// Less than half the values means we'll left align the text
if (pointPosition.x + textWidth > furthestRight) {
furthestRight = pointPosition.x + textWidth;
furthestRightIndex = i;
}
} else if (i > this.getValueCount() / 2) {
// More than half the values means we'll right align the text
if (pointPosition.x - textWidth < furthestLeft) {
furthestLeft = pointPosition.x - textWidth;
furthestLeftIndex = i;
}
}
}
xProtrusionLeft = furthestLeft;
xProtrusionRight = Math.ceil(furthestRight - this.width);
furthestRightAngle = this.getIndexAngle(furthestRightIndex);
furthestLeftAngle = this.getIndexAngle(furthestLeftIndex);
radiusReductionRight = xProtrusionRight / Math.sin(furthestRightAngle + Math.PI / 2);
radiusReductionLeft = xProtrusionLeft / Math.sin(furthestLeftAngle + Math.PI / 2);
// Ensure we actually need to reduce the size of the chart
radiusReductionRight = (helpers.isNumber(radiusReductionRight)) ? radiusReductionRight : 0;
radiusReductionLeft = (helpers.isNumber(radiusReductionLeft)) ? radiusReductionLeft : 0;
this.drawingArea = Math.round(largestPossibleRadius - (radiusReductionLeft + radiusReductionRight) / 2);
this.setCenterPoint(radiusReductionLeft, radiusReductionRight);
},
setCenterPoint: function(leftMovement, rightMovement) {
var maxRight = this.width - rightMovement - this.drawingArea,
maxLeft = leftMovement + this.drawingArea;
this.xCenter = Math.round(((maxLeft + maxRight) / 2) + this.left);
// Always vertically in the centre as the text height doesn't change
this.yCenter = Math.round((this.height / 2) + this.top);
},
getIndexAngle: function(index) {
var angleMultiplier = (Math.PI * 2) / this.getValueCount();
// Start from the top instead of right, so remove a quarter of the circle
return index * angleMultiplier - (Math.PI / 2);
},
getDistanceFromCenterForValue: function(value) {
if (value === null) {
return 0; // null always in center
}
// Take into account half font size + the yPadding of the top value
var scalingFactor = this.drawingArea / (this.max - this.min);
if (this.options.reverse) {
return (this.max - value) * scalingFactor;
} else {
return (value - this.min) * scalingFactor;
}
},
getPointPosition: function(index, distanceFromCenter) {
var thisAngle = this.getIndexAngle(index);
return {
x: Math.round(Math.cos(thisAngle) * distanceFromCenter) + this.xCenter,
y: Math.round(Math.sin(thisAngle) * distanceFromCenter) + this.yCenter
};
},
getPointPositionForValue: function(index, value) {
return this.getPointPosition(index, this.getDistanceFromCenterForValue(value));
},
draw: function() {
if (this.options.display) {
var ctx = this.ctx;
helpers.each(this.ticks, function(label, index) {
// Don't draw a centre value (if it is minimum)
if (index > 0 || this.options.reverse) {
var yCenterOffset = this.getDistanceFromCenterForValue(this.ticks[index]);
var yHeight = this.yCenter - yCenterOffset;
// Draw circular lines around the scale
if (this.options.gridLines.display) {
ctx.strokeStyle = this.options.gridLines.color;
ctx.lineWidth = this.options.gridLines.lineWidth;
if (this.options.lineArc) {
// Draw circular arcs between the points
ctx.beginPath();
ctx.arc(this.xCenter, this.yCenter, yCenterOffset, 0, Math.PI * 2);
ctx.closePath();
ctx.stroke();
} else {
// Draw straight lines connecting each index
ctx.beginPath();
for (var i = 0; i < this.getValueCount(); i++) {
var pointPosition = this.getPointPosition(i, this.getDistanceFromCenterForValue(this.ticks[index]));
if (i === 0) {
ctx.moveTo(pointPosition.x, pointPosition.y);
} else {
ctx.lineTo(pointPosition.x, pointPosition.y);
}
}
ctx.closePath();
ctx.stroke();
}
}
if (this.options.ticks.display) {
ctx.font = helpers.fontString(this.options.ticks.fontSize, this.options.ticks.fontStyle, this.options.ticks.fontFamily);
if (this.options.ticks.showLabelBackdrop) {
var labelWidth = ctx.measureText(label).width;
ctx.fillStyle = this.options.ticks.backdropColor;
ctx.fillRect(
this.xCenter - labelWidth / 2 - this.options.ticks.backdropPaddingX,
yHeight - this.options.ticks.fontSize / 2 - this.options.ticks.backdropPaddingY,
labelWidth + this.options.ticks.backdropPaddingX * 2,
this.options.ticks.fontSize + this.options.ticks.backdropPaddingY * 2
);
}
ctx.textAlign = 'center';
ctx.textBaseline = "middle";
ctx.fillStyle = this.options.ticks.fontColor;
ctx.fillText(label, this.xCenter, yHeight);
}
}
}, this);
if (!this.options.lineArc) {
ctx.lineWidth = this.options.angleLines.lineWidth;
ctx.strokeStyle = this.options.angleLines.color;
for (var i = this.getValueCount() - 1; i >= 0; i--) {
if (this.options.angleLines.display) {
var outerPosition = this.getPointPosition(i, this.getDistanceFromCenterForValue(this.options.reverse ? this.min : this.max));
ctx.beginPath();
ctx.moveTo(this.xCenter, this.yCenter);
ctx.lineTo(outerPosition.x, outerPosition.y);
ctx.stroke();
ctx.closePath();
}
// Extra 3px out for some label spacing
var pointLabelPosition = this.getPointPosition(i, this.getDistanceFromCenterForValue(this.options.reverse ? this.min : this.max) + 5);
ctx.font = helpers.fontString(this.options.pointLabels.fontSize, this.options.pointLabels.fontStyle, this.options.pointLabels.fontFamily);
ctx.fillStyle = this.options.pointLabels.fontColor;
var labelsCount = this.chart.data.labels.length,
halfLabelsCount = this.chart.data.labels.length / 2,
quarterLabelsCount = halfLabelsCount / 2,
upperHalf = (i < quarterLabelsCount || i > labelsCount - quarterLabelsCount),
exactQuarter = (i === quarterLabelsCount || i === labelsCount - quarterLabelsCount);
if (i === 0) {
ctx.textAlign = 'center';
} else if (i === halfLabelsCount) {
ctx.textAlign = 'center';
} else if (i < halfLabelsCount) {
ctx.textAlign = 'left';
} else {
ctx.textAlign = 'right';
}
// Set the correct text baseline based on outer positioning
if (exactQuarter) {
ctx.textBaseline = 'middle';
} else if (upperHalf) {
ctx.textBaseline = 'bottom';
} else {
ctx.textBaseline = 'top';
}
ctx.fillText(this.chart.data.labels[i], pointLabelPosition.x, pointLabelPosition.y);
}
}
}
}
});
Chart.scaleService.registerScaleType("radialLinear", LinearRadialScale, defaultConfig);
}).call(this);
(function(moment) {
"use strict";
if (!moment) {
console.warn('Chart.js - Moment.js could not be found! You must include it before Chart.js to use the time scale. Download at path_to_url
return;
}
var root = this,
Chart = root.Chart,
helpers = Chart.helpers;
var time = {
units: [
{
name: 'millisecond',
steps: [1, 2, 5, 10, 20, 50, 100, 250, 500]
}, {
name: 'second',
steps: [1, 2, 5, 10, 30]
}, {
name: 'minute',
steps: [1, 2, 5, 10, 30]
}, {
name: 'hour',
steps: [1, 2, 3, 6, 12]
}, {
name: 'day',
steps: [1, 2, 5]
}, {
name: 'week',
maxStep: 4
}, {
name: 'month',
maxStep: 3
}, {
name: 'quarter',
maxStep: 4,
}, {
name: 'year',
maxStep: false
},
],
};
var defaultConfig = {
position: "bottom",
time: {
format: false, // false == date objects or use pattern string from path_to_url#/parsing/string-format/
unit: false, // false == automatic or override with week, month, year, etc.
round: false, // none, or override with week, month, year, etc.
displayFormat: false, // DEPRECATED
// defaults to unit's corresponding unitFormat below or override using pattern string from path_to_url#/displaying/format/
displayFormats: {
'millisecond': 'SSS [ms]',
'second': 'h:mm:ss a', // 11:20:01 AM
'minute': 'h:mm:ss a', // 11:20:01 AM
'hour': 'MMM D, hA', // Sept 4, 5PM
'day': 'll', // Sep 4 2015
'week': 'll', // Week 46, or maybe "[W]WW - YYYY" ?
'month': 'MMM YYYY', // Sept 2015
'quarter': '[Q]Q - YYYY', // Q3
'year': 'YYYY', // 2015
},
},
};
var TimeScale = Chart.Scale.extend({
getLabelMoment: function(datasetIndex, index) {
return this.labelMoments[datasetIndex][index];
},
determineDataLimits: function() {
this.labelMoments = [];
// Only parse these once. If the dataset does not have data as x,y pairs, we will use
// these
var scaleLabelMoments = [];
if (this.chart.data.labels && this.chart.data.labels.length > 0) {
helpers.each(this.chart.data.labels, function(label, index) {
var labelMoment = this.parseTime(label);
if (this.options.time.round) {
labelMoment.startOf(this.options.time.round);
}
scaleLabelMoments.push(labelMoment);
}, this);
if (this.options.time.min) {
this.firstTick = this.parseTime(this.options.time.min);
} else {
this.firstTick = moment.min.call(this, scaleLabelMoments);
}
if (this.options.time.max) {
this.lastTick = this.parseTime(this.options.time.max);
} else {
this.lastTick = moment.max.call(this, scaleLabelMoments);
}
} else {
this.firstTick = null;
this.lastTick = null;
}
helpers.each(this.chart.data.datasets, function(dataset, datasetIndex) {
var momentsForDataset = [];
if (typeof dataset.data[0] === 'object') {
helpers.each(dataset.data, function(value, index) {
var labelMoment = this.parseTime(this.getRightValue(value));
if (this.options.time.round) {
labelMoment.startOf(this.options.time.round);
}
momentsForDataset.push(labelMoment);
// May have gone outside the scale ranges, make sure we keep the first and last ticks updated
this.firstTick = this.firstTick !== null ? moment.min(this.firstTick, labelMoment) : labelMoment;
this.lastTick = this.lastTick !== null ? moment.max(this.lastTick, labelMoment) : labelMoment;
}, this);
} else {
// We have no labels. Use the ones from the scale
momentsForDataset = scaleLabelMoments;
}
this.labelMoments.push(momentsForDataset);
}, this);
// We will modify these, so clone for later
this.firstTick = (this.firstTick || moment()).clone();
this.lastTick = (this.lastTick || moment()).clone();
},
buildTicks: function(index) {
this.ticks = [];
this.unitScale = 1; // How much we scale the unit by, ie 2 means 2x unit per step
// Set unit override if applicable
if (this.options.time.unit) {
this.tickUnit = this.options.time.unit || 'day';
this.displayFormat = this.options.time.displayFormats[this.tickUnit];
this.tickRange = Math.ceil(this.lastTick.diff(this.firstTick, this.tickUnit, true));
} else {
// Determine the smallest needed unit of the time
var innerWidth = this.width - (this.paddingLeft + this.paddingRight);
var labelCapacity = innerWidth / (this.options.ticks.fontSize + 10);
var buffer = this.options.time.round ? 0 : 2;
// Start as small as possible
this.tickUnit = 'millisecond';
this.tickRange = Math.ceil(this.lastTick.diff(this.firstTick, this.tickUnit, true) + buffer);
this.displayFormat = this.options.time.displayFormats[this.tickUnit];
var unitDefinitionIndex = 0;
var unitDefinition = time.units[unitDefinitionIndex];
// While we aren't ideal and we don't have units left
while (unitDefinitionIndex < time.units.length) {
// Can we scale this unit. If `false` we can scale infinitely
//var canScaleUnit = ;
this.unitScale = 1;
if (helpers.isArray(unitDefinition.steps) && Math.ceil(this.tickRange / labelCapacity) < helpers.max(unitDefinition.steps)) {
// Use one of the prefedined steps
for (var idx = 0; idx < unitDefinition.steps.length; ++idx) {
if (unitDefinition.steps[idx] > Math.ceil(this.tickRange / labelCapacity)) {
this.unitScale = unitDefinition.steps[idx];
break;
}
}
break;
} else if ((unitDefinition.maxStep === false) || (Math.ceil(this.tickRange / labelCapacity) < unitDefinition.maxStep)) {
// We have a max step. Scale this unit
this.unitScale = Math.ceil(this.tickRange / labelCapacity);
break;
} else {
// Move to the next unit up
++unitDefinitionIndex;
unitDefinition = time.units[unitDefinitionIndex];
this.tickUnit = unitDefinition.name;
this.tickRange = Math.ceil(this.lastTick.diff(this.firstTick, this.tickUnit) + buffer);
this.displayFormat = this.options.time.displayFormats[unitDefinition.name];
}
}
}
this.firstTick.startOf(this.tickUnit);
this.lastTick.endOf(this.tickUnit);
this.smallestLabelSeparation = this.width;
helpers.each(this.chart.data.datasets, function(dataset, datasetIndex) {
for (var i = 1; i < this.labelMoments[datasetIndex].length; i++) {
this.smallestLabelSeparation = Math.min(this.smallestLabelSeparation, this.labelMoments[datasetIndex][i].diff(this.labelMoments[datasetIndex][i - 1], this.tickUnit, true));
}
}, this);
// Tick displayFormat override
if (this.options.time.displayFormat) {
this.displayFormat = this.options.time.displayFormat;
}
// For every unit in between the first and last moment, create a moment and add it to the ticks tick
for (var i = 0; i <= this.tickRange; ++i) {
if (i % this.unitScale === 0) {
this.ticks.push(this.firstTick.clone().add(i, this.tickUnit));
} else if (i === this.tickRange) {
// Expand out the last one if not an exact multiple
this.tickRange = Math.ceil(this.tickRange / this.unitScale) * this.unitScale;
this.ticks.push(this.firstTick.clone().add(this.tickRange, this.tickUnit));
this.lastTick = this.ticks[this.ticks.length - 1].clone();
break;
}
}
},
// Get tooltip label
getLabelForIndex: function(index, datasetIndex) {
var label = this.chart.data.labels && index < this.chart.data.labels.length ? this.chart.data.labels[index] : '';
if (typeof this.chart.data.datasets[datasetIndex].data[0] === 'object') {
label = this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
}
// Format nicely
if (this.options.time.tooltipFormat) {
label = this.parseTime(label).format(this.options.time.tooltipFormat);
}
return label;
},
convertTicksToLabels: function() {
this.ticks = this.ticks.map(function(tick, index, ticks) {
var formattedTick = tick.format(this.displayFormat);
if (this.options.ticks.userCallback) {
return this.options.ticks.userCallback(formattedTick, index, ticks);
} else {
return formattedTick;
}
}, this);
},
getPixelForValue: function(value, index, datasetIndex, includeOffset) {
var labelMoment = this.getLabelMoment(datasetIndex, index);
var offset = labelMoment.diff(this.firstTick, this.tickUnit, true);
var decimal = offset / this.tickRange;
if (this.isHorizontal()) {
var innerWidth = this.width - (this.paddingLeft + this.paddingRight);
var valueWidth = innerWidth / Math.max(this.ticks.length - 1, 1);
var valueOffset = (innerWidth * decimal) + this.paddingLeft;
return this.left + Math.round(valueOffset);
} else {
var innerHeight = this.height - (this.paddingTop + this.paddingBottom);
var valueHeight = innerHeight / Math.max(this.ticks.length - 1, 1);
var heightOffset = (innerHeight * decimal) + this.paddingTop;
return this.top + Math.round(heightOffset);
}
},
parseTime: function(label) {
// Date objects
if (typeof label.getMonth === 'function' || typeof label == 'number') {
return moment(label);
}
// Moment support
if (label.isValid && label.isValid()) {
return label;
}
// Custom parsing (return an instance of moment)
if (typeof this.options.time.format !== 'string' && this.options.time.format.call) {
return this.options.time.format(label);
}
// Moment format parsing
return moment(label, this.options.time.format);
},
});
Chart.scaleService.registerScaleType("time", TimeScale, defaultConfig);
}).call(this, moment);
/*!
* Chart.js
* path_to_url
* Version: 2.0.0-beta2
*
* Released under the MIT license
* path_to_url
*/
(function() {
"use strict";
var root = this,
Chart = root.Chart,
helpers = Chart.helpers;
Chart.defaults.global.elements.arc = {
backgroundColor: Chart.defaults.global.defaultColor,
borderColor: "#fff",
borderWidth: 2
};
Chart.elements.Arc = Chart.Element.extend({
inLabelRange: function(mouseX) {
var vm = this._view;
if (vm) {
return (Math.pow(mouseX - vm.x, 2) < Math.pow(vm.radius + vm.hoverRadius, 2));
} else {
return false;
}
},
inRange: function(chartX, chartY) {
var vm = this._view;
if (vm) {
var pointRelativePosition = helpers.getAngleFromPoint(vm, {
x: chartX,
y: chartY
});
// Put into the range of (-PI/2, 3PI/2]
var startAngle = vm.startAngle < (-0.5 * Math.PI) ? vm.startAngle + (2.0 * Math.PI) : vm.startAngle > (1.5 * Math.PI) ? vm.startAngle - (2.0 * Math.PI) : vm.startAngle;
var endAngle = vm.endAngle < (-0.5 * Math.PI) ? vm.endAngle + (2.0 * Math.PI) : vm.endAngle > (1.5 * Math.PI) ? vm.endAngle - (2.0 * Math.PI) : vm.endAngle;
//Check if within the range of the open/close angle
var betweenAngles = (pointRelativePosition.angle >= startAngle && pointRelativePosition.angle <= endAngle),
withinRadius = (pointRelativePosition.distance >= vm.innerRadius && pointRelativePosition.distance <= vm.outerRadius);
return (betweenAngles && withinRadius);
} else {
return false;
}
},
tooltipPosition: function() {
var vm = this._view;
var centreAngle = vm.startAngle + ((vm.endAngle - vm.startAngle) / 2),
rangeFromCentre = (vm.outerRadius - vm.innerRadius) / 2 + vm.innerRadius;
return {
x: vm.x + (Math.cos(centreAngle) * rangeFromCentre),
y: vm.y + (Math.sin(centreAngle) * rangeFromCentre)
};
},
draw: function() {
var ctx = this._chart.ctx;
var vm = this._view;
ctx.beginPath();
ctx.arc(vm.x, vm.y, vm.outerRadius, vm.startAngle, vm.endAngle);
ctx.arc(vm.x, vm.y, vm.innerRadius, vm.endAngle, vm.startAngle, true);
ctx.closePath();
ctx.strokeStyle = vm.borderColor;
ctx.lineWidth = vm.borderWidth;
ctx.fillStyle = vm.backgroundColor;
ctx.fill();
ctx.lineJoin = 'bevel';
if (vm.borderWidth) {
ctx.stroke();
}
}
});
}).call(this);
/*!
* Chart.js
* path_to_url
* Version: 2.0.0-beta2
*
* Released under the MIT license
* path_to_url
*/
(function() {
"use strict";
var root = this,
Chart = root.Chart,
helpers = Chart.helpers;
Chart.defaults.global.elements.line = {
tension: 0.4,
backgroundColor: Chart.defaults.global.defaultColor,
borderWidth: 3,
borderColor: Chart.defaults.global.defaultColor,
borderCapStyle: 'butt',
borderDash: [],
borderDashOffset: 0.0,
borderJoinStyle: 'miter',
fill: true, // do we fill in the area between the line and its base axis
};
Chart.elements.Line = Chart.Element.extend({
lineToNextPoint: function(previousPoint, point, nextPoint, skipHandler, previousSkipHandler) {
var ctx = this._chart.ctx;
if (point._view.skip) {
skipHandler.call(this, previousPoint, point, nextPoint);
} else if (previousPoint._view.skip) {
previousSkipHandler.call(this, previousPoint, point, nextPoint);
} else if (point._view.tension === 0) {
ctx.lineTo(point._view.x, point._view.y);
} else {
// Line between points
ctx.bezierCurveTo(
previousPoint._view.controlPointNextX,
previousPoint._view.controlPointNextY,
point._view.controlPointPreviousX,
point._view.controlPointPreviousY,
point._view.x,
point._view.y
);
}
},
draw: function() {
var _this = this;
var vm = this._view;
var ctx = this._chart.ctx;
var first = this._children[0];
var last = this._children[this._children.length - 1];
function loopBackToStart(drawLineToCenter) {
if (!first._view.skip && !last._view.skip) {
// Draw a bezier line from last to first
ctx.bezierCurveTo(
last._view.controlPointNextX,
last._view.controlPointNextY,
first._view.controlPointPreviousX,
first._view.controlPointPreviousY,
first._view.x,
first._view.y
);
} else if (drawLineToCenter) {
// Go to center
ctx.lineTo(_this._view.scaleZero.x, _this._view.scaleZero.y);
}
}
ctx.save();
// If we had points and want to fill this line, do so.
if (this._children.length > 0 && vm.fill) {
// Draw the background first (so the border is always on top)
ctx.beginPath();
helpers.each(this._children, function(point, index) {
var previous = helpers.previousItem(this._children, index);
var next = helpers.nextItem(this._children, index);
// First point moves to it's starting position no matter what
if (index === 0) {
if (this._loop) {
ctx.moveTo(vm.scaleZero.x, vm.scaleZero.y);
} else {
ctx.moveTo(point._view.x, vm.scaleZero);
}
if (point._view.skip) {
if (!this._loop) {
ctx.moveTo(next._view.x, this._view.scaleZero);
}
} else {
ctx.lineTo(point._view.x, point._view.y);
}
} else {
this.lineToNextPoint(previous, point, next, function(previousPoint, point, nextPoint) {
if (this._loop) {
// Go to center
ctx.lineTo(this._view.scaleZero.x, this._view.scaleZero.y);
} else {
ctx.lineTo(previousPoint._view.x, this._view.scaleZero);
ctx.moveTo(nextPoint._view.x, this._view.scaleZero);
}
}, function(previousPoint, point) {
// If we skipped the last point, draw a line to ourselves so that the fill is nice
ctx.lineTo(point._view.x, point._view.y);
});
}
}, this);
// For radial scales, loop back around to the first point
if (this._loop) {
loopBackToStart(true);
} else {
//Round off the line by going to the base of the chart, back to the start, then fill.
ctx.lineTo(this._children[this._children.length - 1]._view.x, vm.scaleZero);
ctx.lineTo(this._children[0]._view.x, vm.scaleZero);
}
ctx.fillStyle = vm.backgroundColor || Chart.defaults.global.defaultColor;
ctx.closePath();
ctx.fill();
}
// Now draw the line between all the points with any borders
ctx.lineCap = vm.borderCapStyle || Chart.defaults.global.elements.line.borderCapStyle;
// IE 9 and 10 do not support line dash
if (ctx.setLineDash) {
ctx.setLineDash(vm.borderDash || Chart.defaults.global.elements.line.borderDash);
}
ctx.lineDashOffset = vm.borderDashOffset || Chart.defaults.global.elements.line.borderDashOffset;
ctx.lineJoin = vm.borderJoinStyle || Chart.defaults.global.elements.line.borderJoinStyle;
ctx.lineWidth = vm.borderWidth || Chart.defaults.global.elements.line.borderWidth;
ctx.strokeStyle = vm.borderColor || Chart.defaults.global.defaultColor;
ctx.beginPath();
helpers.each(this._children, function(point, index) {
var previous = helpers.previousItem(this._children, index);
var next = helpers.nextItem(this._children, index);
if (index === 0) {
ctx.moveTo(point._view.x, point._view.y);
} else {
this.lineToNextPoint(previous, point, next, function(previousPoint, point, nextPoint) {
ctx.moveTo(nextPoint._view.x, nextPoint._view.y);
}, function(previousPoint, point) {
// If we skipped the last point, move up to our point preventing a line from being drawn
ctx.moveTo(point._view.x, point._view.y);
});
}
}, this);
if (this._loop && this._children.length > 0) {
loopBackToStart();
}
ctx.stroke();
ctx.restore();
},
});
}).call(this);
/*!
* Chart.js
* path_to_url
* Version: 2.0.0-beta2
*
* Released under the MIT license
* path_to_url
*/
(function() {
"use strict";
var root = this,
Chart = root.Chart,
helpers = Chart.helpers;
Chart.defaults.global.elements.point = {
radius: 3,
backgroundColor: Chart.defaults.global.defaultColor,
borderWidth: 1,
borderColor: Chart.defaults.global.defaultColor,
// Hover
hitRadius: 1,
hoverRadius: 4,
hoverBorderWidth: 1,
};
Chart.elements.Point = Chart.Element.extend({
inRange: function(mouseX, mouseY) {
var vm = this._view;
if (vm) {
var hoverRange = vm.hitRadius + vm.radius;
return ((Math.pow(mouseX - vm.x, 2) + Math.pow(mouseY - vm.y, 2)) < Math.pow(hoverRange, 2));
} else {
return false;
}
},
inLabelRange: function(mouseX) {
var vm = this._view;
if (vm) {
return (Math.pow(mouseX - vm.x, 2) < Math.pow(vm.radius + vm.hitRadius, 2));
} else {
return false;
}
},
tooltipPosition: function() {
var vm = this._view;
return {
x: vm.x,
y: vm.y,
padding: vm.radius + vm.borderWidth
};
},
draw: function() {
var vm = this._view;
var ctx = this._chart.ctx;
if (vm.skip) {
return;
}
if (vm.radius > 0 || vm.borderWidth > 0) {
ctx.beginPath();
ctx.arc(vm.x, vm.y, vm.radius || Chart.defaults.global.elements.point.radius, 0, Math.PI * 2);
ctx.closePath();
ctx.strokeStyle = vm.borderColor || Chart.defaults.global.defaultColor;
ctx.lineWidth = vm.borderWidth || Chart.defaults.global.elements.point.borderWidth;
ctx.fillStyle = vm.backgroundColor || Chart.defaults.global.defaultColor;
ctx.fill();
ctx.stroke();
}
}
});
}).call(this);
(function() {
"use strict";
var root = this,
Chart = root.Chart,
helpers = Chart.helpers;
Chart.defaults.global.elements.rectangle = {
backgroundColor: Chart.defaults.global.defaultColor,
borderWidth: 0,
borderColor: Chart.defaults.global.defaultColor,
};
Chart.elements.Rectangle = Chart.Element.extend({
draw: function() {
var ctx = this._chart.ctx;
var vm = this._view;
var halfWidth = vm.width / 2,
leftX = vm.x - halfWidth,
rightX = vm.x + halfWidth,
top = vm.base - (vm.base - vm.y),
halfStroke = vm.borderWidth / 2;
// Canvas doesn't allow us to stroke inside the width so we can
// adjust the sizes to fit if we're setting a stroke on the line
if (vm.borderWidth) {
leftX += halfStroke;
rightX -= halfStroke;
top += halfStroke;
}
ctx.beginPath();
ctx.fillStyle = vm.backgroundColor;
ctx.strokeStyle = vm.borderColor;
ctx.lineWidth = vm.borderWidth;
// It'd be nice to keep this class totally generic to any rectangle
// and simply specify which border to miss out.
ctx.moveTo(leftX, vm.base);
ctx.lineTo(leftX, top);
ctx.lineTo(rightX, top);
ctx.lineTo(rightX, vm.base);
ctx.fill();
if (vm.borderWidth) {
ctx.stroke();
}
},
height: function() {
var vm = this._view;
return vm.base - vm.y;
},
inRange: function(mouseX, mouseY) {
var vm = this._view;
var inRange = false;
if (vm) {
if (vm.y < vm.base) {
inRange = (mouseX >= vm.x - vm.width / 2 && mouseX <= vm.x + vm.width / 2) && (mouseY >= vm.y && mouseY <= vm.base);
} else {
inRange = (mouseX >= vm.x - vm.width / 2 && mouseX <= vm.x + vm.width / 2) && (mouseY >= vm.base && mouseY <= vm.y);
}
}
return inRange;
},
inLabelRange: function(mouseX) {
var vm = this._view;
if (vm) {
return (mouseX >= vm.x - vm.width / 2 && mouseX <= vm.x + vm.width / 2);
} else {
return false;
}
},
tooltipPosition: function() {
var vm = this._view;
return {
x: vm.x,
y: vm.y
};
},
});
}).call(this);
(function() {
"use strict";
var root = this;
var Chart = root.Chart;
var helpers = Chart.helpers;
Chart.Bar = function(context, config) {
config.type = 'bar';
return new Chart(context, config);
};
}).call(this);
(function() {
"use strict";
var root = this;
var Chart = root.Chart;
var helpers = Chart.helpers;
var defaultConfig = {
hover: {
mode: 'single',
},
scales: {
xAxes: [{
type: "linear", // bubble should probably use a linear scale by default
position: "bottom",
id: "x-axis-0", // need an ID so datasets can reference the scale
}],
yAxes: [{
type: "linear",
position: "left",
id: "y-axis-0",
}],
},
tooltips: {
callbacks: {
title: function(tooltipItems, data) {
// Title doesn't make sense for scatter since we format the data as a point
return '';
},
label: function(tooltipItem, data) {
return '(' + tooltipItem.xLabel + ', ' + tooltipItem.yLabel + ')';
}
}
},
};
// Register the default config for this type
Chart.defaults.bubble = defaultConfig;
Chart.Bubble = function(context, config) {
config.type = 'bubble';
return new Chart(context, config);
};
}).call(this);
(function() {
"use strict";
var root = this;
var Chart = root.Chart;
var helpers = Chart.helpers;
Chart.Doughnut = function(context, config) {
config.type = 'doughnut';
return new Chart(context, config);
};
}).call(this);
(function() {
"use strict";
var root = this;
var Chart = root.Chart;
var helpers = Chart.helpers;
Chart.Line = function(context, config) {
config.type = 'line';
return new Chart(context, config);
};
}).call(this);
(function() {
"use strict";
var root = this;
var Chart = root.Chart;
var helpers = Chart.helpers;
Chart.PolarArea = function(context, config) {
config.type = 'polarArea';
return new Chart(context, config);
};
}).call(this);
(function() {
"use strict";
var root = this;
var Chart = root.Chart;
var helpers = Chart.helpers;
var defaultConfig = {
aspectRatio: 1,
};
Chart.Radar = function(context, config) {
config.options = helpers.configMerge(defaultConfig, config.options);
config.type = 'radar';
return new Chart(context, config);
};
}).call(this);
(function() {
"use strict";
var root = this;
var Chart = root.Chart;
var helpers = Chart.helpers;
var defaultConfig = {
hover: {
mode: 'single',
},
scales: {
xAxes: [{
type: "linear", // scatter should not use a category axis
position: "bottom",
id: "x-axis-1", // need an ID so datasets can reference the scale
}],
yAxes: [{
type: "linear",
position: "left",
id: "y-axis-1",
}],
},
tooltips: {
callbacks: {
title: function(tooltipItems, data) {
// Title doesn't make sense for scatter since we format the data as a point
return '';
},
label: function(tooltipItem, data) {
return '(' + tooltipItem.xLabel + ', ' + tooltipItem.yLabel + ')';
}
}
},
};
// Register the default config for this type
Chart.defaults.scatter = defaultConfig;
// Scatter charts use line controllers
Chart.controllers.scatter = Chart.controllers.line;
Chart.Scatter = function(context, config) {
config.type = 'scatter';
return new Chart(context, config);
};
}).call(this);
return Chart;
}));
``` | /content/code_sandbox/public/vendor/chartjs/Chart.js | javascript | 2016-03-03T01:33:10 | 2024-08-16T12:05:02 | Attendize | Attendize/Attendize | 3,955 | 69,687 |
```smalltalk
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// .'',;:cldxkO00KKXXNNWWWNNXKOkxdollcc::::::;:::ccllloooolllllllllooollc:,'... ...........',;cldxkO000Okxdlc::;;;,,;;;::cclllllll
// ..',;:ldxO0KXXNNNNNNNNXXK0kxdolcc::::::;;;,,,,,,;;;;;;;;;;:::cclllllc:;'.... ...........',;:ldxO0KXXXK0Okxdolc::;;;;::cllodddddo
// ...',:loxO0KXNNNNNXXKK0Okxdolc::;::::::::;;;,,'''''.....''',;:clllllc:;,'............''''''''',;:loxO0KXNNNNNXK0Okxdollccccllodxxxxxxd
// ....';:ldkO0KXXXKK00Okxdolcc:;;;;;::cclllcc:;;,''..... ....',;clooddolcc:;;;;,,;;;;;::::;;;;;;:cloxk0KXNWWWWWWNXKK0Okxddoooddxxkkkkkxx
// .....';:ldxkOOOOOkxxdolcc:;;;,,,;;:cllooooolcc:;'... ..,:codxkkkxddooollloooooooollcc:::::clodkO0KXNWWWWWWNNXK00Okxxxxxxxxkkkkxxx
// . ....';:cloddddo___________,,,,;;:clooddddoolc:,... ..,:ldx__00OOOkkk___kkkkkkxxdollc::::cclodkO0KXXNNNNNNXXK0OOkxxxxxxxxxxxxddd
// .......',;:cccc:| |,,,;;:cclooddddoll:;'.. ..';cox| \KKK000| |KK00OOkxdocc___;::clldxxkO0KKKKK00Okkxdddddddddddddddoo
// .......'',,,,,''| ________|',,;;::cclloooooolc:;'......___:ldk| \KK000| |XKKK0Okxolc| |;;::cclodxxkkkkxxdoolllcclllooodddooooo
// ''......''''....| | ....'',,,,;;;::cclloooollc:;,''.'| |oxk| \OOO0| |KKK00Oxdoll|___|;;;;;::ccllllllcc::;;,,;;;:cclloooooooo
// ;;,''.......... | |_____',,;;;____:___cllo________.___| |___| \xkk| |KK_______ool___:::;________;;;_______...'',;;:ccclllloo
// c:;,''......... | |:::/ ' |lo/ | | \dx| |0/ \d| |cc/ |'/ \......',,;;:ccllo
// ol:;,'..........| _____|ll/ __ |o/ ______|____ ___| | \o| |/ ___ \| |o/ ______|/ ___ \ .......'',;:clo
// dlc;,...........| |::clooo| / | |x\___ \KXKKK0| |dol| |\ \| | | | | |d\___ \..| | / / ....',:cl
// xoc;'... .....'| |llodddd| \__| |_____\ \KKK0O| |lc:| |'\ | |___| | |_____\ \.| |_/___/... ...',;:c
// dlc;'... ....',;| |oddddddo\ | |Okkx| |::;| |..\ |\ /| | | \ |... ....',;:c
// ol:,'.......',:c|___|xxxddollc\_____,___|_________/ddoll|___|,,,|___|...\_____|:\ ______/l|___|_________/...\________|'........',;::cc
// c:;'.......';:codxxkkkkxxolc::;::clodxkOO0OOkkxdollc::;;,,''''',,,,''''''''''',,'''''',;:loxkkOOkxol:;,'''',,;:ccllcc:;,'''''',;::ccll
// ;,'.......',:codxkOO0OOkxdlc:;,,;;:cldxxkkxxdolc:;;,,''.....'',;;:::;;,,,'''''........,;cldkO0KK0Okdoc::;;::cloodddoolc:;;;;;::ccllooo
// .........',;:lodxOO0000Okdoc:,,',,;:clloddoolc:;,''.......'',;:clooollc:;;,,''.......',:ldkOKXNNXX0Oxdolllloddxxxxxxdolccccccllooodddd
// . .....';:cldxkO0000Okxol:;,''',,;::cccc:;,,'.......'',;:cldxxkkxxdolc:;;,'.......';coxOKXNWWWNXKOkxddddxxkkkkkkxdoollllooddxxxxkkk
// ....',;:codxkO000OOxdoc:;,''',,,;;;;,''.......',,;:clodkO00000Okxolc::;,,''..',;:ldxOKXNWWWNNK0OkkkkkkkkkkkxxddooooodxxkOOOOO000
// ....',;;clodxkkOOOkkdolc:;,,,,,,,,'..........,;:clodxkO0KKXKK0Okxdolcc::;;,,,;;:codkO0XXNNNNXKK0OOOOOkkkkxxdoollloodxkO0KKKXXXXX
//
// VERSION: 1.1.1
// path_to_url
using System;
using System.Runtime.CompilerServices;
// Switch between using floats or doubles for input position
using FNLfloat = System.Single;
//using FNLfloat = System.Double;
public class FastNoiseLite
{
private const short INLINE = 256; // MethodImplOptions.AggressiveInlining;
private const short OPTIMISE = 512; // MethodImplOptions.AggressiveOptimization;
public enum NoiseType
{
OpenSimplex2,
OpenSimplex2S,
Cellular,
Perlin,
ValueCubic,
Value
};
public enum RotationType3D
{
None,
ImproveXYPlanes,
ImproveXZPlanes
};
public enum FractalType
{
None,
FBm,
Ridged,
PingPong,
DomainWarpProgressive,
DomainWarpIndependent
};
public enum CellularDistanceFunction
{
Euclidean,
EuclideanSq,
Manhattan,
Hybrid
};
public enum CellularReturnType
{
CellValue,
Distance,
Distance2,
Distance2Add,
Distance2Sub,
Distance2Mul,
Distance2Div
};
public enum DomainWarpType
{
OpenSimplex2,
OpenSimplex2Reduced,
BasicGrid
};
private enum TransformType3D
{
None,
ImproveXYPlanes,
ImproveXZPlanes,
DefaultOpenSimplex2
};
private int mSeed = 1337;
private float mFrequency = 0.01f;
private NoiseType mNoiseType = NoiseType.OpenSimplex2;
private RotationType3D mRotationType3D = RotationType3D.None;
private TransformType3D mTransformType3D = TransformType3D.DefaultOpenSimplex2;
private FractalType mFractalType = FractalType.None;
private int mOctaves = 3;
private float mLacunarity = 2.0f;
private float mGain = 0.5f;
private float mWeightedStrength = 0.0f;
private float mPingPongStrength = 2.0f;
private float mFractalBounding = 1 / 1.75f;
private CellularDistanceFunction mCellularDistanceFunction = CellularDistanceFunction.EuclideanSq;
private CellularReturnType mCellularReturnType = CellularReturnType.Distance;
private float mCellularJitterModifier = 1.0f;
private DomainWarpType mDomainWarpType = DomainWarpType.OpenSimplex2;
private TransformType3D mWarpTransformType3D = TransformType3D.DefaultOpenSimplex2;
private float mDomainWarpAmp = 1.0f;
/// <summary>
/// Create new FastNoise object with optional seed
/// </summary>
public FastNoiseLite(int seed = 1337)
{
SetSeed(seed);
}
/// <summary>
/// Sets seed used for all noise types
/// </summary>
/// <remarks>
/// Default: 1337
/// </remarks>
public void SetSeed(int seed) { mSeed = seed; }
/// <summary>
/// Sets frequency for all noise types
/// </summary>
/// <remarks>
/// Default: 0.01
/// </remarks>
public void SetFrequency(float frequency) { mFrequency = frequency; }
/// <summary>
/// Sets noise algorithm used for GetNoise(...)
/// </summary>
/// <remarks>
/// Default: OpenSimplex2
/// </remarks>
public void SetNoiseType(NoiseType noiseType)
{
mNoiseType = noiseType;
UpdateTransformType3D();
}
/// <summary>
/// Sets domain rotation type for 3D Noise and 3D DomainWarp.
/// Can aid in reducing directional artifacts when sampling a 2D plane in 3D
/// </summary>
/// <remarks>
/// Default: None
/// </remarks>
public void SetRotationType3D(RotationType3D rotationType3D)
{
mRotationType3D = rotationType3D;
UpdateTransformType3D();
UpdateWarpTransformType3D();
}
/// <summary>
/// Sets method for combining octaves in all fractal noise types
/// </summary>
/// <remarks>
/// Default: None
/// Note: FractalType.DomainWarp... only affects DomainWarp(...)
/// </remarks>
public void SetFractalType(FractalType fractalType) { mFractalType = fractalType; }
/// <summary>
/// Sets octave count for all fractal noise types
/// </summary>
/// <remarks>
/// Default: 3
/// </remarks>
public void SetFractalOctaves(int octaves)
{
mOctaves = octaves;
CalculateFractalBounding();
}
/// <summary>
/// Sets octave lacunarity for all fractal noise types
/// </summary>
/// <remarks>
/// Default: 2.0
/// </remarks>
public void SetFractalLacunarity(float lacunarity) { mLacunarity = lacunarity; }
/// <summary>
/// Sets octave gain for all fractal noise types
/// </summary>
/// <remarks>
/// Default: 0.5
/// </remarks>
public void SetFractalGain(float gain)
{
mGain = gain;
CalculateFractalBounding();
}
/// <summary>
/// Sets octave weighting for all none DomainWarp fratal types
/// </summary>
/// <remarks>
/// Default: 0.0
/// Note: Keep between 0...1 to maintain -1...1 output bounding
/// </remarks>
public void SetFractalWeightedStrength(float weightedStrength) { mWeightedStrength = weightedStrength; }
/// <summary>
/// Sets strength of the fractal ping pong effect
/// </summary>
/// <remarks>
/// Default: 2.0
/// </remarks>
public void SetFractalPingPongStrength(float pingPongStrength) { mPingPongStrength = pingPongStrength; }
/// <summary>
/// Sets distance function used in cellular noise calculations
/// </summary>
/// <remarks>
/// Default: Distance
/// </remarks>
public void SetCellularDistanceFunction(CellularDistanceFunction cellularDistanceFunction) { mCellularDistanceFunction = cellularDistanceFunction; }
/// <summary>
/// Sets return type from cellular noise calculations
/// </summary>
/// <remarks>
/// Default: EuclideanSq
/// </remarks>
public void SetCellularReturnType(CellularReturnType cellularReturnType) { mCellularReturnType = cellularReturnType; }
/// <summary>
/// Sets the maximum distance a cellular point can move from it's grid position
/// </summary>
/// <remarks>
/// Default: 1.0
/// Note: Setting this higher than 1 will cause artifacts
/// </remarks>
public void SetCellularJitter(float cellularJitter) { mCellularJitterModifier = cellularJitter; }
/// <summary>
/// Sets the warp algorithm when using DomainWarp(...)
/// </summary>
/// <remarks>
/// Default: OpenSimplex2
/// </remarks>
public void SetDomainWarpType(DomainWarpType domainWarpType)
{
mDomainWarpType = domainWarpType;
UpdateWarpTransformType3D();
}
/// <summary>
/// Sets the maximum warp distance from original position when using DomainWarp(...)
/// </summary>
/// <remarks>
/// Default: 1.0
/// </remarks>
public void SetDomainWarpAmp(float domainWarpAmp) { mDomainWarpAmp = domainWarpAmp; }
/// <summary>
/// 2D noise at given position using current settings
/// </summary>
/// <returns>
/// Noise output bounded between -1...1
/// </returns>
[MethodImpl(OPTIMISE)]
public float GetNoise(FNLfloat x, FNLfloat y)
{
TransformNoiseCoordinate(ref x, ref y);
switch (mFractalType)
{
default:
return GenNoiseSingle(mSeed, x, y);
case FractalType.FBm:
return GenFractalFBm(x, y);
case FractalType.Ridged:
return GenFractalRidged(x, y);
case FractalType.PingPong:
return GenFractalPingPong(x, y);
}
}
/// <summary>
/// 3D noise at given position using current settings
/// </summary>
/// <returns>
/// Noise output bounded between -1...1
/// </returns>
[MethodImpl(OPTIMISE)]
public float GetNoise(FNLfloat x, FNLfloat y, FNLfloat z)
{
TransformNoiseCoordinate(ref x, ref y, ref z);
switch (mFractalType)
{
default:
return GenNoiseSingle(mSeed, x, y, z);
case FractalType.FBm:
return GenFractalFBm(x, y, z);
case FractalType.Ridged:
return GenFractalRidged(x, y, z);
case FractalType.PingPong:
return GenFractalPingPong(x, y, z);
}
}
/// <summary>
/// 2D warps the input position using current domain warp settings
/// </summary>
/// <example>
/// Example usage with GetNoise
/// <code>DomainWarp(ref x, ref y)
/// noise = GetNoise(x, y)</code>
/// </example>
[MethodImpl(OPTIMISE)]
public void DomainWarp(ref FNLfloat x, ref FNLfloat y)
{
switch (mFractalType)
{
default:
DomainWarpSingle(ref x, ref y);
break;
case FractalType.DomainWarpProgressive:
DomainWarpFractalProgressive(ref x, ref y);
break;
case FractalType.DomainWarpIndependent:
DomainWarpFractalIndependent(ref x, ref y);
break;
}
}
/// <summary>
/// 3D warps the input position using current domain warp settings
/// </summary>
/// <example>
/// Example usage with GetNoise
/// <code>DomainWarp(ref x, ref y, ref z)
/// noise = GetNoise(x, y, z)</code>
/// </example>
[MethodImpl(OPTIMISE)]
public void DomainWarp(ref FNLfloat x, ref FNLfloat y, ref FNLfloat z)
{
switch (mFractalType)
{
default:
DomainWarpSingle(ref x, ref y, ref z);
break;
case FractalType.DomainWarpProgressive:
DomainWarpFractalProgressive(ref x, ref y, ref z);
break;
case FractalType.DomainWarpIndependent:
DomainWarpFractalIndependent(ref x, ref y, ref z);
break;
}
}
private static readonly float[] Gradients2D =
{
0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, 0.793353340291235f, 0.793353340291235f, 0.608761429008721f,
0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, -0.130526192220051f, 0.923879532511287f, -0.38268343236509f,
0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, -0.923879532511287f, 0.130526192220052f, -0.99144486137381f,
-0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, -0.793353340291235f, -0.793353340291235f, -0.608761429008721f,
-0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, 0.130526192220051f, -0.923879532511287f, 0.38268343236509f,
-0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, 0.923879532511287f, -0.130526192220052f, 0.99144486137381f,
0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, 0.793353340291235f, 0.793353340291235f, 0.608761429008721f,
0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, -0.130526192220051f, 0.923879532511287f, -0.38268343236509f,
0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, -0.923879532511287f, 0.130526192220052f, -0.99144486137381f,
-0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, -0.793353340291235f, -0.793353340291235f, -0.608761429008721f,
-0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, 0.130526192220051f, -0.923879532511287f, 0.38268343236509f,
-0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, 0.923879532511287f, -0.130526192220052f, 0.99144486137381f,
0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, 0.793353340291235f, 0.793353340291235f, 0.608761429008721f,
0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, -0.130526192220051f, 0.923879532511287f, -0.38268343236509f,
0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, -0.923879532511287f, 0.130526192220052f, -0.99144486137381f,
-0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, -0.793353340291235f, -0.793353340291235f, -0.608761429008721f,
-0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, 0.130526192220051f, -0.923879532511287f, 0.38268343236509f,
-0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, 0.923879532511287f, -0.130526192220052f, 0.99144486137381f,
0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, 0.793353340291235f, 0.793353340291235f, 0.608761429008721f,
0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, -0.130526192220051f, 0.923879532511287f, -0.38268343236509f,
0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, -0.923879532511287f, 0.130526192220052f, -0.99144486137381f,
-0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, -0.793353340291235f, -0.793353340291235f, -0.608761429008721f,
-0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, 0.130526192220051f, -0.923879532511287f, 0.38268343236509f,
-0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, 0.923879532511287f, -0.130526192220052f, 0.99144486137381f,
0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, 0.793353340291235f, 0.793353340291235f, 0.608761429008721f,
0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, -0.130526192220051f, 0.923879532511287f, -0.38268343236509f,
0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, -0.923879532511287f, 0.130526192220052f, -0.99144486137381f,
-0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, -0.793353340291235f, -0.793353340291235f, -0.608761429008721f,
-0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, 0.130526192220051f, -0.923879532511287f, 0.38268343236509f,
-0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, 0.923879532511287f, -0.130526192220052f, 0.99144486137381f,
0.38268343236509f, 0.923879532511287f, 0.923879532511287f, 0.38268343236509f, 0.923879532511287f, -0.38268343236509f, 0.38268343236509f, -0.923879532511287f,
-0.38268343236509f, -0.923879532511287f, -0.923879532511287f, -0.38268343236509f, -0.923879532511287f, 0.38268343236509f, -0.38268343236509f, 0.923879532511287f,
};
private static readonly float[] RandVecs2D =
{
-0.2700222198f, -0.9628540911f, 0.3863092627f, -0.9223693152f, 0.04444859006f, -0.999011673f, -0.5992523158f, -0.8005602176f, -0.7819280288f, 0.6233687174f, 0.9464672271f, 0.3227999196f, -0.6514146797f, -0.7587218957f, 0.9378472289f, 0.347048376f,
-0.8497875957f, -0.5271252623f, -0.879042592f, 0.4767432447f, -0.892300288f, -0.4514423508f, -0.379844434f, -0.9250503802f, -0.9951650832f, 0.0982163789f, 0.7724397808f, -0.6350880136f, 0.7573283322f, -0.6530343002f, -0.9928004525f, -0.119780055f,
-0.0532665713f, 0.9985803285f, 0.9754253726f, -0.2203300762f, -0.7665018163f, 0.6422421394f, 0.991636706f, 0.1290606184f, -0.994696838f, 0.1028503788f, -0.5379205513f, -0.84299554f, 0.5022815471f, -0.8647041387f, 0.4559821461f, -0.8899889226f,
-0.8659131224f, -0.5001944266f, 0.0879458407f, -0.9961252577f, -0.5051684983f, 0.8630207346f, 0.7753185226f, -0.6315704146f, -0.6921944612f, 0.7217110418f, -0.5191659449f, -0.8546734591f, 0.8978622882f, -0.4402764035f, -0.1706774107f, 0.9853269617f,
-0.9353430106f, -0.3537420705f, -0.9992404798f, 0.03896746794f, -0.2882064021f, -0.9575683108f, -0.9663811329f, 0.2571137995f, -0.8759714238f, -0.4823630009f, -0.8303123018f, -0.5572983775f, 0.05110133755f, -0.9986934731f, -0.8558373281f, -0.5172450752f,
0.09887025282f, 0.9951003332f, 0.9189016087f, 0.3944867976f, -0.2439375892f, -0.9697909324f, -0.8121409387f, -0.5834613061f, -0.9910431363f, 0.1335421355f, 0.8492423985f, -0.5280031709f, -0.9717838994f, -0.2358729591f, 0.9949457207f, 0.1004142068f,
0.6241065508f, -0.7813392434f, 0.662910307f, 0.7486988212f, -0.7197418176f, 0.6942418282f, -0.8143370775f, -0.5803922158f, 0.104521054f, -0.9945226741f, -0.1065926113f, -0.9943027784f, 0.445799684f, -0.8951327509f, 0.105547406f, 0.9944142724f,
-0.992790267f, 0.1198644477f, -0.8334366408f, 0.552615025f, 0.9115561563f, -0.4111755999f, 0.8285544909f, -0.5599084351f, 0.7217097654f, -0.6921957921f, 0.4940492677f, -0.8694339084f, -0.3652321272f, -0.9309164803f, -0.9696606758f, 0.2444548501f,
0.08925509731f, -0.996008799f, 0.5354071276f, -0.8445941083f, -0.1053576186f, 0.9944343981f, -0.9890284586f, 0.1477251101f, 0.004856104961f, 0.9999882091f, 0.9885598478f, 0.1508291331f, 0.9286129562f, -0.3710498316f, -0.5832393863f, -0.8123003252f,
0.3015207509f, 0.9534596146f, -0.9575110528f, 0.2883965738f, 0.9715802154f, -0.2367105511f, 0.229981792f, 0.9731949318f, 0.955763816f, -0.2941352207f, 0.740956116f, 0.6715534485f, -0.9971513787f, -0.07542630764f, 0.6905710663f, -0.7232645452f,
-0.290713703f, -0.9568100872f, 0.5912777791f, -0.8064679708f, -0.9454592212f, -0.325740481f, 0.6664455681f, 0.74555369f, 0.6236134912f, 0.7817328275f, 0.9126993851f, -0.4086316587f, -0.8191762011f, 0.5735419353f, -0.8812745759f, -0.4726046147f,
0.9953313627f, 0.09651672651f, 0.9855650846f, -0.1692969699f, -0.8495980887f, 0.5274306472f, 0.6174853946f, -0.7865823463f, 0.8508156371f, 0.52546432f, 0.9985032451f, -0.05469249926f, 0.1971371563f, -0.9803759185f, 0.6607855748f, -0.7505747292f,
-0.03097494063f, 0.9995201614f, -0.6731660801f, 0.739491331f, -0.7195018362f, -0.6944905383f, 0.9727511689f, 0.2318515979f, 0.9997059088f, -0.0242506907f, 0.4421787429f, -0.8969269532f, 0.9981350961f, -0.061043673f, -0.9173660799f, -0.3980445648f,
-0.8150056635f, -0.5794529907f, -0.8789331304f, 0.4769450202f, 0.0158605829f, 0.999874213f, -0.8095464474f, 0.5870558317f, -0.9165898907f, -0.3998286786f, -0.8023542565f, 0.5968480938f, -0.5176737917f, 0.8555780767f, -0.8154407307f, -0.5788405779f,
0.4022010347f, -0.9155513791f, -0.9052556868f, -0.4248672045f, 0.7317445619f, 0.6815789728f, -0.5647632201f, -0.8252529947f, -0.8403276335f, -0.5420788397f, -0.9314281527f, 0.363925262f, 0.5238198472f, 0.8518290719f, 0.7432803869f, -0.6689800195f,
-0.985371561f, -0.1704197369f, 0.4601468731f, 0.88784281f, 0.825855404f, 0.5638819483f, 0.6182366099f, 0.7859920446f, 0.8331502863f, -0.553046653f, 0.1500307506f, 0.9886813308f, -0.662330369f, -0.7492119075f, -0.668598664f, 0.743623444f,
0.7025606278f, 0.7116238924f, -0.5419389763f, -0.8404178401f, -0.3388616456f, 0.9408362159f, 0.8331530315f, 0.5530425174f, -0.2989720662f, -0.9542618632f, 0.2638522993f, 0.9645630949f, 0.124108739f, -0.9922686234f, -0.7282649308f, -0.6852956957f,
0.6962500149f, 0.7177993569f, -0.9183535368f, 0.3957610156f, -0.6326102274f, -0.7744703352f, -0.9331891859f, -0.359385508f, -0.1153779357f, -0.9933216659f, 0.9514974788f, -0.3076565421f, -0.08987977445f, -0.9959526224f, 0.6678496916f, 0.7442961705f,
0.7952400393f, -0.6062947138f, -0.6462007402f, -0.7631674805f, -0.2733598753f, 0.9619118351f, 0.9669590226f, -0.254931851f, -0.9792894595f, 0.2024651934f, -0.5369502995f, -0.8436138784f, -0.270036471f, -0.9628500944f, -0.6400277131f, 0.7683518247f,
-0.7854537493f, -0.6189203566f, 0.06005905383f, -0.9981948257f, -0.02455770378f, 0.9996984141f, -0.65983623f, 0.751409442f, -0.6253894466f, -0.7803127835f, -0.6210408851f, -0.7837781695f, 0.8348888491f, 0.5504185768f, -0.1592275245f, 0.9872419133f,
0.8367622488f, 0.5475663786f, -0.8675753916f, -0.4973056806f, -0.2022662628f, -0.9793305667f, 0.9399189937f, 0.3413975472f, 0.9877404807f, -0.1561049093f, -0.9034455656f, 0.4287028224f, 0.1269804218f, -0.9919052235f, -0.3819600854f, 0.924178821f,
0.9754625894f, 0.2201652486f, -0.3204015856f, -0.9472818081f, -0.9874760884f, 0.1577687387f, 0.02535348474f, -0.9996785487f, 0.4835130794f, -0.8753371362f, -0.2850799925f, -0.9585037287f, -0.06805516006f, -0.99768156f, -0.7885244045f, -0.6150034663f,
0.3185392127f, -0.9479096845f, 0.8880043089f, 0.4598351306f, 0.6476921488f, -0.7619021462f, 0.9820241299f, 0.1887554194f, 0.9357275128f, -0.3527237187f, -0.8894895414f, 0.4569555293f, 0.7922791302f, 0.6101588153f, 0.7483818261f, 0.6632681526f,
-0.7288929755f, -0.6846276581f, 0.8729032783f, -0.4878932944f, 0.8288345784f, 0.5594937369f, 0.08074567077f, 0.9967347374f, 0.9799148216f, -0.1994165048f, -0.580730673f, -0.8140957471f, -0.4700049791f, -0.8826637636f, 0.2409492979f, 0.9705377045f,
0.9437816757f, -0.3305694308f, -0.8927998638f, -0.4504535528f, -0.8069622304f, 0.5906030467f, 0.06258973166f, 0.9980393407f, -0.9312597469f, 0.3643559849f, 0.5777449785f, 0.8162173362f, -0.3360095855f, -0.941858566f, 0.697932075f, -0.7161639607f,
-0.002008157227f, -0.9999979837f, -0.1827294312f, -0.9831632392f, -0.6523911722f, 0.7578824173f, -0.4302626911f, -0.9027037258f, -0.9985126289f, -0.05452091251f, -0.01028102172f, -0.9999471489f, -0.4946071129f, 0.8691166802f, -0.2999350194f, 0.9539596344f,
0.8165471961f, 0.5772786819f, 0.2697460475f, 0.962931498f, -0.7306287391f, -0.6827749597f, -0.7590952064f, -0.6509796216f, -0.907053853f, 0.4210146171f, -0.5104861064f, -0.8598860013f, 0.8613350597f, 0.5080373165f, 0.5007881595f, -0.8655698812f,
-0.654158152f, 0.7563577938f, -0.8382755311f, -0.545246856f, 0.6940070834f, 0.7199681717f, 0.06950936031f, 0.9975812994f, 0.1702942185f, -0.9853932612f, 0.2695973274f, 0.9629731466f, 0.5519612192f, -0.8338697815f, 0.225657487f, -0.9742067022f,
0.4215262855f, -0.9068161835f, 0.4881873305f, -0.8727388672f, -0.3683854996f, -0.9296731273f, -0.9825390578f, 0.1860564427f, 0.81256471f, 0.5828709909f, 0.3196460933f, -0.9475370046f, 0.9570913859f, 0.2897862643f, -0.6876655497f, -0.7260276109f,
-0.9988770922f, -0.047376731f, -0.1250179027f, 0.992154486f, -0.8280133617f, 0.560708367f, 0.9324863769f, -0.3612051451f, 0.6394653183f, 0.7688199442f, -0.01623847064f, -0.9998681473f, -0.9955014666f, -0.09474613458f, -0.81453315f, 0.580117012f,
0.4037327978f, -0.9148769469f, 0.9944263371f, 0.1054336766f, -0.1624711654f, 0.9867132919f, -0.9949487814f, -0.100383875f, -0.6995302564f, 0.7146029809f, 0.5263414922f, -0.85027327f, -0.5395221479f, 0.841971408f, 0.6579370318f, 0.7530729462f,
0.01426758847f, -0.9998982128f, -0.6734383991f, 0.7392433447f, 0.639412098f, -0.7688642071f, 0.9211571421f, 0.3891908523f, -0.146637214f, -0.9891903394f, -0.782318098f, 0.6228791163f, -0.5039610839f, -0.8637263605f, -0.7743120191f, -0.6328039957f,
};
private static readonly float[] Gradients3D =
{
0, 1, 1, 0, 0,-1, 1, 0, 0, 1,-1, 0, 0,-1,-1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0,-1, 0, -1, 0,-1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1,-1, 0, 0, -1,-1, 0, 0,
0, 1, 1, 0, 0,-1, 1, 0, 0, 1,-1, 0, 0,-1,-1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0,-1, 0, -1, 0,-1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1,-1, 0, 0, -1,-1, 0, 0,
0, 1, 1, 0, 0,-1, 1, 0, 0, 1,-1, 0, 0,-1,-1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0,-1, 0, -1, 0,-1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1,-1, 0, 0, -1,-1, 0, 0,
0, 1, 1, 0, 0,-1, 1, 0, 0, 1,-1, 0, 0,-1,-1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0,-1, 0, -1, 0,-1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1,-1, 0, 0, -1,-1, 0, 0,
0, 1, 1, 0, 0,-1, 1, 0, 0, 1,-1, 0, 0,-1,-1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0,-1, 0, -1, 0,-1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1,-1, 0, 0, -1,-1, 0, 0,
1, 1, 0, 0, 0,-1, 1, 0, -1, 1, 0, 0, 0,-1,-1, 0
};
private static readonly float[] RandVecs3D =
{
-0.7292736885f, -0.6618439697f, 0.1735581948f, 0, 0.790292081f, -0.5480887466f, -0.2739291014f, 0, 0.7217578935f, 0.6226212466f, -0.3023380997f, 0, 0.565683137f, -0.8208298145f, -0.0790000257f, 0, 0.760049034f, -0.5555979497f, -0.3370999617f, 0, 0.3713945616f, 0.5011264475f, 0.7816254623f, 0, -0.1277062463f, -0.4254438999f, -0.8959289049f, 0, -0.2881560924f, -0.5815838982f, 0.7607405838f, 0,
0.5849561111f, -0.662820239f, -0.4674352136f, 0, 0.3307171178f, 0.0391653737f, 0.94291689f, 0, 0.8712121778f, -0.4113374369f, -0.2679381538f, 0, 0.580981015f, 0.7021915846f, 0.4115677815f, 0, 0.503756873f, 0.6330056931f, -0.5878203852f, 0, 0.4493712205f, 0.601390195f, 0.6606022552f, 0, -0.6878403724f, 0.09018890807f, -0.7202371714f, 0, -0.5958956522f, -0.6469350577f, 0.475797649f, 0,
-0.5127052122f, 0.1946921978f, -0.8361987284f, 0, -0.9911507142f, -0.05410276466f, -0.1212153153f, 0, -0.2149721042f, 0.9720882117f, -0.09397607749f, 0, -0.7518650936f, -0.5428057603f, 0.3742469607f, 0, 0.5237068895f, 0.8516377189f, -0.02107817834f, 0, 0.6333504779f, 0.1926167129f, -0.7495104896f, 0, -0.06788241606f, 0.3998305789f, 0.9140719259f, 0, -0.5538628599f, -0.4729896695f, -0.6852128902f, 0,
-0.7261455366f, -0.5911990757f, 0.3509933228f, 0, -0.9229274737f, -0.1782808786f, 0.3412049336f, 0, -0.6968815002f, 0.6511274338f, 0.3006480328f, 0, 0.9608044783f, -0.2098363234f, -0.1811724921f, 0, 0.06817146062f, -0.9743405129f, 0.2145069156f, 0, -0.3577285196f, -0.6697087264f, -0.6507845481f, 0, -0.1868621131f, 0.7648617052f, -0.6164974636f, 0, -0.6541697588f, 0.3967914832f, 0.6439087246f, 0,
0.6993340405f, -0.6164538506f, 0.3618239211f, 0, -0.1546665739f, 0.6291283928f, 0.7617583057f, 0, -0.6841612949f, -0.2580482182f, -0.6821542638f, 0, 0.5383980957f, 0.4258654885f, 0.7271630328f, 0, -0.5026987823f, -0.7939832935f, -0.3418836993f, 0, 0.3202971715f, 0.2834415347f, 0.9039195862f, 0, 0.8683227101f, -0.0003762656404f, -0.4959995258f, 0, 0.791120031f, -0.08511045745f, 0.6057105799f, 0,
-0.04011016052f, -0.4397248749f, 0.8972364289f, 0, 0.9145119872f, 0.3579346169f, -0.1885487608f, 0, -0.9612039066f, -0.2756484276f, 0.01024666929f, 0, 0.6510361721f, -0.2877799159f, -0.7023778346f, 0, -0.2041786351f, 0.7365237271f, 0.644859585f, 0, -0.7718263711f, 0.3790626912f, 0.5104855816f, 0, -0.3060082741f, -0.7692987727f, 0.5608371729f, 0, 0.454007341f, -0.5024843065f, 0.7357899537f, 0,
0.4816795475f, 0.6021208291f, -0.6367380315f, 0, 0.6961980369f, -0.3222197429f, 0.641469197f, 0, -0.6532160499f, -0.6781148932f, 0.3368515753f, 0, 0.5089301236f, -0.6154662304f, -0.6018234363f, 0, -0.1635919754f, -0.9133604627f, -0.372840892f, 0, 0.52408019f, -0.8437664109f, 0.1157505864f, 0, 0.5902587356f, 0.4983817807f, -0.6349883666f, 0, 0.5863227872f, 0.494764745f, 0.6414307729f, 0,
0.6779335087f, 0.2341345225f, 0.6968408593f, 0, 0.7177054546f, -0.6858979348f, 0.120178631f, 0, -0.5328819713f, -0.5205125012f, 0.6671608058f, 0, -0.8654874251f, -0.0700727088f, -0.4960053754f, 0, -0.2861810166f, 0.7952089234f, 0.5345495242f, 0, -0.04849529634f, 0.9810836427f, -0.1874115585f, 0, -0.6358521667f, 0.6058348682f, 0.4781800233f, 0, 0.6254794696f, -0.2861619734f, 0.7258696564f, 0,
-0.2585259868f, 0.5061949264f, -0.8227581726f, 0, 0.02136306781f, 0.5064016808f, -0.8620330371f, 0, 0.200111773f, 0.8599263484f, 0.4695550591f, 0, 0.4743561372f, 0.6014985084f, -0.6427953014f, 0, 0.6622993731f, -0.5202474575f, -0.5391679918f, 0, 0.08084972818f, -0.6532720452f, 0.7527940996f, 0, -0.6893687501f, 0.0592860349f, 0.7219805347f, 0, -0.1121887082f, -0.9673185067f, 0.2273952515f, 0,
0.7344116094f, 0.5979668656f, -0.3210532909f, 0, 0.5789393465f, -0.2488849713f, 0.7764570201f, 0, 0.6988182827f, 0.3557169806f, -0.6205791146f, 0, -0.8636845529f, -0.2748771249f, -0.4224826141f, 0, -0.4247027957f, -0.4640880967f, 0.777335046f, 0, 0.5257722489f, -0.8427017621f, 0.1158329937f, 0, 0.9343830603f, 0.316302472f, -0.1639543925f, 0, -0.1016836419f, -0.8057303073f, -0.5834887393f, 0,
-0.6529238969f, 0.50602126f, -0.5635892736f, 0, -0.2465286165f, -0.9668205684f, -0.06694497494f, 0, -0.9776897119f, -0.2099250524f, -0.007368825344f, 0, 0.7736893337f, 0.5734244712f, 0.2694238123f, 0, -0.6095087895f, 0.4995678998f, 0.6155736747f, 0, 0.5794535482f, 0.7434546771f, 0.3339292269f, 0, -0.8226211154f, 0.08142581855f, 0.5627293636f, 0, -0.510385483f, 0.4703667658f, 0.7199039967f, 0,
-0.5764971849f, -0.07231656274f, -0.8138926898f, 0, 0.7250628871f, 0.3949971505f, -0.5641463116f, 0, -0.1525424005f, 0.4860840828f, -0.8604958341f, 0, -0.5550976208f, -0.4957820792f, 0.667882296f, 0, -0.1883614327f, 0.9145869398f, 0.357841725f, 0, 0.7625556724f, -0.5414408243f, -0.3540489801f, 0, -0.5870231946f, -0.3226498013f, -0.7424963803f, 0, 0.3051124198f, 0.2262544068f, -0.9250488391f, 0,
0.6379576059f, 0.577242424f, -0.5097070502f, 0, -0.5966775796f, 0.1454852398f, -0.7891830656f, 0, -0.658330573f, 0.6555487542f, -0.3699414651f, 0, 0.7434892426f, 0.2351084581f, 0.6260573129f, 0, 0.5562114096f, 0.8264360377f, -0.0873632843f, 0, -0.3028940016f, -0.8251527185f, 0.4768419182f, 0, 0.1129343818f, -0.985888439f, -0.1235710781f, 0, 0.5937652891f, -0.5896813806f, 0.5474656618f, 0,
0.6757964092f, -0.5835758614f, -0.4502648413f, 0, 0.7242302609f, -0.1152719764f, 0.6798550586f, 0, -0.9511914166f, 0.0753623979f, -0.2992580792f, 0, 0.2539470961f, -0.1886339355f, 0.9486454084f, 0, 0.571433621f, -0.1679450851f, -0.8032795685f, 0, -0.06778234979f, 0.3978269256f, 0.9149531629f, 0, 0.6074972649f, 0.733060024f, -0.3058922593f, 0, -0.5435478392f, 0.1675822484f, 0.8224791405f, 0,
-0.5876678086f, -0.3380045064f, -0.7351186982f, 0, -0.7967562402f, 0.04097822706f, -0.6029098428f, 0, -0.1996350917f, 0.8706294745f, 0.4496111079f, 0, -0.02787660336f, -0.9106232682f, -0.4122962022f, 0, -0.7797625996f, -0.6257634692f, 0.01975775581f, 0, -0.5211232846f, 0.7401644346f, -0.4249554471f, 0, 0.8575424857f, 0.4053272873f, -0.3167501783f, 0, 0.1045223322f, 0.8390195772f, -0.5339674439f, 0,
0.3501822831f, 0.9242524096f, -0.1520850155f, 0, 0.1987849858f, 0.07647613266f, 0.9770547224f, 0, 0.7845996363f, 0.6066256811f, -0.1280964233f, 0, 0.09006737436f, -0.9750989929f, -0.2026569073f, 0, -0.8274343547f, -0.542299559f, 0.1458203587f, 0, -0.3485797732f, -0.415802277f, 0.840000362f, 0, -0.2471778936f, -0.7304819962f, -0.6366310879f, 0, -0.3700154943f, 0.8577948156f, 0.3567584454f, 0,
0.5913394901f, -0.548311967f, -0.5913303597f, 0, 0.1204873514f, -0.7626472379f, -0.6354935001f, 0, 0.616959265f, 0.03079647928f, 0.7863922953f, 0, 0.1258156836f, -0.6640829889f, -0.7369967419f, 0, -0.6477565124f, -0.1740147258f, -0.7417077429f, 0, 0.6217889313f, -0.7804430448f, -0.06547655076f, 0, 0.6589943422f, -0.6096987708f, 0.4404473475f, 0, -0.2689837504f, -0.6732403169f, -0.6887635427f, 0,
-0.3849775103f, 0.5676542638f, 0.7277093879f, 0, 0.5754444408f, 0.8110471154f, -0.1051963504f, 0, 0.9141593684f, 0.3832947817f, 0.131900567f, 0, -0.107925319f, 0.9245493968f, 0.3654593525f, 0, 0.377977089f, 0.3043148782f, 0.8743716458f, 0, -0.2142885215f, -0.8259286236f, 0.5214617324f, 0, 0.5802544474f, 0.4148098596f, -0.7008834116f, 0, -0.1982660881f, 0.8567161266f, -0.4761596756f, 0,
-0.03381553704f, 0.3773180787f, -0.9254661404f, 0, -0.6867922841f, -0.6656597827f, 0.2919133642f, 0, 0.7731742607f, -0.2875793547f, -0.5652430251f, 0, -0.09655941928f, 0.9193708367f, -0.3813575004f, 0, 0.2715702457f, -0.9577909544f, -0.09426605581f, 0, 0.2451015704f, -0.6917998565f, -0.6792188003f, 0, 0.977700782f, -0.1753855374f, 0.1155036542f, 0, -0.5224739938f, 0.8521606816f, 0.02903615945f, 0,
-0.7734880599f, -0.5261292347f, 0.3534179531f, 0, -0.7134492443f, -0.269547243f, 0.6467878011f, 0, 0.1644037271f, 0.5105846203f, -0.8439637196f, 0, 0.6494635788f, 0.05585611296f, 0.7583384168f, 0, -0.4711970882f, 0.5017280509f, -0.7254255765f, 0, -0.6335764307f, -0.2381686273f, -0.7361091029f, 0, -0.9021533097f, -0.270947803f, -0.3357181763f, 0, -0.3793711033f, 0.872258117f, 0.3086152025f, 0,
-0.6855598966f, -0.3250143309f, 0.6514394162f, 0, 0.2900942212f, -0.7799057743f, -0.5546100667f, 0, -0.2098319339f, 0.85037073f, 0.4825351604f, 0, -0.4592603758f, 0.6598504336f, -0.5947077538f, 0, 0.8715945488f, 0.09616365406f, -0.4807031248f, 0, -0.6776666319f, 0.7118504878f, -0.1844907016f, 0, 0.7044377633f, 0.312427597f, 0.637304036f, 0, -0.7052318886f, -0.2401093292f, -0.6670798253f, 0,
0.081921007f, -0.7207336136f, -0.6883545647f, 0, -0.6993680906f, -0.5875763221f, -0.4069869034f, 0, -0.1281454481f, 0.6419895885f, 0.7559286424f, 0, -0.6337388239f, -0.6785471501f, -0.3714146849f, 0, 0.5565051903f, -0.2168887573f, -0.8020356851f, 0, -0.5791554484f, 0.7244372011f, -0.3738578718f, 0, 0.1175779076f, -0.7096451073f, 0.6946792478f, 0, -0.6134619607f, 0.1323631078f, 0.7785527795f, 0,
0.6984635305f, -0.02980516237f, -0.715024719f, 0, 0.8318082963f, -0.3930171956f, 0.3919597455f, 0, 0.1469576422f, 0.05541651717f, -0.9875892167f, 0, 0.708868575f, -0.2690503865f, 0.6520101478f, 0, 0.2726053183f, 0.67369766f, -0.68688995f, 0, -0.6591295371f, 0.3035458599f, -0.6880466294f, 0, 0.4815131379f, -0.7528270071f, 0.4487723203f, 0, 0.9430009463f, 0.1675647412f, -0.2875261255f, 0,
0.434802957f, 0.7695304522f, -0.4677277752f, 0, 0.3931996188f, 0.594473625f, 0.7014236729f, 0, 0.7254336655f, -0.603925654f, 0.3301814672f, 0, 0.7590235227f, -0.6506083235f, 0.02433313207f, 0, -0.8552768592f, -0.3430042733f, 0.3883935666f, 0, -0.6139746835f, 0.6981725247f, 0.3682257648f, 0, -0.7465905486f, -0.5752009504f, 0.3342849376f, 0, 0.5730065677f, 0.810555537f, -0.1210916791f, 0,
-0.9225877367f, -0.3475211012f, -0.167514036f, 0, -0.7105816789f, -0.4719692027f, -0.5218416899f, 0, -0.08564609717f, 0.3583001386f, 0.929669703f, 0, -0.8279697606f, -0.2043157126f, 0.5222271202f, 0, 0.427944023f, 0.278165994f, 0.8599346446f, 0, 0.5399079671f, -0.7857120652f, -0.3019204161f, 0, 0.5678404253f, -0.5495413974f, -0.6128307303f, 0, -0.9896071041f, 0.1365639107f, -0.04503418428f, 0,
-0.6154342638f, -0.6440875597f, 0.4543037336f, 0, 0.1074204368f, -0.7946340692f, 0.5975094525f, 0, -0.3595449969f, -0.8885529948f, 0.28495784f, 0, -0.2180405296f, 0.1529888965f, 0.9638738118f, 0, -0.7277432317f, -0.6164050508f, -0.3007234646f, 0, 0.7249729114f, -0.00669719484f, 0.6887448187f, 0, -0.5553659455f, -0.5336586252f, 0.6377908264f, 0, 0.5137558015f, 0.7976208196f, -0.3160000073f, 0,
-0.3794024848f, 0.9245608561f, -0.03522751494f, 0, 0.8229248658f, 0.2745365933f, -0.4974176556f, 0, -0.5404114394f, 0.6091141441f, 0.5804613989f, 0, 0.8036581901f, -0.2703029469f, 0.5301601931f, 0, 0.6044318879f, 0.6832968393f, 0.4095943388f, 0, 0.06389988817f, 0.9658208605f, -0.2512108074f, 0, 0.1087113286f, 0.7402471173f, -0.6634877936f, 0, -0.713427712f, -0.6926784018f, 0.1059128479f, 0,
0.6458897819f, -0.5724548511f, -0.5050958653f, 0, -0.6553931414f, 0.7381471625f, 0.159995615f, 0, 0.3910961323f, 0.9188871375f, -0.05186755998f, 0, -0.4879022471f, -0.5904376907f, 0.6429111375f, 0, 0.6014790094f, 0.7707441366f, -0.2101820095f, 0, -0.5677173047f, 0.7511360995f, 0.3368851762f, 0, 0.7858573506f, 0.226674665f, 0.5753666838f, 0, -0.4520345543f, -0.604222686f, -0.6561857263f, 0,
0.002272116345f, 0.4132844051f, -0.9105991643f, 0, -0.5815751419f, -0.5162925989f, 0.6286591339f, 0, -0.03703704785f, 0.8273785755f, 0.5604221175f, 0, -0.5119692504f, 0.7953543429f, -0.3244980058f, 0, -0.2682417366f, -0.9572290247f, -0.1084387619f, 0, -0.2322482736f, -0.9679131102f, -0.09594243324f, 0, 0.3554328906f, -0.8881505545f, 0.2913006227f, 0, 0.7346520519f, -0.4371373164f, 0.5188422971f, 0,
0.9985120116f, 0.04659011161f, -0.02833944577f, 0, -0.3727687496f, -0.9082481361f, 0.1900757285f, 0, 0.91737377f, -0.3483642108f, 0.1925298489f, 0, 0.2714911074f, 0.4147529736f, -0.8684886582f, 0, 0.5131763485f, -0.7116334161f, 0.4798207128f, 0, -0.8737353606f, 0.18886992f, -0.4482350644f, 0, 0.8460043821f, -0.3725217914f, 0.3814499973f, 0, 0.8978727456f, -0.1780209141f, -0.4026575304f, 0,
0.2178065647f, -0.9698322841f, -0.1094789531f, 0, -0.1518031304f, -0.7788918132f, -0.6085091231f, 0, -0.2600384876f, -0.4755398075f, -0.8403819825f, 0, 0.572313509f, -0.7474340931f, -0.3373418503f, 0, -0.7174141009f, 0.1699017182f, -0.6756111411f, 0, -0.684180784f, 0.02145707593f, -0.7289967412f, 0, -0.2007447902f, 0.06555605789f, -0.9774476623f, 0, -0.1148803697f, -0.8044887315f, 0.5827524187f, 0,
-0.7870349638f, 0.03447489231f, 0.6159443543f, 0, -0.2015596421f, 0.6859872284f, 0.6991389226f, 0, -0.08581082512f, -0.10920836f, -0.9903080513f, 0, 0.5532693395f, 0.7325250401f, -0.396610771f, 0, -0.1842489331f, -0.9777375055f, -0.1004076743f, 0, 0.0775473789f, -0.9111505856f, 0.4047110257f, 0, 0.1399838409f, 0.7601631212f, -0.6344734459f, 0, 0.4484419361f, -0.845289248f, 0.2904925424f, 0
};
[MethodImpl(INLINE)]
private static float FastMin(float a, float b) { return a < b ? a : b; }
[MethodImpl(INLINE)]
private static float FastMax(float a, float b) { return a > b ? a : b; }
[MethodImpl(INLINE)]
private static float FastAbs(float f) { return f < 0 ? -f : f; }
[MethodImpl(INLINE)]
private static float FastSqrt(float f) { return (float)Math.Sqrt(f); }
[MethodImpl(INLINE)]
private static int FastFloor(FNLfloat f) { return f >= 0 ? (int)f : (int)f - 1; }
[MethodImpl(INLINE)]
private static int FastRound(FNLfloat f) { return f >= 0 ? (int)(f + 0.5f) : (int)(f - 0.5f); }
[MethodImpl(INLINE)]
private static float Lerp(float a, float b, float t) { return a + t * (b - a); }
[MethodImpl(INLINE)]
private static float InterpHermite(float t) { return t * t * (3 - 2 * t); }
[MethodImpl(INLINE)]
private static float InterpQuintic(float t) { return t * t * t * (t * (t * 6 - 15) + 10); }
[MethodImpl(INLINE)]
private static float CubicLerp(float a, float b, float c, float d, float t)
{
float p = (d - c) - (a - b);
return t * t * t * p + t * t * ((a - b) - p) + t * (c - a) + b;
}
[MethodImpl(INLINE)]
private static float PingPong(float t)
{
t -= (int)(t * 0.5f) * 2;
return t < 1 ? t : 2 - t;
}
private void CalculateFractalBounding()
{
float gain = FastAbs(mGain);
float amp = gain;
float ampFractal = 1.0f;
for (int i = 1; i < mOctaves; i++)
{
ampFractal += amp;
amp *= gain;
}
mFractalBounding = 1 / ampFractal;
}
// Hashing
private const int PrimeX = 501125321;
private const int PrimeY = 1136930381;
private const int PrimeZ = 1720413743;
[MethodImpl(INLINE)]
private static int Hash(int seed, int xPrimed, int yPrimed)
{
int hash = seed ^ xPrimed ^ yPrimed;
hash *= 0x27d4eb2d;
return hash;
}
[MethodImpl(INLINE)]
private static int Hash(int seed, int xPrimed, int yPrimed, int zPrimed)
{
int hash = seed ^ xPrimed ^ yPrimed ^ zPrimed;
hash *= 0x27d4eb2d;
return hash;
}
[MethodImpl(INLINE)]
private static float ValCoord(int seed, int xPrimed, int yPrimed)
{
int hash = Hash(seed, xPrimed, yPrimed);
hash *= hash;
hash ^= hash << 19;
return hash * (1 / 2147483648.0f);
}
[MethodImpl(INLINE)]
private static float ValCoord(int seed, int xPrimed, int yPrimed, int zPrimed)
{
int hash = Hash(seed, xPrimed, yPrimed, zPrimed);
hash *= hash;
hash ^= hash << 19;
return hash * (1 / 2147483648.0f);
}
[MethodImpl(INLINE)]
private static float GradCoord(int seed, int xPrimed, int yPrimed, float xd, float yd)
{
int hash = Hash(seed, xPrimed, yPrimed);
hash ^= hash >> 15;
hash &= 127 << 1;
float xg = Gradients2D[hash];
float yg = Gradients2D[hash | 1];
return xd * xg + yd * yg;
}
[MethodImpl(INLINE)]
private static float GradCoord(int seed, int xPrimed, int yPrimed, int zPrimed, float xd, float yd, float zd)
{
int hash = Hash(seed, xPrimed, yPrimed, zPrimed);
hash ^= hash >> 15;
hash &= 63 << 2;
float xg = Gradients3D[hash];
float yg = Gradients3D[hash | 1];
float zg = Gradients3D[hash | 2];
return xd * xg + yd * yg + zd * zg;
}
[MethodImpl(INLINE)]
private static void GradCoordOut(int seed, int xPrimed, int yPrimed, out float xo, out float yo)
{
int hash = Hash(seed, xPrimed, yPrimed) & (255 << 1);
xo = RandVecs2D[hash];
yo = RandVecs2D[hash | 1];
}
[MethodImpl(INLINE)]
private static void GradCoordOut(int seed, int xPrimed, int yPrimed, int zPrimed, out float xo, out float yo, out float zo)
{
int hash = Hash(seed, xPrimed, yPrimed, zPrimed) & (255 << 2);
xo = RandVecs3D[hash];
yo = RandVecs3D[hash | 1];
zo = RandVecs3D[hash | 2];
}
[MethodImpl(INLINE)]
private static void GradCoordDual(int seed, int xPrimed, int yPrimed, float xd, float yd, out float xo, out float yo)
{
int hash = Hash(seed, xPrimed, yPrimed);
int index1 = hash & (127 << 1);
int index2 = (hash >> 7) & (255 << 1);
float xg = Gradients2D[index1];
float yg = Gradients2D[index1 | 1];
float value = xd * xg + yd * yg;
float xgo = RandVecs2D[index2];
float ygo = RandVecs2D[index2 | 1];
xo = value * xgo;
yo = value * ygo;
}
[MethodImpl(INLINE)]
private static void GradCoordDual(int seed, int xPrimed, int yPrimed, int zPrimed, float xd, float yd, float zd, out float xo, out float yo, out float zo)
{
int hash = Hash(seed, xPrimed, yPrimed, zPrimed);
int index1 = hash & (63 << 2);
int index2 = (hash >> 6) & (255 << 2);
float xg = Gradients3D[index1];
float yg = Gradients3D[index1 | 1];
float zg = Gradients3D[index1 | 2];
float value = xd * xg + yd * yg + zd * zg;
float xgo = RandVecs3D[index2];
float ygo = RandVecs3D[index2 | 1];
float zgo = RandVecs3D[index2 | 2];
xo = value * xgo;
yo = value * ygo;
zo = value * zgo;
}
// Generic noise gen
private float GenNoiseSingle(int seed, FNLfloat x, FNLfloat y)
{
switch (mNoiseType)
{
case NoiseType.OpenSimplex2:
return SingleSimplex(seed, x, y);
case NoiseType.OpenSimplex2S:
return SingleOpenSimplex2S(seed, x, y);
case NoiseType.Cellular:
return SingleCellular(seed, x, y);
case NoiseType.Perlin:
return SinglePerlin(seed, x, y);
case NoiseType.ValueCubic:
return SingleValueCubic(seed, x, y);
case NoiseType.Value:
return SingleValue(seed, x, y);
default:
return 0;
}
}
private float GenNoiseSingle(int seed, FNLfloat x, FNLfloat y, FNLfloat z)
{
switch (mNoiseType)
{
case NoiseType.OpenSimplex2:
return SingleOpenSimplex2(seed, x, y, z);
case NoiseType.OpenSimplex2S:
return SingleOpenSimplex2S(seed, x, y, z);
case NoiseType.Cellular:
return SingleCellular(seed, x, y, z);
case NoiseType.Perlin:
return SinglePerlin(seed, x, y, z);
case NoiseType.ValueCubic:
return SingleValueCubic(seed, x, y, z);
case NoiseType.Value:
return SingleValue(seed, x, y, z);
default:
return 0;
}
}
// Noise Coordinate Transforms (frequency, and possible skew or rotation)
[MethodImpl(INLINE)]
private void TransformNoiseCoordinate(ref FNLfloat x, ref FNLfloat y)
{
x *= mFrequency;
y *= mFrequency;
switch (mNoiseType)
{
case NoiseType.OpenSimplex2:
case NoiseType.OpenSimplex2S:
{
const FNLfloat SQRT3 = (FNLfloat)1.7320508075688772935274463415059;
const FNLfloat F2 = 0.5f * (SQRT3 - 1);
FNLfloat t = (x + y) * F2;
x += t;
y += t;
}
break;
default:
break;
}
}
[MethodImpl(INLINE)]
private void TransformNoiseCoordinate(ref FNLfloat x, ref FNLfloat y, ref FNLfloat z)
{
x *= mFrequency;
y *= mFrequency;
z *= mFrequency;
switch (mTransformType3D)
{
case TransformType3D.ImproveXYPlanes:
{
FNLfloat xy = x + y;
FNLfloat s2 = xy * -(FNLfloat)0.211324865405187;
z *= (FNLfloat)0.577350269189626;
x += s2 - z;
y = y + s2 - z;
z += xy * (FNLfloat)0.577350269189626;
}
break;
case TransformType3D.ImproveXZPlanes:
{
FNLfloat xz = x + z;
FNLfloat s2 = xz * -(FNLfloat)0.211324865405187;
y *= (FNLfloat)0.577350269189626;
x += s2 - y;
z += s2 - y;
y += xz * (FNLfloat)0.577350269189626;
}
break;
case TransformType3D.DefaultOpenSimplex2:
{
const FNLfloat R3 = (FNLfloat)(2.0 / 3.0);
FNLfloat r = (x + y + z) * R3; // Rotation, not skew
x = r - x;
y = r - y;
z = r - z;
}
break;
default:
break;
}
}
private void UpdateTransformType3D()
{
switch (mRotationType3D)
{
case RotationType3D.ImproveXYPlanes:
mTransformType3D = TransformType3D.ImproveXYPlanes;
break;
case RotationType3D.ImproveXZPlanes:
mTransformType3D = TransformType3D.ImproveXZPlanes;
break;
default:
switch (mNoiseType)
{
case NoiseType.OpenSimplex2:
case NoiseType.OpenSimplex2S:
mTransformType3D = TransformType3D.DefaultOpenSimplex2;
break;
default:
mTransformType3D = TransformType3D.None;
break;
}
break;
}
}
// Domain Warp Coordinate Transforms
[MethodImpl(INLINE)]
private void TransformDomainWarpCoordinate(ref FNLfloat x, ref FNLfloat y)
{
switch (mDomainWarpType)
{
case DomainWarpType.OpenSimplex2:
case DomainWarpType.OpenSimplex2Reduced:
{
const FNLfloat SQRT3 = (FNLfloat)1.7320508075688772935274463415059;
const FNLfloat F2 = 0.5f * (SQRT3 - 1);
FNLfloat t = (x + y) * F2;
x += t; y += t;
}
break;
default:
break;
}
}
[MethodImpl(INLINE)]
private void TransformDomainWarpCoordinate(ref FNLfloat x, ref FNLfloat y, ref FNLfloat z)
{
switch (mWarpTransformType3D)
{
case TransformType3D.ImproveXYPlanes:
{
FNLfloat xy = x + y;
FNLfloat s2 = xy * -(FNLfloat)0.211324865405187;
z *= (FNLfloat)0.577350269189626;
x += s2 - z;
y = y + s2 - z;
z += xy * (FNLfloat)0.577350269189626;
}
break;
case TransformType3D.ImproveXZPlanes:
{
FNLfloat xz = x + z;
FNLfloat s2 = xz * -(FNLfloat)0.211324865405187;
y *= (FNLfloat)0.577350269189626;
x += s2 - y; z += s2 - y;
y += xz * (FNLfloat)0.577350269189626;
}
break;
case TransformType3D.DefaultOpenSimplex2:
{
const FNLfloat R3 = (FNLfloat)(2.0 / 3.0);
FNLfloat r = (x + y + z) * R3; // Rotation, not skew
x = r - x;
y = r - y;
z = r - z;
}
break;
default:
break;
}
}
private void UpdateWarpTransformType3D()
{
switch (mRotationType3D)
{
case RotationType3D.ImproveXYPlanes:
mWarpTransformType3D = TransformType3D.ImproveXYPlanes;
break;
case RotationType3D.ImproveXZPlanes:
mWarpTransformType3D = TransformType3D.ImproveXZPlanes;
break;
default:
switch (mDomainWarpType)
{
case DomainWarpType.OpenSimplex2:
case DomainWarpType.OpenSimplex2Reduced:
mWarpTransformType3D = TransformType3D.DefaultOpenSimplex2;
break;
default:
mWarpTransformType3D = TransformType3D.None;
break;
}
break;
}
}
// Fractal FBm
private float GenFractalFBm(FNLfloat x, FNLfloat y)
{
int seed = mSeed;
float sum = 0;
float amp = mFractalBounding;
for (int i = 0; i < mOctaves; i++)
{
float noise = GenNoiseSingle(seed++, x, y);
sum += noise * amp;
amp *= Lerp(1.0f, FastMin(noise + 1, 2) * 0.5f, mWeightedStrength);
x *= mLacunarity;
y *= mLacunarity;
amp *= mGain;
}
return sum;
}
private float GenFractalFBm(FNLfloat x, FNLfloat y, FNLfloat z)
{
int seed = mSeed;
float sum = 0;
float amp = mFractalBounding;
for (int i = 0; i < mOctaves; i++)
{
float noise = GenNoiseSingle(seed++, x, y, z);
sum += noise * amp;
amp *= Lerp(1.0f, (noise + 1) * 0.5f, mWeightedStrength);
x *= mLacunarity;
y *= mLacunarity;
z *= mLacunarity;
amp *= mGain;
}
return sum;
}
// Fractal Ridged
private float GenFractalRidged(FNLfloat x, FNLfloat y)
{
int seed = mSeed;
float sum = 0;
float amp = mFractalBounding;
for (int i = 0; i < mOctaves; i++)
{
float noise = FastAbs(GenNoiseSingle(seed++, x, y));
sum += (noise * -2 + 1) * amp;
amp *= Lerp(1.0f, 1 - noise, mWeightedStrength);
x *= mLacunarity;
y *= mLacunarity;
amp *= mGain;
}
return sum;
}
private float GenFractalRidged(FNLfloat x, FNLfloat y, FNLfloat z)
{
int seed = mSeed;
float sum = 0;
float amp = mFractalBounding;
for (int i = 0; i < mOctaves; i++)
{
float noise = FastAbs(GenNoiseSingle(seed++, x, y, z));
sum += (noise * -2 + 1) * amp;
amp *= Lerp(1.0f, 1 - noise, mWeightedStrength);
x *= mLacunarity;
y *= mLacunarity;
z *= mLacunarity;
amp *= mGain;
}
return sum;
}
// Fractal PingPong
private float GenFractalPingPong(FNLfloat x, FNLfloat y)
{
int seed = mSeed;
float sum = 0;
float amp = mFractalBounding;
for (int i = 0; i < mOctaves; i++)
{
float noise = PingPong((GenNoiseSingle(seed++, x, y) + 1) * mPingPongStrength);
sum += (noise - 0.5f) * 2 * amp;
amp *= Lerp(1.0f, noise, mWeightedStrength);
x *= mLacunarity;
y *= mLacunarity;
amp *= mGain;
}
return sum;
}
private float GenFractalPingPong(FNLfloat x, FNLfloat y, FNLfloat z)
{
int seed = mSeed;
float sum = 0;
float amp = mFractalBounding;
for (int i = 0; i < mOctaves; i++)
{
float noise = PingPong((GenNoiseSingle(seed++, x, y, z) + 1) * mPingPongStrength);
sum += (noise - 0.5f) * 2 * amp;
amp *= Lerp(1.0f, noise, mWeightedStrength);
x *= mLacunarity;
y *= mLacunarity;
z *= mLacunarity;
amp *= mGain;
}
return sum;
}
// Simplex/OpenSimplex2 Noise
private float SingleSimplex(int seed, FNLfloat x, FNLfloat y)
{
// 2D OpenSimplex2 case uses the same algorithm as ordinary Simplex.
const float SQRT3 = 1.7320508075688772935274463415059f;
const float G2 = (3 - SQRT3) / 6;
/*
* --- Skew moved to TransformNoiseCoordinate method ---
* const FNfloat F2 = 0.5f * (SQRT3 - 1);
* FNfloat s = (x + y) * F2;
* x += s; y += s;
*/
int i = FastFloor(x);
int j = FastFloor(y);
float xi = (float)(x - i);
float yi = (float)(y - j);
float t = (xi + yi) * G2;
float x0 = (float)(xi - t);
float y0 = (float)(yi - t);
i *= PrimeX;
j *= PrimeY;
float n0, n1, n2;
float a = 0.5f - x0 * x0 - y0 * y0;
if (a <= 0) n0 = 0;
else
{
n0 = (a * a) * (a * a) * GradCoord(seed, i, j, x0, y0);
}
float c = (float)(2 * (1 - 2 * G2) * (1 / G2 - 2)) * t + ((float)(-2 * (1 - 2 * G2) * (1 - 2 * G2)) + a);
if (c <= 0) n2 = 0;
else
{
float x2 = x0 + (2 * (float)G2 - 1);
float y2 = y0 + (2 * (float)G2 - 1);
n2 = (c * c) * (c * c) * GradCoord(seed, i + PrimeX, j + PrimeY, x2, y2);
}
if (y0 > x0)
{
float x1 = x0 + (float)G2;
float y1 = y0 + ((float)G2 - 1);
float b = 0.5f - x1 * x1 - y1 * y1;
if (b <= 0) n1 = 0;
else
{
n1 = (b * b) * (b * b) * GradCoord(seed, i, j + PrimeY, x1, y1);
}
}
else
{
float x1 = x0 + ((float)G2 - 1);
float y1 = y0 + (float)G2;
float b = 0.5f - x1 * x1 - y1 * y1;
if (b <= 0) n1 = 0;
else
{
n1 = (b * b) * (b * b) * GradCoord(seed, i + PrimeX, j, x1, y1);
}
}
return (n0 + n1 + n2) * 99.83685446303647f;
}
private float SingleOpenSimplex2(int seed, FNLfloat x, FNLfloat y, FNLfloat z)
{
// 3D OpenSimplex2 case uses two offset rotated cube grids.
/*
* --- Rotation moved to TransformNoiseCoordinate method ---
* const FNfloat R3 = (FNfloat)(2.0 / 3.0);
* FNfloat r = (x + y + z) * R3; // Rotation, not skew
* x = r - x; y = r - y; z = r - z;
*/
int i = FastRound(x);
int j = FastRound(y);
int k = FastRound(z);
float x0 = (float)(x - i);
float y0 = (float)(y - j);
float z0 = (float)(z - k);
int xNSign = (int)(-1.0f - x0) | 1;
int yNSign = (int)(-1.0f - y0) | 1;
int zNSign = (int)(-1.0f - z0) | 1;
float ax0 = xNSign * -x0;
float ay0 = yNSign * -y0;
float az0 = zNSign * -z0;
i *= PrimeX;
j *= PrimeY;
k *= PrimeZ;
float value = 0;
float a = (0.6f - x0 * x0) - (y0 * y0 + z0 * z0);
for (int l = 0; ; l++)
{
if (a > 0)
{
value += (a * a) * (a * a) * GradCoord(seed, i, j, k, x0, y0, z0);
}
if (ax0 >= ay0 && ax0 >= az0)
{
float b = a + ax0 + ax0;
if (b > 1) {
b -= 1;
value += (b * b) * (b * b) * GradCoord(seed, i - xNSign * PrimeX, j, k, x0 + xNSign, y0, z0);
}
}
else if (ay0 > ax0 && ay0 >= az0)
{
float b = a + ay0 + ay0;
if (b > 1)
{
b -= 1;
value += (b * b) * (b * b) * GradCoord(seed, i, j - yNSign * PrimeY, k, x0, y0 + yNSign, z0);
}
}
else
{
float b = a + az0 + az0;
if (b > 1)
{
b -= 1;
value += (b * b) * (b * b) * GradCoord(seed, i, j, k - zNSign * PrimeZ, x0, y0, z0 + zNSign);
}
}
if (l == 1) break;
ax0 = 0.5f - ax0;
ay0 = 0.5f - ay0;
az0 = 0.5f - az0;
x0 = xNSign * ax0;
y0 = yNSign * ay0;
z0 = zNSign * az0;
a += (0.75f - ax0) - (ay0 + az0);
i += (xNSign >> 1) & PrimeX;
j += (yNSign >> 1) & PrimeY;
k += (zNSign >> 1) & PrimeZ;
xNSign = -xNSign;
yNSign = -yNSign;
zNSign = -zNSign;
seed = ~seed;
}
return value * 32.69428253173828125f;
}
// OpenSimplex2S Noise
private float SingleOpenSimplex2S(int seed, FNLfloat x, FNLfloat y)
{
// 2D OpenSimplex2S case is a modified 2D simplex noise.
const FNLfloat SQRT3 = (FNLfloat)1.7320508075688772935274463415059;
const FNLfloat G2 = (3 - SQRT3) / 6;
/*
* --- Skew moved to TransformNoiseCoordinate method ---
* const FNfloat F2 = 0.5f * (SQRT3 - 1);
* FNfloat s = (x + y) * F2;
* x += s; y += s;
*/
int i = FastFloor(x);
int j = FastFloor(y);
float xi = (float)(x - i);
float yi = (float)(y - j);
i *= PrimeX;
j *= PrimeY;
int i1 = i + PrimeX;
int j1 = j + PrimeY;
float t = (xi + yi) * (float)G2;
float x0 = xi - t;
float y0 = yi - t;
float a0 = (2.0f / 3.0f) - x0 * x0 - y0 * y0;
float value = (a0 * a0) * (a0 * a0) * GradCoord(seed, i, j, x0, y0);
float a1 = (float)(2 * (1 - 2 * G2) * (1 / G2 - 2)) * t + ((float)(-2 * (1 - 2 * G2) * (1 - 2 * G2)) + a0);
float x1 = x0 - (float)(1 - 2 * G2);
float y1 = y0 - (float)(1 - 2 * G2);
value += (a1 * a1) * (a1 * a1) * GradCoord(seed, i1, j1, x1, y1);
// Nested conditionals were faster than compact bit logic/arithmetic.
float xmyi = xi - yi;
if (t > G2)
{
if (xi + xmyi > 1)
{
float x2 = x0 + (float)(3 * G2 - 2);
float y2 = y0 + (float)(3 * G2 - 1);
float a2 = (2.0f / 3.0f) - x2 * x2 - y2 * y2;
if (a2 > 0)
{
value += (a2 * a2) * (a2 * a2) * GradCoord(seed, i + (PrimeX << 1), j + PrimeY, x2, y2);
}
}
else
{
float x2 = x0 + (float)G2;
float y2 = y0 + (float)(G2 - 1);
float a2 = (2.0f / 3.0f) - x2 * x2 - y2 * y2;
if (a2 > 0)
{
value += (a2 * a2) * (a2 * a2) * GradCoord(seed, i, j + PrimeY, x2, y2);
}
}
if (yi - xmyi > 1)
{
float x3 = x0 + (float)(3 * G2 - 1);
float y3 = y0 + (float)(3 * G2 - 2);
float a3 = (2.0f / 3.0f) - x3 * x3 - y3 * y3;
if (a3 > 0)
{
value += (a3 * a3) * (a3 * a3) * GradCoord(seed, i + PrimeX, j + (PrimeY << 1), x3, y3);
}
}
else
{
float x3 = x0 + (float)(G2 - 1);
float y3 = y0 + (float)G2;
float a3 = (2.0f / 3.0f) - x3 * x3 - y3 * y3;
if (a3 > 0)
{
value += (a3 * a3) * (a3 * a3) * GradCoord(seed, i + PrimeX, j, x3, y3);
}
}
}
else
{
if (xi + xmyi < 0)
{
float x2 = x0 + (float)(1 - G2);
float y2 = y0 - (float)G2;
float a2 = (2.0f / 3.0f) - x2 * x2 - y2 * y2;
if (a2 > 0)
{
value += (a2 * a2) * (a2 * a2) * GradCoord(seed, i - PrimeX, j, x2, y2);
}
}
else
{
float x2 = x0 + (float)(G2 - 1);
float y2 = y0 + (float)G2;
float a2 = (2.0f / 3.0f) - x2 * x2 - y2 * y2;
if (a2 > 0)
{
value += (a2 * a2) * (a2 * a2) * GradCoord(seed, i + PrimeX, j, x2, y2);
}
}
if (yi < xmyi)
{
float x2 = x0 - (float)G2;
float y2 = y0 - (float)(G2 - 1);
float a2 = (2.0f / 3.0f) - x2 * x2 - y2 * y2;
if (a2 > 0)
{
value += (a2 * a2) * (a2 * a2) * GradCoord(seed, i, j - PrimeY, x2, y2);
}
}
else
{
float x2 = x0 + (float)G2;
float y2 = y0 + (float)(G2 - 1);
float a2 = (2.0f / 3.0f) - x2 * x2 - y2 * y2;
if (a2 > 0)
{
value += (a2 * a2) * (a2 * a2) * GradCoord(seed, i, j + PrimeY, x2, y2);
}
}
}
return value * 18.24196194486065f;
}
private float SingleOpenSimplex2S(int seed, FNLfloat x, FNLfloat y, FNLfloat z)
{
// 3D OpenSimplex2S case uses two offset rotated cube grids.
/*
* --- Rotation moved to TransformNoiseCoordinate method ---
* const FNfloat R3 = (FNfloat)(2.0 / 3.0);
* FNfloat r = (x + y + z) * R3; // Rotation, not skew
* x = r - x; y = r - y; z = r - z;
*/
int i = FastFloor(x);
int j = FastFloor(y);
int k = FastFloor(z);
float xi = (float)(x - i);
float yi = (float)(y - j);
float zi = (float)(z - k);
i *= PrimeX;
j *= PrimeY;
k *= PrimeZ;
int seed2 = seed + 1293373;
int xNMask = (int)(-0.5f - xi);
int yNMask = (int)(-0.5f - yi);
int zNMask = (int)(-0.5f - zi);
float x0 = xi + xNMask;
float y0 = yi + yNMask;
float z0 = zi + zNMask;
float a0 = 0.75f - x0 * x0 - y0 * y0 - z0 * z0;
float value = (a0 * a0) * (a0 * a0) * GradCoord(seed,
i + (xNMask & PrimeX), j + (yNMask & PrimeY), k + (zNMask & PrimeZ), x0, y0, z0);
float x1 = xi - 0.5f;
float y1 = yi - 0.5f;
float z1 = zi - 0.5f;
float a1 = 0.75f - x1 * x1 - y1 * y1 - z1 * z1;
value += (a1 * a1) * (a1 * a1) * GradCoord(seed2,
i + PrimeX, j + PrimeY, k + PrimeZ, x1, y1, z1);
float xAFlipMask0 = ((xNMask | 1) << 1) * x1;
float yAFlipMask0 = ((yNMask | 1) << 1) * y1;
float zAFlipMask0 = ((zNMask | 1) << 1) * z1;
float xAFlipMask1 = (-2 - (xNMask << 2)) * x1 - 1.0f;
float yAFlipMask1 = (-2 - (yNMask << 2)) * y1 - 1.0f;
float zAFlipMask1 = (-2 - (zNMask << 2)) * z1 - 1.0f;
bool skip5 = false;
float a2 = xAFlipMask0 + a0;
if (a2 > 0)
{
float x2 = x0 - (xNMask | 1);
float y2 = y0;
float z2 = z0;
value += (a2 * a2) * (a2 * a2) * GradCoord(seed,
i + (~xNMask & PrimeX), j + (yNMask & PrimeY), k + (zNMask & PrimeZ), x2, y2, z2);
}
else
{
float a3 = yAFlipMask0 + zAFlipMask0 + a0;
if (a3 > 0)
{
float x3 = x0;
float y3 = y0 - (yNMask | 1);
float z3 = z0 - (zNMask | 1);
value += (a3 * a3) * (a3 * a3) * GradCoord(seed,
i + (xNMask & PrimeX), j + (~yNMask & PrimeY), k + (~zNMask & PrimeZ), x3, y3, z3);
}
float a4 = xAFlipMask1 + a1;
if (a4 > 0)
{
float x4 = (xNMask | 1) + x1;
float y4 = y1;
float z4 = z1;
value += (a4 * a4) * (a4 * a4) * GradCoord(seed2,
i + (xNMask & (PrimeX * 2)), j + PrimeY, k + PrimeZ, x4, y4, z4);
skip5 = true;
}
}
bool skip9 = false;
float a6 = yAFlipMask0 + a0;
if (a6 > 0)
{
float x6 = x0;
float y6 = y0 - (yNMask | 1);
float z6 = z0;
value += (a6 * a6) * (a6 * a6) * GradCoord(seed,
i + (xNMask & PrimeX), j + (~yNMask & PrimeY), k + (zNMask & PrimeZ), x6, y6, z6);
}
else
{
float a7 = xAFlipMask0 + zAFlipMask0 + a0;
if (a7 > 0)
{
float x7 = x0 - (xNMask | 1);
float y7 = y0;
float z7 = z0 - (zNMask | 1);
value += (a7 * a7) * (a7 * a7) * GradCoord(seed,
i + (~xNMask & PrimeX), j + (yNMask & PrimeY), k + (~zNMask & PrimeZ), x7, y7, z7);
}
float a8 = yAFlipMask1 + a1;
if (a8 > 0)
{
float x8 = x1;
float y8 = (yNMask | 1) + y1;
float z8 = z1;
value += (a8 * a8) * (a8 * a8) * GradCoord(seed2,
i + PrimeX, j + (yNMask & (PrimeY << 1)), k + PrimeZ, x8, y8, z8);
skip9 = true;
}
}
bool skipD = false;
float aA = zAFlipMask0 + a0;
if (aA > 0)
{
float xA = x0;
float yA = y0;
float zA = z0 - (zNMask | 1);
value += (aA * aA) * (aA * aA) * GradCoord(seed,
i + (xNMask & PrimeX), j + (yNMask & PrimeY), k + (~zNMask & PrimeZ), xA, yA, zA);
}
else
{
float aB = xAFlipMask0 + yAFlipMask0 + a0;
if (aB > 0)
{
float xB = x0 - (xNMask | 1);
float yB = y0 - (yNMask | 1);
float zB = z0;
value += (aB * aB) * (aB * aB) * GradCoord(seed,
i + (~xNMask & PrimeX), j + (~yNMask & PrimeY), k + (zNMask & PrimeZ), xB, yB, zB);
}
float aC = zAFlipMask1 + a1;
if (aC > 0)
{
float xC = x1;
float yC = y1;
float zC = (zNMask | 1) + z1;
value += (aC * aC) * (aC * aC) * GradCoord(seed2,
i + PrimeX, j + PrimeY, k + (zNMask & (PrimeZ << 1)), xC, yC, zC);
skipD = true;
}
}
if (!skip5)
{
float a5 = yAFlipMask1 + zAFlipMask1 + a1;
if (a5 > 0)
{
float x5 = x1;
float y5 = (yNMask | 1) + y1;
float z5 = (zNMask | 1) + z1;
value += (a5 * a5) * (a5 * a5) * GradCoord(seed2,
i + PrimeX, j + (yNMask & (PrimeY << 1)), k + (zNMask & (PrimeZ << 1)), x5, y5, z5);
}
}
if (!skip9)
{
float a9 = xAFlipMask1 + zAFlipMask1 + a1;
if (a9 > 0)
{
float x9 = (xNMask | 1) + x1;
float y9 = y1;
float z9 = (zNMask | 1) + z1;
value += (a9 * a9) * (a9 * a9) * GradCoord(seed2,
i + (xNMask & (PrimeX * 2)), j + PrimeY, k + (zNMask & (PrimeZ << 1)), x9, y9, z9);
}
}
if (!skipD)
{
float aD = xAFlipMask1 + yAFlipMask1 + a1;
if (aD > 0)
{
float xD = (xNMask | 1) + x1;
float yD = (yNMask | 1) + y1;
float zD = z1;
value += (aD * aD) * (aD * aD) * GradCoord(seed2,
i + (xNMask & (PrimeX << 1)), j + (yNMask & (PrimeY << 1)), k + PrimeZ, xD, yD, zD);
}
}
return value * 9.046026385208288f;
}
// Cellular Noise
private float SingleCellular(int seed, FNLfloat x, FNLfloat y)
{
int xr = FastRound(x);
int yr = FastRound(y);
float distance0 = float.MaxValue;
float distance1 = float.MaxValue;
int closestHash = 0;
float cellularJitter = 0.43701595f * mCellularJitterModifier;
int xPrimed = (xr - 1) * PrimeX;
int yPrimedBase = (yr - 1) * PrimeY;
switch (mCellularDistanceFunction)
{
default:
case CellularDistanceFunction.Euclidean:
case CellularDistanceFunction.EuclideanSq:
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int hash = Hash(seed, xPrimed, yPrimed);
int idx = hash & (255 << 1);
float vecX = (float)(xi - x) + RandVecs2D[idx] * cellularJitter;
float vecY = (float)(yi - y) + RandVecs2D[idx | 1] * cellularJitter;
float newDistance = vecX * vecX + vecY * vecY;
distance1 = FastMax(FastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
yPrimed += PrimeY;
}
xPrimed += PrimeX;
}
break;
case CellularDistanceFunction.Manhattan:
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int hash = Hash(seed, xPrimed, yPrimed);
int idx = hash & (255 << 1);
float vecX = (float)(xi - x) + RandVecs2D[idx] * cellularJitter;
float vecY = (float)(yi - y) + RandVecs2D[idx | 1] * cellularJitter;
float newDistance = FastAbs(vecX) + FastAbs(vecY);
distance1 = FastMax(FastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
yPrimed += PrimeY;
}
xPrimed += PrimeX;
}
break;
case CellularDistanceFunction.Hybrid:
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int hash = Hash(seed, xPrimed, yPrimed);
int idx = hash & (255 << 1);
float vecX = (float)(xi - x) + RandVecs2D[idx] * cellularJitter;
float vecY = (float)(yi - y) + RandVecs2D[idx | 1] * cellularJitter;
float newDistance = (FastAbs(vecX) + FastAbs(vecY)) + (vecX * vecX + vecY * vecY);
distance1 = FastMax(FastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
yPrimed += PrimeY;
}
xPrimed += PrimeX;
}
break;
}
if (mCellularDistanceFunction == CellularDistanceFunction.Euclidean && mCellularReturnType >= CellularReturnType.Distance)
{
distance0 = FastSqrt(distance0);
if (mCellularReturnType >= CellularReturnType.Distance2)
{
distance1 = FastSqrt(distance1);
}
}
switch (mCellularReturnType)
{
case CellularReturnType.CellValue:
return closestHash * (1 / 2147483648.0f);
case CellularReturnType.Distance:
return distance0 - 1;
case CellularReturnType.Distance2:
return distance1 - 1;
case CellularReturnType.Distance2Add:
return (distance1 + distance0) * 0.5f - 1;
case CellularReturnType.Distance2Sub:
return distance1 - distance0 - 1;
case CellularReturnType.Distance2Mul:
return distance1 * distance0 * 0.5f - 1;
case CellularReturnType.Distance2Div:
return distance0 / distance1 - 1;
default:
return 0;
}
}
private float SingleCellular(int seed, FNLfloat x, FNLfloat y, FNLfloat z)
{
int xr = FastRound(x);
int yr = FastRound(y);
int zr = FastRound(z);
float distance0 = float.MaxValue;
float distance1 = float.MaxValue;
int closestHash = 0;
float cellularJitter = 0.39614353f * mCellularJitterModifier;
int xPrimed = (xr - 1) * PrimeX;
int yPrimedBase = (yr - 1) * PrimeY;
int zPrimedBase = (zr - 1) * PrimeZ;
switch (mCellularDistanceFunction)
{
case CellularDistanceFunction.Euclidean:
case CellularDistanceFunction.EuclideanSq:
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int zPrimed = zPrimedBase;
for (int zi = zr - 1; zi <= zr + 1; zi++)
{
int hash = Hash(seed, xPrimed, yPrimed, zPrimed);
int idx = hash & (255 << 2);
float vecX = (float)(xi - x) + RandVecs3D[idx] * cellularJitter;
float vecY = (float)(yi - y) + RandVecs3D[idx | 1] * cellularJitter;
float vecZ = (float)(zi - z) + RandVecs3D[idx | 2] * cellularJitter;
float newDistance = vecX * vecX + vecY * vecY + vecZ * vecZ;
distance1 = FastMax(FastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
zPrimed += PrimeZ;
}
yPrimed += PrimeY;
}
xPrimed += PrimeX;
}
break;
case CellularDistanceFunction.Manhattan:
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int zPrimed = zPrimedBase;
for (int zi = zr - 1; zi <= zr + 1; zi++)
{
int hash = Hash(seed, xPrimed, yPrimed, zPrimed);
int idx = hash & (255 << 2);
float vecX = (float)(xi - x) + RandVecs3D[idx] * cellularJitter;
float vecY = (float)(yi - y) + RandVecs3D[idx | 1] * cellularJitter;
float vecZ = (float)(zi - z) + RandVecs3D[idx | 2] * cellularJitter;
float newDistance = FastAbs(vecX) + FastAbs(vecY) + FastAbs(vecZ);
distance1 = FastMax(FastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
zPrimed += PrimeZ;
}
yPrimed += PrimeY;
}
xPrimed += PrimeX;
}
break;
case CellularDistanceFunction.Hybrid:
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int zPrimed = zPrimedBase;
for (int zi = zr - 1; zi <= zr + 1; zi++)
{
int hash = Hash(seed, xPrimed, yPrimed, zPrimed);
int idx = hash & (255 << 2);
float vecX = (float)(xi - x) + RandVecs3D[idx] * cellularJitter;
float vecY = (float)(yi - y) + RandVecs3D[idx | 1] * cellularJitter;
float vecZ = (float)(zi - z) + RandVecs3D[idx | 2] * cellularJitter;
float newDistance = (FastAbs(vecX) + FastAbs(vecY) + FastAbs(vecZ)) + (vecX * vecX + vecY * vecY + vecZ * vecZ);
distance1 = FastMax(FastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
zPrimed += PrimeZ;
}
yPrimed += PrimeY;
}
xPrimed += PrimeX;
}
break;
default:
break;
}
if (mCellularDistanceFunction == CellularDistanceFunction.Euclidean && mCellularReturnType >= CellularReturnType.Distance)
{
distance0 = FastSqrt(distance0);
if (mCellularReturnType >= CellularReturnType.Distance2)
{
distance1 = FastSqrt(distance1);
}
}
switch (mCellularReturnType)
{
case CellularReturnType.CellValue:
return closestHash * (1 / 2147483648.0f);
case CellularReturnType.Distance:
return distance0 - 1;
case CellularReturnType.Distance2:
return distance1 - 1;
case CellularReturnType.Distance2Add:
return (distance1 + distance0) * 0.5f - 1;
case CellularReturnType.Distance2Sub:
return distance1 - distance0 - 1;
case CellularReturnType.Distance2Mul:
return distance1 * distance0 * 0.5f - 1;
case CellularReturnType.Distance2Div:
return distance0 / distance1 - 1;
default:
return 0;
}
}
// Perlin Noise
private float SinglePerlin(int seed, FNLfloat x, FNLfloat y)
{
int x0 = FastFloor(x);
int y0 = FastFloor(y);
float xd0 = (float)(x - x0);
float yd0 = (float)(y - y0);
float xd1 = xd0 - 1;
float yd1 = yd0 - 1;
float xs = InterpQuintic(xd0);
float ys = InterpQuintic(yd0);
x0 *= PrimeX;
y0 *= PrimeY;
int x1 = x0 + PrimeX;
int y1 = y0 + PrimeY;
float xf0 = Lerp(GradCoord(seed, x0, y0, xd0, yd0), GradCoord(seed, x1, y0, xd1, yd0), xs);
float xf1 = Lerp(GradCoord(seed, x0, y1, xd0, yd1), GradCoord(seed, x1, y1, xd1, yd1), xs);
return Lerp(xf0, xf1, ys) * 1.4247691104677813f;
}
private float SinglePerlin(int seed, FNLfloat x, FNLfloat y, FNLfloat z)
{
int x0 = FastFloor(x);
int y0 = FastFloor(y);
int z0 = FastFloor(z);
float xd0 = (float)(x - x0);
float yd0 = (float)(y - y0);
float zd0 = (float)(z - z0);
float xd1 = xd0 - 1;
float yd1 = yd0 - 1;
float zd1 = zd0 - 1;
float xs = InterpQuintic(xd0);
float ys = InterpQuintic(yd0);
float zs = InterpQuintic(zd0);
x0 *= PrimeX;
y0 *= PrimeY;
z0 *= PrimeZ;
int x1 = x0 + PrimeX;
int y1 = y0 + PrimeY;
int z1 = z0 + PrimeZ;
float xf00 = Lerp(GradCoord(seed, x0, y0, z0, xd0, yd0, zd0), GradCoord(seed, x1, y0, z0, xd1, yd0, zd0), xs);
float xf10 = Lerp(GradCoord(seed, x0, y1, z0, xd0, yd1, zd0), GradCoord(seed, x1, y1, z0, xd1, yd1, zd0), xs);
float xf01 = Lerp(GradCoord(seed, x0, y0, z1, xd0, yd0, zd1), GradCoord(seed, x1, y0, z1, xd1, yd0, zd1), xs);
float xf11 = Lerp(GradCoord(seed, x0, y1, z1, xd0, yd1, zd1), GradCoord(seed, x1, y1, z1, xd1, yd1, zd1), xs);
float yf0 = Lerp(xf00, xf10, ys);
float yf1 = Lerp(xf01, xf11, ys);
return Lerp(yf0, yf1, zs) * 0.964921414852142333984375f;
}
// Value Cubic Noise
private float SingleValueCubic(int seed, FNLfloat x, FNLfloat y)
{
int x1 = FastFloor(x);
int y1 = FastFloor(y);
float xs = (float)(x - x1);
float ys = (float)(y - y1);
x1 *= PrimeX;
y1 *= PrimeY;
int x0 = x1 - PrimeX;
int y0 = y1 - PrimeY;
int x2 = x1 + PrimeX;
int y2 = y1 + PrimeY;
int x3 = x1 + unchecked(PrimeX * 2);
int y3 = y1 + unchecked(PrimeY * 2);
return CubicLerp(
CubicLerp(ValCoord(seed, x0, y0), ValCoord(seed, x1, y0), ValCoord(seed, x2, y0), ValCoord(seed, x3, y0),
xs),
CubicLerp(ValCoord(seed, x0, y1), ValCoord(seed, x1, y1), ValCoord(seed, x2, y1), ValCoord(seed, x3, y1),
xs),
CubicLerp(ValCoord(seed, x0, y2), ValCoord(seed, x1, y2), ValCoord(seed, x2, y2), ValCoord(seed, x3, y2),
xs),
CubicLerp(ValCoord(seed, x0, y3), ValCoord(seed, x1, y3), ValCoord(seed, x2, y3), ValCoord(seed, x3, y3),
xs),
ys) * (1 / (1.5f * 1.5f));
}
private float SingleValueCubic(int seed, FNLfloat x, FNLfloat y, FNLfloat z)
{
int x1 = FastFloor(x);
int y1 = FastFloor(y);
int z1 = FastFloor(z);
float xs = (float)(x - x1);
float ys = (float)(y - y1);
float zs = (float)(z - z1);
x1 *= PrimeX;
y1 *= PrimeY;
z1 *= PrimeZ;
int x0 = x1 - PrimeX;
int y0 = y1 - PrimeY;
int z0 = z1 - PrimeZ;
int x2 = x1 + PrimeX;
int y2 = y1 + PrimeY;
int z2 = z1 + PrimeZ;
int x3 = x1 + unchecked(PrimeX * 2);
int y3 = y1 + unchecked(PrimeY * 2);
int z3 = z1 + unchecked(PrimeZ * 2);
return CubicLerp(
CubicLerp(
CubicLerp(ValCoord(seed, x0, y0, z0), ValCoord(seed, x1, y0, z0), ValCoord(seed, x2, y0, z0), ValCoord(seed, x3, y0, z0), xs),
CubicLerp(ValCoord(seed, x0, y1, z0), ValCoord(seed, x1, y1, z0), ValCoord(seed, x2, y1, z0), ValCoord(seed, x3, y1, z0), xs),
CubicLerp(ValCoord(seed, x0, y2, z0), ValCoord(seed, x1, y2, z0), ValCoord(seed, x2, y2, z0), ValCoord(seed, x3, y2, z0), xs),
CubicLerp(ValCoord(seed, x0, y3, z0), ValCoord(seed, x1, y3, z0), ValCoord(seed, x2, y3, z0), ValCoord(seed, x3, y3, z0), xs),
ys),
CubicLerp(
CubicLerp(ValCoord(seed, x0, y0, z1), ValCoord(seed, x1, y0, z1), ValCoord(seed, x2, y0, z1), ValCoord(seed, x3, y0, z1), xs),
CubicLerp(ValCoord(seed, x0, y1, z1), ValCoord(seed, x1, y1, z1), ValCoord(seed, x2, y1, z1), ValCoord(seed, x3, y1, z1), xs),
CubicLerp(ValCoord(seed, x0, y2, z1), ValCoord(seed, x1, y2, z1), ValCoord(seed, x2, y2, z1), ValCoord(seed, x3, y2, z1), xs),
CubicLerp(ValCoord(seed, x0, y3, z1), ValCoord(seed, x1, y3, z1), ValCoord(seed, x2, y3, z1), ValCoord(seed, x3, y3, z1), xs),
ys),
CubicLerp(
CubicLerp(ValCoord(seed, x0, y0, z2), ValCoord(seed, x1, y0, z2), ValCoord(seed, x2, y0, z2), ValCoord(seed, x3, y0, z2), xs),
CubicLerp(ValCoord(seed, x0, y1, z2), ValCoord(seed, x1, y1, z2), ValCoord(seed, x2, y1, z2), ValCoord(seed, x3, y1, z2), xs),
CubicLerp(ValCoord(seed, x0, y2, z2), ValCoord(seed, x1, y2, z2), ValCoord(seed, x2, y2, z2), ValCoord(seed, x3, y2, z2), xs),
CubicLerp(ValCoord(seed, x0, y3, z2), ValCoord(seed, x1, y3, z2), ValCoord(seed, x2, y3, z2), ValCoord(seed, x3, y3, z2), xs),
ys),
CubicLerp(
CubicLerp(ValCoord(seed, x0, y0, z3), ValCoord(seed, x1, y0, z3), ValCoord(seed, x2, y0, z3), ValCoord(seed, x3, y0, z3), xs),
CubicLerp(ValCoord(seed, x0, y1, z3), ValCoord(seed, x1, y1, z3), ValCoord(seed, x2, y1, z3), ValCoord(seed, x3, y1, z3), xs),
CubicLerp(ValCoord(seed, x0, y2, z3), ValCoord(seed, x1, y2, z3), ValCoord(seed, x2, y2, z3), ValCoord(seed, x3, y2, z3), xs),
CubicLerp(ValCoord(seed, x0, y3, z3), ValCoord(seed, x1, y3, z3), ValCoord(seed, x2, y3, z3), ValCoord(seed, x3, y3, z3), xs),
ys),
zs) * (1 / (1.5f * 1.5f * 1.5f));
}
// Value Noise
private float SingleValue(int seed, FNLfloat x, FNLfloat y)
{
int x0 = FastFloor(x);
int y0 = FastFloor(y);
float xs = InterpHermite((float)(x - x0));
float ys = InterpHermite((float)(y - y0));
x0 *= PrimeX;
y0 *= PrimeY;
int x1 = x0 + PrimeX;
int y1 = y0 + PrimeY;
float xf0 = Lerp(ValCoord(seed, x0, y0), ValCoord(seed, x1, y0), xs);
float xf1 = Lerp(ValCoord(seed, x0, y1), ValCoord(seed, x1, y1), xs);
return Lerp(xf0, xf1, ys);
}
private float SingleValue(int seed, FNLfloat x, FNLfloat y, FNLfloat z)
{
int x0 = FastFloor(x);
int y0 = FastFloor(y);
int z0 = FastFloor(z);
float xs = InterpHermite((float)(x - x0));
float ys = InterpHermite((float)(y - y0));
float zs = InterpHermite((float)(z - z0));
x0 *= PrimeX;
y0 *= PrimeY;
z0 *= PrimeZ;
int x1 = x0 + PrimeX;
int y1 = y0 + PrimeY;
int z1 = z0 + PrimeZ;
float xf00 = Lerp(ValCoord(seed, x0, y0, z0), ValCoord(seed, x1, y0, z0), xs);
float xf10 = Lerp(ValCoord(seed, x0, y1, z0), ValCoord(seed, x1, y1, z0), xs);
float xf01 = Lerp(ValCoord(seed, x0, y0, z1), ValCoord(seed, x1, y0, z1), xs);
float xf11 = Lerp(ValCoord(seed, x0, y1, z1), ValCoord(seed, x1, y1, z1), xs);
float yf0 = Lerp(xf00, xf10, ys);
float yf1 = Lerp(xf01, xf11, ys);
return Lerp(yf0, yf1, zs);
}
// Domain Warp
private void DoSingleDomainWarp(int seed, float amp, float freq, FNLfloat x, FNLfloat y, ref FNLfloat xr, ref FNLfloat yr)
{
switch (mDomainWarpType)
{
case DomainWarpType.OpenSimplex2:
SingleDomainWarpSimplexGradient(seed, amp * 38.283687591552734375f, freq, x, y, ref xr, ref yr, false);
break;
case DomainWarpType.OpenSimplex2Reduced:
SingleDomainWarpSimplexGradient(seed, amp * 16.0f, freq, x, y, ref xr, ref yr, true);
break;
case DomainWarpType.BasicGrid:
SingleDomainWarpBasicGrid(seed, amp, freq, x, y, ref xr, ref yr);
break;
}
}
private void DoSingleDomainWarp(int seed, float amp, float freq, FNLfloat x, FNLfloat y, FNLfloat z, ref FNLfloat xr, ref FNLfloat yr, ref FNLfloat zr)
{
switch (mDomainWarpType)
{
case DomainWarpType.OpenSimplex2:
SingleDomainWarpOpenSimplex2Gradient(seed, amp * 32.69428253173828125f, freq, x, y, z, ref xr, ref yr, ref zr, false);
break;
case DomainWarpType.OpenSimplex2Reduced:
SingleDomainWarpOpenSimplex2Gradient(seed, amp * 7.71604938271605f, freq, x, y, z, ref xr, ref yr, ref zr, true);
break;
case DomainWarpType.BasicGrid:
SingleDomainWarpBasicGrid(seed, amp, freq, x, y, z, ref xr, ref yr, ref zr);
break;
}
}
// Domain Warp Single Wrapper
private void DomainWarpSingle(ref FNLfloat x, ref FNLfloat y)
{
int seed = mSeed;
float amp = mDomainWarpAmp * mFractalBounding;
float freq = mFrequency;
FNLfloat xs = x;
FNLfloat ys = y;
TransformDomainWarpCoordinate(ref xs, ref ys);
DoSingleDomainWarp(seed, amp, freq, xs, ys, ref x, ref y);
}
private void DomainWarpSingle(ref FNLfloat x, ref FNLfloat y, ref FNLfloat z)
{
int seed = mSeed;
float amp = mDomainWarpAmp * mFractalBounding;
float freq = mFrequency;
FNLfloat xs = x;
FNLfloat ys = y;
FNLfloat zs = z;
TransformDomainWarpCoordinate(ref xs, ref ys, ref zs);
DoSingleDomainWarp(seed, amp, freq, xs, ys, zs, ref x, ref y, ref z);
}
// Domain Warp Fractal Progressive
private void DomainWarpFractalProgressive(ref FNLfloat x, ref FNLfloat y)
{
int seed = mSeed;
float amp = mDomainWarpAmp * mFractalBounding;
float freq = mFrequency;
for (int i = 0; i < mOctaves; i++)
{
FNLfloat xs = x;
FNLfloat ys = y;
TransformDomainWarpCoordinate(ref xs, ref ys);
DoSingleDomainWarp(seed, amp, freq, xs, ys, ref x, ref y);
seed++;
amp *= mGain;
freq *= mLacunarity;
}
}
private void DomainWarpFractalProgressive(ref FNLfloat x, ref FNLfloat y, ref FNLfloat z)
{
int seed = mSeed;
float amp = mDomainWarpAmp * mFractalBounding;
float freq = mFrequency;
for (int i = 0; i < mOctaves; i++)
{
FNLfloat xs = x;
FNLfloat ys = y;
FNLfloat zs = z;
TransformDomainWarpCoordinate(ref xs, ref ys, ref zs);
DoSingleDomainWarp(seed, amp, freq, xs, ys, zs, ref x, ref y, ref z);
seed++;
amp *= mGain;
freq *= mLacunarity;
}
}
// Domain Warp Fractal Independant
private void DomainWarpFractalIndependent(ref FNLfloat x, ref FNLfloat y)
{
FNLfloat xs = x;
FNLfloat ys = y;
TransformDomainWarpCoordinate(ref xs, ref ys);
int seed = mSeed;
float amp = mDomainWarpAmp * mFractalBounding;
float freq = mFrequency;
for (int i = 0; i < mOctaves; i++)
{
DoSingleDomainWarp(seed, amp, freq, xs, ys, ref x, ref y);
seed++;
amp *= mGain;
freq *= mLacunarity;
}
}
private void DomainWarpFractalIndependent(ref FNLfloat x, ref FNLfloat y, ref FNLfloat z)
{
FNLfloat xs = x;
FNLfloat ys = y;
FNLfloat zs = z;
TransformDomainWarpCoordinate(ref xs, ref ys, ref zs);
int seed = mSeed;
float amp = mDomainWarpAmp * mFractalBounding;
float freq = mFrequency;
for (int i = 0; i < mOctaves; i++)
{
DoSingleDomainWarp(seed, amp, freq, xs, ys, zs, ref x, ref y, ref z);
seed++;
amp *= mGain;
freq *= mLacunarity;
}
}
// Domain Warp Basic Grid
private void SingleDomainWarpBasicGrid(int seed, float warpAmp, float frequency, FNLfloat x, FNLfloat y, ref FNLfloat xr, ref FNLfloat yr)
{
FNLfloat xf = x * frequency;
FNLfloat yf = y * frequency;
int x0 = FastFloor(xf);
int y0 = FastFloor(yf);
float xs = InterpHermite((float)(xf - x0));
float ys = InterpHermite((float)(yf - y0));
x0 *= PrimeX;
y0 *= PrimeY;
int x1 = x0 + PrimeX;
int y1 = y0 + PrimeY;
int hash0 = Hash(seed, x0, y0) & (255 << 1);
int hash1 = Hash(seed, x1, y0) & (255 << 1);
float lx0x = Lerp(RandVecs2D[hash0], RandVecs2D[hash1], xs);
float ly0x = Lerp(RandVecs2D[hash0 | 1], RandVecs2D[hash1 | 1], xs);
hash0 = Hash(seed, x0, y1) & (255 << 1);
hash1 = Hash(seed, x1, y1) & (255 << 1);
float lx1x = Lerp(RandVecs2D[hash0], RandVecs2D[hash1], xs);
float ly1x = Lerp(RandVecs2D[hash0 | 1], RandVecs2D[hash1 | 1], xs);
xr += Lerp(lx0x, lx1x, ys) * warpAmp;
yr += Lerp(ly0x, ly1x, ys) * warpAmp;
}
private void SingleDomainWarpBasicGrid(int seed, float warpAmp, float frequency, FNLfloat x, FNLfloat y, FNLfloat z, ref FNLfloat xr, ref FNLfloat yr, ref FNLfloat zr)
{
FNLfloat xf = x * frequency;
FNLfloat yf = y * frequency;
FNLfloat zf = z * frequency;
int x0 = FastFloor(xf);
int y0 = FastFloor(yf);
int z0 = FastFloor(zf);
float xs = InterpHermite((float)(xf - x0));
float ys = InterpHermite((float)(yf - y0));
float zs = InterpHermite((float)(zf - z0));
x0 *= PrimeX;
y0 *= PrimeY;
z0 *= PrimeZ;
int x1 = x0 + PrimeX;
int y1 = y0 + PrimeY;
int z1 = z0 + PrimeZ;
int hash0 = Hash(seed, x0, y0, z0) & (255 << 2);
int hash1 = Hash(seed, x1, y0, z0) & (255 << 2);
float lx0x = Lerp(RandVecs3D[hash0], RandVecs3D[hash1], xs);
float ly0x = Lerp(RandVecs3D[hash0 | 1], RandVecs3D[hash1 | 1], xs);
float lz0x = Lerp(RandVecs3D[hash0 | 2], RandVecs3D[hash1 | 2], xs);
hash0 = Hash(seed, x0, y1, z0) & (255 << 2);
hash1 = Hash(seed, x1, y1, z0) & (255 << 2);
float lx1x = Lerp(RandVecs3D[hash0], RandVecs3D[hash1], xs);
float ly1x = Lerp(RandVecs3D[hash0 | 1], RandVecs3D[hash1 | 1], xs);
float lz1x = Lerp(RandVecs3D[hash0 | 2], RandVecs3D[hash1 | 2], xs);
float lx0y = Lerp(lx0x, lx1x, ys);
float ly0y = Lerp(ly0x, ly1x, ys);
float lz0y = Lerp(lz0x, lz1x, ys);
hash0 = Hash(seed, x0, y0, z1) & (255 << 2);
hash1 = Hash(seed, x1, y0, z1) & (255 << 2);
lx0x = Lerp(RandVecs3D[hash0], RandVecs3D[hash1], xs);
ly0x = Lerp(RandVecs3D[hash0 | 1], RandVecs3D[hash1 | 1], xs);
lz0x = Lerp(RandVecs3D[hash0 | 2], RandVecs3D[hash1 | 2], xs);
hash0 = Hash(seed, x0, y1, z1) & (255 << 2);
hash1 = Hash(seed, x1, y1, z1) & (255 << 2);
lx1x = Lerp(RandVecs3D[hash0], RandVecs3D[hash1], xs);
ly1x = Lerp(RandVecs3D[hash0 | 1], RandVecs3D[hash1 | 1], xs);
lz1x = Lerp(RandVecs3D[hash0 | 2], RandVecs3D[hash1 | 2], xs);
xr += Lerp(lx0y, Lerp(lx0x, lx1x, ys), zs) * warpAmp;
yr += Lerp(ly0y, Lerp(ly0x, ly1x, ys), zs) * warpAmp;
zr += Lerp(lz0y, Lerp(lz0x, lz1x, ys), zs) * warpAmp;
}
// Domain Warp Simplex/OpenSimplex2
private void SingleDomainWarpSimplexGradient(int seed, float warpAmp, float frequency, FNLfloat x, FNLfloat y, ref FNLfloat xr, ref FNLfloat yr, bool outGradOnly)
{
const float SQRT3 = 1.7320508075688772935274463415059f;
const float G2 = (3 - SQRT3) / 6;
x *= frequency;
y *= frequency;
/*
* --- Skew moved to TransformNoiseCoordinate method ---
* const FNfloat F2 = 0.5f * (SQRT3 - 1);
* FNfloat s = (x + y) * F2;
* x += s; y += s;
*/
int i = FastFloor(x);
int j = FastFloor(y);
float xi = (float)(x - i);
float yi = (float)(y - j);
float t = (xi + yi) * G2;
float x0 = (float)(xi - t);
float y0 = (float)(yi - t);
i *= PrimeX;
j *= PrimeY;
float vx, vy;
vx = vy = 0;
float a = 0.5f - x0 * x0 - y0 * y0;
if (a > 0)
{
float aaaa = (a * a) * (a * a);
float xo, yo;
if (outGradOnly)
GradCoordOut(seed, i, j, out xo, out yo);
else
GradCoordDual(seed, i, j, x0, y0, out xo, out yo);
vx += aaaa * xo;
vy += aaaa * yo;
}
float c = (float)(2 * (1 - 2 * G2) * (1 / G2 - 2)) * t + ((float)(-2 * (1 - 2 * G2) * (1 - 2 * G2)) + a);
if (c > 0)
{
float x2 = x0 + (2 * (float)G2 - 1);
float y2 = y0 + (2 * (float)G2 - 1);
float cccc = (c * c) * (c * c);
float xo, yo;
if (outGradOnly)
GradCoordOut(seed, i + PrimeX, j + PrimeY, out xo, out yo);
else
GradCoordDual(seed, i + PrimeX, j + PrimeY, x2, y2, out xo, out yo);
vx += cccc * xo;
vy += cccc * yo;
}
if (y0 > x0)
{
float x1 = x0 + (float)G2;
float y1 = y0 + ((float)G2 - 1);
float b = 0.5f - x1 * x1 - y1 * y1;
if (b > 0)
{
float bbbb = (b * b) * (b * b);
float xo, yo;
if (outGradOnly)
GradCoordOut(seed, i, j + PrimeY, out xo, out yo);
else
GradCoordDual(seed, i, j + PrimeY, x1, y1, out xo, out yo);
vx += bbbb * xo;
vy += bbbb * yo;
}
}
else
{
float x1 = x0 + ((float)G2 - 1);
float y1 = y0 + (float)G2;
float b = 0.5f - x1 * x1 - y1 * y1;
if (b > 0)
{
float bbbb = (b * b) * (b * b);
float xo, yo;
if (outGradOnly)
GradCoordOut(seed, i + PrimeX, j, out xo, out yo);
else
GradCoordDual(seed, i + PrimeX, j, x1, y1, out xo, out yo);
vx += bbbb * xo;
vy += bbbb * yo;
}
}
xr += vx * warpAmp;
yr += vy * warpAmp;
}
private void SingleDomainWarpOpenSimplex2Gradient(int seed, float warpAmp, float frequency, FNLfloat x, FNLfloat y, FNLfloat z, ref FNLfloat xr, ref FNLfloat yr, ref FNLfloat zr, bool outGradOnly)
{
x *= frequency;
y *= frequency;
z *= frequency;
/*
* --- Rotation moved to TransformDomainWarpCoordinate method ---
* const FNfloat R3 = (FNfloat)(2.0 / 3.0);
* FNfloat r = (x + y + z) * R3; // Rotation, not skew
* x = r - x; y = r - y; z = r - z;
*/
int i = FastRound(x);
int j = FastRound(y);
int k = FastRound(z);
float x0 = (float)x - i;
float y0 = (float)y - j;
float z0 = (float)z - k;
int xNSign = (int)(-x0 - 1.0f) | 1;
int yNSign = (int)(-y0 - 1.0f) | 1;
int zNSign = (int)(-z0 - 1.0f) | 1;
float ax0 = xNSign * -x0;
float ay0 = yNSign * -y0;
float az0 = zNSign * -z0;
i *= PrimeX;
j *= PrimeY;
k *= PrimeZ;
float vx, vy, vz;
vx = vy = vz = 0;
float a = (0.6f - x0 * x0) - (y0 * y0 + z0 * z0);
for (int l = 0; ; l++)
{
if (a > 0)
{
float aaaa = (a * a) * (a * a);
float xo, yo, zo;
if (outGradOnly)
GradCoordOut(seed, i, j, k, out xo, out yo, out zo);
else
GradCoordDual(seed, i, j, k, x0, y0, z0, out xo, out yo, out zo);
vx += aaaa * xo;
vy += aaaa * yo;
vz += aaaa * zo;
}
float b = a;
int i1 = i;
int j1 = j;
int k1 = k;
float x1 = x0;
float y1 = y0;
float z1 = z0;
if (ax0 >= ay0 && ax0 >= az0)
{
x1 += xNSign;
b = b + ax0 + ax0;
i1 -= xNSign * PrimeX;
}
else if (ay0 > ax0 && ay0 >= az0)
{
y1 += yNSign;
b = b + ay0 + ay0;
j1 -= yNSign * PrimeY;
}
else
{
z1 += zNSign;
b = b + az0 + az0;
k1 -= zNSign * PrimeZ;
}
if (b > 1)
{
b -= 1;
float bbbb = (b * b) * (b * b);
float xo, yo, zo;
if (outGradOnly)
GradCoordOut(seed, i1, j1, k1, out xo, out yo, out zo);
else
GradCoordDual(seed, i1, j1, k1, x1, y1, z1, out xo, out yo, out zo);
vx += bbbb * xo;
vy += bbbb * yo;
vz += bbbb * zo;
}
if (l == 1) break;
ax0 = 0.5f - ax0;
ay0 = 0.5f - ay0;
az0 = 0.5f - az0;
x0 = xNSign * ax0;
y0 = yNSign * ay0;
z0 = zNSign * az0;
a += (0.75f - ax0) - (ay0 + az0);
i += (xNSign >> 1) & PrimeX;
j += (yNSign >> 1) & PrimeY;
k += (zNSign >> 1) & PrimeZ;
xNSign = -xNSign;
yNSign = -yNSign;
zNSign = -zNSign;
seed += 1293373;
}
xr += vx * warpAmp;
yr += vy * warpAmp;
zr += vz * warpAmp;
}
}
``` | /content/code_sandbox/CSharp/FastNoiseLite.cs | smalltalk | 2016-03-28T02:35:12 | 2024-08-16T07:09:20 | FastNoiseLite | Auburn/FastNoiseLite | 2,688 | 39,790 |
```java
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// .'',;:cldxkO00KKXXNNWWWNNXKOkxdollcc::::::;:::ccllloooolllllllllooollc:,'... ...........',;cldxkO000Okxdlc::;;;,,;;;::cclllllll
// ..',;:ldxO0KXXNNNNNNNNXXK0kxdolcc::::::;;;,,,,,,;;;;;;;;;;:::cclllllc:;'.... ...........',;:ldxO0KXXXK0Okxdolc::;;;;::cllodddddo
// ...',:loxO0KXNNNNNXXKK0Okxdolc::;::::::::;;;,,'''''.....''',;:clllllc:;,'............''''''''',;:loxO0KXNNNNNXK0Okxdollccccllodxxxxxxd
// ....';:ldkO0KXXXKK00Okxdolcc:;;;;;::cclllcc:;;,''..... ....',;clooddolcc:;;;;,,;;;;;::::;;;;;;:cloxk0KXNWWWWWWNXKK0Okxddoooddxxkkkkkxx
// .....';:ldxkOOOOOkxxdolcc:;;;,,,;;:cllooooolcc:;'... ..,:codxkkkxddooollloooooooollcc:::::clodkO0KXNWWWWWWNNXK00Okxxxxxxxxkkkkxxx
// . ....';:cloddddo___________,,,,;;:clooddddoolc:,... ..,:ldx__00OOOkkk___kkkkkkxxdollc::::cclodkO0KXXNNNNNNXXK0OOkxxxxxxxxxxxxddd
// .......',;:cccc:| |,,,;;:cclooddddoll:;'.. ..';cox| \KKK000| |KK00OOkxdocc___;::clldxxkO0KKKKK00Okkxdddddddddddddddoo
// .......'',,,,,''| ________|',,;;::cclloooooolc:;'......___:ldk| \KK000| |XKKK0Okxolc| |;;::cclodxxkkkkxxdoolllcclllooodddooooo
// ''......''''....| | ....'',,,,;;;::cclloooollc:;,''.'| |oxk| \OOO0| |KKK00Oxdoll|___|;;;;;::ccllllllcc::;;,,;;;:cclloooooooo
// ;;,''.......... | |_____',,;;;____:___cllo________.___| |___| \xkk| |KK_______ool___:::;________;;;_______...'',;;:ccclllloo
// c:;,''......... | |:::/ ' |lo/ | | \dx| |0/ \d| |cc/ |'/ \......',,;;:ccllo
// ol:;,'..........| _____|ll/ __ |o/ ______|____ ___| | \o| |/ ___ \| |o/ ______|/ ___ \ .......'',;:clo
// dlc;,...........| |::clooo| / | |x\___ \KXKKK0| |dol| |\ \| | | | | |d\___ \..| | / / ....',:cl
// xoc;'... .....'| |llodddd| \__| |_____\ \KKK0O| |lc:| |'\ | |___| | |_____\ \.| |_/___/... ...',;:c
// dlc;'... ....',;| |oddddddo\ | |Okkx| |::;| |..\ |\ /| | | \ |... ....',;:c
// ol:,'.......',:c|___|xxxddollc\_____,___|_________/ddoll|___|,,,|___|...\_____|:\ ______/l|___|_________/...\________|'........',;::cc
// c:;'.......';:codxxkkkkxxolc::;::clodxkOO0OOkkxdollc::;;,,''''',,,,''''''''''',,'''''',;:loxkkOOkxol:;,'''',,;:ccllcc:;,'''''',;::ccll
// ;,'.......',:codxkOO0OOkxdlc:;,,;;:cldxxkkxxdolc:;;,,''.....'',;;:::;;,,,'''''........,;cldkO0KK0Okdoc::;;::cloodddoolc:;;;;;::ccllooo
// .........',;:lodxOO0000Okdoc:,,',,;:clloddoolc:;,''.......'',;:clooollc:;;,,''.......',:ldkOKXNNXX0Oxdolllloddxxxxxxdolccccccllooodddd
// . .....';:cldxkO0000Okxol:;,''',,;::cccc:;,,'.......'',;:cldxxkkxxdolc:;;,'.......';coxOKXNWWWNXKOkxddddxxkkkkkkxdoollllooddxxxxkkk
// ....',;:codxkO000OOxdoc:;,''',,,;;;;,''.......',,;:clodkO00000Okxolc::;,,''..',;:ldxOKXNWWWNNK0OkkkkkkkkkkkxxddooooodxxkOOOOO000
// ....',;;clodxkkOOOkkdolc:;,,,,,,,,'..........,;:clodxkO0KKXKK0Okxdolcc::;;,,,;;:codkO0XXNNNNXKK0OOOOOkkkkxxdoollloodxkO0KKKXXXXX
//
// VERSION: 1.1.1
// path_to_url
// To switch between using floats or doubles for input position,
// perform a file-wide replace on the following strings (including /*FNLfloat*/)
// /*FNLfloat*/ float
// /*FNLfloat*/ double
public class FastNoiseLite
{
public enum NoiseType
{
OpenSimplex2,
OpenSimplex2S,
Cellular,
Perlin,
ValueCubic,
Value
};
public enum RotationType3D
{
None,
ImproveXYPlanes,
ImproveXZPlanes
};
public enum FractalType
{
None,
FBm,
Ridged,
PingPong,
DomainWarpProgressive,
DomainWarpIndependent
};
public enum CellularDistanceFunction
{
Euclidean,
EuclideanSq,
Manhattan,
Hybrid
};
public enum CellularReturnType
{
CellValue,
Distance,
Distance2,
Distance2Add,
Distance2Sub,
Distance2Mul,
Distance2Div
};
public enum DomainWarpType
{
OpenSimplex2,
OpenSimplex2Reduced,
BasicGrid
};
private enum TransformType3D
{
None,
ImproveXYPlanes,
ImproveXZPlanes,
DefaultOpenSimplex2
};
private int mSeed = 1337;
private float mFrequency = 0.01f;
private NoiseType mNoiseType = NoiseType.OpenSimplex2;
private RotationType3D mRotationType3D = RotationType3D.None;
private TransformType3D mTransformType3D = TransformType3D.DefaultOpenSimplex2;
private FractalType mFractalType = FractalType.None;
private int mOctaves = 3;
private float mLacunarity = 2.0f;
private float mGain = 0.5f;
private float mWeightedStrength = 0.0f;
private float mPingPongStrength = 2.0f;
private float mFractalBounding = 1 / 1.75f;
private CellularDistanceFunction mCellularDistanceFunction = CellularDistanceFunction.EuclideanSq;
private CellularReturnType mCellularReturnType = CellularReturnType.Distance;
private float mCellularJitterModifier = 1.0f;
private DomainWarpType mDomainWarpType = DomainWarpType.OpenSimplex2;
private TransformType3D mWarpTransformType3D = TransformType3D.DefaultOpenSimplex2;
private float mDomainWarpAmp = 1.0f;
/// <summary>
/// Create new FastNoise object with default seed
/// </summary>
public FastNoiseLite() { }
/// <summary>
/// Create new FastNoise object with specified seed
/// </summary>
public FastNoiseLite(int seed)
{
SetSeed(seed);
}
/// <summary>
/// Sets seed used for all noise types
/// </summary>
/// <remarks>
/// Default: 1337
/// </remarks>
public void SetSeed(int seed) { mSeed = seed; }
/// <summary>
/// Sets frequency for all noise types
/// </summary>
/// <remarks>
/// Default: 0.01
/// </remarks>
public void SetFrequency(float frequency) { mFrequency = frequency; }
/// <summary>
/// Sets noise algorithm used for GetNoise(...)
/// </summary>
/// <remarks>
/// Default: OpenSimplex2
/// </remarks>
public void SetNoiseType(NoiseType noiseType)
{
mNoiseType = noiseType;
UpdateTransformType3D();
}
/// <summary>
/// Sets domain rotation type for 3D Noise and 3D DomainWarp.
/// Can aid in reducing directional artifacts when sampling a 2D plane in 3D
/// </summary>
/// <remarks>
/// Default: None
/// </remarks>
public void SetRotationType3D(RotationType3D rotationType3D)
{
mRotationType3D = rotationType3D;
UpdateTransformType3D();
UpdateWarpTransformType3D();
}
/// <summary>
/// Sets method for combining octaves in all fractal noise types
/// </summary>
/// <remarks>
/// Default: None
/// Note: FractalType.DomainWarp... only affects DomainWarp(...)
/// </remarks>
public void SetFractalType(FractalType fractalType) { mFractalType = fractalType; }
/// <summary>
/// Sets octave count for all fractal noise types
/// </summary>
/// <remarks>
/// Default: 3
/// </remarks>
public void SetFractalOctaves(int octaves)
{
mOctaves = octaves;
CalculateFractalBounding();
}
/// <summary>
/// Sets octave lacunarity for all fractal noise types
/// </summary>
/// <remarks>
/// Default: 2.0
/// </remarks>
public void SetFractalLacunarity(float lacunarity) { mLacunarity = lacunarity; }
/// <summary>
/// Sets octave gain for all fractal noise types
/// </summary>
/// <remarks>
/// Default: 0.5
/// </remarks>
public void SetFractalGain(float gain)
{
mGain = gain;
CalculateFractalBounding();
}
/// <summary>
/// Sets octave weighting for all none DomainWarp fratal types
/// </summary>
/// <remarks>
/// Default: 0.0
/// Note: Keep between 0...1 to maintain -1...1 output bounding
/// </remarks>
public void SetFractalWeightedStrength(float weightedStrength) { mWeightedStrength = weightedStrength; }
/// <summary>
/// Sets strength of the fractal ping pong effect
/// </summary>
/// <remarks>
/// Default: 2.0
/// </remarks>
public void SetFractalPingPongStrength(float pingPongStrength) { mPingPongStrength = pingPongStrength; }
/// <summary>
/// Sets distance function used in cellular noise calculations
/// </summary>
/// <remarks>
/// Default: Distance
/// </remarks>
public void SetCellularDistanceFunction(CellularDistanceFunction cellularDistanceFunction) { mCellularDistanceFunction = cellularDistanceFunction; }
/// <summary>
/// Sets return type from cellular noise calculations
/// </summary>
/// <remarks>
/// Default: EuclideanSq
/// </remarks>
public void SetCellularReturnType(CellularReturnType cellularReturnType) { mCellularReturnType = cellularReturnType; }
/// <summary>
/// Sets the maximum distance a cellular point can move from it's grid position
/// </summary>
/// <remarks>
/// Default: 1.0
/// Note: Setting this higher than 1 will cause artifacts
/// </remarks>
public void SetCellularJitter(float cellularJitter) { mCellularJitterModifier = cellularJitter; }
/// <summary>
/// Sets the warp algorithm when using DomainWarp(...)
/// </summary>
/// <remarks>
/// Default: OpenSimplex2
/// </remarks>
public void SetDomainWarpType(DomainWarpType domainWarpType)
{
mDomainWarpType = domainWarpType;
UpdateWarpTransformType3D();
}
/// <summary>
/// Sets the maximum warp distance from original position when using DomainWarp(...)
/// </summary>
/// <remarks>
/// Default: 1.0
/// </remarks>
public void SetDomainWarpAmp(float domainWarpAmp) { mDomainWarpAmp = domainWarpAmp; }
/// <summary>
/// 2D noise at given position using current settings
/// </summary>
/// <returns>
/// Noise output bounded between -1...1
/// </returns>
public float GetNoise(/*FNLfloat*/ float x, /*FNLfloat*/ float y)
{
x *= mFrequency;
y *= mFrequency;
switch (mNoiseType)
{
case OpenSimplex2:
case OpenSimplex2S:
{
final /*FNLfloat*/ float SQRT3 = (/*FNLfloat*/ float)1.7320508075688772935274463415059;
final /*FNLfloat*/ float F2 = 0.5f * (SQRT3 - 1);
/*FNLfloat*/ float t = (x + y) * F2;
x += t;
y += t;
}
break;
default:
break;
}
switch (mFractalType)
{
default:
return GenNoiseSingle(mSeed, x, y);
case FBm:
return GenFractalFBm(x, y);
case Ridged:
return GenFractalRidged(x, y);
case PingPong:
return GenFractalPingPong(x, y);
}
}
/// <summary>
/// 3D noise at given position using current settings
/// </summary>
/// <returns>
/// Noise output bounded between -1...1
/// </returns>
public float GetNoise(/*FNLfloat*/ float x, /*FNLfloat*/ float y, /*FNLfloat*/ float z)
{
x *= mFrequency;
y *= mFrequency;
z *= mFrequency;
switch (mTransformType3D)
{
case ImproveXYPlanes:
{
/*FNLfloat*/ float xy = x + y;
/*FNLfloat*/ float s2 = xy * -(/*FNLfloat*/ float)0.211324865405187;
z *= (/*FNLfloat*/ float)0.577350269189626;
x += s2 - z;
y = y + s2 - z;
z += xy * (/*FNLfloat*/ float)0.577350269189626;
}
break;
case ImproveXZPlanes:
{
/*FNLfloat*/ float xz = x + z;
/*FNLfloat*/ float s2 = xz * -(/*FNLfloat*/ float)0.211324865405187;
y *= (/*FNLfloat*/ float)0.577350269189626;
x += s2 - y;
z += s2 - y;
y += xz * (/*FNLfloat*/ float)0.577350269189626;
}
break;
case DefaultOpenSimplex2:
{
final /*FNLfloat*/ float R3 = (/*FNLfloat*/ float)(2.0 / 3.0);
/*FNLfloat*/ float r = (x + y + z) * R3; // Rotation, not skew
x = r - x;
y = r - y;
z = r - z;
}
break;
default:
break;
}
switch (mFractalType)
{
default:
return GenNoiseSingle(mSeed, x, y, z);
case FBm:
return GenFractalFBm(x, y, z);
case Ridged:
return GenFractalRidged(x, y, z);
case PingPong:
return GenFractalPingPong(x, y, z);
}
}
/// <summary>
/// 2D warps the input position using current domain warp settings
/// </summary>
/// <example>
/// Example usage with GetNoise
/// <code>DomainWarp(coord)
/// noise = GetNoise(x, y)</code>
/// </example>
public void DomainWarp(Vector2 coord)
{
switch (mFractalType)
{
default:
DomainWarpSingle(coord);
break;
case DomainWarpProgressive:
DomainWarpFractalProgressive(coord);
break;
case DomainWarpIndependent:
DomainWarpFractalIndependent(coord);
break;
}
}
/// <summary>
/// 3D warps the input position using current domain warp settings
/// </summary>
/// <example>
/// Example usage with GetNoise
/// <code>DomainWarp(coord)
/// noise = GetNoise(x, y, z)</code>
/// </example>
public void DomainWarp(Vector3 coord)
{
switch (mFractalType)
{
default:
DomainWarpSingle(coord);
break;
case DomainWarpProgressive:
DomainWarpFractalProgressive(coord);
break;
case DomainWarpIndependent:
DomainWarpFractalIndependent(coord);
break;
}
}
private static final float[] Gradients2D = {
0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, 0.793353340291235f, 0.793353340291235f, 0.608761429008721f,
0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, -0.130526192220051f, 0.923879532511287f, -0.38268343236509f,
0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, -0.923879532511287f, 0.130526192220052f, -0.99144486137381f,
-0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, -0.793353340291235f, -0.793353340291235f, -0.608761429008721f,
-0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, 0.130526192220051f, -0.923879532511287f, 0.38268343236509f,
-0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, 0.923879532511287f, -0.130526192220052f, 0.99144486137381f,
0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, 0.793353340291235f, 0.793353340291235f, 0.608761429008721f,
0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, -0.130526192220051f, 0.923879532511287f, -0.38268343236509f,
0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, -0.923879532511287f, 0.130526192220052f, -0.99144486137381f,
-0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, -0.793353340291235f, -0.793353340291235f, -0.608761429008721f,
-0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, 0.130526192220051f, -0.923879532511287f, 0.38268343236509f,
-0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, 0.923879532511287f, -0.130526192220052f, 0.99144486137381f,
0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, 0.793353340291235f, 0.793353340291235f, 0.608761429008721f,
0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, -0.130526192220051f, 0.923879532511287f, -0.38268343236509f,
0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, -0.923879532511287f, 0.130526192220052f, -0.99144486137381f,
-0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, -0.793353340291235f, -0.793353340291235f, -0.608761429008721f,
-0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, 0.130526192220051f, -0.923879532511287f, 0.38268343236509f,
-0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, 0.923879532511287f, -0.130526192220052f, 0.99144486137381f,
0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, 0.793353340291235f, 0.793353340291235f, 0.608761429008721f,
0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, -0.130526192220051f, 0.923879532511287f, -0.38268343236509f,
0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, -0.923879532511287f, 0.130526192220052f, -0.99144486137381f,
-0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, -0.793353340291235f, -0.793353340291235f, -0.608761429008721f,
-0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, 0.130526192220051f, -0.923879532511287f, 0.38268343236509f,
-0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, 0.923879532511287f, -0.130526192220052f, 0.99144486137381f,
0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, 0.793353340291235f, 0.793353340291235f, 0.608761429008721f,
0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, -0.130526192220051f, 0.923879532511287f, -0.38268343236509f,
0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, -0.923879532511287f, 0.130526192220052f, -0.99144486137381f,
-0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, -0.793353340291235f, -0.793353340291235f, -0.608761429008721f,
-0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, 0.130526192220051f, -0.923879532511287f, 0.38268343236509f,
-0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, 0.923879532511287f, -0.130526192220052f, 0.99144486137381f,
0.38268343236509f, 0.923879532511287f, 0.923879532511287f, 0.38268343236509f, 0.923879532511287f, -0.38268343236509f, 0.38268343236509f, -0.923879532511287f,
-0.38268343236509f, -0.923879532511287f, -0.923879532511287f, -0.38268343236509f, -0.923879532511287f, 0.38268343236509f, -0.38268343236509f, 0.923879532511287f,
};
private static final float[] RandVecs2D = {
-0.2700222198f, -0.9628540911f, 0.3863092627f, -0.9223693152f, 0.04444859006f, -0.999011673f, -0.5992523158f, -0.8005602176f, -0.7819280288f, 0.6233687174f, 0.9464672271f, 0.3227999196f, -0.6514146797f, -0.7587218957f, 0.9378472289f, 0.347048376f,
-0.8497875957f, -0.5271252623f, -0.879042592f, 0.4767432447f, -0.892300288f, -0.4514423508f, -0.379844434f, -0.9250503802f, -0.9951650832f, 0.0982163789f, 0.7724397808f, -0.6350880136f, 0.7573283322f, -0.6530343002f, -0.9928004525f, -0.119780055f,
-0.0532665713f, 0.9985803285f, 0.9754253726f, -0.2203300762f, -0.7665018163f, 0.6422421394f, 0.991636706f, 0.1290606184f, -0.994696838f, 0.1028503788f, -0.5379205513f, -0.84299554f, 0.5022815471f, -0.8647041387f, 0.4559821461f, -0.8899889226f,
-0.8659131224f, -0.5001944266f, 0.0879458407f, -0.9961252577f, -0.5051684983f, 0.8630207346f, 0.7753185226f, -0.6315704146f, -0.6921944612f, 0.7217110418f, -0.5191659449f, -0.8546734591f, 0.8978622882f, -0.4402764035f, -0.1706774107f, 0.9853269617f,
-0.9353430106f, -0.3537420705f, -0.9992404798f, 0.03896746794f, -0.2882064021f, -0.9575683108f, -0.9663811329f, 0.2571137995f, -0.8759714238f, -0.4823630009f, -0.8303123018f, -0.5572983775f, 0.05110133755f, -0.9986934731f, -0.8558373281f, -0.5172450752f,
0.09887025282f, 0.9951003332f, 0.9189016087f, 0.3944867976f, -0.2439375892f, -0.9697909324f, -0.8121409387f, -0.5834613061f, -0.9910431363f, 0.1335421355f, 0.8492423985f, -0.5280031709f, -0.9717838994f, -0.2358729591f, 0.9949457207f, 0.1004142068f,
0.6241065508f, -0.7813392434f, 0.662910307f, 0.7486988212f, -0.7197418176f, 0.6942418282f, -0.8143370775f, -0.5803922158f, 0.104521054f, -0.9945226741f, -0.1065926113f, -0.9943027784f, 0.445799684f, -0.8951327509f, 0.105547406f, 0.9944142724f,
-0.992790267f, 0.1198644477f, -0.8334366408f, 0.552615025f, 0.9115561563f, -0.4111755999f, 0.8285544909f, -0.5599084351f, 0.7217097654f, -0.6921957921f, 0.4940492677f, -0.8694339084f, -0.3652321272f, -0.9309164803f, -0.9696606758f, 0.2444548501f,
0.08925509731f, -0.996008799f, 0.5354071276f, -0.8445941083f, -0.1053576186f, 0.9944343981f, -0.9890284586f, 0.1477251101f, 0.004856104961f, 0.9999882091f, 0.9885598478f, 0.1508291331f, 0.9286129562f, -0.3710498316f, -0.5832393863f, -0.8123003252f,
0.3015207509f, 0.9534596146f, -0.9575110528f, 0.2883965738f, 0.9715802154f, -0.2367105511f, 0.229981792f, 0.9731949318f, 0.955763816f, -0.2941352207f, 0.740956116f, 0.6715534485f, -0.9971513787f, -0.07542630764f, 0.6905710663f, -0.7232645452f,
-0.290713703f, -0.9568100872f, 0.5912777791f, -0.8064679708f, -0.9454592212f, -0.325740481f, 0.6664455681f, 0.74555369f, 0.6236134912f, 0.7817328275f, 0.9126993851f, -0.4086316587f, -0.8191762011f, 0.5735419353f, -0.8812745759f, -0.4726046147f,
0.9953313627f, 0.09651672651f, 0.9855650846f, -0.1692969699f, -0.8495980887f, 0.5274306472f, 0.6174853946f, -0.7865823463f, 0.8508156371f, 0.52546432f, 0.9985032451f, -0.05469249926f, 0.1971371563f, -0.9803759185f, 0.6607855748f, -0.7505747292f,
-0.03097494063f, 0.9995201614f, -0.6731660801f, 0.739491331f, -0.7195018362f, -0.6944905383f, 0.9727511689f, 0.2318515979f, 0.9997059088f, -0.0242506907f, 0.4421787429f, -0.8969269532f, 0.9981350961f, -0.061043673f, -0.9173660799f, -0.3980445648f,
-0.8150056635f, -0.5794529907f, -0.8789331304f, 0.4769450202f, 0.0158605829f, 0.999874213f, -0.8095464474f, 0.5870558317f, -0.9165898907f, -0.3998286786f, -0.8023542565f, 0.5968480938f, -0.5176737917f, 0.8555780767f, -0.8154407307f, -0.5788405779f,
0.4022010347f, -0.9155513791f, -0.9052556868f, -0.4248672045f, 0.7317445619f, 0.6815789728f, -0.5647632201f, -0.8252529947f, -0.8403276335f, -0.5420788397f, -0.9314281527f, 0.363925262f, 0.5238198472f, 0.8518290719f, 0.7432803869f, -0.6689800195f,
-0.985371561f, -0.1704197369f, 0.4601468731f, 0.88784281f, 0.825855404f, 0.5638819483f, 0.6182366099f, 0.7859920446f, 0.8331502863f, -0.553046653f, 0.1500307506f, 0.9886813308f, -0.662330369f, -0.7492119075f, -0.668598664f, 0.743623444f,
0.7025606278f, 0.7116238924f, -0.5419389763f, -0.8404178401f, -0.3388616456f, 0.9408362159f, 0.8331530315f, 0.5530425174f, -0.2989720662f, -0.9542618632f, 0.2638522993f, 0.9645630949f, 0.124108739f, -0.9922686234f, -0.7282649308f, -0.6852956957f,
0.6962500149f, 0.7177993569f, -0.9183535368f, 0.3957610156f, -0.6326102274f, -0.7744703352f, -0.9331891859f, -0.359385508f, -0.1153779357f, -0.9933216659f, 0.9514974788f, -0.3076565421f, -0.08987977445f, -0.9959526224f, 0.6678496916f, 0.7442961705f,
0.7952400393f, -0.6062947138f, -0.6462007402f, -0.7631674805f, -0.2733598753f, 0.9619118351f, 0.9669590226f, -0.254931851f, -0.9792894595f, 0.2024651934f, -0.5369502995f, -0.8436138784f, -0.270036471f, -0.9628500944f, -0.6400277131f, 0.7683518247f,
-0.7854537493f, -0.6189203566f, 0.06005905383f, -0.9981948257f, -0.02455770378f, 0.9996984141f, -0.65983623f, 0.751409442f, -0.6253894466f, -0.7803127835f, -0.6210408851f, -0.7837781695f, 0.8348888491f, 0.5504185768f, -0.1592275245f, 0.9872419133f,
0.8367622488f, 0.5475663786f, -0.8675753916f, -0.4973056806f, -0.2022662628f, -0.9793305667f, 0.9399189937f, 0.3413975472f, 0.9877404807f, -0.1561049093f, -0.9034455656f, 0.4287028224f, 0.1269804218f, -0.9919052235f, -0.3819600854f, 0.924178821f,
0.9754625894f, 0.2201652486f, -0.3204015856f, -0.9472818081f, -0.9874760884f, 0.1577687387f, 0.02535348474f, -0.9996785487f, 0.4835130794f, -0.8753371362f, -0.2850799925f, -0.9585037287f, -0.06805516006f, -0.99768156f, -0.7885244045f, -0.6150034663f,
0.3185392127f, -0.9479096845f, 0.8880043089f, 0.4598351306f, 0.6476921488f, -0.7619021462f, 0.9820241299f, 0.1887554194f, 0.9357275128f, -0.3527237187f, -0.8894895414f, 0.4569555293f, 0.7922791302f, 0.6101588153f, 0.7483818261f, 0.6632681526f,
-0.7288929755f, -0.6846276581f, 0.8729032783f, -0.4878932944f, 0.8288345784f, 0.5594937369f, 0.08074567077f, 0.9967347374f, 0.9799148216f, -0.1994165048f, -0.580730673f, -0.8140957471f, -0.4700049791f, -0.8826637636f, 0.2409492979f, 0.9705377045f,
0.9437816757f, -0.3305694308f, -0.8927998638f, -0.4504535528f, -0.8069622304f, 0.5906030467f, 0.06258973166f, 0.9980393407f, -0.9312597469f, 0.3643559849f, 0.5777449785f, 0.8162173362f, -0.3360095855f, -0.941858566f, 0.697932075f, -0.7161639607f,
-0.002008157227f, -0.9999979837f, -0.1827294312f, -0.9831632392f, -0.6523911722f, 0.7578824173f, -0.4302626911f, -0.9027037258f, -0.9985126289f, -0.05452091251f, -0.01028102172f, -0.9999471489f, -0.4946071129f, 0.8691166802f, -0.2999350194f, 0.9539596344f,
0.8165471961f, 0.5772786819f, 0.2697460475f, 0.962931498f, -0.7306287391f, -0.6827749597f, -0.7590952064f, -0.6509796216f, -0.907053853f, 0.4210146171f, -0.5104861064f, -0.8598860013f, 0.8613350597f, 0.5080373165f, 0.5007881595f, -0.8655698812f,
-0.654158152f, 0.7563577938f, -0.8382755311f, -0.545246856f, 0.6940070834f, 0.7199681717f, 0.06950936031f, 0.9975812994f, 0.1702942185f, -0.9853932612f, 0.2695973274f, 0.9629731466f, 0.5519612192f, -0.8338697815f, 0.225657487f, -0.9742067022f,
0.4215262855f, -0.9068161835f, 0.4881873305f, -0.8727388672f, -0.3683854996f, -0.9296731273f, -0.9825390578f, 0.1860564427f, 0.81256471f, 0.5828709909f, 0.3196460933f, -0.9475370046f, 0.9570913859f, 0.2897862643f, -0.6876655497f, -0.7260276109f,
-0.9988770922f, -0.047376731f, -0.1250179027f, 0.992154486f, -0.8280133617f, 0.560708367f, 0.9324863769f, -0.3612051451f, 0.6394653183f, 0.7688199442f, -0.01623847064f, -0.9998681473f, -0.9955014666f, -0.09474613458f, -0.81453315f, 0.580117012f,
0.4037327978f, -0.9148769469f, 0.9944263371f, 0.1054336766f, -0.1624711654f, 0.9867132919f, -0.9949487814f, -0.100383875f, -0.6995302564f, 0.7146029809f, 0.5263414922f, -0.85027327f, -0.5395221479f, 0.841971408f, 0.6579370318f, 0.7530729462f,
0.01426758847f, -0.9998982128f, -0.6734383991f, 0.7392433447f, 0.639412098f, -0.7688642071f, 0.9211571421f, 0.3891908523f, -0.146637214f, -0.9891903394f, -0.782318098f, 0.6228791163f, -0.5039610839f, -0.8637263605f, -0.7743120191f, -0.6328039957f,
};
private static final float[] Gradients3D = {
0, 1, 1, 0, 0,-1, 1, 0, 0, 1,-1, 0, 0,-1,-1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0,-1, 0, -1, 0,-1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1,-1, 0, 0, -1,-1, 0, 0,
0, 1, 1, 0, 0,-1, 1, 0, 0, 1,-1, 0, 0,-1,-1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0,-1, 0, -1, 0,-1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1,-1, 0, 0, -1,-1, 0, 0,
0, 1, 1, 0, 0,-1, 1, 0, 0, 1,-1, 0, 0,-1,-1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0,-1, 0, -1, 0,-1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1,-1, 0, 0, -1,-1, 0, 0,
0, 1, 1, 0, 0,-1, 1, 0, 0, 1,-1, 0, 0,-1,-1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0,-1, 0, -1, 0,-1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1,-1, 0, 0, -1,-1, 0, 0,
0, 1, 1, 0, 0,-1, 1, 0, 0, 1,-1, 0, 0,-1,-1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0,-1, 0, -1, 0,-1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1,-1, 0, 0, -1,-1, 0, 0,
1, 1, 0, 0, 0,-1, 1, 0, -1, 1, 0, 0, 0,-1,-1, 0
};
private static final float[] RandVecs3D = {
-0.7292736885f, -0.6618439697f, 0.1735581948f, 0, 0.790292081f, -0.5480887466f, -0.2739291014f, 0, 0.7217578935f, 0.6226212466f, -0.3023380997f, 0, 0.565683137f, -0.8208298145f, -0.0790000257f, 0, 0.760049034f, -0.5555979497f, -0.3370999617f, 0, 0.3713945616f, 0.5011264475f, 0.7816254623f, 0, -0.1277062463f, -0.4254438999f, -0.8959289049f, 0, -0.2881560924f, -0.5815838982f, 0.7607405838f, 0,
0.5849561111f, -0.662820239f, -0.4674352136f, 0, 0.3307171178f, 0.0391653737f, 0.94291689f, 0, 0.8712121778f, -0.4113374369f, -0.2679381538f, 0, 0.580981015f, 0.7021915846f, 0.4115677815f, 0, 0.503756873f, 0.6330056931f, -0.5878203852f, 0, 0.4493712205f, 0.601390195f, 0.6606022552f, 0, -0.6878403724f, 0.09018890807f, -0.7202371714f, 0, -0.5958956522f, -0.6469350577f, 0.475797649f, 0,
-0.5127052122f, 0.1946921978f, -0.8361987284f, 0, -0.9911507142f, -0.05410276466f, -0.1212153153f, 0, -0.2149721042f, 0.9720882117f, -0.09397607749f, 0, -0.7518650936f, -0.5428057603f, 0.3742469607f, 0, 0.5237068895f, 0.8516377189f, -0.02107817834f, 0, 0.6333504779f, 0.1926167129f, -0.7495104896f, 0, -0.06788241606f, 0.3998305789f, 0.9140719259f, 0, -0.5538628599f, -0.4729896695f, -0.6852128902f, 0,
-0.7261455366f, -0.5911990757f, 0.3509933228f, 0, -0.9229274737f, -0.1782808786f, 0.3412049336f, 0, -0.6968815002f, 0.6511274338f, 0.3006480328f, 0, 0.9608044783f, -0.2098363234f, -0.1811724921f, 0, 0.06817146062f, -0.9743405129f, 0.2145069156f, 0, -0.3577285196f, -0.6697087264f, -0.6507845481f, 0, -0.1868621131f, 0.7648617052f, -0.6164974636f, 0, -0.6541697588f, 0.3967914832f, 0.6439087246f, 0,
0.6993340405f, -0.6164538506f, 0.3618239211f, 0, -0.1546665739f, 0.6291283928f, 0.7617583057f, 0, -0.6841612949f, -0.2580482182f, -0.6821542638f, 0, 0.5383980957f, 0.4258654885f, 0.7271630328f, 0, -0.5026987823f, -0.7939832935f, -0.3418836993f, 0, 0.3202971715f, 0.2834415347f, 0.9039195862f, 0, 0.8683227101f, -0.0003762656404f, -0.4959995258f, 0, 0.791120031f, -0.08511045745f, 0.6057105799f, 0,
-0.04011016052f, -0.4397248749f, 0.8972364289f, 0, 0.9145119872f, 0.3579346169f, -0.1885487608f, 0, -0.9612039066f, -0.2756484276f, 0.01024666929f, 0, 0.6510361721f, -0.2877799159f, -0.7023778346f, 0, -0.2041786351f, 0.7365237271f, 0.644859585f, 0, -0.7718263711f, 0.3790626912f, 0.5104855816f, 0, -0.3060082741f, -0.7692987727f, 0.5608371729f, 0, 0.454007341f, -0.5024843065f, 0.7357899537f, 0,
0.4816795475f, 0.6021208291f, -0.6367380315f, 0, 0.6961980369f, -0.3222197429f, 0.641469197f, 0, -0.6532160499f, -0.6781148932f, 0.3368515753f, 0, 0.5089301236f, -0.6154662304f, -0.6018234363f, 0, -0.1635919754f, -0.9133604627f, -0.372840892f, 0, 0.52408019f, -0.8437664109f, 0.1157505864f, 0, 0.5902587356f, 0.4983817807f, -0.6349883666f, 0, 0.5863227872f, 0.494764745f, 0.6414307729f, 0,
0.6779335087f, 0.2341345225f, 0.6968408593f, 0, 0.7177054546f, -0.6858979348f, 0.120178631f, 0, -0.5328819713f, -0.5205125012f, 0.6671608058f, 0, -0.8654874251f, -0.0700727088f, -0.4960053754f, 0, -0.2861810166f, 0.7952089234f, 0.5345495242f, 0, -0.04849529634f, 0.9810836427f, -0.1874115585f, 0, -0.6358521667f, 0.6058348682f, 0.4781800233f, 0, 0.6254794696f, -0.2861619734f, 0.7258696564f, 0,
-0.2585259868f, 0.5061949264f, -0.8227581726f, 0, 0.02136306781f, 0.5064016808f, -0.8620330371f, 0, 0.200111773f, 0.8599263484f, 0.4695550591f, 0, 0.4743561372f, 0.6014985084f, -0.6427953014f, 0, 0.6622993731f, -0.5202474575f, -0.5391679918f, 0, 0.08084972818f, -0.6532720452f, 0.7527940996f, 0, -0.6893687501f, 0.0592860349f, 0.7219805347f, 0, -0.1121887082f, -0.9673185067f, 0.2273952515f, 0,
0.7344116094f, 0.5979668656f, -0.3210532909f, 0, 0.5789393465f, -0.2488849713f, 0.7764570201f, 0, 0.6988182827f, 0.3557169806f, -0.6205791146f, 0, -0.8636845529f, -0.2748771249f, -0.4224826141f, 0, -0.4247027957f, -0.4640880967f, 0.777335046f, 0, 0.5257722489f, -0.8427017621f, 0.1158329937f, 0, 0.9343830603f, 0.316302472f, -0.1639543925f, 0, -0.1016836419f, -0.8057303073f, -0.5834887393f, 0,
-0.6529238969f, 0.50602126f, -0.5635892736f, 0, -0.2465286165f, -0.9668205684f, -0.06694497494f, 0, -0.9776897119f, -0.2099250524f, -0.007368825344f, 0, 0.7736893337f, 0.5734244712f, 0.2694238123f, 0, -0.6095087895f, 0.4995678998f, 0.6155736747f, 0, 0.5794535482f, 0.7434546771f, 0.3339292269f, 0, -0.8226211154f, 0.08142581855f, 0.5627293636f, 0, -0.510385483f, 0.4703667658f, 0.7199039967f, 0,
-0.5764971849f, -0.07231656274f, -0.8138926898f, 0, 0.7250628871f, 0.3949971505f, -0.5641463116f, 0, -0.1525424005f, 0.4860840828f, -0.8604958341f, 0, -0.5550976208f, -0.4957820792f, 0.667882296f, 0, -0.1883614327f, 0.9145869398f, 0.357841725f, 0, 0.7625556724f, -0.5414408243f, -0.3540489801f, 0, -0.5870231946f, -0.3226498013f, -0.7424963803f, 0, 0.3051124198f, 0.2262544068f, -0.9250488391f, 0,
0.6379576059f, 0.577242424f, -0.5097070502f, 0, -0.5966775796f, 0.1454852398f, -0.7891830656f, 0, -0.658330573f, 0.6555487542f, -0.3699414651f, 0, 0.7434892426f, 0.2351084581f, 0.6260573129f, 0, 0.5562114096f, 0.8264360377f, -0.0873632843f, 0, -0.3028940016f, -0.8251527185f, 0.4768419182f, 0, 0.1129343818f, -0.985888439f, -0.1235710781f, 0, 0.5937652891f, -0.5896813806f, 0.5474656618f, 0,
0.6757964092f, -0.5835758614f, -0.4502648413f, 0, 0.7242302609f, -0.1152719764f, 0.6798550586f, 0, -0.9511914166f, 0.0753623979f, -0.2992580792f, 0, 0.2539470961f, -0.1886339355f, 0.9486454084f, 0, 0.571433621f, -0.1679450851f, -0.8032795685f, 0, -0.06778234979f, 0.3978269256f, 0.9149531629f, 0, 0.6074972649f, 0.733060024f, -0.3058922593f, 0, -0.5435478392f, 0.1675822484f, 0.8224791405f, 0,
-0.5876678086f, -0.3380045064f, -0.7351186982f, 0, -0.7967562402f, 0.04097822706f, -0.6029098428f, 0, -0.1996350917f, 0.8706294745f, 0.4496111079f, 0, -0.02787660336f, -0.9106232682f, -0.4122962022f, 0, -0.7797625996f, -0.6257634692f, 0.01975775581f, 0, -0.5211232846f, 0.7401644346f, -0.4249554471f, 0, 0.8575424857f, 0.4053272873f, -0.3167501783f, 0, 0.1045223322f, 0.8390195772f, -0.5339674439f, 0,
0.3501822831f, 0.9242524096f, -0.1520850155f, 0, 0.1987849858f, 0.07647613266f, 0.9770547224f, 0, 0.7845996363f, 0.6066256811f, -0.1280964233f, 0, 0.09006737436f, -0.9750989929f, -0.2026569073f, 0, -0.8274343547f, -0.542299559f, 0.1458203587f, 0, -0.3485797732f, -0.415802277f, 0.840000362f, 0, -0.2471778936f, -0.7304819962f, -0.6366310879f, 0, -0.3700154943f, 0.8577948156f, 0.3567584454f, 0,
0.5913394901f, -0.548311967f, -0.5913303597f, 0, 0.1204873514f, -0.7626472379f, -0.6354935001f, 0, 0.616959265f, 0.03079647928f, 0.7863922953f, 0, 0.1258156836f, -0.6640829889f, -0.7369967419f, 0, -0.6477565124f, -0.1740147258f, -0.7417077429f, 0, 0.6217889313f, -0.7804430448f, -0.06547655076f, 0, 0.6589943422f, -0.6096987708f, 0.4404473475f, 0, -0.2689837504f, -0.6732403169f, -0.6887635427f, 0,
-0.3849775103f, 0.5676542638f, 0.7277093879f, 0, 0.5754444408f, 0.8110471154f, -0.1051963504f, 0, 0.9141593684f, 0.3832947817f, 0.131900567f, 0, -0.107925319f, 0.9245493968f, 0.3654593525f, 0, 0.377977089f, 0.3043148782f, 0.8743716458f, 0, -0.2142885215f, -0.8259286236f, 0.5214617324f, 0, 0.5802544474f, 0.4148098596f, -0.7008834116f, 0, -0.1982660881f, 0.8567161266f, -0.4761596756f, 0,
-0.03381553704f, 0.3773180787f, -0.9254661404f, 0, -0.6867922841f, -0.6656597827f, 0.2919133642f, 0, 0.7731742607f, -0.2875793547f, -0.5652430251f, 0, -0.09655941928f, 0.9193708367f, -0.3813575004f, 0, 0.2715702457f, -0.9577909544f, -0.09426605581f, 0, 0.2451015704f, -0.6917998565f, -0.6792188003f, 0, 0.977700782f, -0.1753855374f, 0.1155036542f, 0, -0.5224739938f, 0.8521606816f, 0.02903615945f, 0,
-0.7734880599f, -0.5261292347f, 0.3534179531f, 0, -0.7134492443f, -0.269547243f, 0.6467878011f, 0, 0.1644037271f, 0.5105846203f, -0.8439637196f, 0, 0.6494635788f, 0.05585611296f, 0.7583384168f, 0, -0.4711970882f, 0.5017280509f, -0.7254255765f, 0, -0.6335764307f, -0.2381686273f, -0.7361091029f, 0, -0.9021533097f, -0.270947803f, -0.3357181763f, 0, -0.3793711033f, 0.872258117f, 0.3086152025f, 0,
-0.6855598966f, -0.3250143309f, 0.6514394162f, 0, 0.2900942212f, -0.7799057743f, -0.5546100667f, 0, -0.2098319339f, 0.85037073f, 0.4825351604f, 0, -0.4592603758f, 0.6598504336f, -0.5947077538f, 0, 0.8715945488f, 0.09616365406f, -0.4807031248f, 0, -0.6776666319f, 0.7118504878f, -0.1844907016f, 0, 0.7044377633f, 0.312427597f, 0.637304036f, 0, -0.7052318886f, -0.2401093292f, -0.6670798253f, 0,
0.081921007f, -0.7207336136f, -0.6883545647f, 0, -0.6993680906f, -0.5875763221f, -0.4069869034f, 0, -0.1281454481f, 0.6419895885f, 0.7559286424f, 0, -0.6337388239f, -0.6785471501f, -0.3714146849f, 0, 0.5565051903f, -0.2168887573f, -0.8020356851f, 0, -0.5791554484f, 0.7244372011f, -0.3738578718f, 0, 0.1175779076f, -0.7096451073f, 0.6946792478f, 0, -0.6134619607f, 0.1323631078f, 0.7785527795f, 0,
0.6984635305f, -0.02980516237f, -0.715024719f, 0, 0.8318082963f, -0.3930171956f, 0.3919597455f, 0, 0.1469576422f, 0.05541651717f, -0.9875892167f, 0, 0.708868575f, -0.2690503865f, 0.6520101478f, 0, 0.2726053183f, 0.67369766f, -0.68688995f, 0, -0.6591295371f, 0.3035458599f, -0.6880466294f, 0, 0.4815131379f, -0.7528270071f, 0.4487723203f, 0, 0.9430009463f, 0.1675647412f, -0.2875261255f, 0,
0.434802957f, 0.7695304522f, -0.4677277752f, 0, 0.3931996188f, 0.594473625f, 0.7014236729f, 0, 0.7254336655f, -0.603925654f, 0.3301814672f, 0, 0.7590235227f, -0.6506083235f, 0.02433313207f, 0, -0.8552768592f, -0.3430042733f, 0.3883935666f, 0, -0.6139746835f, 0.6981725247f, 0.3682257648f, 0, -0.7465905486f, -0.5752009504f, 0.3342849376f, 0, 0.5730065677f, 0.810555537f, -0.1210916791f, 0,
-0.9225877367f, -0.3475211012f, -0.167514036f, 0, -0.7105816789f, -0.4719692027f, -0.5218416899f, 0, -0.08564609717f, 0.3583001386f, 0.929669703f, 0, -0.8279697606f, -0.2043157126f, 0.5222271202f, 0, 0.427944023f, 0.278165994f, 0.8599346446f, 0, 0.5399079671f, -0.7857120652f, -0.3019204161f, 0, 0.5678404253f, -0.5495413974f, -0.6128307303f, 0, -0.9896071041f, 0.1365639107f, -0.04503418428f, 0,
-0.6154342638f, -0.6440875597f, 0.4543037336f, 0, 0.1074204368f, -0.7946340692f, 0.5975094525f, 0, -0.3595449969f, -0.8885529948f, 0.28495784f, 0, -0.2180405296f, 0.1529888965f, 0.9638738118f, 0, -0.7277432317f, -0.6164050508f, -0.3007234646f, 0, 0.7249729114f, -0.00669719484f, 0.6887448187f, 0, -0.5553659455f, -0.5336586252f, 0.6377908264f, 0, 0.5137558015f, 0.7976208196f, -0.3160000073f, 0,
-0.3794024848f, 0.9245608561f, -0.03522751494f, 0, 0.8229248658f, 0.2745365933f, -0.4974176556f, 0, -0.5404114394f, 0.6091141441f, 0.5804613989f, 0, 0.8036581901f, -0.2703029469f, 0.5301601931f, 0, 0.6044318879f, 0.6832968393f, 0.4095943388f, 0, 0.06389988817f, 0.9658208605f, -0.2512108074f, 0, 0.1087113286f, 0.7402471173f, -0.6634877936f, 0, -0.713427712f, -0.6926784018f, 0.1059128479f, 0,
0.6458897819f, -0.5724548511f, -0.5050958653f, 0, -0.6553931414f, 0.7381471625f, 0.159995615f, 0, 0.3910961323f, 0.9188871375f, -0.05186755998f, 0, -0.4879022471f, -0.5904376907f, 0.6429111375f, 0, 0.6014790094f, 0.7707441366f, -0.2101820095f, 0, -0.5677173047f, 0.7511360995f, 0.3368851762f, 0, 0.7858573506f, 0.226674665f, 0.5753666838f, 0, -0.4520345543f, -0.604222686f, -0.6561857263f, 0,
0.002272116345f, 0.4132844051f, -0.9105991643f, 0, -0.5815751419f, -0.5162925989f, 0.6286591339f, 0, -0.03703704785f, 0.8273785755f, 0.5604221175f, 0, -0.5119692504f, 0.7953543429f, -0.3244980058f, 0, -0.2682417366f, -0.9572290247f, -0.1084387619f, 0, -0.2322482736f, -0.9679131102f, -0.09594243324f, 0, 0.3554328906f, -0.8881505545f, 0.2913006227f, 0, 0.7346520519f, -0.4371373164f, 0.5188422971f, 0,
0.9985120116f, 0.04659011161f, -0.02833944577f, 0, -0.3727687496f, -0.9082481361f, 0.1900757285f, 0, 0.91737377f, -0.3483642108f, 0.1925298489f, 0, 0.2714911074f, 0.4147529736f, -0.8684886582f, 0, 0.5131763485f, -0.7116334161f, 0.4798207128f, 0, -0.8737353606f, 0.18886992f, -0.4482350644f, 0, 0.8460043821f, -0.3725217914f, 0.3814499973f, 0, 0.8978727456f, -0.1780209141f, -0.4026575304f, 0,
0.2178065647f, -0.9698322841f, -0.1094789531f, 0, -0.1518031304f, -0.7788918132f, -0.6085091231f, 0, -0.2600384876f, -0.4755398075f, -0.8403819825f, 0, 0.572313509f, -0.7474340931f, -0.3373418503f, 0, -0.7174141009f, 0.1699017182f, -0.6756111411f, 0, -0.684180784f, 0.02145707593f, -0.7289967412f, 0, -0.2007447902f, 0.06555605789f, -0.9774476623f, 0, -0.1148803697f, -0.8044887315f, 0.5827524187f, 0,
-0.7870349638f, 0.03447489231f, 0.6159443543f, 0, -0.2015596421f, 0.6859872284f, 0.6991389226f, 0, -0.08581082512f, -0.10920836f, -0.9903080513f, 0, 0.5532693395f, 0.7325250401f, -0.396610771f, 0, -0.1842489331f, -0.9777375055f, -0.1004076743f, 0, 0.0775473789f, -0.9111505856f, 0.4047110257f, 0, 0.1399838409f, 0.7601631212f, -0.6344734459f, 0, 0.4484419361f, -0.845289248f, 0.2904925424f, 0
};
private static float FastMin(float a, float b) { return a < b ? a : b; }
private static float FastMax(float a, float b) { return a > b ? a : b; }
private static float FastAbs(float f) { return f < 0 ? -f : f; }
private static float FastSqrt(float f) { return (float)Math.sqrt(f); }
private static int FastFloor(/*FNLfloat*/ float f) { return f >= 0 ? (int)f : (int)f - 1; }
private static int FastRound(/*FNLfloat*/ float f) { return f >= 0 ? (int)(f + 0.5f) : (int)(f - 0.5f); }
private static float Lerp(float a, float b, float t) { return a + t * (b - a); }
private static float InterpHermite(float t) { return t * t * (3 - 2 * t); }
private static float InterpQuintic(float t) { return t * t * t * (t * (t * 6 - 15) + 10); }
private static float CubicLerp(float a, float b, float c, float d, float t)
{
float p = (d - c) - (a - b);
return t * t * t * p + t * t * ((a - b) - p) + t * (c - a) + b;
}
private static float PingPong(float t)
{
t -= (int)(t * 0.5f) * 2;
return t < 1 ? t : 2 - t;
}
private void CalculateFractalBounding()
{
float gain = FastAbs(mGain);
float amp = gain;
float ampFractal = 1.0f;
for (int i = 1; i < mOctaves; i++)
{
ampFractal += amp;
amp *= gain;
}
mFractalBounding = 1 / ampFractal;
}
// Hashing
private static final int PrimeX = 501125321;
private static final int PrimeY = 1136930381;
private static final int PrimeZ = 1720413743;
private static int Hash(int seed, int xPrimed, int yPrimed)
{
int hash = seed ^ xPrimed ^ yPrimed;
hash *= 0x27d4eb2d;
return hash;
}
private static int Hash(int seed, int xPrimed, int yPrimed, int zPrimed)
{
int hash = seed ^ xPrimed ^ yPrimed ^ zPrimed;
hash *= 0x27d4eb2d;
return hash;
}
private static float ValCoord(int seed, int xPrimed, int yPrimed)
{
int hash = Hash(seed, xPrimed, yPrimed);
hash *= hash;
hash ^= hash << 19;
return hash * (1 / 2147483648.0f);
}
private static float ValCoord(int seed, int xPrimed, int yPrimed, int zPrimed)
{
int hash = Hash(seed, xPrimed, yPrimed, zPrimed);
hash *= hash;
hash ^= hash << 19;
return hash * (1 / 2147483648.0f);
}
private static float GradCoord(int seed, int xPrimed, int yPrimed, float xd, float yd)
{
int hash = Hash(seed, xPrimed, yPrimed);
hash ^= hash >> 15;
hash &= 127 << 1;
float xg = Gradients2D[hash];
float yg = Gradients2D[hash | 1];
return xd * xg + yd * yg;
}
private static float GradCoord(int seed, int xPrimed, int yPrimed, int zPrimed, float xd, float yd, float zd)
{
int hash = Hash(seed, xPrimed, yPrimed, zPrimed);
hash ^= hash >> 15;
hash &= 63 << 2;
float xg = Gradients3D[hash];
float yg = Gradients3D[hash | 1];
float zg = Gradients3D[hash | 2];
return xd * xg + yd * yg + zd * zg;
}
// Generic noise gen
private float GenNoiseSingle(int seed, /*FNLfloat*/ float x, /*FNLfloat*/ float y)
{
switch (mNoiseType)
{
case OpenSimplex2:
return SingleSimplex(seed, x, y);
case OpenSimplex2S:
return SingleOpenSimplex2S(seed, x, y);
case Cellular:
return SingleCellular(seed, x, y);
case Perlin:
return SinglePerlin(seed, x, y);
case ValueCubic:
return SingleValueCubic(seed, x, y);
case Value:
return SingleValue(seed, x, y);
default:
return 0;
}
}
private float GenNoiseSingle(int seed, /*FNLfloat*/ float x, /*FNLfloat*/ float y, /*FNLfloat*/ float z)
{
switch (mNoiseType)
{
case OpenSimplex2:
return SingleOpenSimplex2(seed, x, y, z);
case OpenSimplex2S:
return SingleOpenSimplex2S(seed, x, y, z);
case Cellular:
return SingleCellular(seed, x, y, z);
case Perlin:
return SinglePerlin(seed, x, y, z);
case ValueCubic:
return SingleValueCubic(seed, x, y, z);
case Value:
return SingleValue(seed, x, y, z);
default:
return 0;
}
}
// Noise Coordinate Transforms (frequency, and possible skew or rotation)
private void UpdateTransformType3D()
{
switch (mRotationType3D)
{
case ImproveXYPlanes:
mTransformType3D = TransformType3D.ImproveXYPlanes;
break;
case ImproveXZPlanes:
mTransformType3D = TransformType3D.ImproveXZPlanes;
break;
default:
switch (mNoiseType)
{
case OpenSimplex2:
case OpenSimplex2S:
mTransformType3D = TransformType3D.DefaultOpenSimplex2;
break;
default:
mTransformType3D = TransformType3D.None;
break;
}
break;
}
}
private void UpdateWarpTransformType3D()
{
switch (mRotationType3D)
{
case ImproveXYPlanes:
mWarpTransformType3D = TransformType3D.ImproveXYPlanes;
break;
case ImproveXZPlanes:
mWarpTransformType3D = TransformType3D.ImproveXZPlanes;
break;
default:
switch (mDomainWarpType)
{
case OpenSimplex2:
case OpenSimplex2Reduced:
mWarpTransformType3D = TransformType3D.DefaultOpenSimplex2;
break;
default:
mWarpTransformType3D = TransformType3D.None;
break;
}
break;
}
}
// Fractal FBm
private float GenFractalFBm(/*FNLfloat*/ float x, /*FNLfloat*/ float y)
{
int seed = mSeed;
float sum = 0;
float amp = mFractalBounding;
for (int i = 0; i < mOctaves; i++)
{
float noise = GenNoiseSingle(seed++, x, y);
sum += noise * amp;
amp *= Lerp(1.0f, FastMin(noise + 1, 2) * 0.5f, mWeightedStrength);
x *= mLacunarity;
y *= mLacunarity;
amp *= mGain;
}
return sum;
}
private float GenFractalFBm(/*FNLfloat*/ float x, /*FNLfloat*/ float y, /*FNLfloat*/ float z)
{
int seed = mSeed;
float sum = 0;
float amp = mFractalBounding;
for (int i = 0; i < mOctaves; i++)
{
float noise = GenNoiseSingle(seed++, x, y, z);
sum += noise * amp;
amp *= Lerp(1.0f, (noise + 1) * 0.5f, mWeightedStrength);
x *= mLacunarity;
y *= mLacunarity;
z *= mLacunarity;
amp *= mGain;
}
return sum;
}
// Fractal Ridged
private float GenFractalRidged(/*FNLfloat*/ float x, /*FNLfloat*/ float y)
{
int seed = mSeed;
float sum = 0;
float amp = mFractalBounding;
for (int i = 0; i < mOctaves; i++)
{
float noise = FastAbs(GenNoiseSingle(seed++, x, y));
sum += (noise * -2 + 1) * amp;
amp *= Lerp(1.0f, 1 - noise, mWeightedStrength);
x *= mLacunarity;
y *= mLacunarity;
amp *= mGain;
}
return sum;
}
private float GenFractalRidged(/*FNLfloat*/ float x, /*FNLfloat*/ float y, /*FNLfloat*/ float z)
{
int seed = mSeed;
float sum = 0;
float amp = mFractalBounding;
for (int i = 0; i < mOctaves; i++)
{
float noise = FastAbs(GenNoiseSingle(seed++, x, y, z));
sum += (noise * -2 + 1) * amp;
amp *= Lerp(1.0f, 1 - noise, mWeightedStrength);
x *= mLacunarity;
y *= mLacunarity;
z *= mLacunarity;
amp *= mGain;
}
return sum;
}
// Fractal PingPong
private float GenFractalPingPong(/*FNLfloat*/ float x, /*FNLfloat*/ float y)
{
int seed = mSeed;
float sum = 0;
float amp = mFractalBounding;
for (int i = 0; i < mOctaves; i++)
{
float noise = PingPong((GenNoiseSingle(seed++, x, y) + 1) * mPingPongStrength);
sum += (noise - 0.5f) * 2 * amp;
amp *= Lerp(1.0f, noise, mWeightedStrength);
x *= mLacunarity;
y *= mLacunarity;
amp *= mGain;
}
return sum;
}
private float GenFractalPingPong(/*FNLfloat*/ float x, /*FNLfloat*/ float y, /*FNLfloat*/ float z)
{
int seed = mSeed;
float sum = 0;
float amp = mFractalBounding;
for (int i = 0; i < mOctaves; i++)
{
float noise = PingPong((GenNoiseSingle(seed++, x, y, z) + 1) * mPingPongStrength);
sum += (noise - 0.5f) * 2 * amp;
amp *= Lerp(1.0f, noise, mWeightedStrength);
x *= mLacunarity;
y *= mLacunarity;
z *= mLacunarity;
amp *= mGain;
}
return sum;
}
// Simplex/OpenSimplex2 Noise
private float SingleSimplex(int seed, /*FNLfloat*/ float x, /*FNLfloat*/ float y)
{
// 2D OpenSimplex2 case uses the same algorithm as ordinary Simplex.
final float SQRT3 = 1.7320508075688772935274463415059f;
final float G2 = (3 - SQRT3) / 6;
/*
* --- Skew moved to switch statements before fractal evaluation ---
* final FNLfloat F2 = 0.5f * (SQRT3 - 1);
* FNLfloat s = (x + y) * F2;
* x += s; y += s;
*/
int i = FastFloor(x);
int j = FastFloor(y);
float xi = (float)(x - i);
float yi = (float)(y - j);
float t = (xi + yi) * G2;
float x0 = (float)(xi - t);
float y0 = (float)(yi - t);
i *= PrimeX;
j *= PrimeY;
float n0, n1, n2;
float a = 0.5f - x0 * x0 - y0 * y0;
if (a <= 0) n0 = 0;
else
{
n0 = (a * a) * (a * a) * GradCoord(seed, i, j, x0, y0);
}
float c = (float)(2 * (1 - 2 * G2) * (1 / G2 - 2)) * t + ((float)(-2 * (1 - 2 * G2) * (1 - 2 * G2)) + a);
if (c <= 0) n2 = 0;
else
{
float x2 = x0 + (2 * (float)G2 - 1);
float y2 = y0 + (2 * (float)G2 - 1);
n2 = (c * c) * (c * c) * GradCoord(seed, i + PrimeX, j + PrimeY, x2, y2);
}
if (y0 > x0)
{
float x1 = x0 + (float)G2;
float y1 = y0 + ((float)G2 - 1);
float b = 0.5f - x1 * x1 - y1 * y1;
if (b <= 0) n1 = 0;
else
{
n1 = (b * b) * (b * b) * GradCoord(seed, i, j + PrimeY, x1, y1);
}
}
else
{
float x1 = x0 + ((float)G2 - 1);
float y1 = y0 + (float)G2;
float b = 0.5f - x1 * x1 - y1 * y1;
if (b <= 0) n1 = 0;
else
{
n1 = (b * b) * (b * b) * GradCoord(seed, i + PrimeX, j, x1, y1);
}
}
return (n0 + n1 + n2) * 99.83685446303647f;
}
private float SingleOpenSimplex2(int seed, /*FNLfloat*/ float x, /*FNLfloat*/ float y, /*FNLfloat*/ float z)
{
// 3D OpenSimplex2 case uses two offset rotated cube grids.
/*
* --- Rotation moved to switch statements before fractal evaluation ---
* final FNLfloat R3 = (FNLfloat)(2.0 / 3.0);
* FNLfloat r = (x + y + z) * R3; // Rotation, not skew
* x = r - x; y = r - y; z = r - z;
*/
int i = FastRound(x);
int j = FastRound(y);
int k = FastRound(z);
float x0 = (float)(x - i);
float y0 = (float)(y - j);
float z0 = (float)(z - k);
int xNSign = (int)(-1.0f - x0) | 1;
int yNSign = (int)(-1.0f - y0) | 1;
int zNSign = (int)(-1.0f - z0) | 1;
float ax0 = xNSign * -x0;
float ay0 = yNSign * -y0;
float az0 = zNSign * -z0;
i *= PrimeX;
j *= PrimeY;
k *= PrimeZ;
float value = 0;
float a = (0.6f - x0 * x0) - (y0 * y0 + z0 * z0);
for (int l = 0; ; l++)
{
if (a > 0)
{
value += (a * a) * (a * a) * GradCoord(seed, i, j, k, x0, y0, z0);
}
if (ax0 >= ay0 && ax0 >= az0)
{
float b = a + ax0 + ax0;
if (b > 1)
{
b -= 1;
value += (b * b) * (b * b) * GradCoord(seed, i - xNSign * PrimeX, j, k, x0 + xNSign, y0, z0);
}
}
else if (ay0 > ax0 && ay0 >= az0)
{
float b = a + ay0 + ay0;
if (b > 1)
{
b -= 1;
value += (b * b) * (b * b) * GradCoord(seed, i, j - yNSign * PrimeY, k, x0, y0 + yNSign, z0);
}
}
else
{
float b = a + az0 + az0;
if (b > 1)
{
b -= 1;
value += (b * b) * (b * b) * GradCoord(seed, i, j, k - zNSign * PrimeZ, x0, y0, z0 + zNSign);
}
}
if (l == 1) break;
ax0 = 0.5f - ax0;
ay0 = 0.5f - ay0;
az0 = 0.5f - az0;
x0 = xNSign * ax0;
y0 = yNSign * ay0;
z0 = zNSign * az0;
a += (0.75f - ax0) - (ay0 + az0);
i += (xNSign >> 1) & PrimeX;
j += (yNSign >> 1) & PrimeY;
k += (zNSign >> 1) & PrimeZ;
xNSign = -xNSign;
yNSign = -yNSign;
zNSign = -zNSign;
seed = ~seed;
}
return value * 32.69428253173828125f;
}
// OpenSimplex2S Noise
private float SingleOpenSimplex2S(int seed, /*FNLfloat*/ float x, /*FNLfloat*/ float y)
{
// 2D OpenSimplex2S case is a modified 2D simplex noise.
final /*FNLfloat*/ float SQRT3 = (/*FNLfloat*/ float)1.7320508075688772935274463415059;
final /*FNLfloat*/ float G2 = (3 - SQRT3) / 6;
/*
* --- Skew moved to TransformNoiseCoordinate method ---
* final FNLfloat F2 = 0.5f * (SQRT3 - 1);
* FNLfloat s = (x + y) * F2;
* x += s; y += s;
*/
int i = FastFloor(x);
int j = FastFloor(y);
float xi = (float)(x - i);
float yi = (float)(y - j);
i *= PrimeX;
j *= PrimeY;
int i1 = i + PrimeX;
int j1 = j + PrimeY;
float t = (xi + yi) * (float)G2;
float x0 = xi - t;
float y0 = yi - t;
float a0 = (2.0f / 3.0f) - x0 * x0 - y0 * y0;
float value = (a0 * a0) * (a0 * a0) * GradCoord(seed, i, j, x0, y0);
float a1 = (float)(2 * (1 - 2 * G2) * (1 / G2 - 2)) * t + ((float)(-2 * (1 - 2 * G2) * (1 - 2 * G2)) + a0);
float x1 = x0 - (float)(1 - 2 * G2);
float y1 = y0 - (float)(1 - 2 * G2);
value += (a1 * a1) * (a1 * a1) * GradCoord(seed, i1, j1, x1, y1);
// Nested conditionals were faster than compact bit logic/arithmetic.
float xmyi = xi - yi;
if (t > G2)
{
if (xi + xmyi > 1)
{
float x2 = x0 + (float)(3 * G2 - 2);
float y2 = y0 + (float)(3 * G2 - 1);
float a2 = (2.0f / 3.0f) - x2 * x2 - y2 * y2;
if (a2 > 0)
{
value += (a2 * a2) * (a2 * a2) * GradCoord(seed, i + (PrimeX << 1), j + PrimeY, x2, y2);
}
}
else
{
float x2 = x0 + (float)G2;
float y2 = y0 + (float)(G2 - 1);
float a2 = (2.0f / 3.0f) - x2 * x2 - y2 * y2;
if (a2 > 0)
{
value += (a2 * a2) * (a2 * a2) * GradCoord(seed, i, j + PrimeY, x2, y2);
}
}
if (yi - xmyi > 1)
{
float x3 = x0 + (float)(3 * G2 - 1);
float y3 = y0 + (float)(3 * G2 - 2);
float a3 = (2.0f / 3.0f) - x3 * x3 - y3 * y3;
if (a3 > 0)
{
value += (a3 * a3) * (a3 * a3) * GradCoord(seed, i + PrimeX, j + (PrimeY << 1), x3, y3);
}
}
else
{
float x3 = x0 + (float)(G2 - 1);
float y3 = y0 + (float)G2;
float a3 = (2.0f / 3.0f) - x3 * x3 - y3 * y3;
if (a3 > 0)
{
value += (a3 * a3) * (a3 * a3) * GradCoord(seed, i + PrimeX, j, x3, y3);
}
}
}
else
{
if (xi + xmyi < 0)
{
float x2 = x0 + (float)(1 - G2);
float y2 = y0 - (float)G2;
float a2 = (2.0f / 3.0f) - x2 * x2 - y2 * y2;
if (a2 > 0)
{
value += (a2 * a2) * (a2 * a2) * GradCoord(seed, i - PrimeX, j, x2, y2);
}
}
else
{
float x2 = x0 + (float)(G2 - 1);
float y2 = y0 + (float)G2;
float a2 = (2.0f / 3.0f) - x2 * x2 - y2 * y2;
if (a2 > 0)
{
value += (a2 * a2) * (a2 * a2) * GradCoord(seed, i + PrimeX, j, x2, y2);
}
}
if (yi < xmyi)
{
float x2 = x0 - (float)G2;
float y2 = y0 - (float)(G2 - 1);
float a2 = (2.0f / 3.0f) - x2 * x2 - y2 * y2;
if (a2 > 0)
{
value += (a2 * a2) * (a2 * a2) * GradCoord(seed, i, j - PrimeY, x2, y2);
}
}
else
{
float x2 = x0 + (float)G2;
float y2 = y0 + (float)(G2 - 1);
float a2 = (2.0f / 3.0f) - x2 * x2 - y2 * y2;
if (a2 > 0)
{
value += (a2 * a2) * (a2 * a2) * GradCoord(seed, i, j + PrimeY, x2, y2);
}
}
}
return value * 18.24196194486065f;
}
private float SingleOpenSimplex2S(int seed, /*FNLfloat*/ float x, /*FNLfloat*/ float y, /*FNLfloat*/ float z)
{
// 3D OpenSimplex2S case uses two offset rotated cube grids.
/*
* --- Rotation moved to TransformNoiseCoordinate method ---
* final FNLfloat R3 = (FNLfloat)(2.0 / 3.0);
* FNLfloat r = (x + y + z) * R3; // Rotation, not skew
* x = r - x; y = r - y; z = r - z;
*/
int i = FastFloor(x);
int j = FastFloor(y);
int k = FastFloor(z);
float xi = (float)(x - i);
float yi = (float)(y - j);
float zi = (float)(z - k);
i *= PrimeX;
j *= PrimeY;
k *= PrimeZ;
int seed2 = seed + 1293373;
int xNMask = (int)(-0.5f - xi);
int yNMask = (int)(-0.5f - yi);
int zNMask = (int)(-0.5f - zi);
float x0 = xi + xNMask;
float y0 = yi + yNMask;
float z0 = zi + zNMask;
float a0 = 0.75f - x0 * x0 - y0 * y0 - z0 * z0;
float value = (a0 * a0) * (a0 * a0) * GradCoord(seed,
i + (xNMask & PrimeX), j + (yNMask & PrimeY), k + (zNMask & PrimeZ), x0, y0, z0);
float x1 = xi - 0.5f;
float y1 = yi - 0.5f;
float z1 = zi - 0.5f;
float a1 = 0.75f - x1 * x1 - y1 * y1 - z1 * z1;
value += (a1 * a1) * (a1 * a1) * GradCoord(seed2,
i + PrimeX, j + PrimeY, k + PrimeZ, x1, y1, z1);
float xAFlipMask0 = ((xNMask | 1) << 1) * x1;
float yAFlipMask0 = ((yNMask | 1) << 1) * y1;
float zAFlipMask0 = ((zNMask | 1) << 1) * z1;
float xAFlipMask1 = (-2 - (xNMask << 2)) * x1 - 1.0f;
float yAFlipMask1 = (-2 - (yNMask << 2)) * y1 - 1.0f;
float zAFlipMask1 = (-2 - (zNMask << 2)) * z1 - 1.0f;
boolean skip5 = false;
float a2 = xAFlipMask0 + a0;
if (a2 > 0)
{
float x2 = x0 - (xNMask | 1);
float y2 = y0;
float z2 = z0;
value += (a2 * a2) * (a2 * a2) * GradCoord(seed,
i + (~xNMask & PrimeX), j + (yNMask & PrimeY), k + (zNMask & PrimeZ), x2, y2, z2);
}
else
{
float a3 = yAFlipMask0 + zAFlipMask0 + a0;
if (a3 > 0)
{
float x3 = x0;
float y3 = y0 - (yNMask | 1);
float z3 = z0 - (zNMask | 1);
value += (a3 * a3) * (a3 * a3) * GradCoord(seed,
i + (xNMask & PrimeX), j + (~yNMask & PrimeY), k + (~zNMask & PrimeZ), x3, y3, z3);
}
float a4 = xAFlipMask1 + a1;
if (a4 > 0)
{
float x4 = (xNMask | 1) + x1;
float y4 = y1;
float z4 = z1;
value += (a4 * a4) * (a4 * a4) * GradCoord(seed2,
i + (xNMask & (PrimeX * 2)), j + PrimeY, k + PrimeZ, x4, y4, z4);
skip5 = true;
}
}
boolean skip9 = false;
float a6 = yAFlipMask0 + a0;
if (a6 > 0)
{
float x6 = x0;
float y6 = y0 - (yNMask | 1);
float z6 = z0;
value += (a6 * a6) * (a6 * a6) * GradCoord(seed,
i + (xNMask & PrimeX), j + (~yNMask & PrimeY), k + (zNMask & PrimeZ), x6, y6, z6);
}
else
{
float a7 = xAFlipMask0 + zAFlipMask0 + a0;
if (a7 > 0)
{
float x7 = x0 - (xNMask | 1);
float y7 = y0;
float z7 = z0 - (zNMask | 1);
value += (a7 * a7) * (a7 * a7) * GradCoord(seed,
i + (~xNMask & PrimeX), j + (yNMask & PrimeY), k + (~zNMask & PrimeZ), x7, y7, z7);
}
float a8 = yAFlipMask1 + a1;
if (a8 > 0)
{
float x8 = x1;
float y8 = (yNMask | 1) + y1;
float z8 = z1;
value += (a8 * a8) * (a8 * a8) * GradCoord(seed2,
i + PrimeX, j + (yNMask & (PrimeY << 1)), k + PrimeZ, x8, y8, z8);
skip9 = true;
}
}
boolean skipD = false;
float aA = zAFlipMask0 + a0;
if (aA > 0)
{
float xA = x0;
float yA = y0;
float zA = z0 - (zNMask | 1);
value += (aA * aA) * (aA * aA) * GradCoord(seed,
i + (xNMask & PrimeX), j + (yNMask & PrimeY), k + (~zNMask & PrimeZ), xA, yA, zA);
}
else
{
float aB = xAFlipMask0 + yAFlipMask0 + a0;
if (aB > 0)
{
float xB = x0 - (xNMask | 1);
float yB = y0 - (yNMask | 1);
float zB = z0;
value += (aB * aB) * (aB * aB) * GradCoord(seed,
i + (~xNMask & PrimeX), j + (~yNMask & PrimeY), k + (zNMask & PrimeZ), xB, yB, zB);
}
float aC = zAFlipMask1 + a1;
if (aC > 0)
{
float xC = x1;
float yC = y1;
float zC = (zNMask | 1) + z1;
value += (aC * aC) * (aC * aC) * GradCoord(seed2,
i + PrimeX, j + PrimeY, k + (zNMask & (PrimeZ << 1)), xC, yC, zC);
skipD = true;
}
}
if (!skip5)
{
float a5 = yAFlipMask1 + zAFlipMask1 + a1;
if (a5 > 0)
{
float x5 = x1;
float y5 = (yNMask | 1) + y1;
float z5 = (zNMask | 1) + z1;
value += (a5 * a5) * (a5 * a5) * GradCoord(seed2,
i + PrimeX, j + (yNMask & (PrimeY << 1)), k + (zNMask & (PrimeZ << 1)), x5, y5, z5);
}
}
if (!skip9)
{
float a9 = xAFlipMask1 + zAFlipMask1 + a1;
if (a9 > 0)
{
float x9 = (xNMask | 1) + x1;
float y9 = y1;
float z9 = (zNMask | 1) + z1;
value += (a9 * a9) * (a9 * a9) * GradCoord(seed2,
i + (xNMask & (PrimeX * 2)), j + PrimeY, k + (zNMask & (PrimeZ << 1)), x9, y9, z9);
}
}
if (!skipD)
{
float aD = xAFlipMask1 + yAFlipMask1 + a1;
if (aD > 0)
{
float xD = (xNMask | 1) + x1;
float yD = (yNMask | 1) + y1;
float zD = z1;
value += (aD * aD) * (aD * aD) * GradCoord(seed2,
i + (xNMask & (PrimeX << 1)), j + (yNMask & (PrimeY << 1)), k + PrimeZ, xD, yD, zD);
}
}
return value * 9.046026385208288f;
}
// Cellular Noise
private float SingleCellular(int seed, /*FNLfloat*/ float x, /*FNLfloat*/ float y)
{
int xr = FastRound(x);
int yr = FastRound(y);
float distance0 = Float.MAX_VALUE;
float distance1 = Float.MAX_VALUE;
int closestHash = 0;
float cellularJitter = 0.43701595f * mCellularJitterModifier;
int xPrimed = (xr - 1) * PrimeX;
int yPrimedBase = (yr - 1) * PrimeY;
switch (mCellularDistanceFunction)
{
default:
case Euclidean:
case EuclideanSq:
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int hash = Hash(seed, xPrimed, yPrimed);
int idx = hash & (255 << 1);
float vecX = (float)(xi - x) + RandVecs2D[idx] * cellularJitter;
float vecY = (float)(yi - y) + RandVecs2D[idx | 1] * cellularJitter;
float newDistance = vecX * vecX + vecY * vecY;
distance1 = FastMax(FastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
yPrimed += PrimeY;
}
xPrimed += PrimeX;
}
break;
case Manhattan:
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int hash = Hash(seed, xPrimed, yPrimed);
int idx = hash & (255 << 1);
float vecX = (float)(xi - x) + RandVecs2D[idx] * cellularJitter;
float vecY = (float)(yi - y) + RandVecs2D[idx | 1] * cellularJitter;
float newDistance = FastAbs(vecX) + FastAbs(vecY);
distance1 = FastMax(FastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
yPrimed += PrimeY;
}
xPrimed += PrimeX;
}
break;
case Hybrid:
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int hash = Hash(seed, xPrimed, yPrimed);
int idx = hash & (255 << 1);
float vecX = (float)(xi - x) + RandVecs2D[idx] * cellularJitter;
float vecY = (float)(yi - y) + RandVecs2D[idx | 1] * cellularJitter;
float newDistance = (FastAbs(vecX) + FastAbs(vecY)) + (vecX * vecX + vecY * vecY);
distance1 = FastMax(FastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
yPrimed += PrimeY;
}
xPrimed += PrimeX;
}
break;
}
if (mCellularDistanceFunction == CellularDistanceFunction.Euclidean && mCellularReturnType != CellularReturnType.CellValue)
{
distance0 = FastSqrt(distance0);
if (mCellularReturnType != CellularReturnType.Distance)
{
distance1 = FastSqrt(distance1);
}
}
switch (mCellularReturnType)
{
case CellValue:
return closestHash * (1 / 2147483648.0f);
case Distance:
return distance0 - 1;
case Distance2:
return distance1 - 1;
case Distance2Add:
return (distance1 + distance0) * 0.5f - 1;
case Distance2Sub:
return distance1 - distance0 - 1;
case Distance2Mul:
return distance1 * distance0 * 0.5f - 1;
case Distance2Div:
return distance0 / distance1 - 1;
default:
return 0;
}
}
private float SingleCellular(int seed, /*FNLfloat*/ float x, /*FNLfloat*/ float y, /*FNLfloat*/ float z)
{
int xr = FastRound(x);
int yr = FastRound(y);
int zr = FastRound(z);
float distance0 = Float.MAX_VALUE;
float distance1 = Float.MAX_VALUE;
int closestHash = 0;
float cellularJitter = 0.39614353f * mCellularJitterModifier;
int xPrimed = (xr - 1) * PrimeX;
int yPrimedBase = (yr - 1) * PrimeY;
int zPrimedBase = (zr - 1) * PrimeZ;
switch (mCellularDistanceFunction)
{
case Euclidean:
case EuclideanSq:
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int zPrimed = zPrimedBase;
for (int zi = zr - 1; zi <= zr + 1; zi++)
{
int hash = Hash(seed, xPrimed, yPrimed, zPrimed);
int idx = hash & (255 << 2);
float vecX = (float)(xi - x) + RandVecs3D[idx] * cellularJitter;
float vecY = (float)(yi - y) + RandVecs3D[idx | 1] * cellularJitter;
float vecZ = (float)(zi - z) + RandVecs3D[idx | 2] * cellularJitter;
float newDistance = vecX * vecX + vecY * vecY + vecZ * vecZ;
distance1 = FastMax(FastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
zPrimed += PrimeZ;
}
yPrimed += PrimeY;
}
xPrimed += PrimeX;
}
break;
case Manhattan:
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int zPrimed = zPrimedBase;
for (int zi = zr - 1; zi <= zr + 1; zi++)
{
int hash = Hash(seed, xPrimed, yPrimed, zPrimed);
int idx = hash & (255 << 2);
float vecX = (float)(xi - x) + RandVecs3D[idx] * cellularJitter;
float vecY = (float)(yi - y) + RandVecs3D[idx | 1] * cellularJitter;
float vecZ = (float)(zi - z) + RandVecs3D[idx | 2] * cellularJitter;
float newDistance = FastAbs(vecX) + FastAbs(vecY) + FastAbs(vecZ);
distance1 = FastMax(FastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
zPrimed += PrimeZ;
}
yPrimed += PrimeY;
}
xPrimed += PrimeX;
}
break;
case Hybrid:
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int zPrimed = zPrimedBase;
for (int zi = zr - 1; zi <= zr + 1; zi++)
{
int hash = Hash(seed, xPrimed, yPrimed, zPrimed);
int idx = hash & (255 << 2);
float vecX = (float)(xi - x) + RandVecs3D[idx] * cellularJitter;
float vecY = (float)(yi - y) + RandVecs3D[idx | 1] * cellularJitter;
float vecZ = (float)(zi - z) + RandVecs3D[idx | 2] * cellularJitter;
float newDistance = (FastAbs(vecX) + FastAbs(vecY) + FastAbs(vecZ)) + (vecX * vecX + vecY * vecY + vecZ * vecZ);
distance1 = FastMax(FastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
zPrimed += PrimeZ;
}
yPrimed += PrimeY;
}
xPrimed += PrimeX;
}
break;
default:
break;
}
if (mCellularDistanceFunction == CellularDistanceFunction.Euclidean && mCellularReturnType != CellularReturnType.CellValue)
{
distance0 = FastSqrt(distance0);
if (mCellularReturnType != CellularReturnType.Distance)
{
distance1 = FastSqrt(distance1);
}
}
switch (mCellularReturnType)
{
case CellValue:
return closestHash * (1 / 2147483648.0f);
case Distance:
return distance0 - 1;
case Distance2:
return distance1 - 1;
case Distance2Add:
return (distance1 + distance0) * 0.5f - 1;
case Distance2Sub:
return distance1 - distance0 - 1;
case Distance2Mul:
return distance1 * distance0 * 0.5f - 1;
case Distance2Div:
return distance0 / distance1 - 1;
default:
return 0;
}
}
// Perlin Noise
private float SinglePerlin(int seed, /*FNLfloat*/ float x, /*FNLfloat*/ float y)
{
int x0 = FastFloor(x);
int y0 = FastFloor(y);
float xd0 = (float)(x - x0);
float yd0 = (float)(y - y0);
float xd1 = xd0 - 1;
float yd1 = yd0 - 1;
float xs = InterpQuintic(xd0);
float ys = InterpQuintic(yd0);
x0 *= PrimeX;
y0 *= PrimeY;
int x1 = x0 + PrimeX;
int y1 = y0 + PrimeY;
float xf0 = Lerp(GradCoord(seed, x0, y0, xd0, yd0), GradCoord(seed, x1, y0, xd1, yd0), xs);
float xf1 = Lerp(GradCoord(seed, x0, y1, xd0, yd1), GradCoord(seed, x1, y1, xd1, yd1), xs);
return Lerp(xf0, xf1, ys) * 1.4247691104677813f;
}
private float SinglePerlin(int seed, /*FNLfloat*/ float x, /*FNLfloat*/ float y, /*FNLfloat*/ float z)
{
int x0 = FastFloor(x);
int y0 = FastFloor(y);
int z0 = FastFloor(z);
float xd0 = (float)(x - x0);
float yd0 = (float)(y - y0);
float zd0 = (float)(z - z0);
float xd1 = xd0 - 1;
float yd1 = yd0 - 1;
float zd1 = zd0 - 1;
float xs = InterpQuintic(xd0);
float ys = InterpQuintic(yd0);
float zs = InterpQuintic(zd0);
x0 *= PrimeX;
y0 *= PrimeY;
z0 *= PrimeZ;
int x1 = x0 + PrimeX;
int y1 = y0 + PrimeY;
int z1 = z0 + PrimeZ;
float xf00 = Lerp(GradCoord(seed, x0, y0, z0, xd0, yd0, zd0), GradCoord(seed, x1, y0, z0, xd1, yd0, zd0), xs);
float xf10 = Lerp(GradCoord(seed, x0, y1, z0, xd0, yd1, zd0), GradCoord(seed, x1, y1, z0, xd1, yd1, zd0), xs);
float xf01 = Lerp(GradCoord(seed, x0, y0, z1, xd0, yd0, zd1), GradCoord(seed, x1, y0, z1, xd1, yd0, zd1), xs);
float xf11 = Lerp(GradCoord(seed, x0, y1, z1, xd0, yd1, zd1), GradCoord(seed, x1, y1, z1, xd1, yd1, zd1), xs);
float yf0 = Lerp(xf00, xf10, ys);
float yf1 = Lerp(xf01, xf11, ys);
return Lerp(yf0, yf1, zs) * 0.964921414852142333984375f;
}
// Value Cubic Noise
private float SingleValueCubic(int seed, /*FNLfloat*/ float x, /*FNLfloat*/ float y)
{
int x1 = FastFloor(x);
int y1 = FastFloor(y);
float xs = (float)(x - x1);
float ys = (float)(y - y1);
x1 *= PrimeX;
y1 *= PrimeY;
int x0 = x1 - PrimeX;
int y0 = y1 - PrimeY;
int x2 = x1 + PrimeX;
int y2 = y1 + PrimeY;
int x3 = x1 + (PrimeX << 1);
int y3 = y1 + (PrimeY << 1);
return CubicLerp(
CubicLerp(ValCoord(seed, x0, y0), ValCoord(seed, x1, y0), ValCoord(seed, x2, y0), ValCoord(seed, x3, y0),
xs),
CubicLerp(ValCoord(seed, x0, y1), ValCoord(seed, x1, y1), ValCoord(seed, x2, y1), ValCoord(seed, x3, y1),
xs),
CubicLerp(ValCoord(seed, x0, y2), ValCoord(seed, x1, y2), ValCoord(seed, x2, y2), ValCoord(seed, x3, y2),
xs),
CubicLerp(ValCoord(seed, x0, y3), ValCoord(seed, x1, y3), ValCoord(seed, x2, y3), ValCoord(seed, x3, y3),
xs),
ys) * (1 / (1.5f * 1.5f));
}
private float SingleValueCubic(int seed, /*FNLfloat*/ float x, /*FNLfloat*/ float y, /*FNLfloat*/ float z)
{
int x1 = FastFloor(x);
int y1 = FastFloor(y);
int z1 = FastFloor(z);
float xs = (float)(x - x1);
float ys = (float)(y - y1);
float zs = (float)(z - z1);
x1 *= PrimeX;
y1 *= PrimeY;
z1 *= PrimeZ;
int x0 = x1 - PrimeX;
int y0 = y1 - PrimeY;
int z0 = z1 - PrimeZ;
int x2 = x1 + PrimeX;
int y2 = y1 + PrimeY;
int z2 = z1 + PrimeZ;
int x3 = x1 + (PrimeX << 1);
int y3 = y1 + (PrimeY << 1);
int z3 = z1 + (PrimeZ << 1);
return CubicLerp(
CubicLerp(
CubicLerp(ValCoord(seed, x0, y0, z0), ValCoord(seed, x1, y0, z0), ValCoord(seed, x2, y0, z0), ValCoord(seed, x3, y0, z0), xs),
CubicLerp(ValCoord(seed, x0, y1, z0), ValCoord(seed, x1, y1, z0), ValCoord(seed, x2, y1, z0), ValCoord(seed, x3, y1, z0), xs),
CubicLerp(ValCoord(seed, x0, y2, z0), ValCoord(seed, x1, y2, z0), ValCoord(seed, x2, y2, z0), ValCoord(seed, x3, y2, z0), xs),
CubicLerp(ValCoord(seed, x0, y3, z0), ValCoord(seed, x1, y3, z0), ValCoord(seed, x2, y3, z0), ValCoord(seed, x3, y3, z0), xs),
ys),
CubicLerp(
CubicLerp(ValCoord(seed, x0, y0, z1), ValCoord(seed, x1, y0, z1), ValCoord(seed, x2, y0, z1), ValCoord(seed, x3, y0, z1), xs),
CubicLerp(ValCoord(seed, x0, y1, z1), ValCoord(seed, x1, y1, z1), ValCoord(seed, x2, y1, z1), ValCoord(seed, x3, y1, z1), xs),
CubicLerp(ValCoord(seed, x0, y2, z1), ValCoord(seed, x1, y2, z1), ValCoord(seed, x2, y2, z1), ValCoord(seed, x3, y2, z1), xs),
CubicLerp(ValCoord(seed, x0, y3, z1), ValCoord(seed, x1, y3, z1), ValCoord(seed, x2, y3, z1), ValCoord(seed, x3, y3, z1), xs),
ys),
CubicLerp(
CubicLerp(ValCoord(seed, x0, y0, z2), ValCoord(seed, x1, y0, z2), ValCoord(seed, x2, y0, z2), ValCoord(seed, x3, y0, z2), xs),
CubicLerp(ValCoord(seed, x0, y1, z2), ValCoord(seed, x1, y1, z2), ValCoord(seed, x2, y1, z2), ValCoord(seed, x3, y1, z2), xs),
CubicLerp(ValCoord(seed, x0, y2, z2), ValCoord(seed, x1, y2, z2), ValCoord(seed, x2, y2, z2), ValCoord(seed, x3, y2, z2), xs),
CubicLerp(ValCoord(seed, x0, y3, z2), ValCoord(seed, x1, y3, z2), ValCoord(seed, x2, y3, z2), ValCoord(seed, x3, y3, z2), xs),
ys),
CubicLerp(
CubicLerp(ValCoord(seed, x0, y0, z3), ValCoord(seed, x1, y0, z3), ValCoord(seed, x2, y0, z3), ValCoord(seed, x3, y0, z3), xs),
CubicLerp(ValCoord(seed, x0, y1, z3), ValCoord(seed, x1, y1, z3), ValCoord(seed, x2, y1, z3), ValCoord(seed, x3, y1, z3), xs),
CubicLerp(ValCoord(seed, x0, y2, z3), ValCoord(seed, x1, y2, z3), ValCoord(seed, x2, y2, z3), ValCoord(seed, x3, y2, z3), xs),
CubicLerp(ValCoord(seed, x0, y3, z3), ValCoord(seed, x1, y3, z3), ValCoord(seed, x2, y3, z3), ValCoord(seed, x3, y3, z3), xs),
ys),
zs) * (1 / (1.5f * 1.5f * 1.5f));
}
// Value Noise
private float SingleValue(int seed, /*FNLfloat*/ float x, /*FNLfloat*/ float y)
{
int x0 = FastFloor(x);
int y0 = FastFloor(y);
float xs = InterpHermite((float)(x - x0));
float ys = InterpHermite((float)(y - y0));
x0 *= PrimeX;
y0 *= PrimeY;
int x1 = x0 + PrimeX;
int y1 = y0 + PrimeY;
float xf0 = Lerp(ValCoord(seed, x0, y0), ValCoord(seed, x1, y0), xs);
float xf1 = Lerp(ValCoord(seed, x0, y1), ValCoord(seed, x1, y1), xs);
return Lerp(xf0, xf1, ys);
}
private float SingleValue(int seed, /*FNLfloat*/ float x, /*FNLfloat*/ float y, /*FNLfloat*/ float z)
{
int x0 = FastFloor(x);
int y0 = FastFloor(y);
int z0 = FastFloor(z);
float xs = InterpHermite((float)(x - x0));
float ys = InterpHermite((float)(y - y0));
float zs = InterpHermite((float)(z - z0));
x0 *= PrimeX;
y0 *= PrimeY;
z0 *= PrimeZ;
int x1 = x0 + PrimeX;
int y1 = y0 + PrimeY;
int z1 = z0 + PrimeZ;
float xf00 = Lerp(ValCoord(seed, x0, y0, z0), ValCoord(seed, x1, y0, z0), xs);
float xf10 = Lerp(ValCoord(seed, x0, y1, z0), ValCoord(seed, x1, y1, z0), xs);
float xf01 = Lerp(ValCoord(seed, x0, y0, z1), ValCoord(seed, x1, y0, z1), xs);
float xf11 = Lerp(ValCoord(seed, x0, y1, z1), ValCoord(seed, x1, y1, z1), xs);
float yf0 = Lerp(xf00, xf10, ys);
float yf1 = Lerp(xf01, xf11, ys);
return Lerp(yf0, yf1, zs);
}
// Domain Warp
private void DoSingleDomainWarp(int seed, float amp, float freq, /*FNLfloat*/ float x, /*FNLfloat*/ float y, Vector2 coord)
{
switch (mDomainWarpType)
{
case OpenSimplex2:
SingleDomainWarpSimplexGradient(seed, amp * 38.283687591552734375f, freq, x, y, coord, false);
break;
case OpenSimplex2Reduced:
SingleDomainWarpSimplexGradient(seed, amp * 16.0f, freq, x, y, coord, true);
break;
case BasicGrid:
SingleDomainWarpBasicGrid(seed, amp, freq, x, y, coord);
break;
}
}
private void DoSingleDomainWarp(int seed, float amp, float freq, /*FNLfloat*/ float x, /*FNLfloat*/ float y, /*FNLfloat*/ float z, Vector3 coord)
{
switch (mDomainWarpType)
{
case OpenSimplex2:
SingleDomainWarpOpenSimplex2Gradient(seed, amp * 32.69428253173828125f, freq, x, y, z, coord, false);
break;
case OpenSimplex2Reduced:
SingleDomainWarpOpenSimplex2Gradient(seed, amp * 7.71604938271605f, freq, x, y, z, coord, true);
break;
case BasicGrid:
SingleDomainWarpBasicGrid(seed, amp, freq, x, y, z, coord);
break;
}
}
// Domain Warp Single Wrapper
private void DomainWarpSingle(Vector2 coord)
{
int seed = mSeed;
float amp = mDomainWarpAmp * mFractalBounding;
float freq = mFrequency;
/*FNLfloat*/ float xs = coord.x;
/*FNLfloat*/ float ys = coord.y;
switch (mDomainWarpType)
{
case OpenSimplex2:
case OpenSimplex2Reduced:
{
final /*FNLfloat*/ float SQRT3 = (/*FNLfloat*/ float)1.7320508075688772935274463415059;
final /*FNLfloat*/ float F2 = 0.5f * (SQRT3 - 1);
/*FNLfloat*/ float t = (xs + ys) * F2;
xs += t; ys += t;
}
break;
default:
break;
}
DoSingleDomainWarp(seed, amp, freq, xs, ys, coord);
}
private void DomainWarpSingle(Vector3 coord)
{
int seed = mSeed;
float amp = mDomainWarpAmp * mFractalBounding;
float freq = mFrequency;
/*FNLfloat*/ float xs = coord.x;
/*FNLfloat*/ float ys = coord.y;
/*FNLfloat*/ float zs = coord.z;
switch (mWarpTransformType3D)
{
case ImproveXYPlanes:
{
/*FNLfloat*/ float xy = xs + ys;
/*FNLfloat*/ float s2 = xy * -(/*FNLfloat*/ float)0.211324865405187;
zs *= (/*FNLfloat*/ float)0.577350269189626;
xs += s2 - zs;
ys = ys + s2 - zs;
zs += xy * (/*FNLfloat*/ float)0.577350269189626;
}
break;
case ImproveXZPlanes:
{
/*FNLfloat*/ float xz = xs + zs;
/*FNLfloat*/ float s2 = xz * -(/*FNLfloat*/ float)0.211324865405187;
ys *= (/*FNLfloat*/ float)0.577350269189626;
xs += s2 - ys; zs += s2 - ys;
ys += xz * (/*FNLfloat*/ float)0.577350269189626;
}
break;
case DefaultOpenSimplex2:
{
final /*FNLfloat*/ float R3 = (/*FNLfloat*/ float)(2.0 / 3.0);
/*FNLfloat*/ float r = (xs + ys + zs) * R3; // Rotation, not skew
xs = r - xs;
ys = r - ys;
zs = r - zs;
}
break;
default:
break;
}
DoSingleDomainWarp(seed, amp, freq, xs, ys, zs, coord);
}
// Domain Warp Fractal Progressive
private void DomainWarpFractalProgressive(Vector2 coord)
{
int seed = mSeed;
float amp = mDomainWarpAmp * mFractalBounding;
float freq = mFrequency;
for (int i = 0; i < mOctaves; i++)
{
/*FNLfloat*/ float xs = coord.x;
/*FNLfloat*/ float ys = coord.y;
switch (mDomainWarpType)
{
case OpenSimplex2:
case OpenSimplex2Reduced:
{
final /*FNLfloat*/ float SQRT3 = (/*FNLfloat*/ float)1.7320508075688772935274463415059;
final /*FNLfloat*/ float F2 = 0.5f * (SQRT3 - 1);
/*FNLfloat*/ float t = (xs + ys) * F2;
xs += t; ys += t;
}
break;
default:
break;
}
DoSingleDomainWarp(seed, amp, freq, xs, ys, coord);
seed++;
amp *= mGain;
freq *= mLacunarity;
}
}
private void DomainWarpFractalProgressive(Vector3 coord)
{
int seed = mSeed;
float amp = mDomainWarpAmp * mFractalBounding;
float freq = mFrequency;
for (int i = 0; i < mOctaves; i++)
{
/*FNLfloat*/ float xs = coord.x;
/*FNLfloat*/ float ys = coord.y;
/*FNLfloat*/ float zs = coord.z;
switch (mWarpTransformType3D)
{
case ImproveXYPlanes:
{
/*FNLfloat*/ float xy = xs + ys;
/*FNLfloat*/ float s2 = xy * -(/*FNLfloat*/ float)0.211324865405187;
zs *= (/*FNLfloat*/ float)0.577350269189626;
xs += s2 - zs;
ys = ys + s2 - zs;
zs += xy * (/*FNLfloat*/ float)0.577350269189626;
}
break;
case ImproveXZPlanes:
{
/*FNLfloat*/ float xz = xs + zs;
/*FNLfloat*/ float s2 = xz * -(/*FNLfloat*/ float)0.211324865405187;
ys *= (/*FNLfloat*/ float)0.577350269189626;
xs += s2 - ys; zs += s2 - ys;
ys += xz * (/*FNLfloat*/ float)0.577350269189626;
}
break;
case DefaultOpenSimplex2:
{
final /*FNLfloat*/ float R3 = (/*FNLfloat*/ float)(2.0 / 3.0);
/*FNLfloat*/ float r = (xs + ys + zs) * R3; // Rotation, not skew
xs = r - xs;
ys = r - ys;
zs = r - zs;
}
break;
default:
break;
}
DoSingleDomainWarp(seed, amp, freq, xs, ys, zs, coord);
seed++;
amp *= mGain;
freq *= mLacunarity;
}
}
// Domain Warp Fractal Independant
private void DomainWarpFractalIndependent(Vector2 coord)
{
/*FNLfloat*/ float xs = coord.x;
/*FNLfloat*/ float ys = coord.y;
switch (mDomainWarpType)
{
case OpenSimplex2:
case OpenSimplex2Reduced:
{
final /*FNLfloat*/ float SQRT3 = (/*FNLfloat*/ float)1.7320508075688772935274463415059;
final /*FNLfloat*/ float F2 = 0.5f * (SQRT3 - 1);
/*FNLfloat*/ float t = (xs + ys) * F2;
xs += t; ys += t;
}
break;
default:
break;
}
int seed = mSeed;
float amp = mDomainWarpAmp * mFractalBounding;
float freq = mFrequency;
for (int i = 0; i < mOctaves; i++)
{
DoSingleDomainWarp(seed, amp, freq, xs, ys, coord);
seed++;
amp *= mGain;
freq *= mLacunarity;
}
}
private void DomainWarpFractalIndependent(Vector3 coord)
{
/*FNLfloat*/ float xs = coord.x;
/*FNLfloat*/ float ys = coord.y;
/*FNLfloat*/ float zs = coord.z;
switch (mWarpTransformType3D)
{
case ImproveXYPlanes:
{
/*FNLfloat*/ float xy = xs + ys;
/*FNLfloat*/ float s2 = xy * -(/*FNLfloat*/ float)0.211324865405187;
zs *= (/*FNLfloat*/ float)0.577350269189626;
xs += s2 - zs;
ys = ys + s2 - zs;
zs += xy * (/*FNLfloat*/ float)0.577350269189626;
}
break;
case ImproveXZPlanes:
{
/*FNLfloat*/ float xz = xs + zs;
/*FNLfloat*/ float s2 = xz * -(/*FNLfloat*/ float)0.211324865405187;
ys *= (/*FNLfloat*/ float)0.577350269189626;
xs += s2 - ys; zs += s2 - ys;
ys += xz * (/*FNLfloat*/ float)0.577350269189626;
}
break;
case DefaultOpenSimplex2:
{
final /*FNLfloat*/ float R3 = (/*FNLfloat*/ float)(2.0 / 3.0);
/*FNLfloat*/ float r = (xs + ys + zs) * R3; // Rotation, not skew
xs = r - xs;
ys = r - ys;
zs = r - zs;
}
break;
default:
break;
}
int seed = mSeed;
float amp = mDomainWarpAmp * mFractalBounding;
float freq = mFrequency;
for (int i = 0; i < mOctaves; i++)
{
DoSingleDomainWarp(seed, amp, freq, xs, ys, zs, coord);
seed++;
amp *= mGain;
freq *= mLacunarity;
}
}
// Domain Warp Basic Grid
private void SingleDomainWarpBasicGrid(int seed, float warpAmp, float frequency, /*FNLfloat*/ float x, /*FNLfloat*/ float y, Vector2 coord)
{
/*FNLfloat*/ float xf = x * frequency;
/*FNLfloat*/ float yf = y * frequency;
int x0 = FastFloor(xf);
int y0 = FastFloor(yf);
float xs = InterpHermite((float)(xf - x0));
float ys = InterpHermite((float)(yf - y0));
x0 *= PrimeX;
y0 *= PrimeY;
int x1 = x0 + PrimeX;
int y1 = y0 + PrimeY;
int hash0 = Hash(seed, x0, y0) & (255 << 1);
int hash1 = Hash(seed, x1, y0) & (255 << 1);
float lx0x = Lerp(RandVecs2D[hash0], RandVecs2D[hash1], xs);
float ly0x = Lerp(RandVecs2D[hash0 | 1], RandVecs2D[hash1 | 1], xs);
hash0 = Hash(seed, x0, y1) & (255 << 1);
hash1 = Hash(seed, x1, y1) & (255 << 1);
float lx1x = Lerp(RandVecs2D[hash0], RandVecs2D[hash1], xs);
float ly1x = Lerp(RandVecs2D[hash0 | 1], RandVecs2D[hash1 | 1], xs);
coord.x += Lerp(lx0x, lx1x, ys) * warpAmp;
coord.y += Lerp(ly0x, ly1x, ys) * warpAmp;
}
private void SingleDomainWarpBasicGrid(int seed, float warpAmp, float frequency, /*FNLfloat*/ float x, /*FNLfloat*/ float y, /*FNLfloat*/ float z, Vector3 coord)
{
/*FNLfloat*/ float xf = x * frequency;
/*FNLfloat*/ float yf = y * frequency;
/*FNLfloat*/ float zf = z * frequency;
int x0 = FastFloor(xf);
int y0 = FastFloor(yf);
int z0 = FastFloor(zf);
float xs = InterpHermite((float)(xf - x0));
float ys = InterpHermite((float)(yf - y0));
float zs = InterpHermite((float)(zf - z0));
x0 *= PrimeX;
y0 *= PrimeY;
z0 *= PrimeZ;
int x1 = x0 + PrimeX;
int y1 = y0 + PrimeY;
int z1 = z0 + PrimeZ;
int hash0 = Hash(seed, x0, y0, z0) & (255 << 2);
int hash1 = Hash(seed, x1, y0, z0) & (255 << 2);
float lx0x = Lerp(RandVecs3D[hash0], RandVecs3D[hash1], xs);
float ly0x = Lerp(RandVecs3D[hash0 | 1], RandVecs3D[hash1 | 1], xs);
float lz0x = Lerp(RandVecs3D[hash0 | 2], RandVecs3D[hash1 | 2], xs);
hash0 = Hash(seed, x0, y1, z0) & (255 << 2);
hash1 = Hash(seed, x1, y1, z0) & (255 << 2);
float lx1x = Lerp(RandVecs3D[hash0], RandVecs3D[hash1], xs);
float ly1x = Lerp(RandVecs3D[hash0 | 1], RandVecs3D[hash1 | 1], xs);
float lz1x = Lerp(RandVecs3D[hash0 | 2], RandVecs3D[hash1 | 2], xs);
float lx0y = Lerp(lx0x, lx1x, ys);
float ly0y = Lerp(ly0x, ly1x, ys);
float lz0y = Lerp(lz0x, lz1x, ys);
hash0 = Hash(seed, x0, y0, z1) & (255 << 2);
hash1 = Hash(seed, x1, y0, z1) & (255 << 2);
lx0x = Lerp(RandVecs3D[hash0], RandVecs3D[hash1], xs);
ly0x = Lerp(RandVecs3D[hash0 | 1], RandVecs3D[hash1 | 1], xs);
lz0x = Lerp(RandVecs3D[hash0 | 2], RandVecs3D[hash1 | 2], xs);
hash0 = Hash(seed, x0, y1, z1) & (255 << 2);
hash1 = Hash(seed, x1, y1, z1) & (255 << 2);
lx1x = Lerp(RandVecs3D[hash0], RandVecs3D[hash1], xs);
ly1x = Lerp(RandVecs3D[hash0 | 1], RandVecs3D[hash1 | 1], xs);
lz1x = Lerp(RandVecs3D[hash0 | 2], RandVecs3D[hash1 | 2], xs);
coord.x += Lerp(lx0y, Lerp(lx0x, lx1x, ys), zs) * warpAmp;
coord.y += Lerp(ly0y, Lerp(ly0x, ly1x, ys), zs) * warpAmp;
coord.z += Lerp(lz0y, Lerp(lz0x, lz1x, ys), zs) * warpAmp;
}
// Domain Warp Simplex/OpenSimplex2
private void SingleDomainWarpSimplexGradient(int seed, float warpAmp, float frequency, /*FNLfloat*/ float x, /*FNLfloat*/ float y, Vector2 coord, boolean outGradOnly)
{
final float SQRT3 = 1.7320508075688772935274463415059f;
final float G2 = (3 - SQRT3) / 6;
x *= frequency;
y *= frequency;
/*
* --- Skew moved to switch statements before fractal evaluation ---
* final FNLfloat F2 = 0.5f * (SQRT3 - 1);
* FNLfloat s = (x + y) * F2;
* x += s; y += s;
*/
int i = FastFloor(x);
int j = FastFloor(y);
float xi = (float)(x - i);
float yi = (float)(y - j);
float t = (xi + yi) * G2;
float x0 = (float)(xi - t);
float y0 = (float)(yi - t);
i *= PrimeX;
j *= PrimeY;
float vx, vy;
vx = vy = 0;
float a = 0.5f - x0 * x0 - y0 * y0;
if (a > 0)
{
float aaaa = (a * a) * (a * a);
float xo, yo;
if (outGradOnly)
{
int hash = Hash(seed, i, j) & (255 << 1);
xo = RandVecs2D[hash];
yo = RandVecs2D[hash | 1];
}
else
{
int hash = Hash(seed, i, j);
int index1 = hash & (127 << 1);
int index2 = (hash >> 7) & (255 << 1);
float xg = Gradients2D[index1];
float yg = Gradients2D[index1 | 1];
float value = x0 * xg + y0 * yg;
float xgo = RandVecs2D[index2];
float ygo = RandVecs2D[index2 | 1];
xo = value * xgo;
yo = value * ygo;
}
vx += aaaa * xo;
vy += aaaa * yo;
}
float c = (float)(2 * (1 - 2 * G2) * (1 / G2 - 2)) * t + ((float)(-2 * (1 - 2 * G2) * (1 - 2 * G2)) + a);
if (c > 0)
{
float x2 = x0 + (2 * (float)G2 - 1);
float y2 = y0 + (2 * (float)G2 - 1);
float cccc = (c * c) * (c * c);
float xo, yo;
if (outGradOnly)
{
int hash = Hash(seed, i + PrimeX, j + PrimeY) & (255 << 1);
xo = RandVecs2D[hash];
yo = RandVecs2D[hash | 1];
}
else
{
int hash = Hash(seed, i + PrimeX, j + PrimeY);
int index1 = hash & (127 << 1);
int index2 = (hash >> 7) & (255 << 1);
float xg = Gradients2D[index1];
float yg = Gradients2D[index1 | 1];
float value = x2 * xg + y2 * yg;
float xgo = RandVecs2D[index2];
float ygo = RandVecs2D[index2 | 1];
xo = value * xgo;
yo = value * ygo;
}
vx += cccc * xo;
vy += cccc * yo;
}
if (y0 > x0)
{
float x1 = x0 + (float)G2;
float y1 = y0 + ((float)G2 - 1);
float b = 0.5f - x1 * x1 - y1 * y1;
if (b > 0)
{
float bbbb = (b * b) * (b * b);
float xo, yo;
if (outGradOnly)
{
int hash = Hash(seed, i, j + PrimeY) & (255 << 1);
xo = RandVecs2D[hash];
yo = RandVecs2D[hash | 1];
}
else
{
int hash = Hash(seed, i, j + PrimeY);
int index1 = hash & (127 << 1);
int index2 = (hash >> 7) & (255 << 1);
float xg = Gradients2D[index1];
float yg = Gradients2D[index1 | 1];
float value = x1 * xg + y1 * yg;
float xgo = RandVecs2D[index2];
float ygo = RandVecs2D[index2 | 1];
xo = value * xgo;
yo = value * ygo;
}
vx += bbbb * xo;
vy += bbbb * yo;
}
}
else
{
float x1 = x0 + ((float)G2 - 1);
float y1 = y0 + (float)G2;
float b = 0.5f - x1 * x1 - y1 * y1;
if (b > 0)
{
float bbbb = (b * b) * (b * b);
float xo, yo;
if (outGradOnly)
{
int hash = Hash(seed, i + PrimeX, j) & (255 << 1);
xo = RandVecs2D[hash];
yo = RandVecs2D[hash | 1];
}
else
{
int hash = Hash(seed, i + PrimeX, j);
int index1 = hash & (127 << 1);
int index2 = (hash >> 7) & (255 << 1);
float xg = Gradients2D[index1];
float yg = Gradients2D[index1 | 1];
float value = x1 * xg + y1 * yg;
float xgo = RandVecs2D[index2];
float ygo = RandVecs2D[index2 | 1];
xo = value * xgo;
yo = value * ygo;
}
vx += bbbb * xo;
vy += bbbb * yo;
}
}
coord.x += vx * warpAmp;
coord.y += vy * warpAmp;
}
private void SingleDomainWarpOpenSimplex2Gradient(int seed, float warpAmp, float frequency, /*FNLfloat*/ float x, /*FNLfloat*/ float y, /*FNLfloat*/ float z, Vector3 coord, boolean outGradOnly)
{
x *= frequency;
y *= frequency;
z *= frequency;
/*
* --- Rotation moved to switch statements before fractal evaluation ---
* final FNLfloat R3 = (FNLfloat)(2.0 / 3.0);
* FNLfloat r = (x + y + z) * R3; // Rotation, not skew
* x = r - x; y = r - y; z = r - z;
*/
int i = FastRound(x);
int j = FastRound(y);
int k = FastRound(z);
float x0 = (float)x - i;
float y0 = (float)y - j;
float z0 = (float)z - k;
int xNSign = (int)(-x0 - 1.0f) | 1;
int yNSign = (int)(-y0 - 1.0f) | 1;
int zNSign = (int)(-z0 - 1.0f) | 1;
float ax0 = xNSign * -x0;
float ay0 = yNSign * -y0;
float az0 = zNSign * -z0;
i *= PrimeX;
j *= PrimeY;
k *= PrimeZ;
float vx, vy, vz;
vx = vy = vz = 0;
float a = (0.6f - x0 * x0) - (y0 * y0 + z0 * z0);
for (int l = 0; ; l++)
{
if (a > 0)
{
float aaaa = (a * a) * (a * a);
float xo, yo, zo;
if (outGradOnly)
{
int hash = Hash(seed, i, j, k) & (255 << 2);
xo = RandVecs3D[hash];
yo = RandVecs3D[hash | 1];
zo = RandVecs3D[hash | 2];
}
else
{
int hash = Hash(seed, i, j, k);
int index1 = hash & (63 << 2);
int index2 = (hash >> 6) & (255 << 2);
float xg = Gradients3D[index1];
float yg = Gradients3D[index1 | 1];
float zg = Gradients3D[index1 | 2];
float value = x0 * xg + y0 * yg + z0 * zg;
float xgo = RandVecs3D[index2];
float ygo = RandVecs3D[index2 | 1];
float zgo = RandVecs3D[index2 | 2];
xo = value * xgo;
yo = value * ygo;
zo = value * zgo;
}
vx += aaaa * xo;
vy += aaaa * yo;
vz += aaaa * zo;
}
float b = a;
int i1 = i;
int j1 = j;
int k1 = k;
float x1 = x0;
float y1 = y0;
float z1 = z0;
if (ax0 >= ay0 && ax0 >= az0)
{
x1 += xNSign;
b = b + ax0 + ax0;
i1 -= xNSign * PrimeX;
}
else if (ay0 > ax0 && ay0 >= az0)
{
y1 += yNSign;
b = b + ay0 + ay0;
j1 -= yNSign * PrimeY;
}
else
{
z1 += zNSign;
b = b + az0 + az0;
k1 -= zNSign * PrimeZ;
}
if (b > 1)
{
b -= 1;
float bbbb = (b * b) * (b * b);
float xo, yo, zo;
if (outGradOnly)
{
int hash = Hash(seed, i1, j1, k1) & (255 << 2);
xo = RandVecs3D[hash];
yo = RandVecs3D[hash | 1];
zo = RandVecs3D[hash | 2];
}
else
{
int hash = Hash(seed, i1, j1, k1);
int index1 = hash & (63 << 2);
int index2 = (hash >> 6) & (255 << 2);
float xg = Gradients3D[index1];
float yg = Gradients3D[index1 | 1];
float zg = Gradients3D[index1 | 2];
float value = x1 * xg + y1 * yg + z1 * zg;
float xgo = RandVecs3D[index2];
float ygo = RandVecs3D[index2 | 1];
float zgo = RandVecs3D[index2 | 2];
xo = value * xgo;
yo = value * ygo;
zo = value * zgo;
}
vx += bbbb * xo;
vy += bbbb * yo;
vz += bbbb * zo;
}
if (l == 1) break;
ax0 = 0.5f - ax0;
ay0 = 0.5f - ay0;
az0 = 0.5f - az0;
x0 = xNSign * ax0;
y0 = yNSign * ay0;
z0 = zNSign * az0;
a += (0.75f - ax0) - (ay0 + az0);
i += (xNSign >> 1) & PrimeX;
j += (yNSign >> 1) & PrimeY;
k += (zNSign >> 1) & PrimeZ;
xNSign = -xNSign;
yNSign = -yNSign;
zNSign = -zNSign;
seed += 1293373;
}
coord.x += vx * warpAmp;
coord.y += vy * warpAmp;
coord.z += vz * warpAmp;
}
public static class Vector2
{
public /*FNLfloat*/ float x;
public /*FNLfloat*/ float y;
public Vector2(/*FNLfloat*/ float x, /*FNLfloat*/ float y)
{
this.x = x;
this.y = y;
}
}
public static class Vector3
{
public /*FNLfloat*/ float x;
public /*FNLfloat*/ float y;
public /*FNLfloat*/ float z;
public Vector3(/*FNLfloat*/ float x, /*FNLfloat*/ float y, /*FNLfloat*/ float z)
{
this.x = x;
this.y = y;
this.z = z;
}
}
}
``` | /content/code_sandbox/Java/FastNoiseLite.java | java | 2016-03-28T02:35:12 | 2024-08-16T07:09:20 | FastNoiseLite | Auburn/FastNoiseLite | 2,688 | 40,752 |
```rust
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// .'',;:cldxkO00KKXXNNWWWNNXKOkxdollcc::::::;:::ccllloooolllllllllooollc:,'... ...........',;cldxkO000Okxdlc::;;;,,;;;::cclllllll
// ..',;:ldxO0KXXNNNNNNNNXXK0kxdolcc::::::;;;,,,,,,;;;;;;;;;;:::cclllllc:;'.... ...........',;:ldxO0KXXXK0Okxdolc::;;;;::cllodddddo
// ...',:loxO0KXNNNNNXXKK0Okxdolc::;::::::::;;;,,'''''.....''',;:clllllc:;,'............''''''''',;:loxO0KXNNNNNXK0Okxdollccccllodxxxxxxd
// ....';:ldkO0KXXXKK00Okxdolcc:;;;;;::cclllcc:;;,''..... ....',;clooddolcc:;;;;,,;;;;;::::;;;;;;:cloxk0KXNWWWWWWNXKK0Okxddoooddxxkkkkkxx
// .....';:ldxkOOOOOkxxdolcc:;;;,,,;;:cllooooolcc:;'... ..,:codxkkkxddooollloooooooollcc:::::clodkO0KXNWWWWWWNNXK00Okxxxxxxxxkkkkxxx
// . ....';:cloddddo___________,,,,;;:clooddddoolc:,... ..,:ldx__00OOOkkk___kkkkkkxxdollc::::cclodkO0KXXNNNNNNXXK0OOkxxxxxxxxxxxxddd
// .......',;:cccc:| |,,,;;:cclooddddoll:;'.. ..';cox| \KKK000| |KK00OOkxdocc___;::clldxxkO0KKKKK00Okkxdddddddddddddddoo
// .......'',,,,,''| ________|',,;;::cclloooooolc:;'......___:ldk| \KK000| |XKKK0Okxolc| |;;::cclodxxkkkkxxdoolllcclllooodddooooo
// ''......''''....| | ....'',,,,;;;::cclloooollc:;,''.'| |oxk| \OOO0| |KKK00Oxdoll|___|;;;;;::ccllllllcc::;;,,;;;:cclloooooooo
// ;;,''.......... | |_____',,;;;____:___cllo________.___| |___| \xkk| |KK_______ool___:::;________;;;_______...'',;;:ccclllloo
// c:;,''......... | |:::/ ' |lo/ | | \dx| |0/ \d| |cc/ |'/ \......',,;;:ccllo
// ol:;,'..........| _____|ll/ __ |o/ ______|____ ___| | \o| |/ ___ \| |o/ ______|/ ___ \ .......'',;:clo
// dlc;,...........| |::clooo| / | |x\___ \KXKKK0| |dol| |\ \| | | | | |d\___ \..| | / / ....',:cl
// xoc;'... .....'| |llodddd| \__| |_____\ \KKK0O| |lc:| |'\ | |___| | |_____\ \.| |_/___/... ...',;:c
// dlc;'... ....',;| |oddddddo\ | |Okkx| |::;| |..\ |\ /| | | \ |... ....',;:c
// ol:,'.......',:c|___|xxxddollc\_____,___|_________/ddoll|___|,,,|___|...\_____|:\ ______/l|___|_________/...\________|'........',;::cc
// c:;'.......';:codxxkkkkxxolc::;::clodxkOO0OOkkxdollc::;;,,''''',,,,''''''''''',,'''''',;:loxkkOOkxol:;,'''',,;:ccllcc:;,'''''',;::ccll
// ;,'.......',:codxkOO0OOkxdlc:;,,;;:cldxxkkxxdolc:;;,,''.....'',;;:::;;,,,'''''........,;cldkO0KK0Okdoc::;;::cloodddoolc:;;;;;::ccllooo
// .........',;:lodxOO0000Okdoc:,,',,;:clloddoolc:;,''.......'',;:clooollc:;;,,''.......',:ldkOKXNNXX0Oxdolllloddxxxxxxdolccccccllooodddd
// . .....';:cldxkO0000Okxol:;,''',,;::cccc:;,,'.......'',;:cldxxkkxxdolc:;;,'.......';coxOKXNWWWNXKOkxddddxxkkkkkkxdoollllooddxxxxkkk
// ....',;:codxkO000OOxdoc:;,''',,,;;;;,''.......',,;:clodkO00000Okxolc::;,,''..',;:ldxOKXNWWWNNK0OkkkkkkkkkkkxxddooooodxxkOOOOO000
// ....',;;clodxkkOOOkkdolc:;,,,,,,,,'..........,;:clodxkO0KKXKK0Okxdolcc::;;,,,;;:codkO0XXNNNNXKK0OOOOOkkkkxxdoollloodxkO0KKKXXXXX
//
// VERSION: 1.1.1
// path_to_url
// path_to_url
//
// Ported to Rust by Keavon Chambers:
// Discord: Keavon (preferred) | Email: see <path_to_url for the address | GitHub: Keavon (path_to_url
#![doc = include_str!("../README.md")]
#![cfg_attr(not(feature = "std"), no_std)]
#![allow(clippy::excessive_precision)]
// ===================================================================================
// "f64" feature flag:
// For choosing the desired floating point precision of input position X/Y coordinates
// ===================================================================================
// Switch between using floats or doubles for input X/Y coordinate positions
#[cfg(not(feature = "f64"))]
type Float = f32;
#[cfg(feature = "f64")]
type Float = f64;
// ===========================================================================================================================================================
// "std" and "libm" feature flags:
// Ensures access to `sqrt()`, `trunc()`, and `abs()` floating point functions from either the Rust standard library, or the `libm` crate for `no_std` support
// ===========================================================================================================================================================
// Use the `num-traits` crate's `Float` trait if the user has enabled the `libm` feature flag
#[cfg(feature = "libm")]
use num_traits::float::Float as FloatOps;
// Use the standard library's `f32` type for floating point math operators if we're in an `std` (not `no_std`) context and the user hasn't enabled the `libm` feature flag
#[cfg(all(feature = "std", not(feature = "libm")))]
use f32 as FloatOps;
// Ensures a user-facing compile error if this crate is misused by having neither the "std" or "libm" feature flags
#[cfg(all(not(feature = "std"), not(feature = "libm")))]
compile_error!("`fastnoise-lite` crate: either the "std" or "libm" feature must be enabled");
#[cfg(all(not(feature = "std"), not(feature = "libm")))]
use Float as FloatOps;
#[cfg(all(not(feature = "std"), not(feature = "libm")))]
impl DummyFloatExt for Float {}
#[cfg(all(not(feature = "std"), not(feature = "libm")))]
trait DummyFloatExt: Sized {
// Dummy trait to allow compilation without std or libm
fn sqrt(self) -> Self {
unimplemented!()
}
fn trunc(self) -> Self {
unimplemented!()
}
fn abs(self) -> Self {
unimplemented!()
}
}
// ========================================
// Option enums for FastNoise Lite settings
// ========================================
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum NoiseType {
OpenSimplex2,
OpenSimplex2S,
Cellular,
Perlin,
ValueCubic,
Value,
}
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum RotationType3D {
None,
ImproveXYPlanes,
ImproveXZPlanes,
}
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum FractalType {
None,
FBm,
Ridged,
PingPong,
DomainWarpProgressive,
DomainWarpIndependent,
}
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum CellularDistanceFunction {
Euclidean,
EuclideanSq,
Manhattan,
Hybrid,
}
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
pub enum CellularReturnType {
CellValue = 0,
Distance = 1,
Distance2 = 2,
Distance2Add = 3,
Distance2Sub = 4,
Distance2Mul = 5,
Distance2Div = 6,
}
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum DomainWarpType {
OpenSimplex2,
OpenSimplex2Reduced,
BasicGrid,
}
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum TransformType3D {
None,
ImproveXYPlanes,
ImproveXZPlanes,
DefaultOpenSimplex2,
}
// ========================================
// FastNoise Lite settings/generator object
// ========================================
/// The object you construct, configure, and then use to sample the noise.
///
/// 1. Construct this with [`FastNoiseLite::new`] or [`FastNoiseLite::with_seed`].
/// 2. Configure it from its defaults with the various `set_*` functions.
/// 3. Optionally, use [`FastNoiseLite::domain_warp_2d`] or [`FastNoiseLite::domain_warp_3d`] to translate the input coordinates to their warped positions.
/// 4. Use [`FastNoiseLite::get_noise_2d`] or [`FastNoiseLite::get_noise_3d`] to sample the noise at the (ordinary or warped) input coordinates.
///
/// # Example
///
/// ```rs
/// use fastnoise_lite::*;
///
/// // Create and configure the FastNoise object
/// let mut noise = FastNoiseLite::new();
/// noise.set_noise_type(Some(NoiseType::OpenSimplex2));
///
/// const WIDTH: usize = 128;
/// const HEIGHT: usize = 128;
/// let mut noise_data = [[0.; HEIGHT]; WIDTH];
///
/// // Sample noise pixels
/// for x in 0..WIDTH {
/// for y in 0..HEIGHT {
/// // Domain warp can optionally be employed to transform the coordinates before sampling:
/// // let (x, y) = noise.domain_warp_2d(x as f32, y as f32);
///
/// let negative_1_to_1 = noise.get_noise_2d(x as f32, y as f32);
/// // You may want to remap the -1..1 range data to the 0..1 range:
/// noise_data[x][y] = (neg_1_to_1 + 1.) / 2.;
///
/// // (Uses of `as f32` above should become `as f64` if you're using FNL with the "f64" feature flag)
/// }
/// }
///
/// // Do something with this data...
/// ```
#[derive(Clone, Debug)]
pub struct FastNoiseLite {
pub seed: i32,
pub frequency: f32,
pub noise_type: NoiseType,
pub rotation_type_3d: RotationType3D,
transform_type_3d: TransformType3D,
pub fractal_type: FractalType,
pub octaves: i32,
pub lacunarity: f32,
pub gain: f32,
pub weighted_strength: f32,
pub ping_pong_strength: f32,
fractal_bounding: f32,
pub cellular_distance_function: CellularDistanceFunction,
pub cellular_return_type: CellularReturnType,
pub cellular_jitter_modifier: f32,
pub domain_warp_type: DomainWarpType,
warp_transform_type_3d: TransformType3D,
pub domain_warp_amp: f32,
}
impl Default for FastNoiseLite {
fn default() -> Self {
Self {
seed: 1337,
frequency: 0.01,
noise_type: NoiseType::OpenSimplex2,
rotation_type_3d: RotationType3D::None,
/* private */ transform_type_3d: TransformType3D::DefaultOpenSimplex2,
fractal_type: FractalType::None,
octaves: 3,
lacunarity: 2.,
gain: 0.5,
weighted_strength: 0.,
ping_pong_strength: 2.,
/* private */ fractal_bounding: 1. / 1.75,
cellular_distance_function: CellularDistanceFunction::EuclideanSq,
cellular_return_type: CellularReturnType::Distance,
cellular_jitter_modifier: 1.,
domain_warp_type: DomainWarpType::OpenSimplex2,
/* private */ warp_transform_type_3d: TransformType3D::DefaultOpenSimplex2,
domain_warp_amp: 1.,
}
}
}
impl FastNoiseLite {
// =====================
// Constructor functions
// =====================
/// # Constructor
///
/// Create new FastNoise object with the default seed of `1337`.
pub fn new() -> Self {
Self::default()
}
/// Create new FastNoise object with a specific seed.
pub fn with_seed(seed: i32) -> Self {
let mut fnl = Self::default();
fnl.set_seed(Some(seed));
fnl
}
// ============================
// Setter convenience functions
// ============================
/// Sets seed used for all noise types.
///
/// If set to [`None`], it is reset to its default: `1337`.
pub fn set_seed(&mut self, seed: Option<i32>) {
self.seed = seed.unwrap_or(Self::default().seed);
}
/// Sets frequency used for all noise types.
///
/// If set to [`None`], it is reset to its default: `0.01`.
pub fn set_frequency(&mut self, frequency: Option<f32>) {
self.frequency = frequency.unwrap_or(Self::default().frequency);
}
/// Sets noise algorithm used for [`get_noise_2d`](Self::get_noise_2d)/[`get_noise_3d`](Self::get_noise_3d).
///
/// If set to [`None`], it is reset to its default: [`NoiseType::OpenSimplex2`].
pub fn set_noise_type(&mut self, noise_type: Option<NoiseType>) {
self.noise_type = noise_type.unwrap_or(Self::default().noise_type);
self.update_transform_type_3d();
}
/// Sets domain rotation type for 3D Noise and 3D DomainWarp.
/// Can aid in reducing directional artifacts when sampling a 2D plane in 3D.
///
/// If set to [`None`], it is reset to its default: [`RotationType3D::None`].
pub fn set_rotation_type_3d(&mut self, rotation_type_3d: Option<RotationType3D>) {
self.rotation_type_3d = rotation_type_3d.unwrap_or(Self::default().rotation_type_3d);
self.update_transform_type_3d();
self.update_warp_transform_type_3d();
}
/// Sets method for combining octaves in all fractal noise types.
///
/// If set to [`None`], it is reset to its default: [`FractalType::None`].
///
/// Note: [`FractalType::DomainWarpProgressive`]/[`FractalType::DomainWarpIndependent`] only affects [`domain_warp_2d`](Self::domain_warp_2d).
pub fn set_fractal_type(&mut self, fractal_type: Option<FractalType>) {
self.fractal_type = fractal_type.unwrap_or(Self::default().fractal_type);
}
/// Sets octave count for all fractal noise types.
///
/// If set to [`None`], it is reset to its default: `3`.
pub fn set_fractal_octaves(&mut self, octaves: Option<i32>) {
self.octaves = octaves.unwrap_or(Self::default().octaves);
self.calculate_fractal_bounding();
}
/// Sets octave lacunarity for all fractal noise types.
///
/// If set to [`None`], it is reset to its default: `2.0`.
pub fn set_fractal_lacunarity(&mut self, lacunarity: Option<f32>) {
self.lacunarity = lacunarity.unwrap_or(Self::default().lacunarity);
}
/// Sets octave gain for all fractal noise types.
///
/// If set to [`None`], it is reset to its default: `0.5`.
pub fn set_fractal_gain(&mut self, gain: Option<f32>) {
self.gain = gain.unwrap_or(Self::default().gain);
self.calculate_fractal_bounding();
}
/// Sets octave weighting for all none DomainWarp fractal types.
///
/// If set to [`None`], it is reset to its default: `0.0`.
///
/// Note: Keep between 0..1 to maintain -1..1 output bounding.
pub fn set_fractal_weighted_strength(&mut self, weighted_strength: Option<f32>) {
self.weighted_strength = weighted_strength.unwrap_or(Self::default().weighted_strength);
}
/// Sets strength of the fractal ping pong effect.
///
/// If set to [`None`], it is reset to its default: `2.0`.
pub fn set_fractal_ping_pong_strength(&mut self, ping_pong_strength: Option<f32>) {
self.ping_pong_strength = ping_pong_strength.unwrap_or(Self::default().ping_pong_strength);
}
/// Sets distance function used in cellular noise calculations.
///
/// If set to [`None`], it is reset to its default: [`CellularDistanceFunction::EuclideanSq`].
pub fn set_cellular_distance_function(
&mut self,
cellular_distance_function: Option<CellularDistanceFunction>,
) {
self.cellular_distance_function =
cellular_distance_function.unwrap_or(Self::default().cellular_distance_function);
}
/// Sets return type from cellular noise calculations.
///
/// If set to [`None`], it is reset to its default: [`CellularReturnType::Distance`].
pub fn set_cellular_return_type(&mut self, cellular_return_type: Option<CellularReturnType>) {
self.cellular_return_type =
cellular_return_type.unwrap_or(Self::default().cellular_return_type);
}
/// Sets the maximum distance a cellular point can move from its grid position.
///
/// If set to [`None`], it is reset to its default: `1.0`.
///
/// Note: Setting this higher than 1 will cause artifacts.
pub fn set_cellular_jitter(&mut self, cellular_jitter: Option<f32>) {
self.cellular_jitter_modifier =
cellular_jitter.unwrap_or(Self::default().cellular_jitter_modifier);
}
/// Sets the warp algorithm when using [`domain_warp_2d`](Self::domain_warp_2d).
///
/// If set to [`None`], it is reset to its default: [`DomainWarpType::OpenSimplex2`].
pub fn set_domain_warp_type(&mut self, domain_warp_type: Option<DomainWarpType>) {
self.domain_warp_type = domain_warp_type.unwrap_or(Self::default().domain_warp_type);
self.update_warp_transform_type_3d();
}
/// Sets the maximum warp distance from original position when using [`domain_warp_2d`](Self::domain_warp_2d).
///
/// If set to [`None`], it is reset to its default: `1.0`.
pub fn set_domain_warp_amp(&mut self, domain_warp_amp: Option<f32>) {
self.domain_warp_amp = domain_warp_amp.unwrap_or(Self::default().domain_warp_amp);
}
// =========================
// Noise generator functions
// =========================
/// 2D noise at given position using current settings.
///
/// Noise output bounded between -1..1.
///
/// Example usage:
/// ```rs
/// let noise = get_noise_2d(x, y); // Value in the -1..1 range
/// let noise = (noise + 1.) / 2.; // Consider remapping it to the 0..1 range
/// ```
pub fn get_noise_2d(&self, x: Float, y: Float) -> f32 {
let (x, y) = self.transform_noise_coordinate_2d(x, y);
match self.fractal_type {
FractalType::FBm => self.gen_fractal_fbm_2d(x, y),
FractalType::Ridged => self.gen_fractal_ridged_2d(x, y),
FractalType::PingPong => self.gen_fractal_ping_pong_2d(x, y),
_ => self.gen_noise_single_2d(self.seed, x, y),
}
}
/// 3D noise at given position using current settings.
///
/// Noise output is bounded between -1..1.
///
/// Example usage:
/// ```rs
/// let noise = get_noise_3d(x, y, z); // Value in the -1..1 range
/// let noise = (noise + 1.) / 2.; // Consider remapping it to the 0..1 range
/// ```
pub fn get_noise_3d(&self, x: Float, y: Float, z: Float) -> f32 {
let (x, y, z) = self.transform_noise_coordinate_3d(x, y, z);
match self.fractal_type {
FractalType::FBm => self.gen_fractal_fbm_3d(x, y, z),
FractalType::Ridged => self.gen_fractal_ridged_3d(x, y, z),
FractalType::PingPong => self.gen_fractal_ping_pong_3d(x, y, z),
_ => self.gen_noise_single_3d(self.seed, x, y, z),
}
}
// ===============================================
// Domain warp coordinate transformation functions
// ===============================================
/// 2D warps the input position using current domain warp settings.
///
/// Example usage:
/// ```rs
/// let (x, y) = domain_warp_2d(x, y);
/// let noise = get_noise_2d(x, y); // Value in the -1..1 range
/// let noise = (noise + 1.) / 2.; // Consider remapping it to the 0..1 range
/// ```
pub fn domain_warp_2d(&self, x: Float, y: Float) -> (Float, Float) {
match self.fractal_type {
FractalType::DomainWarpProgressive => self.domain_warp_fractal_progressive_2d(x, y),
FractalType::DomainWarpIndependent => self.domain_warp_fractal_independent_2d(x, y),
_ => self.domain_warp_single_2d(x, y),
}
}
/// 3D warps the input position using current domain warp settings.
///
/// Example usage:
/// ```rs
/// let (x, y, z) = domain_warp_3d(x, y, z);
/// let noise = get_noise_3d(x, y, z); // Value in the -1..1 range
/// let noise = (noise + 1.) / 2.; // Consider remapping it to the 0..1 range
/// ```
pub fn domain_warp_3d(&self, x: Float, y: Float, z: Float) -> (Float, Float, Float) {
match self.fractal_type {
FractalType::DomainWarpProgressive => self.domain_warp_fractal_progressive_3d(x, y, z),
FractalType::DomainWarpIndependent => self.domain_warp_fractal_independent_3d(x, y, z),
_ => self.domain_warp_single_3d(x, y, z),
}
}
// =================
// Lookup table data
// =================
#[rustfmt::skip]
const GRADIENTS_2D: [f32; 256] = [
0.130526192220052, 0.99144486137381, 0.38268343236509, 0.923879532511287, 0.608761429008721, 0.793353340291235, 0.793353340291235, 0.608761429008721,
0.923879532511287, 0.38268343236509, 0.99144486137381, 0.130526192220051, 0.99144486137381, -0.130526192220051, 0.923879532511287, -0.38268343236509,
0.793353340291235, -0.60876142900872, 0.608761429008721, -0.793353340291235, 0.38268343236509, -0.923879532511287, 0.130526192220052, -0.99144486137381,
-0.130526192220052, -0.99144486137381, -0.38268343236509, -0.923879532511287, -0.608761429008721, -0.793353340291235, -0.793353340291235, -0.608761429008721,
-0.923879532511287, -0.38268343236509, -0.99144486137381, -0.130526192220052, -0.99144486137381, 0.130526192220051, -0.923879532511287, 0.38268343236509,
-0.793353340291235, 0.608761429008721, -0.608761429008721, 0.793353340291235, -0.38268343236509, 0.923879532511287, -0.130526192220052, 0.99144486137381,
0.130526192220052, 0.99144486137381, 0.38268343236509, 0.923879532511287, 0.608761429008721, 0.793353340291235, 0.793353340291235, 0.608761429008721,
0.923879532511287, 0.38268343236509, 0.99144486137381, 0.130526192220051, 0.99144486137381, -0.130526192220051, 0.923879532511287, -0.38268343236509,
0.793353340291235, -0.60876142900872, 0.608761429008721, -0.793353340291235, 0.38268343236509, -0.923879532511287, 0.130526192220052, -0.99144486137381,
-0.130526192220052, -0.99144486137381, -0.38268343236509, -0.923879532511287, -0.608761429008721, -0.793353340291235, -0.793353340291235, -0.608761429008721,
-0.923879532511287, -0.38268343236509, -0.99144486137381, -0.130526192220052, -0.99144486137381, 0.130526192220051, -0.923879532511287, 0.38268343236509,
-0.793353340291235, 0.608761429008721, -0.608761429008721, 0.793353340291235, -0.38268343236509, 0.923879532511287, -0.130526192220052, 0.99144486137381,
0.130526192220052, 0.99144486137381, 0.38268343236509, 0.923879532511287, 0.608761429008721, 0.793353340291235, 0.793353340291235, 0.608761429008721,
0.923879532511287, 0.38268343236509, 0.99144486137381, 0.130526192220051, 0.99144486137381, -0.130526192220051, 0.923879532511287, -0.38268343236509,
0.793353340291235, -0.60876142900872, 0.608761429008721, -0.793353340291235, 0.38268343236509, -0.923879532511287, 0.130526192220052, -0.99144486137381,
-0.130526192220052, -0.99144486137381, -0.38268343236509, -0.923879532511287, -0.608761429008721, -0.793353340291235, -0.793353340291235, -0.608761429008721,
-0.923879532511287, -0.38268343236509, -0.99144486137381, -0.130526192220052, -0.99144486137381, 0.130526192220051, -0.923879532511287, 0.38268343236509,
-0.793353340291235, 0.608761429008721, -0.608761429008721, 0.793353340291235, -0.38268343236509, 0.923879532511287, -0.130526192220052, 0.99144486137381,
0.130526192220052, 0.99144486137381, 0.38268343236509, 0.923879532511287, 0.608761429008721, 0.793353340291235, 0.793353340291235, 0.608761429008721,
0.923879532511287, 0.38268343236509, 0.99144486137381, 0.130526192220051, 0.99144486137381, -0.130526192220051, 0.923879532511287, -0.38268343236509,
0.793353340291235, -0.60876142900872, 0.608761429008721, -0.793353340291235, 0.38268343236509, -0.923879532511287, 0.130526192220052, -0.99144486137381,
-0.130526192220052, -0.99144486137381, -0.38268343236509, -0.923879532511287, -0.608761429008721, -0.793353340291235, -0.793353340291235, -0.608761429008721,
-0.923879532511287, -0.38268343236509, -0.99144486137381, -0.130526192220052, -0.99144486137381, 0.130526192220051, -0.923879532511287, 0.38268343236509,
-0.793353340291235, 0.608761429008721, -0.608761429008721, 0.793353340291235, -0.38268343236509, 0.923879532511287, -0.130526192220052, 0.99144486137381,
0.130526192220052, 0.99144486137381, 0.38268343236509, 0.923879532511287, 0.608761429008721, 0.793353340291235, 0.793353340291235, 0.608761429008721,
0.923879532511287, 0.38268343236509, 0.99144486137381, 0.130526192220051, 0.99144486137381, -0.130526192220051, 0.923879532511287, -0.38268343236509,
0.793353340291235, -0.60876142900872, 0.608761429008721, -0.793353340291235, 0.38268343236509, -0.923879532511287, 0.130526192220052, -0.99144486137381,
-0.130526192220052, -0.99144486137381, -0.38268343236509, -0.923879532511287, -0.608761429008721, -0.793353340291235, -0.793353340291235, -0.608761429008721,
-0.923879532511287, -0.38268343236509, -0.99144486137381, -0.130526192220052, -0.99144486137381, 0.130526192220051, -0.923879532511287, 0.38268343236509,
-0.793353340291235, 0.608761429008721, -0.608761429008721, 0.793353340291235, -0.38268343236509, 0.923879532511287, -0.130526192220052, 0.99144486137381,
0.38268343236509, 0.923879532511287, 0.923879532511287, 0.38268343236509, 0.923879532511287, -0.38268343236509, 0.38268343236509, -0.923879532511287,
-0.38268343236509, -0.923879532511287, -0.923879532511287, -0.38268343236509, -0.923879532511287, 0.38268343236509, -0.38268343236509, 0.923879532511287,
];
#[rustfmt::skip]
const RAND_VECS_2D: [f32; 512] = [
-0.2700222198, -0.9628540911, 0.3863092627, -0.9223693152, 0.04444859006, -0.999011673, -0.5992523158, -0.8005602176, -0.7819280288, 0.6233687174, 0.9464672271, 0.3227999196, -0.6514146797, -0.7587218957, 0.9378472289, 0.347048376,
-0.8497875957, -0.5271252623, -0.879042592, 0.4767432447, -0.892300288, -0.4514423508, -0.379844434, -0.9250503802, -0.9951650832, 0.0982163789, 0.7724397808, -0.6350880136, 0.7573283322, -0.6530343002, -0.9928004525, -0.119780055,
-0.0532665713, 0.9985803285, 0.9754253726, -0.2203300762, -0.7665018163, 0.6422421394, 0.991636706, 0.1290606184, -0.994696838, 0.1028503788, -0.5379205513, -0.84299554, 0.5022815471, -0.8647041387, 0.4559821461, -0.8899889226,
-0.8659131224, -0.5001944266, 0.0879458407, -0.9961252577, -0.5051684983, 0.8630207346, 0.7753185226, -0.6315704146, -0.6921944612, 0.7217110418, -0.5191659449, -0.8546734591, 0.8978622882, -0.4402764035, -0.1706774107, 0.9853269617,
-0.9353430106, -0.3537420705, -0.9992404798, 0.03896746794, -0.2882064021, -0.9575683108, -0.9663811329, 0.2571137995, -0.8759714238, -0.4823630009, -0.8303123018, -0.5572983775, 0.05110133755, -0.9986934731, -0.8558373281, -0.5172450752,
0.09887025282, 0.9951003332, 0.9189016087, 0.3944867976, -0.2439375892, -0.9697909324, -0.8121409387, -0.5834613061, -0.9910431363, 0.1335421355, 0.8492423985, -0.5280031709, -0.9717838994, -0.2358729591, 0.9949457207, 0.1004142068,
0.6241065508, -0.7813392434, 0.662910307, 0.7486988212, -0.7197418176, 0.6942418282, -0.8143370775, -0.5803922158, 0.104521054, -0.9945226741, -0.1065926113, -0.9943027784, 0.445799684, -0.8951327509, 0.105547406, 0.9944142724,
-0.992790267, 0.1198644477, -0.8334366408, 0.552615025, 0.9115561563, -0.4111755999, 0.8285544909, -0.5599084351, 0.7217097654, -0.6921957921, 0.4940492677, -0.8694339084, -0.3652321272, -0.9309164803, -0.9696606758, 0.2444548501,
0.08925509731, -0.996008799, 0.5354071276, -0.8445941083, -0.1053576186, 0.9944343981, -0.9890284586, 0.1477251101, 0.004856104961, 0.9999882091, 0.9885598478, 0.1508291331, 0.9286129562, -0.3710498316, -0.5832393863, -0.8123003252,
0.3015207509, 0.9534596146, -0.9575110528, 0.2883965738, 0.9715802154, -0.2367105511, 0.229981792, 0.9731949318, 0.955763816, -0.2941352207, 0.740956116, 0.6715534485, -0.9971513787, -0.07542630764, 0.6905710663, -0.7232645452,
-0.290713703, -0.9568100872, 0.5912777791, -0.8064679708, -0.9454592212, -0.325740481, 0.6664455681, 0.74555369, 0.6236134912, 0.7817328275, 0.9126993851, -0.4086316587, -0.8191762011, 0.5735419353, -0.8812745759, -0.4726046147,
0.9953313627, 0.09651672651, 0.9855650846, -0.1692969699, -0.8495980887, 0.5274306472, 0.6174853946, -0.7865823463, 0.8508156371, 0.52546432, 0.9985032451, -0.05469249926, 0.1971371563, -0.9803759185, 0.6607855748, -0.7505747292,
-0.03097494063, 0.9995201614, -0.6731660801, 0.739491331, -0.7195018362, -0.6944905383, 0.9727511689, 0.2318515979, 0.9997059088, -0.0242506907, 0.4421787429, -0.8969269532, 0.9981350961, -0.061043673, -0.9173660799, -0.3980445648,
-0.8150056635, -0.5794529907, -0.8789331304, 0.4769450202, 0.0158605829, 0.999874213, -0.8095464474, 0.5870558317, -0.9165898907, -0.3998286786, -0.8023542565, 0.5968480938, -0.5176737917, 0.8555780767, -0.8154407307, -0.5788405779,
0.4022010347, -0.9155513791, -0.9052556868, -0.4248672045, 0.7317445619, 0.6815789728, -0.5647632201, -0.8252529947, -0.8403276335, -0.5420788397, -0.9314281527, 0.363925262, 0.5238198472, 0.8518290719, 0.7432803869, -0.6689800195,
-0.985371561, -0.1704197369, 0.4601468731, 0.88784281, 0.825855404, 0.5638819483, 0.6182366099, 0.7859920446, 0.8331502863, -0.553046653, 0.1500307506, 0.9886813308, -0.662330369, -0.7492119075, -0.668598664, 0.743623444,
0.7025606278, 0.7116238924, -0.5419389763, -0.8404178401, -0.3388616456, 0.9408362159, 0.8331530315, 0.5530425174, -0.2989720662, -0.9542618632, 0.2638522993, 0.9645630949, 0.124108739, -0.9922686234, -0.7282649308, -0.6852956957,
0.6962500149, 0.7177993569, -0.9183535368, 0.3957610156, -0.6326102274, -0.7744703352, -0.9331891859, -0.359385508, -0.1153779357, -0.9933216659, 0.9514974788, -0.3076565421, -0.08987977445, -0.9959526224, 0.6678496916, 0.7442961705,
0.7952400393, -0.6062947138, -0.6462007402, -0.7631674805, -0.2733598753, 0.9619118351, 0.9669590226, -0.254931851, -0.9792894595, 0.2024651934, -0.5369502995, -0.8436138784, -0.270036471, -0.9628500944, -0.6400277131, 0.7683518247,
-0.7854537493, -0.6189203566, 0.06005905383, -0.9981948257, -0.02455770378, 0.9996984141, -0.65983623, 0.751409442, -0.6253894466, -0.7803127835, -0.6210408851, -0.7837781695, 0.8348888491, 0.5504185768, -0.1592275245, 0.9872419133,
0.8367622488, 0.5475663786, -0.8675753916, -0.4973056806, -0.2022662628, -0.9793305667, 0.9399189937, 0.3413975472, 0.9877404807, -0.1561049093, -0.9034455656, 0.4287028224, 0.1269804218, -0.9919052235, -0.3819600854, 0.924178821,
0.9754625894, 0.2201652486, -0.3204015856, -0.9472818081, -0.9874760884, 0.1577687387, 0.02535348474, -0.9996785487, 0.4835130794, -0.8753371362, -0.2850799925, -0.9585037287, -0.06805516006, -0.99768156, -0.7885244045, -0.6150034663,
0.3185392127, -0.9479096845, 0.8880043089, 0.4598351306, 0.6476921488, -0.7619021462, 0.9820241299, 0.1887554194, 0.9357275128, -0.3527237187, -0.8894895414, 0.4569555293, 0.7922791302, 0.6101588153, 0.7483818261, 0.6632681526,
-0.7288929755, -0.6846276581, 0.8729032783, -0.4878932944, 0.8288345784, 0.5594937369, 0.08074567077, 0.9967347374, 0.9799148216, -0.1994165048, -0.580730673, -0.8140957471, -0.4700049791, -0.8826637636, 0.2409492979, 0.9705377045,
0.9437816757, -0.3305694308, -0.8927998638, -0.4504535528, -0.8069622304, 0.5906030467, 0.06258973166, 0.9980393407, -0.9312597469, 0.3643559849, 0.5777449785, 0.8162173362, -0.3360095855, -0.941858566, 0.697932075, -0.7161639607,
-0.002008157227, -0.9999979837, -0.1827294312, -0.9831632392, -0.6523911722, 0.7578824173, -0.4302626911, -0.9027037258, -0.9985126289, -0.05452091251, -0.01028102172, -0.9999471489, -0.4946071129, 0.8691166802, -0.2999350194, 0.9539596344,
0.8165471961, 0.5772786819, 0.2697460475, 0.962931498, -0.7306287391, -0.6827749597, -0.7590952064, -0.6509796216, -0.907053853, 0.4210146171, -0.5104861064, -0.8598860013, 0.8613350597, 0.5080373165, 0.5007881595, -0.8655698812,
-0.654158152, 0.7563577938, -0.8382755311, -0.545246856, 0.6940070834, 0.7199681717, 0.06950936031, 0.9975812994, 0.1702942185, -0.9853932612, 0.2695973274, 0.9629731466, 0.5519612192, -0.8338697815, 0.225657487, -0.9742067022,
0.4215262855, -0.9068161835, 0.4881873305, -0.8727388672, -0.3683854996, -0.9296731273, -0.9825390578, 0.1860564427, 0.81256471, 0.5828709909, 0.3196460933, -0.9475370046, 0.9570913859, 0.2897862643, -0.6876655497, -0.7260276109,
-0.9988770922, -0.047376731, -0.1250179027, 0.992154486, -0.8280133617, 0.560708367, 0.9324863769, -0.3612051451, 0.6394653183, 0.7688199442, -0.01623847064, -0.9998681473, -0.9955014666, -0.09474613458, -0.81453315, 0.580117012,
0.4037327978, -0.9148769469, 0.9944263371, 0.1054336766, -0.1624711654, 0.9867132919, -0.9949487814, -0.100383875, -0.6995302564, 0.7146029809, 0.5263414922, -0.85027327, -0.5395221479, 0.841971408, 0.6579370318, 0.7530729462,
0.01426758847, -0.9998982128, -0.6734383991, 0.7392433447, 0.639412098, -0.7688642071, 0.9211571421, 0.3891908523, -0.146637214, -0.9891903394, -0.782318098, 0.6228791163, -0.5039610839, -0.8637263605, -0.7743120191, -0.6328039957,
];
#[rustfmt::skip]
const GRADIENTS_3D: [f32; 256] = [
0., 1., 1., 0., 0.,-1., 1., 0., 0., 1.,-1., 0., 0.,-1.,-1., 0.,
1., 0., 1., 0., -1., 0., 1., 0., 1., 0.,-1., 0., -1., 0.,-1., 0.,
1., 1., 0., 0., -1., 1., 0., 0., 1.,-1., 0., 0., -1.,-1., 0., 0.,
0., 1., 1., 0., 0.,-1., 1., 0., 0., 1.,-1., 0., 0.,-1.,-1., 0.,
1., 0., 1., 0., -1., 0., 1., 0., 1., 0.,-1., 0., -1., 0.,-1., 0.,
1., 1., 0., 0., -1., 1., 0., 0., 1.,-1., 0., 0., -1.,-1., 0., 0.,
0., 1., 1., 0., 0.,-1., 1., 0., 0., 1.,-1., 0., 0.,-1.,-1., 0.,
1., 0., 1., 0., -1., 0., 1., 0., 1., 0.,-1., 0., -1., 0.,-1., 0.,
1., 1., 0., 0., -1., 1., 0., 0., 1.,-1., 0., 0., -1.,-1., 0., 0.,
0., 1., 1., 0., 0.,-1., 1., 0., 0., 1.,-1., 0., 0.,-1.,-1., 0.,
1., 0., 1., 0., -1., 0., 1., 0., 1., 0.,-1., 0., -1., 0.,-1., 0.,
1., 1., 0., 0., -1., 1., 0., 0., 1.,-1., 0., 0., -1.,-1., 0., 0.,
0., 1., 1., 0., 0.,-1., 1., 0., 0., 1.,-1., 0., 0.,-1.,-1., 0.,
1., 0., 1., 0., -1., 0., 1., 0., 1., 0.,-1., 0., -1., 0.,-1., 0.,
1., 1., 0., 0., -1., 1., 0., 0., 1.,-1., 0., 0., -1.,-1., 0., 0.,
1., 1., 0., 0., 0.,-1., 1., 0., -1., 1., 0., 0., 0.,-1.,-1., 0.,
];
#[rustfmt::skip]
const RAND_VECS_3D: [f32; 1024] = [
-0.7292736885, -0.6618439697, 0.1735581948, 0., 0.790292081, -0.5480887466, -0.2739291014, 0., 0.7217578935, 0.6226212466, -0.3023380997, 0., 0.565683137, -0.8208298145, -0.0790000257, 0., 0.760049034, -0.5555979497, -0.3370999617, 0., 0.3713945616, 0.5011264475, 0.7816254623, 0., -0.1277062463, -0.4254438999, -0.8959289049, 0., -0.2881560924, -0.5815838982, 0.7607405838, 0.,
0.5849561111, -0.662820239, -0.4674352136, 0., 0.3307171178, 0.0391653737, 0.94291689, 0., 0.8712121778, -0.4113374369, -0.2679381538, 0., 0.580981015, 0.7021915846, 0.4115677815, 0., 0.503756873, 0.6330056931, -0.5878203852, 0., 0.4493712205, 0.601390195, 0.6606022552, 0., -0.6878403724, 0.09018890807, -0.7202371714, 0., -0.5958956522, -0.6469350577, 0.475797649, 0.,
-0.5127052122, 0.1946921978, -0.8361987284, 0., -0.9911507142, -0.05410276466, -0.1212153153, 0., -0.2149721042, 0.9720882117, -0.09397607749, 0., -0.7518650936, -0.5428057603, 0.3742469607, 0., 0.5237068895, 0.8516377189, -0.02107817834, 0., 0.6333504779, 0.1926167129, -0.7495104896, 0., -0.06788241606, 0.3998305789, 0.9140719259, 0., -0.5538628599, -0.4729896695, -0.6852128902, 0.,
-0.7261455366, -0.5911990757, 0.3509933228, 0., -0.9229274737, -0.1782808786, 0.3412049336, 0., -0.6968815002, 0.6511274338, 0.3006480328, 0., 0.9608044783, -0.2098363234, -0.1811724921, 0., 0.06817146062, -0.9743405129, 0.2145069156, 0., -0.3577285196, -0.6697087264, -0.6507845481, 0., -0.1868621131, 0.7648617052, -0.6164974636, 0., -0.6541697588, 0.3967914832, 0.6439087246, 0.,
0.6993340405, -0.6164538506, 0.3618239211, 0., -0.1546665739, 0.6291283928, 0.7617583057, 0., -0.6841612949, -0.2580482182, -0.6821542638, 0., 0.5383980957, 0.4258654885, 0.7271630328, 0., -0.5026987823, -0.7939832935, -0.3418836993, 0., 0.3202971715, 0.2834415347, 0.9039195862, 0., 0.8683227101, -0.0003762656404, -0.4959995258, 0., 0.791120031, -0.08511045745, 0.6057105799, 0.,
-0.04011016052, -0.4397248749, 0.8972364289, 0., 0.9145119872, 0.3579346169, -0.1885487608, 0., -0.9612039066, -0.2756484276, 0.01024666929, 0., 0.6510361721, -0.2877799159, -0.7023778346, 0., -0.2041786351, 0.7365237271, 0.644859585, 0., -0.7718263711, 0.3790626912, 0.5104855816, 0., -0.3060082741, -0.7692987727, 0.5608371729, 0., 0.454007341, -0.5024843065, 0.7357899537, 0.,
0.4816795475, 0.6021208291, -0.6367380315, 0., 0.6961980369, -0.3222197429, 0.641469197, 0., -0.6532160499, -0.6781148932, 0.3368515753, 0., 0.5089301236, -0.6154662304, -0.6018234363, 0., -0.1635919754, -0.9133604627, -0.372840892, 0., 0.52408019, -0.8437664109, 0.1157505864, 0., 0.5902587356, 0.4983817807, -0.6349883666, 0., 0.5863227872, 0.494764745, 0.6414307729, 0.,
0.6779335087, 0.2341345225, 0.6968408593, 0., 0.7177054546, -0.6858979348, 0.120178631, 0., -0.5328819713, -0.5205125012, 0.6671608058, 0., -0.8654874251, -0.0700727088, -0.4960053754, 0., -0.2861810166, 0.7952089234, 0.5345495242, 0., -0.04849529634, 0.9810836427, -0.1874115585, 0., -0.6358521667, 0.6058348682, 0.4781800233, 0., 0.6254794696, -0.2861619734, 0.7258696564, 0.,
-0.2585259868, 0.5061949264, -0.8227581726, 0., 0.02136306781, 0.5064016808, -0.8620330371, 0., 0.200111773, 0.8599263484, 0.4695550591, 0., 0.4743561372, 0.6014985084, -0.6427953014, 0., 0.6622993731, -0.5202474575, -0.5391679918, 0., 0.08084972818, -0.6532720452, 0.7527940996, 0., -0.6893687501, 0.0592860349, 0.7219805347, 0., -0.1121887082, -0.9673185067, 0.2273952515, 0.,
0.7344116094, 0.5979668656, -0.3210532909, 0., 0.5789393465, -0.2488849713, 0.7764570201, 0., 0.6988182827, 0.3557169806, -0.6205791146, 0., -0.8636845529, -0.2748771249, -0.4224826141, 0., -0.4247027957, -0.4640880967, 0.777335046, 0., 0.5257722489, -0.8427017621, 0.1158329937, 0., 0.9343830603, 0.316302472, -0.1639543925, 0., -0.1016836419, -0.8057303073, -0.5834887393, 0.,
-0.6529238969, 0.50602126, -0.5635892736, 0., -0.2465286165, -0.9668205684, -0.06694497494, 0., -0.9776897119, -0.2099250524, -0.007368825344, 0., 0.7736893337, 0.5734244712, 0.2694238123, 0., -0.6095087895, 0.4995678998, 0.6155736747, 0., 0.5794535482, 0.7434546771, 0.3339292269, 0., -0.8226211154, 0.08142581855, 0.5627293636, 0., -0.510385483, 0.4703667658, 0.7199039967, 0.,
-0.5764971849, -0.07231656274, -0.8138926898, 0., 0.7250628871, 0.3949971505, -0.5641463116, 0., -0.1525424005, 0.4860840828, -0.8604958341, 0., -0.5550976208, -0.4957820792, 0.667882296, 0., -0.1883614327, 0.9145869398, 0.357841725, 0., 0.7625556724, -0.5414408243, -0.3540489801, 0., -0.5870231946, -0.3226498013, -0.7424963803, 0., 0.3051124198, 0.2262544068, -0.9250488391, 0.,
0.6379576059, 0.577242424, -0.5097070502, 0., -0.5966775796, 0.1454852398, -0.7891830656, 0., -0.658330573, 0.6555487542, -0.3699414651, 0., 0.7434892426, 0.2351084581, 0.6260573129, 0., 0.5562114096, 0.8264360377, -0.0873632843, 0., -0.3028940016, -0.8251527185, 0.4768419182, 0., 0.1129343818, -0.985888439, -0.1235710781, 0., 0.5937652891, -0.5896813806, 0.5474656618, 0.,
0.6757964092, -0.5835758614, -0.4502648413, 0., 0.7242302609, -0.1152719764, 0.6798550586, 0., -0.9511914166, 0.0753623979, -0.2992580792, 0., 0.2539470961, -0.1886339355, 0.9486454084, 0., 0.571433621, -0.1679450851, -0.8032795685, 0., -0.06778234979, 0.3978269256, 0.9149531629, 0., 0.6074972649, 0.733060024, -0.3058922593, 0., -0.5435478392, 0.1675822484, 0.8224791405, 0.,
-0.5876678086, -0.3380045064, -0.7351186982, 0., -0.7967562402, 0.04097822706, -0.6029098428, 0., -0.1996350917, 0.8706294745, 0.4496111079, 0., -0.02787660336, -0.9106232682, -0.4122962022, 0., -0.7797625996, -0.6257634692, 0.01975775581, 0., -0.5211232846, 0.7401644346, -0.4249554471, 0., 0.8575424857, 0.4053272873, -0.3167501783, 0., 0.1045223322, 0.8390195772, -0.5339674439, 0.,
0.3501822831, 0.9242524096, -0.1520850155, 0., 0.1987849858, 0.07647613266, 0.9770547224, 0., 0.7845996363, 0.6066256811, -0.1280964233, 0., 0.09006737436, -0.9750989929, -0.2026569073, 0., -0.8274343547, -0.542299559, 0.1458203587, 0., -0.3485797732, -0.415802277, 0.840000362, 0., -0.2471778936, -0.7304819962, -0.6366310879, 0., -0.3700154943, 0.8577948156, 0.3567584454, 0.,
0.5913394901, -0.548311967, -0.5913303597, 0., 0.1204873514, -0.7626472379, -0.6354935001, 0., 0.616959265, 0.03079647928, 0.7863922953, 0., 0.1258156836, -0.6640829889, -0.7369967419, 0., -0.6477565124, -0.1740147258, -0.7417077429, 0., 0.6217889313, -0.7804430448, -0.06547655076, 0., 0.6589943422, -0.6096987708, 0.4404473475, 0., -0.2689837504, -0.6732403169, -0.6887635427, 0.,
-0.3849775103, 0.5676542638, 0.7277093879, 0., 0.5754444408, 0.8110471154, -0.1051963504, 0., 0.9141593684, 0.3832947817, 0.131900567, 0., -0.107925319, 0.9245493968, 0.3654593525, 0., 0.377977089, 0.3043148782, 0.8743716458, 0., -0.2142885215, -0.8259286236, 0.5214617324, 0., 0.5802544474, 0.4148098596, -0.7008834116, 0., -0.1982660881, 0.8567161266, -0.4761596756, 0.,
-0.03381553704, 0.3773180787, -0.9254661404, 0., -0.6867922841, -0.6656597827, 0.2919133642, 0., 0.7731742607, -0.2875793547, -0.5652430251, 0., -0.09655941928, 0.9193708367, -0.3813575004, 0., 0.2715702457, -0.9577909544, -0.09426605581, 0., 0.2451015704, -0.6917998565, -0.6792188003, 0., 0.977700782, -0.1753855374, 0.1155036542, 0., -0.5224739938, 0.8521606816, 0.02903615945, 0.,
-0.7734880599, -0.5261292347, 0.3534179531, 0., -0.7134492443, -0.269547243, 0.6467878011, 0., 0.1644037271, 0.5105846203, -0.8439637196, 0., 0.6494635788, 0.05585611296, 0.7583384168, 0., -0.4711970882, 0.5017280509, -0.7254255765, 0., -0.6335764307, -0.2381686273, -0.7361091029, 0., -0.9021533097, -0.270947803, -0.3357181763, 0., -0.3793711033, 0.872258117, 0.3086152025, 0.,
-0.6855598966, -0.3250143309, 0.6514394162, 0., 0.2900942212, -0.7799057743, -0.5546100667, 0., -0.2098319339, 0.85037073, 0.4825351604, 0., -0.4592603758, 0.6598504336, -0.5947077538, 0., 0.8715945488, 0.09616365406, -0.4807031248, 0., -0.6776666319, 0.7118504878, -0.1844907016, 0., 0.7044377633, 0.312427597, 0.637304036, 0., -0.7052318886, -0.2401093292, -0.6670798253, 0.,
0.081921007, -0.7207336136, -0.6883545647, 0., -0.6993680906, -0.5875763221, -0.4069869034, 0., -0.1281454481, 0.6419895885, 0.7559286424, 0., -0.6337388239, -0.6785471501, -0.3714146849, 0., 0.5565051903, -0.2168887573, -0.8020356851, 0., -0.5791554484, 0.7244372011, -0.3738578718, 0., 0.1175779076, -0.7096451073, 0.6946792478, 0., -0.6134619607, 0.1323631078, 0.7785527795, 0.,
0.6984635305, -0.02980516237, -0.715024719, 0., 0.8318082963, -0.3930171956, 0.3919597455, 0., 0.1469576422, 0.05541651717, -0.9875892167, 0., 0.708868575, -0.2690503865, 0.6520101478, 0., 0.2726053183, 0.67369766, -0.68688995, 0., -0.6591295371, 0.3035458599, -0.6880466294, 0., 0.4815131379, -0.7528270071, 0.4487723203, 0., 0.9430009463, 0.1675647412, -0.2875261255, 0.,
0.434802957, 0.7695304522, -0.4677277752, 0., 0.3931996188, 0.594473625, 0.7014236729, 0., 0.7254336655, -0.603925654, 0.3301814672, 0., 0.7590235227, -0.6506083235, 0.02433313207, 0., -0.8552768592, -0.3430042733, 0.3883935666, 0., -0.6139746835, 0.6981725247, 0.3682257648, 0., -0.7465905486, -0.5752009504, 0.3342849376, 0., 0.5730065677, 0.810555537, -0.1210916791, 0.,
-0.9225877367, -0.3475211012, -0.167514036, 0., -0.7105816789, -0.4719692027, -0.5218416899, 0., -0.08564609717, 0.3583001386, 0.929669703, 0., -0.8279697606, -0.2043157126, 0.5222271202, 0., 0.427944023, 0.278165994, 0.8599346446, 0., 0.5399079671, -0.7857120652, -0.3019204161, 0., 0.5678404253, -0.5495413974, -0.6128307303, 0., -0.9896071041, 0.1365639107, -0.04503418428, 0.,
-0.6154342638, -0.6440875597, 0.4543037336, 0., 0.1074204368, -0.7946340692, 0.5975094525, 0., -0.3595449969, -0.8885529948, 0.28495784, 0., -0.2180405296, 0.1529888965, 0.9638738118, 0., -0.7277432317, -0.6164050508, -0.3007234646, 0., 0.7249729114, -0.00669719484, 0.6887448187, 0., -0.5553659455, -0.5336586252, 0.6377908264, 0., 0.5137558015, 0.7976208196, -0.3160000073, 0.,
-0.3794024848, 0.9245608561, -0.03522751494, 0., 0.8229248658, 0.2745365933, -0.4974176556, 0., -0.5404114394, 0.6091141441, 0.5804613989, 0., 0.8036581901, -0.2703029469, 0.5301601931, 0., 0.6044318879, 0.6832968393, 0.4095943388, 0., 0.06389988817, 0.9658208605, -0.2512108074, 0., 0.1087113286, 0.7402471173, -0.6634877936, 0., -0.713427712, -0.6926784018, 0.1059128479, 0.,
0.6458897819, -0.5724548511, -0.5050958653, 0., -0.6553931414, 0.7381471625, 0.159995615, 0., 0.3910961323, 0.9188871375, -0.05186755998, 0., -0.4879022471, -0.5904376907, 0.6429111375, 0., 0.6014790094, 0.7707441366, -0.2101820095, 0., -0.5677173047, 0.7511360995, 0.3368851762, 0., 0.7858573506, 0.226674665, 0.5753666838, 0., -0.4520345543, -0.604222686, -0.6561857263, 0.,
0.002272116345, 0.4132844051, -0.9105991643, 0., -0.5815751419, -0.5162925989, 0.6286591339, 0., -0.03703704785, 0.8273785755, 0.5604221175, 0., -0.5119692504, 0.7953543429, -0.3244980058, 0., -0.2682417366, -0.9572290247, -0.1084387619, 0., -0.2322482736, -0.9679131102, -0.09594243324, 0., 0.3554328906, -0.8881505545, 0.2913006227, 0., 0.7346520519, -0.4371373164, 0.5188422971, 0.,
0.9985120116, 0.04659011161, -0.02833944577, 0., -0.3727687496, -0.9082481361, 0.1900757285, 0., 0.91737377, -0.3483642108, 0.1925298489, 0., 0.2714911074, 0.4147529736, -0.8684886582, 0., 0.5131763485, -0.7116334161, 0.4798207128, 0., -0.8737353606, 0.18886992, -0.4482350644, 0., 0.8460043821, -0.3725217914, 0.3814499973, 0., 0.8978727456, -0.1780209141, -0.4026575304, 0.,
0.2178065647, -0.9698322841, -0.1094789531, 0., -0.1518031304, -0.7788918132, -0.6085091231, 0., -0.2600384876, -0.4755398075, -0.8403819825, 0., 0.572313509, -0.7474340931, -0.3373418503, 0., -0.7174141009, 0.1699017182, -0.6756111411, 0., -0.684180784, 0.02145707593, -0.7289967412, 0., -0.2007447902, 0.06555605789, -0.9774476623, 0., -0.1148803697, -0.8044887315, 0.5827524187, 0.,
-0.7870349638, 0.03447489231, 0.6159443543, 0., -0.2015596421, 0.6859872284, 0.6991389226, 0., -0.08581082512, -0.10920836, -0.9903080513, 0., 0.5532693395, 0.7325250401, -0.396610771, 0., -0.1842489331, -0.9777375055, -0.1004076743, 0., 0.0775473789, -0.9111505856, 0.4047110257, 0., 0.1399838409, 0.7601631212, -0.6344734459, 0., 0.4484419361, -0.845289248, 0.2904925424, 0.,
];
// ==============
// Math functions
// ==============
#[inline(always)]
fn fast_floor(f: Float) -> i32 {
if f >= 0. {
f as i32
} else {
f as i32 - 1
}
}
#[inline(always)]
fn fast_round(f: Float) -> i32 {
if f >= 0. {
(f + 0.5) as i32
} else {
(f - 0.5) as i32
}
}
#[inline(always)]
fn lerp(a: f32, b: f32, t: f32) -> f32 {
a + t * (b - a)
}
#[inline(always)]
fn interp_hermite(t: f32) -> f32 {
t * t * (t * -2. + 3.)
}
#[inline(always)]
fn interp_quintic(t: f32) -> f32 {
t * t * t * (t * (t * 6. - 15.) + 10.)
}
#[inline(always)]
fn cubic_lerp(a: f32, b: f32, c: f32, d: f32, t: f32) -> f32 {
let p = (d - c) - (a - b);
t * t * t * p + t * t * ((a - b) - p) + t * (c - a) + b
}
#[inline(always)]
fn ping_pong(t: f32) -> f32 {
let t = t - FloatOps::trunc(t * 0.5) * 2.;
if t < 1. {
t
} else {
2. - t
}
}
fn calculate_fractal_bounding(&mut self) {
let gain = FloatOps::abs(self.gain);
let mut amp = gain;
let mut amp_fractal = 1.;
for _ in 1..self.octaves {
amp_fractal += amp;
amp *= gain;
}
self.fractal_bounding = 1. / amp_fractal;
}
// ==============
// Hash functions
// ==============
// Primes for hashing
const PRIME_X: i32 = 501125321;
const PRIME_Y: i32 = 1136930381;
const PRIME_Z: i32 = 1720413743;
const PRIME_X_2: i32 = Self::PRIME_X.wrapping_mul(2);
const PRIME_Y_2: i32 = Self::PRIME_Y.wrapping_mul(2);
const PRIME_Z_2: i32 = Self::PRIME_Z.wrapping_mul(2);
#[inline(always)]
fn hash_2d(seed: i32, x_primed: i32, y_primed: i32) -> i32 {
let hash = seed ^ x_primed ^ y_primed;
hash.wrapping_mul(0x27d4eb2d)
}
#[inline(always)]
fn hash_3d(seed: i32, x_primed: i32, y_primed: i32, z_primed: i32) -> i32 {
let hash = seed ^ x_primed ^ y_primed ^ z_primed;
hash.wrapping_mul(0x27d4eb2d)
}
// ===================================
// Internal noise generator algorithms
// ===================================
#[inline(always)]
fn val_coord_2d(seed: i32, x_primed: i32, y_primed: i32) -> f32 {
let hash = Self::hash_2d(seed, x_primed, y_primed);
let hash = hash.wrapping_mul(hash);
let hash = hash ^ (hash << 19);
hash as f32 * (1. / 2147483648.)
}
#[inline(always)]
fn val_coord_3d(seed: i32, x_primed: i32, y_primed: i32, z_primed: i32) -> f32 {
let hash = Self::hash_3d(seed, x_primed, y_primed, z_primed);
let hash = hash.wrapping_mul(hash);
let hash = hash ^ (hash << 19);
hash as f32 * (1. / 2147483648.)
}
#[inline(always)]
fn grad_coord_2d(seed: i32, x_primed: i32, y_primed: i32, xd: f32, yd: f32) -> f32 {
let hash = Self::hash_2d(seed, x_primed, y_primed);
let hash = hash ^ (hash >> 15);
let hash = hash & (127 << 1);
let xg = Self::GRADIENTS_2D[hash as usize];
let yg = Self::GRADIENTS_2D[(hash | 1) as usize];
xd * xg + yd * yg
}
#[inline(always)]
fn grad_coord_3d(
seed: i32,
x_primed: i32,
y_primed: i32,
z_primed: i32,
xd: f32,
yd: f32,
zd: f32,
) -> f32 {
let hash = Self::hash_3d(seed, x_primed, y_primed, z_primed);
let hash = hash ^ (hash >> 15);
let hash = hash & (63 << 2);
let xg = Self::GRADIENTS_3D[hash as usize];
let yg = Self::GRADIENTS_3D[(hash | 1) as usize];
let zg = Self::GRADIENTS_3D[(hash | 2) as usize];
xd * xg + yd * yg + zd * zg
}
#[inline(always)]
fn grad_coord_out_2d(seed: i32, x_primed: i32, y_primed: i32) -> (f32, f32) {
let hash = Self::hash_2d(seed, x_primed, y_primed) & (255 << 1);
let xo = Self::RAND_VECS_2D[hash as usize];
let yo = Self::RAND_VECS_2D[(hash | 1) as usize];
(xo, yo)
}
#[inline(always)]
fn grad_coord_out_3d(
seed: i32,
x_primed: i32,
y_primed: i32,
z_primed: i32,
) -> (f32, f32, f32) {
let hash = Self::hash_3d(seed, x_primed, y_primed, z_primed) & (255 << 2);
let xo = Self::RAND_VECS_3D[hash as usize];
let yo = Self::RAND_VECS_3D[(hash | 1) as usize];
let zo = Self::RAND_VECS_3D[(hash | 2) as usize];
(xo, yo, zo)
}
#[inline(always)]
fn grad_coord_dual_2d(seed: i32, x_primed: i32, y_primed: i32, xd: f32, yd: f32) -> (f32, f32) {
let hash = Self::hash_2d(seed, x_primed, y_primed);
let index1 = hash & (127 << 1);
let index2 = (hash >> 7) & (255 << 1);
let xg = Self::GRADIENTS_2D[index1 as usize];
let yg = Self::GRADIENTS_2D[(index1 | 1) as usize];
let value = xd * xg + yd * yg;
let xgo = Self::RAND_VECS_2D[index2 as usize];
let ygo = Self::RAND_VECS_2D[(index2 | 1) as usize];
let xo = value * xgo;
let yo = value * ygo;
(xo, yo)
}
#[inline(always)]
fn grad_coord_dual_3d(
seed: i32,
x_primed: i32,
y_primed: i32,
z_primed: i32,
xd: f32,
yd: f32,
zd: f32,
) -> (f32, f32, f32) {
let hash = Self::hash_3d(seed, x_primed, y_primed, z_primed);
let index1 = hash & (63 << 2);
let index2 = (hash >> 6) & (255 << 2);
let xg = Self::GRADIENTS_3D[index1 as usize];
let yg = Self::GRADIENTS_3D[(index1 | 1) as usize];
let zg = Self::GRADIENTS_3D[(index1 | 2) as usize];
let value = xd * xg + yd * yg + zd * zg;
let xgo = Self::RAND_VECS_3D[index2 as usize];
let ygo = Self::RAND_VECS_3D[(index2 | 1) as usize];
let zgo = Self::RAND_VECS_3D[(index2 | 2) as usize];
let xo = value * xgo;
let yo = value * ygo;
let zo = value * zgo;
(xo, yo, zo)
}
// Generic noise gen
fn gen_noise_single_2d(&self, seed: i32, x: Float, y: Float) -> f32 {
match self.noise_type {
NoiseType::OpenSimplex2 => self.single_simplex_2d(seed, x, y),
NoiseType::OpenSimplex2S => self.single_open_simplex_2s_2d(seed, x, y),
NoiseType::Cellular => self.single_cellular_2d(seed, x, y),
NoiseType::Perlin => self.single_perlin_2d(seed, x, y),
NoiseType::ValueCubic => self.single_value_cubic_2d(seed, x, y),
NoiseType::Value => self.single_value_2d(seed, x, y),
}
}
fn gen_noise_single_3d(&self, seed: i32, x: Float, y: Float, z: Float) -> f32 {
match self.noise_type {
NoiseType::OpenSimplex2 => self.single_open_simplex_2(seed, x, y, z),
NoiseType::OpenSimplex2S => self.single_open_simplex_2s_3d(seed, x, y, z),
NoiseType::Cellular => self.single_cellular_3d(seed, x, y, z),
NoiseType::Perlin => self.single_perlin_3d(seed, x, y, z),
NoiseType::ValueCubic => self.single_value_cubic_3d(seed, x, y, z),
NoiseType::Value => self.single_value_3d(seed, x, y, z),
}
}
// Noise Coordinate Transforms (frequency, and possible skew or rotation)
#[inline(always)]
fn transform_noise_coordinate_2d(&self, x: Float, y: Float) -> (Float, Float) {
let mut x = x * self.frequency as Float;
let mut y = y * self.frequency as Float;
match self.noise_type {
NoiseType::OpenSimplex2 | NoiseType::OpenSimplex2S => {
let sqrt3 = 1.7320508075688772935274463415059;
let f2 = 0.5 * (sqrt3 - 1.);
let t = (x + y) * f2;
x += t;
y += t;
}
_ => {}
}
(x, y)
}
#[inline(always)]
fn transform_noise_coordinate_3d(&self, x: Float, y: Float, z: Float) -> (Float, Float, Float) {
let mut x = x * self.frequency as Float;
let mut y = y * self.frequency as Float;
let mut z = z * self.frequency as Float;
match self.transform_type_3d {
TransformType3D::ImproveXYPlanes => {
let xy = x + y;
let s2 = xy * -0.211324865405187;
z *= 0.577350269189626;
x += s2 - z;
y = y + s2 - z;
z += xy * 0.577350269189626;
}
TransformType3D::ImproveXZPlanes => {
let xz = x + z;
let s2 = xz * -0.211324865405187;
y *= 0.577350269189626;
x += s2 - y;
z += s2 - y;
y += xz * 0.577350269189626;
}
TransformType3D::DefaultOpenSimplex2 => {
let r3 = 2. / 3.;
let r = (x + y + z) * r3; // Rotation, not skew
x = r - x;
y = r - y;
z = r - z;
}
_ => {}
}
(x, y, z)
}
fn update_transform_type_3d(&mut self) {
match self.rotation_type_3d {
RotationType3D::ImproveXYPlanes => {
self.transform_type_3d = TransformType3D::ImproveXYPlanes;
}
RotationType3D::ImproveXZPlanes => {
self.transform_type_3d = TransformType3D::ImproveXZPlanes;
}
_ => match self.noise_type {
NoiseType::OpenSimplex2 | NoiseType::OpenSimplex2S => {
self.transform_type_3d = TransformType3D::DefaultOpenSimplex2;
}
_ => {
self.transform_type_3d = TransformType3D::None;
}
},
}
}
// Domain Warp Coordinate Transforms
#[inline(always)]
fn transform_domain_warp_coordinate_2d(&self, x: Float, y: Float) -> (Float, Float) {
let mut x = x;
let mut y = y;
match self.domain_warp_type {
DomainWarpType::OpenSimplex2 | DomainWarpType::OpenSimplex2Reduced => {
let sqrt3 = 1.7320508075688772935274463415059;
let f2 = 0.5 * (sqrt3 - 1.);
let t = (x + y) * f2;
x += t;
y += t;
}
_ => {}
}
(x, y)
}
#[inline(always)]
fn transform_domain_warp_coordinate_3d(
&self,
x: Float,
y: Float,
z: Float,
) -> (Float, Float, Float) {
let mut x = x;
let mut y = y;
let mut z = z;
match self.warp_transform_type_3d {
TransformType3D::ImproveXYPlanes => {
let xy = x + y;
let s2 = xy * -0.211324865405187;
z *= 0.577350269189626;
x += s2 - z;
y = y + s2 - z;
z += xy * 0.577350269189626;
}
TransformType3D::ImproveXZPlanes => {
let xz = x + z;
let s2 = xz * -0.211324865405187;
y *= 0.577350269189626;
x += s2 - y;
z += s2 - y;
y += xz * 0.577350269189626;
}
TransformType3D::DefaultOpenSimplex2 => {
let r3 = 2. / 3.;
let r = (x + y + z) * r3; // Rotation, not skew
x = r - x;
y = r - y;
z = r - z;
}
_ => {}
}
(x, y, z)
}
fn update_warp_transform_type_3d(&mut self) {
match self.rotation_type_3d {
RotationType3D::ImproveXYPlanes => {
self.warp_transform_type_3d = TransformType3D::ImproveXYPlanes;
}
RotationType3D::ImproveXZPlanes => {
self.warp_transform_type_3d = TransformType3D::ImproveXZPlanes;
}
_ => match self.domain_warp_type {
DomainWarpType::OpenSimplex2 | DomainWarpType::OpenSimplex2Reduced => {
self.warp_transform_type_3d = TransformType3D::DefaultOpenSimplex2;
}
_ => {
self.warp_transform_type_3d = TransformType3D::None;
}
},
}
}
// Fractal FBm
fn gen_fractal_fbm_2d(&self, x: Float, y: Float) -> f32 {
let mut x = x;
let mut y = y;
let mut seed = self.seed;
let mut sum = 0.;
let mut amp = self.fractal_bounding;
for _ in 0..self.octaves {
let noise = self.gen_noise_single_2d(seed, x, y);
seed += 1;
sum += noise * amp;
amp *= Self::lerp(1., (noise + 1.).min(2.) * 0.5, self.weighted_strength);
x *= self.lacunarity as Float;
y *= self.lacunarity as Float;
amp *= self.gain;
}
sum
}
fn gen_fractal_fbm_3d(&self, x: Float, y: Float, z: Float) -> f32 {
let mut x = x;
let mut y = y;
let mut z = z;
let mut seed = self.seed;
let mut sum = 0.;
let mut amp = self.fractal_bounding;
for _ in 0..self.octaves {
let noise = self.gen_noise_single_3d(seed, x, y, z);
seed += 1;
sum += noise * amp;
amp *= Self::lerp(1., (noise + 1.) * 0.5, self.weighted_strength);
x *= self.lacunarity as Float;
y *= self.lacunarity as Float;
z *= self.lacunarity as Float;
amp *= self.gain;
}
sum
}
// Fractal Ridged
fn gen_fractal_ridged_2d(&self, x: Float, y: Float) -> f32 {
let mut x = x;
let mut y = y;
let mut seed = self.seed;
let mut sum = 0.;
let mut amp = self.fractal_bounding;
for _ in 0..self.octaves {
let noise = FloatOps::abs(self.gen_noise_single_2d(seed, x, y));
seed += 1;
sum += (noise * -2. + 1.) * amp;
amp *= Self::lerp(1., 1. - noise, self.weighted_strength);
x *= self.lacunarity as Float;
y *= self.lacunarity as Float;
amp *= self.gain;
}
sum
}
fn gen_fractal_ridged_3d(&self, x: Float, y: Float, z: Float) -> f32 {
let mut x = x;
let mut y = y;
let mut z = z;
let mut seed = self.seed;
let mut sum = 0.;
let mut amp = self.fractal_bounding;
for _ in 0..self.octaves {
let noise = FloatOps::abs(self.gen_noise_single_3d(seed, x, y, z));
seed += 1;
sum += (noise * -2. + 1.) * amp;
amp *= Self::lerp(1., 1. - noise, self.weighted_strength);
x *= self.lacunarity as Float;
y *= self.lacunarity as Float;
z *= self.lacunarity as Float;
amp *= self.gain;
}
sum
}
// Fractal PingPong
fn gen_fractal_ping_pong_2d(&self, x: Float, y: Float) -> f32 {
let mut x = x;
let mut y = y;
let mut seed = self.seed;
let mut sum = 0.;
let mut amp = self.fractal_bounding; // DEBUG: This is 0.400000006, should be 0.4
for _ in 0..self.octaves {
let noise = Self::ping_pong(
(self.gen_noise_single_2d(seed, x, y) + 1.) * self.ping_pong_strength,
);
seed += 1;
sum += (noise - 0.5) * 2. * amp;
amp *= Self::lerp(1., noise, self.weighted_strength);
x *= self.lacunarity as Float;
y *= self.lacunarity as Float;
amp *= self.gain;
}
sum
}
fn gen_fractal_ping_pong_3d(&self, x: Float, y: Float, z: Float) -> f32 {
let mut x = x;
let mut y = y;
let mut z = z;
let mut seed = self.seed;
let mut sum = 0.;
let mut amp = self.fractal_bounding;
for _ in 0..self.octaves {
let noise = Self::ping_pong(
(self.gen_noise_single_3d(seed, x, y, z) + 1.) * self.ping_pong_strength,
);
seed += 1;
sum += (noise - 0.5) * 2. * amp;
amp *= Self::lerp(1., noise, self.weighted_strength);
x *= self.lacunarity as Float;
y *= self.lacunarity as Float;
z *= self.lacunarity as Float;
amp *= self.gain;
}
sum
}
// Simplex/OpenSimplex2 Noise
fn single_simplex_2d(&self, seed: i32, x: Float, y: Float) -> f32 {
// 2D OpenSimplex2 case uses the same algorithm as ordinary Simplex.
let sqrt3 = 1.7320508075688772935274463415059;
let g2 = (3. - sqrt3) / 6.;
/*
* --- Skew moved to TransformNoiseCoordinateXY method ---
* let f2 = 0.5 * (sqrt3 - 1.);
* let s = (x + y) * f2;
* x += s; y += s;
*/
let i = Self::fast_floor(x);
let j = Self::fast_floor(y);
#[allow(clippy::unnecessary_cast)]
let xi = (x - i as Float) as f32;
#[allow(clippy::unnecessary_cast)]
let yi = (y - j as Float) as f32;
let t = (xi + yi) * g2;
let x0 = xi - t;
let y0 = yi - t;
let i = i.wrapping_mul(Self::PRIME_X);
let j = j.wrapping_mul(Self::PRIME_Y);
let a = 0.5 - x0 * x0 - y0 * y0;
let n0 = if a <= 0. {
0.
} else {
(a * a) * (a * a) * Self::grad_coord_2d(seed, i, j, x0, y0)
};
let c = (2. * (1. - 2. * g2) * (1. / g2 - 2.)) * t
+ ((-2. * (1. - 2. * g2) * (1. - 2. * g2)) + a);
let n2 = if c <= 0. {
0.
} else {
let x2 = x0 + (2. * g2 - 1.);
let y2 = y0 + (2. * g2 - 1.);
(c * c)
* (c * c)
* Self::grad_coord_2d(
seed,
i.wrapping_add(Self::PRIME_X),
j.wrapping_add(Self::PRIME_Y),
x2,
y2,
)
};
let n1 = if y0 > x0 {
let x1 = x0 + g2;
let y1 = y0 + (g2 - 1.);
let b = 0.5 - x1 * x1 - y1 * y1;
if b <= 0. {
0.
} else {
(b * b)
* (b * b)
* Self::grad_coord_2d(seed, i, j.wrapping_add(Self::PRIME_Y), x1, y1)
}
} else {
let x1 = x0 + (g2 - 1.);
let y1 = y0 + g2;
let b = 0.5 - x1 * x1 - y1 * y1;
if b <= 0. {
0.
} else {
(b * b)
* (b * b)
* Self::grad_coord_2d(seed, i.wrapping_add(Self::PRIME_X), j, x1, y1)
}
};
(n0 + n1 + n2) * 99.83685446303647
}
fn single_open_simplex_2(&self, seed: i32, x: Float, y: Float, z: Float) -> f32 {
// 3D OpenSimplex2 case uses two offset rotated cube grids.
/*
* --- Rotation moved to TransformNoiseCoordinateXYZ method ---
* let r3 = 2. / 3.;
* let r = (x + y + z) * r3; // Rotation, not skew
* x = r - x; y = r - y; z = r - z;
*/
let mut seed = seed;
let i = Self::fast_round(x);
let j = Self::fast_round(y);
let k = Self::fast_round(z);
#[allow(clippy::unnecessary_cast)]
let mut x0 = (x - i as Float) as f32;
#[allow(clippy::unnecessary_cast)]
let mut y0 = (y - j as Float) as f32;
#[allow(clippy::unnecessary_cast)]
let mut z0 = (z - k as Float) as f32;
let mut x_n_sign = (-1. - x0) as i32 | 1;
let mut y_n_sign = (-1. - y0) as i32 | 1;
let mut z_n_sign = (-1. - z0) as i32 | 1;
let mut ax0 = x_n_sign as f32 * -x0;
let mut ay0 = y_n_sign as f32 * -y0;
let mut az0 = z_n_sign as f32 * -z0;
let mut i = i.wrapping_mul(Self::PRIME_X);
let mut j = j.wrapping_mul(Self::PRIME_Y);
let mut k = k.wrapping_mul(Self::PRIME_Z);
let mut value = 0.;
let mut a = (0.6 - x0 * x0) - (y0 * y0 + z0 * z0);
let mut l = 0;
loop {
if a > 0. {
value += (a * a) * (a * a) * Self::grad_coord_3d(seed, i, j, k, x0, y0, z0);
}
if ax0 >= ay0 && ax0 >= az0 {
let b = a + ax0 + ax0;
if b > 1. {
let b = b - 1.;
value += (b * b)
* (b * b)
* Self::grad_coord_3d(
seed,
i.wrapping_sub(x_n_sign.wrapping_mul(Self::PRIME_X)),
j,
k,
x0 + x_n_sign as f32,
y0,
z0,
);
}
} else if ay0 > ax0 && ay0 >= az0 {
let b = a + ay0 + ay0;
if b > 1. {
let b = b - 1.;
value += (b * b)
* (b * b)
* Self::grad_coord_3d(
seed,
i,
j.wrapping_sub(y_n_sign.wrapping_mul(Self::PRIME_Y)),
k,
x0,
y0 + y_n_sign as f32,
z0,
);
}
} else {
let b = a + az0 + az0;
if b > 1. {
let b = b - 1.;
value += (b * b)
* (b * b)
* Self::grad_coord_3d(
seed,
i,
j,
k.wrapping_sub(z_n_sign.wrapping_mul(Self::PRIME_Z)),
x0,
y0,
z0 + z_n_sign as f32,
);
}
}
if l == 1 {
break;
}
ax0 = 0.5 - ax0;
ay0 = 0.5 - ay0;
az0 = 0.5 - az0;
x0 = x_n_sign as f32 * ax0;
y0 = y_n_sign as f32 * ay0;
z0 = z_n_sign as f32 * az0;
a = a + (0.75 - ax0) - (ay0 + az0);
i = i.wrapping_add((x_n_sign >> 1) & Self::PRIME_X);
j = j.wrapping_add((y_n_sign >> 1) & Self::PRIME_Y);
k = k.wrapping_add((z_n_sign >> 1) & Self::PRIME_Z);
x_n_sign = -x_n_sign;
y_n_sign = -y_n_sign;
z_n_sign = -z_n_sign;
seed = !seed;
l += 1;
}
value * 32.69428253173828125
}
// OpenSimplex2S Noise
fn single_open_simplex_2s_2d(&self, seed: i32, x: Float, y: Float) -> f32 {
// 2D OpenSimplex2S case is a modified 2D simplex noise.
let sqrt3 = 1.7320508075688772935274463415059;
let g2 = (3. - sqrt3) / 6.;
/*
* --- Skew moved to TransformNoiseCoordinateXY method ---
* let f2 = 0.5 * (sqrt3 - 1);
* let s = (x + y) * f2;
* x += s; y += s;
*/
let i = Self::fast_floor(x);
let j = Self::fast_floor(y);
#[allow(clippy::unnecessary_cast)]
let xi = (x - i as Float) as f32;
#[allow(clippy::unnecessary_cast)]
let yi = (y - j as Float) as f32;
let i = i.wrapping_mul(Self::PRIME_X);
let j = j.wrapping_mul(Self::PRIME_Y);
let i1 = i.wrapping_add(Self::PRIME_X);
let j1 = j.wrapping_add(Self::PRIME_Y);
let t = (xi + yi) * g2;
let x0 = xi - t;
let y0 = yi - t;
let a0 = (2. / 3.) - x0 * x0 - y0 * y0;
let mut value = (a0 * a0) * (a0 * a0) * Self::grad_coord_2d(seed, i, j, x0, y0);
let a1 = (2. * (1. - 2. * g2) * (1. / g2 - 2.)) * t
+ ((-2. * (1. - 2. * g2) * (1. - 2. * g2)) + a0);
let x1 = x0 - (1. - 2. * g2);
let y1 = y0 - (1. - 2. * g2);
value += (a1 * a1) * (a1 * a1) * Self::grad_coord_2d(seed, i1, j1, x1, y1);
// Nested conditionals were faster than compact bit logic/arithmetic.
let xmyi = xi - yi;
if t > g2 {
if xi + xmyi > 1. {
let x2 = x0 + (3. * g2 - 2.);
let y2 = y0 + (3. * g2 - 1.);
let a2 = (2. / 3.) - x2 * x2 - y2 * y2;
if a2 > 0. {
value += (a2 * a2)
* (a2 * a2)
* Self::grad_coord_2d(
seed,
i.wrapping_add(Self::PRIME_X << 1),
j.wrapping_add(Self::PRIME_Y),
x2,
y2,
)
}
} else {
let x2 = x0 + g2;
let y2 = y0 + (g2 - 1.);
let a2 = (2. / 3.) - x2 * x2 - y2 * y2;
if a2 > 0. {
value += (a2 * a2)
* (a2 * a2)
* Self::grad_coord_2d(seed, i, j.wrapping_add(Self::PRIME_Y), x2, y2)
}
}
if yi - xmyi > 1. {
let x3 = x0 + (3. * g2 - 1.);
let y3 = y0 + (3. * g2 - 2.);
let a3 = (2. / 3.) - x3 * x3 - y3 * y3;
if a3 > 0. {
value += (a3 * a3)
* (a3 * a3)
* Self::grad_coord_2d(
seed,
i.wrapping_add(Self::PRIME_X),
j.wrapping_add(Self::PRIME_Y << 1),
x3,
y3,
)
}
} else {
let x3 = x0 + (g2 - 1.);
let y3 = y0 + g2;
let a3 = (2. / 3.) - x3 * x3 - y3 * y3;
if a3 > 0. {
value += (a3 * a3)
* (a3 * a3)
* Self::grad_coord_2d(seed, i.wrapping_add(Self::PRIME_X), j, x3, y3)
}
}
} else {
if xi + xmyi < 0. {
let x2 = x0 + (1. - g2);
let y2 = y0 - g2;
let a2 = (2. / 3.) - x2 * x2 - y2 * y2;
if a2 > 0. {
value += (a2 * a2)
* (a2 * a2)
* Self::grad_coord_2d(seed, i.wrapping_sub(Self::PRIME_X), j, x2, y2)
}
} else {
let x2 = x0 + (g2 - 1.);
let y2 = y0 + g2;
let a2 = (2. / 3.) - x2 * x2 - y2 * y2;
if a2 > 0. {
value += (a2 * a2)
* (a2 * a2)
* Self::grad_coord_2d(seed, i.wrapping_add(Self::PRIME_X), j, x2, y2)
}
}
if yi < xmyi {
let x2 = x0 - g2;
let y2 = y0 - (g2 - 1.);
let a2 = (2. / 3.) - x2 * x2 - y2 * y2;
if a2 > 0. {
value += (a2 * a2)
* (a2 * a2)
* Self::grad_coord_2d(seed, i, j.wrapping_sub(Self::PRIME_Y), x2, y2)
}
} else {
let x2 = x0 + g2;
let y2 = y0 + (g2 - 1.);
let a2 = (2. / 3.) - x2 * x2 - y2 * y2;
if a2 > 0. {
value += (a2 * a2)
* (a2 * a2)
* Self::grad_coord_2d(seed, i, j.wrapping_add(Self::PRIME_Y), x2, y2)
}
}
}
value * 18.24196194486065
}
fn single_open_simplex_2s_3d(&self, seed: i32, x: Float, y: Float, z: Float) -> f32 {
// 3D OpenSimplex2S case uses two offset rotated cube grids.
/*
* --- Rotation moved to TransformNoiseCoordinateXYZ method ---
* let R3 = 2. / 3.;
* let r = (x + y + z) * R3; // Rotation, not skew
* x = r - x; y = r - y; z = r - z;
*/
let i = Self::fast_floor(x);
let j = Self::fast_floor(y);
let k = Self::fast_floor(z);
#[allow(clippy::unnecessary_cast)]
let xi = (x - i as Float) as f32;
#[allow(clippy::unnecessary_cast)]
let yi = (y - j as Float) as f32;
#[allow(clippy::unnecessary_cast)]
let zi = (z - k as Float) as f32;
let i = i.wrapping_mul(Self::PRIME_X);
let j = j.wrapping_mul(Self::PRIME_Y);
let k = k.wrapping_mul(Self::PRIME_Z);
let seed2 = seed + 1293373;
let x_n_mask = (-0.5 - xi) as i32;
let y_n_mask = (-0.5 - yi) as i32;
let z_n_mask = (-0.5 - zi) as i32;
let x0 = xi + x_n_mask as f32;
let y0 = yi + y_n_mask as f32;
let z0 = zi + z_n_mask as f32;
let a0 = 0.75 - x0 * x0 - y0 * y0 - z0 * z0;
let mut value = (a0 * a0)
* (a0 * a0)
* Self::grad_coord_3d(
seed,
i.wrapping_add(x_n_mask & Self::PRIME_X),
j.wrapping_add(y_n_mask & Self::PRIME_Y),
k.wrapping_add(z_n_mask & Self::PRIME_Z),
x0,
y0,
z0,
);
let x1 = xi - 0.5;
let y1 = yi - 0.5;
let z1 = zi - 0.5;
let a1 = 0.75 - x1 * x1 - y1 * y1 - z1 * z1;
value += (a1 * a1)
* (a1 * a1)
* Self::grad_coord_3d(
seed2,
i.wrapping_add(Self::PRIME_X),
j.wrapping_add(Self::PRIME_Y),
k.wrapping_add(Self::PRIME_Z),
x1,
y1,
z1,
);
let x_a_flip_mask_0 = ((x_n_mask | 1) << 1) as f32 * x1;
let y_a_flip_mask_0 = ((y_n_mask | 1) << 1) as f32 * y1;
let z_a_flip_mask_0 = ((z_n_mask | 1) << 1) as f32 * z1;
let x_a_flip_mask_1 = (-2 - (x_n_mask << 2)) as f32 * x1 - 1.;
let y_a_flip_mask_1 = (-2 - (y_n_mask << 2)) as f32 * y1 - 1.;
let z_a_flip_mask_1 = (-2 - (z_n_mask << 2)) as f32 * z1 - 1.;
let mut skip_5 = false;
let a2 = x_a_flip_mask_0 + a0;
if a2 > 0. {
let x2 = x0 - (x_n_mask | 1) as f32;
let y2 = y0;
let z2 = z0;
value += (a2 * a2)
* (a2 * a2)
* Self::grad_coord_3d(
seed,
i.wrapping_add(!x_n_mask & Self::PRIME_X),
j.wrapping_add(y_n_mask & Self::PRIME_Y),
k.wrapping_add(z_n_mask & Self::PRIME_Z),
x2,
y2,
z2,
);
} else {
let a3 = y_a_flip_mask_0 + z_a_flip_mask_0 + a0;
if a3 > 0. {
let x3 = x0;
let y3 = y0 - (y_n_mask | 1) as f32;
let z3 = z0 - (z_n_mask | 1) as f32;
value += (a3 * a3)
* (a3 * a3)
* Self::grad_coord_3d(
seed,
i.wrapping_add(x_n_mask & Self::PRIME_X),
j.wrapping_add(!y_n_mask & Self::PRIME_Y),
k.wrapping_add(!z_n_mask & Self::PRIME_Z),
x3,
y3,
z3,
);
}
let a4 = x_a_flip_mask_1 + a1;
if a4 > 0. {
let x4 = (x_n_mask | 1) as f32 + x1;
let y4 = y1;
let z4 = z1;
value += (a4 * a4)
* (a4 * a4)
* Self::grad_coord_3d(
seed2,
i.wrapping_add(x_n_mask & Self::PRIME_X_2),
j.wrapping_add(Self::PRIME_Y),
k.wrapping_add(Self::PRIME_Z),
x4,
y4,
z4,
);
skip_5 = true;
}
}
let mut skip_9 = false;
let a6 = y_a_flip_mask_0 + a0;
if a6 > 0. {
let x6 = x0;
let y6 = y0 - (y_n_mask | 1) as f32;
let z6 = z0;
value += (a6 * a6)
* (a6 * a6)
* Self::grad_coord_3d(
seed,
i.wrapping_add(x_n_mask & Self::PRIME_X),
j.wrapping_add(!y_n_mask & Self::PRIME_Y),
k.wrapping_add(z_n_mask & Self::PRIME_Z),
x6,
y6,
z6,
);
} else {
let a7 = x_a_flip_mask_0 + z_a_flip_mask_0 + a0;
if a7 > 0. {
let x7 = x0 - (x_n_mask | 1) as f32;
let y7 = y0;
let z7 = z0 - (z_n_mask | 1) as f32;
value += (a7 * a7)
* (a7 * a7)
* Self::grad_coord_3d(
seed,
i.wrapping_add(!x_n_mask & Self::PRIME_X),
j.wrapping_add(y_n_mask & Self::PRIME_Y),
k.wrapping_add(!z_n_mask & Self::PRIME_Z),
x7,
y7,
z7,
);
}
let a8 = y_a_flip_mask_1 + a1;
if a8 > 0. {
let x8 = x1;
let y8 = (y_n_mask | 1) as f32 + y1;
let z8 = z1;
value += (a8 * a8)
* (a8 * a8)
* Self::grad_coord_3d(
seed2,
i.wrapping_add(Self::PRIME_X),
j.wrapping_add(y_n_mask & (Self::PRIME_Y << 1)),
k.wrapping_add(Self::PRIME_Z),
x8,
y8,
z8,
);
skip_9 = true;
}
}
let mut skip_d = false;
let a_a = z_a_flip_mask_0 + a0;
if a_a > 0. {
let x_a = x0;
let y_a = y0;
let z_a = z0 - (z_n_mask | 1) as f32;
value += (a_a * a_a)
* (a_a * a_a)
* Self::grad_coord_3d(
seed,
i.wrapping_add(x_n_mask & Self::PRIME_X),
j.wrapping_add(y_n_mask & Self::PRIME_Y),
k.wrapping_add(!z_n_mask & Self::PRIME_Z),
x_a,
y_a,
z_a,
);
} else {
let a_b = x_a_flip_mask_0 + y_a_flip_mask_0 + a0;
if a_b > 0. {
let x_b = x0 - (x_n_mask | 1) as f32;
let y_b = y0 - (y_n_mask | 1) as f32;
let z_b = z0;
value += (a_b * a_b)
* (a_b * a_b)
* Self::grad_coord_3d(
seed,
i.wrapping_add(!x_n_mask & Self::PRIME_X),
j.wrapping_add(!y_n_mask & Self::PRIME_Y),
k.wrapping_add(z_n_mask & Self::PRIME_Z),
x_b,
y_b,
z_b,
);
}
let a_c = z_a_flip_mask_1 + a1;
if a_c > 0. {
let x_c = x1;
let y_c = y1;
let z_c = (z_n_mask | 1) as f32 + z1;
value += (a_c * a_c)
* (a_c * a_c)
* Self::grad_coord_3d(
seed2,
i.wrapping_add(Self::PRIME_X),
j.wrapping_add(Self::PRIME_Y),
k.wrapping_add(z_n_mask & (Self::PRIME_Z << 1)),
x_c,
y_c,
z_c,
);
skip_d = true;
}
}
if !skip_5 {
let a5 = y_a_flip_mask_1 + z_a_flip_mask_1 + a1;
if a5 > 0. {
let x5 = x1;
let y5 = (y_n_mask | 1) as f32 + y1;
let z5 = (z_n_mask | 1) as f32 + z1;
value += (a5 * a5)
* (a5 * a5)
* Self::grad_coord_3d(
seed2,
i.wrapping_add(Self::PRIME_X),
j.wrapping_add(y_n_mask & (Self::PRIME_Y << 1)),
k.wrapping_add(z_n_mask & (Self::PRIME_Z << 1)),
x5,
y5,
z5,
);
}
}
if !skip_9 {
let a9 = x_a_flip_mask_1 + z_a_flip_mask_1 + a1;
if a9 > 0. {
let x9 = (x_n_mask | 1) as f32 + x1;
let y9 = y1;
let z9 = (z_n_mask | 1) as f32 + z1;
value += (a9 * a9)
* (a9 * a9)
* Self::grad_coord_3d(
seed2,
i.wrapping_add(x_n_mask & Self::PRIME_X_2),
j.wrapping_add(Self::PRIME_Y),
k.wrapping_add(z_n_mask & (Self::PRIME_Z << 1)),
x9,
y9,
z9,
);
}
}
if !skip_d {
let a_d = x_a_flip_mask_1 + y_a_flip_mask_1 + a1;
if a_d > 0. {
let x_d = (x_n_mask | 1) as f32 + x1;
let y_d = (y_n_mask | 1) as f32 + y1;
let z_d = z1;
value += (a_d * a_d)
* (a_d * a_d)
* Self::grad_coord_3d(
seed2,
i.wrapping_add(x_n_mask & (Self::PRIME_X << 1)),
j.wrapping_add(y_n_mask & (Self::PRIME_Y << 1)),
k.wrapping_add(Self::PRIME_Z),
x_d,
y_d,
z_d,
);
}
}
value * 9.046026385208288
}
// Cellular Noise
fn single_cellular_2d(&self, seed: i32, x: Float, y: Float) -> f32 {
let xr = Self::fast_round(x);
let yr = Self::fast_round(y);
let mut distance0 = f32::MAX;
let mut distance1 = f32::MAX;
let mut closest_hash = 0;
let cellular_jitter = 0.43701595 * self.cellular_jitter_modifier;
let mut x_primed = (xr - 1).wrapping_mul(Self::PRIME_X);
let y_primed_base = (yr - 1).wrapping_mul(Self::PRIME_Y);
match self.cellular_distance_function {
CellularDistanceFunction::Euclidean | CellularDistanceFunction::EuclideanSq => {
for xi in xr - 1..=xr + 1 {
let mut y_primed = y_primed_base;
for yi in yr - 1..=yr + 1 {
let hash = Self::hash_2d(seed, x_primed, y_primed);
let idx = hash & (255 << 1);
#[allow(clippy::unnecessary_cast)]
let vec_x = (xi as Float - x) as f32
+ Self::RAND_VECS_2D[idx as usize] * cellular_jitter;
#[allow(clippy::unnecessary_cast)]
let vec_y = (yi as Float - y) as f32
+ Self::RAND_VECS_2D[(idx | 1) as usize] * cellular_jitter;
let new_distance = vec_x * vec_x + vec_y * vec_y;
distance1 = distance1.min(new_distance).max(distance0);
if new_distance < distance0 {
distance0 = new_distance;
closest_hash = hash;
}
y_primed = y_primed.wrapping_add(Self::PRIME_Y);
}
x_primed = x_primed.wrapping_add(Self::PRIME_X);
}
}
CellularDistanceFunction::Manhattan => {
for xi in xr - 1..=xr + 1 {
let mut y_primed = y_primed_base;
for yi in yr - 1..=yr + 1 {
let hash = Self::hash_2d(seed, x_primed, y_primed);
let idx = hash & (255 << 1);
#[allow(clippy::unnecessary_cast)]
let vec_x = (xi as Float - x) as f32
+ Self::RAND_VECS_2D[idx as usize] * cellular_jitter;
#[allow(clippy::unnecessary_cast)]
let vec_y = (yi as Float - y) as f32
+ Self::RAND_VECS_2D[(idx | 1) as usize] * cellular_jitter;
let new_distance = FloatOps::abs(vec_x) + FloatOps::abs(vec_y);
distance1 = distance1.min(new_distance).max(distance0);
if new_distance < distance0 {
distance0 = new_distance;
closest_hash = hash;
}
y_primed = y_primed.wrapping_add(Self::PRIME_Y);
}
x_primed = x_primed.wrapping_add(Self::PRIME_X);
}
}
CellularDistanceFunction::Hybrid => {
for xi in xr - 1..=xr + 1 {
let mut y_primed = y_primed_base;
for yi in yr - 1..=yr + 1 {
let hash = Self::hash_2d(seed, x_primed, y_primed);
let idx = hash & (255 << 1);
#[allow(clippy::unnecessary_cast)]
let vec_x = (xi as Float - x) as f32
+ Self::RAND_VECS_2D[idx as usize] * cellular_jitter;
#[allow(clippy::unnecessary_cast)]
let vec_y = (yi as Float - y) as f32
+ Self::RAND_VECS_2D[(idx | 1) as usize] * cellular_jitter;
let new_distance = (FloatOps::abs(vec_x) + FloatOps::abs(vec_y))
+ (vec_x * vec_x + vec_y * vec_y);
distance1 = distance1.min(new_distance).max(distance0);
if new_distance < distance0 {
distance0 = new_distance;
closest_hash = hash;
}
y_primed = y_primed.wrapping_add(Self::PRIME_Y);
}
x_primed = x_primed.wrapping_add(Self::PRIME_X);
}
}
}
if self.cellular_distance_function == CellularDistanceFunction::Euclidean
&& self.cellular_return_type >= CellularReturnType::Distance
{
distance0 = FloatOps::sqrt(distance0);
if self.cellular_return_type >= CellularReturnType::Distance2 {
distance1 = FloatOps::sqrt(distance1);
}
}
match self.cellular_return_type {
CellularReturnType::CellValue => closest_hash as f32 * (1. / 2147483648.),
CellularReturnType::Distance => distance0 - 1.,
CellularReturnType::Distance2 => distance1 - 1.,
CellularReturnType::Distance2Add => (distance1 + distance0) * 0.5 - 1.,
CellularReturnType::Distance2Sub => distance1 - distance0 - 1.,
CellularReturnType::Distance2Mul => distance1 * distance0 * 0.5 - 1.,
CellularReturnType::Distance2Div => distance0 / distance1 - 1.,
}
}
fn single_cellular_3d(&self, seed: i32, x: Float, y: Float, z: Float) -> f32 {
let xr = Self::fast_round(x);
let yr = Self::fast_round(y);
let zr = Self::fast_round(z);
let mut distance0 = f32::MAX;
let mut distance1 = f32::MAX;
let mut closest_hash = 0;
let cellular_jitter = 0.39614353 * self.cellular_jitter_modifier;
let mut x_primed = (xr - 1).wrapping_mul(Self::PRIME_X);
let y_primed_base = (yr - 1).wrapping_mul(Self::PRIME_Y);
let z_primed_base = (zr - 1).wrapping_mul(Self::PRIME_Z);
match self.cellular_distance_function {
CellularDistanceFunction::Euclidean | CellularDistanceFunction::EuclideanSq => {
for xi in xr - 1..=xr + 1 {
let mut y_primed = y_primed_base;
for yi in yr - 1..=yr + 1 {
let mut z_primed = z_primed_base;
for zi in zr - 1..=zr + 1 {
let hash = Self::hash_3d(seed, x_primed, y_primed, z_primed);
let idx = hash & (255 << 2);
#[allow(clippy::unnecessary_cast)]
let vec_x = (xi as Float - x) as f32
+ Self::RAND_VECS_3D[idx as usize] * cellular_jitter;
#[allow(clippy::unnecessary_cast)]
let vec_y = (yi as Float - y) as f32
+ Self::RAND_VECS_3D[(idx | 1) as usize] * cellular_jitter;
#[allow(clippy::unnecessary_cast)]
let vec_z = (zi as Float - z) as f32
+ Self::RAND_VECS_3D[(idx | 2) as usize] * cellular_jitter;
let new_distance = vec_x * vec_x + vec_y * vec_y + vec_z * vec_z;
distance1 = distance1.min(new_distance).max(distance0);
if new_distance < distance0 {
distance0 = new_distance;
closest_hash = hash;
}
z_primed = z_primed.wrapping_add(Self::PRIME_Z);
}
y_primed = y_primed.wrapping_add(Self::PRIME_Y);
}
x_primed = x_primed.wrapping_add(Self::PRIME_X);
}
}
CellularDistanceFunction::Manhattan => {
for xi in xr - 1..=xr + 1 {
let mut y_primed = y_primed_base;
for yi in yr - 1..=yr + 1 {
let mut z_primed = z_primed_base;
for zi in zr - 1..=zr + 1 {
let hash = Self::hash_3d(seed, x_primed, y_primed, z_primed);
let idx = hash & (255 << 2);
#[allow(clippy::unnecessary_cast)]
let vec_x = (xi as Float - x) as f32
+ Self::RAND_VECS_3D[idx as usize] * cellular_jitter;
#[allow(clippy::unnecessary_cast)]
let vec_y = (yi as Float - y) as f32
+ Self::RAND_VECS_3D[(idx | 1) as usize] * cellular_jitter;
#[allow(clippy::unnecessary_cast)]
let vec_z = (zi as Float - z) as f32
+ Self::RAND_VECS_3D[(idx | 2) as usize] * cellular_jitter;
let new_distance =
FloatOps::abs(vec_x) + FloatOps::abs(vec_y) + FloatOps::abs(vec_z);
distance1 = distance1.min(new_distance).max(distance0);
if new_distance < distance0 {
distance0 = new_distance;
closest_hash = hash;
}
z_primed = z_primed.wrapping_add(Self::PRIME_Z);
}
y_primed = y_primed.wrapping_add(Self::PRIME_Y);
}
x_primed = x_primed.wrapping_add(Self::PRIME_X);
}
}
CellularDistanceFunction::Hybrid => {
for xi in xr - 1..=xr + 1 {
let mut y_primed = y_primed_base;
for yi in yr - 1..=yr + 1 {
let mut z_primed = z_primed_base;
for zi in zr - 1..=zr + 1 {
let hash = Self::hash_3d(seed, x_primed, y_primed, z_primed);
let idx = hash & (255 << 2);
#[allow(clippy::unnecessary_cast)]
let vec_x = (xi as Float - x) as f32
+ Self::RAND_VECS_3D[idx as usize] * cellular_jitter;
#[allow(clippy::unnecessary_cast)]
let vec_y = (yi as Float - y) as f32
+ Self::RAND_VECS_3D[(idx | 1) as usize] * cellular_jitter;
#[allow(clippy::unnecessary_cast)]
let vec_z = (zi as Float - z) as f32
+ Self::RAND_VECS_3D[(idx | 2) as usize] * cellular_jitter;
let new_distance = (FloatOps::abs(vec_x)
+ FloatOps::abs(vec_y)
+ FloatOps::abs(vec_z))
+ (vec_x * vec_x + vec_y * vec_y + vec_z * vec_z);
distance1 = distance1.min(new_distance).max(distance0);
if new_distance < distance0 {
distance0 = new_distance;
closest_hash = hash;
}
z_primed = z_primed.wrapping_add(Self::PRIME_Z);
}
y_primed = y_primed.wrapping_add(Self::PRIME_Y);
}
x_primed = x_primed.wrapping_add(Self::PRIME_X);
}
}
}
if self.cellular_distance_function == CellularDistanceFunction::Euclidean
&& self.cellular_return_type >= CellularReturnType::Distance
{
distance0 = FloatOps::sqrt(distance0);
if self.cellular_return_type >= CellularReturnType::Distance2 {
distance1 = FloatOps::sqrt(distance1);
}
}
match self.cellular_return_type {
CellularReturnType::CellValue => closest_hash as f32 * (1. / 2147483648.),
CellularReturnType::Distance => distance0 - 1.,
CellularReturnType::Distance2 => distance1 - 1.,
CellularReturnType::Distance2Add => (distance1 + distance0) * 0.5 - 1.,
CellularReturnType::Distance2Sub => distance1 - distance0 - 1.,
CellularReturnType::Distance2Mul => distance1 * distance0 * 0.5 - 1.,
CellularReturnType::Distance2Div => distance0 / distance1 - 1.,
}
}
// Perlin Noise
fn single_perlin_2d(&self, seed: i32, x: Float, y: Float) -> f32 {
let x0 = Self::fast_floor(x);
let y0 = Self::fast_floor(y);
#[allow(clippy::unnecessary_cast)]
let xd0 = (x - x0 as Float) as f32;
#[allow(clippy::unnecessary_cast)]
let yd0 = (y - y0 as Float) as f32;
let xd1 = xd0 - 1.;
let yd1 = yd0 - 1.;
let xs = Self::interp_quintic(xd0);
let ys = Self::interp_quintic(yd0);
let x0 = x0.wrapping_mul(Self::PRIME_X);
let y0 = y0.wrapping_mul(Self::PRIME_Y);
let x1 = x0.wrapping_add(Self::PRIME_X);
let y1 = y0.wrapping_add(Self::PRIME_Y);
let xf0 = Self::lerp(
Self::grad_coord_2d(seed, x0, y0, xd0, yd0),
Self::grad_coord_2d(seed, x1, y0, xd1, yd0),
xs,
);
let xf1 = Self::lerp(
Self::grad_coord_2d(seed, x0, y1, xd0, yd1),
Self::grad_coord_2d(seed, x1, y1, xd1, yd1),
xs,
);
Self::lerp(xf0, xf1, ys) * 1.4247691104677813
}
fn single_perlin_3d(&self, seed: i32, x: Float, y: Float, z: Float) -> f32 {
let x0 = Self::fast_floor(x);
let y0 = Self::fast_floor(y);
let z0 = Self::fast_floor(z);
#[allow(clippy::unnecessary_cast)]
let xd0 = (x - x0 as Float) as f32;
#[allow(clippy::unnecessary_cast)]
let yd0 = (y - y0 as Float) as f32;
#[allow(clippy::unnecessary_cast)]
let zd0 = (z - z0 as Float) as f32;
let xd1 = xd0 - 1.;
let yd1 = yd0 - 1.;
let zd1 = zd0 - 1.;
let xs = Self::interp_quintic(xd0);
let ys = Self::interp_quintic(yd0);
let zs = Self::interp_quintic(zd0);
let x0 = x0.wrapping_mul(Self::PRIME_X);
let y0 = y0.wrapping_mul(Self::PRIME_Y);
let z0 = z0.wrapping_mul(Self::PRIME_Z);
let x1 = x0.wrapping_add(Self::PRIME_X);
let y1 = y0.wrapping_add(Self::PRIME_Y);
let z1 = z0.wrapping_add(Self::PRIME_Z);
let xf00 = Self::lerp(
Self::grad_coord_3d(seed, x0, y0, z0, xd0, yd0, zd0),
Self::grad_coord_3d(seed, x1, y0, z0, xd1, yd0, zd0),
xs,
);
let xf10 = Self::lerp(
Self::grad_coord_3d(seed, x0, y1, z0, xd0, yd1, zd0),
Self::grad_coord_3d(seed, x1, y1, z0, xd1, yd1, zd0),
xs,
);
let xf01 = Self::lerp(
Self::grad_coord_3d(seed, x0, y0, z1, xd0, yd0, zd1),
Self::grad_coord_3d(seed, x1, y0, z1, xd1, yd0, zd1),
xs,
);
let xf11 = Self::lerp(
Self::grad_coord_3d(seed, x0, y1, z1, xd0, yd1, zd1),
Self::grad_coord_3d(seed, x1, y1, z1, xd1, yd1, zd1),
xs,
);
let yf0 = Self::lerp(xf00, xf10, ys);
let yf1 = Self::lerp(xf01, xf11, ys);
Self::lerp(yf0, yf1, zs) * 0.964921414852142333984375
}
// Value Cubic Noise
fn single_value_cubic_2d(&self, seed: i32, x: Float, y: Float) -> f32 {
let x1 = Self::fast_floor(x);
let y1 = Self::fast_floor(y);
#[allow(clippy::unnecessary_cast)]
let xs = (x - x1 as Float) as f32;
#[allow(clippy::unnecessary_cast)]
let ys = (y - y1 as Float) as f32;
let x1 = x1.wrapping_mul(Self::PRIME_X);
let y1 = y1.wrapping_mul(Self::PRIME_Y);
let x0 = x1.wrapping_sub(Self::PRIME_X);
let y0 = y1.wrapping_sub(Self::PRIME_Y);
let x2 = x1.wrapping_add(Self::PRIME_X);
let y2 = y1.wrapping_add(Self::PRIME_Y);
let x3 = x1.wrapping_add(Self::PRIME_X_2);
let y3 = y1.wrapping_add(Self::PRIME_Y_2);
Self::cubic_lerp(
Self::cubic_lerp(
Self::val_coord_2d(seed, x0, y0),
Self::val_coord_2d(seed, x1, y0),
Self::val_coord_2d(seed, x2, y0),
Self::val_coord_2d(seed, x3, y0),
xs,
),
Self::cubic_lerp(
Self::val_coord_2d(seed, x0, y1),
Self::val_coord_2d(seed, x1, y1),
Self::val_coord_2d(seed, x2, y1),
Self::val_coord_2d(seed, x3, y1),
xs,
),
Self::cubic_lerp(
Self::val_coord_2d(seed, x0, y2),
Self::val_coord_2d(seed, x1, y2),
Self::val_coord_2d(seed, x2, y2),
Self::val_coord_2d(seed, x3, y2),
xs,
),
Self::cubic_lerp(
Self::val_coord_2d(seed, x0, y3),
Self::val_coord_2d(seed, x1, y3),
Self::val_coord_2d(seed, x2, y3),
Self::val_coord_2d(seed, x3, y3),
xs,
),
ys,
) * (1. / (1.5 * 1.5))
}
fn single_value_cubic_3d(&self, seed: i32, x: Float, y: Float, z: Float) -> f32 {
let x1 = Self::fast_floor(x);
let y1 = Self::fast_floor(y);
let z1 = Self::fast_floor(z);
#[allow(clippy::unnecessary_cast)]
let xs = (x - x1 as Float) as f32;
#[allow(clippy::unnecessary_cast)]
let ys = (y - y1 as Float) as f32;
#[allow(clippy::unnecessary_cast)]
let zs = (z - z1 as Float) as f32;
let x1 = x1.wrapping_mul(Self::PRIME_X);
let y1 = y1.wrapping_mul(Self::PRIME_Y);
let z1 = z1.wrapping_mul(Self::PRIME_Z);
let x0 = x1.wrapping_sub(Self::PRIME_X);
let y0 = y1.wrapping_sub(Self::PRIME_Y);
let z0 = z1.wrapping_sub(Self::PRIME_Z);
let x2 = x1.wrapping_add(Self::PRIME_X);
let y2 = y1.wrapping_add(Self::PRIME_Y);
let z2 = z1.wrapping_add(Self::PRIME_Z);
let x3 = x1.wrapping_add(Self::PRIME_X_2);
let y3 = y1.wrapping_add(Self::PRIME_Y_2);
let z3 = z1.wrapping_add(Self::PRIME_Z_2);
Self::cubic_lerp(
Self::cubic_lerp(
Self::cubic_lerp(
Self::val_coord_3d(seed, x0, y0, z0),
Self::val_coord_3d(seed, x1, y0, z0),
Self::val_coord_3d(seed, x2, y0, z0),
Self::val_coord_3d(seed, x3, y0, z0),
xs,
),
Self::cubic_lerp(
Self::val_coord_3d(seed, x0, y1, z0),
Self::val_coord_3d(seed, x1, y1, z0),
Self::val_coord_3d(seed, x2, y1, z0),
Self::val_coord_3d(seed, x3, y1, z0),
xs,
),
Self::cubic_lerp(
Self::val_coord_3d(seed, x0, y2, z0),
Self::val_coord_3d(seed, x1, y2, z0),
Self::val_coord_3d(seed, x2, y2, z0),
Self::val_coord_3d(seed, x3, y2, z0),
xs,
),
Self::cubic_lerp(
Self::val_coord_3d(seed, x0, y3, z0),
Self::val_coord_3d(seed, x1, y3, z0),
Self::val_coord_3d(seed, x2, y3, z0),
Self::val_coord_3d(seed, x3, y3, z0),
xs,
),
ys,
),
Self::cubic_lerp(
Self::cubic_lerp(
Self::val_coord_3d(seed, x0, y0, z1),
Self::val_coord_3d(seed, x1, y0, z1),
Self::val_coord_3d(seed, x2, y0, z1),
Self::val_coord_3d(seed, x3, y0, z1),
xs,
),
Self::cubic_lerp(
Self::val_coord_3d(seed, x0, y1, z1),
Self::val_coord_3d(seed, x1, y1, z1),
Self::val_coord_3d(seed, x2, y1, z1),
Self::val_coord_3d(seed, x3, y1, z1),
xs,
),
Self::cubic_lerp(
Self::val_coord_3d(seed, x0, y2, z1),
Self::val_coord_3d(seed, x1, y2, z1),
Self::val_coord_3d(seed, x2, y2, z1),
Self::val_coord_3d(seed, x3, y2, z1),
xs,
),
Self::cubic_lerp(
Self::val_coord_3d(seed, x0, y3, z1),
Self::val_coord_3d(seed, x1, y3, z1),
Self::val_coord_3d(seed, x2, y3, z1),
Self::val_coord_3d(seed, x3, y3, z1),
xs,
),
ys,
),
Self::cubic_lerp(
Self::cubic_lerp(
Self::val_coord_3d(seed, x0, y0, z2),
Self::val_coord_3d(seed, x1, y0, z2),
Self::val_coord_3d(seed, x2, y0, z2),
Self::val_coord_3d(seed, x3, y0, z2),
xs,
),
Self::cubic_lerp(
Self::val_coord_3d(seed, x0, y1, z2),
Self::val_coord_3d(seed, x1, y1, z2),
Self::val_coord_3d(seed, x2, y1, z2),
Self::val_coord_3d(seed, x3, y1, z2),
xs,
),
Self::cubic_lerp(
Self::val_coord_3d(seed, x0, y2, z2),
Self::val_coord_3d(seed, x1, y2, z2),
Self::val_coord_3d(seed, x2, y2, z2),
Self::val_coord_3d(seed, x3, y2, z2),
xs,
),
Self::cubic_lerp(
Self::val_coord_3d(seed, x0, y3, z2),
Self::val_coord_3d(seed, x1, y3, z2),
Self::val_coord_3d(seed, x2, y3, z2),
Self::val_coord_3d(seed, x3, y3, z2),
xs,
),
ys,
),
Self::cubic_lerp(
Self::cubic_lerp(
Self::val_coord_3d(seed, x0, y0, z3),
Self::val_coord_3d(seed, x1, y0, z3),
Self::val_coord_3d(seed, x2, y0, z3),
Self::val_coord_3d(seed, x3, y0, z3),
xs,
),
Self::cubic_lerp(
Self::val_coord_3d(seed, x0, y1, z3),
Self::val_coord_3d(seed, x1, y1, z3),
Self::val_coord_3d(seed, x2, y1, z3),
Self::val_coord_3d(seed, x3, y1, z3),
xs,
),
Self::cubic_lerp(
Self::val_coord_3d(seed, x0, y2, z3),
Self::val_coord_3d(seed, x1, y2, z3),
Self::val_coord_3d(seed, x2, y2, z3),
Self::val_coord_3d(seed, x3, y2, z3),
xs,
),
Self::cubic_lerp(
Self::val_coord_3d(seed, x0, y3, z3),
Self::val_coord_3d(seed, x1, y3, z3),
Self::val_coord_3d(seed, x2, y3, z3),
Self::val_coord_3d(seed, x3, y3, z3),
xs,
),
ys,
),
zs,
) * (1. / (1.5 * 1.5 * 1.5))
}
// Value Noise
fn single_value_2d(&self, seed: i32, x: Float, y: Float) -> f32 {
let x0 = Self::fast_floor(x);
let y0 = Self::fast_floor(y);
#[allow(clippy::unnecessary_cast)]
let xs = Self::interp_hermite((x - x0 as Float) as f32);
#[allow(clippy::unnecessary_cast)]
let ys = Self::interp_hermite((y - y0 as Float) as f32);
let x0 = x0.wrapping_mul(Self::PRIME_X);
let y0 = y0.wrapping_mul(Self::PRIME_Y);
let x1 = x0.wrapping_add(Self::PRIME_X);
let y1 = y0.wrapping_add(Self::PRIME_Y);
let xf0 = Self::lerp(
Self::val_coord_2d(seed, x0, y0),
Self::val_coord_2d(seed, x1, y0),
xs,
);
let xf1 = Self::lerp(
Self::val_coord_2d(seed, x0, y1),
Self::val_coord_2d(seed, x1, y1),
xs,
);
Self::lerp(xf0, xf1, ys)
}
fn single_value_3d(&self, seed: i32, x: Float, y: Float, z: Float) -> f32 {
let x0 = Self::fast_floor(x);
let y0 = Self::fast_floor(y);
let z0 = Self::fast_floor(z);
#[allow(clippy::unnecessary_cast)]
let xs = Self::interp_hermite((x - x0 as Float) as f32);
#[allow(clippy::unnecessary_cast)]
let ys = Self::interp_hermite((y - y0 as Float) as f32);
#[allow(clippy::unnecessary_cast)]
let zs = Self::interp_hermite((z - z0 as Float) as f32);
let x0 = x0.wrapping_mul(Self::PRIME_X);
let y0 = y0.wrapping_mul(Self::PRIME_Y);
let z0 = z0.wrapping_mul(Self::PRIME_Z);
let x1 = x0.wrapping_add(Self::PRIME_X);
let y1 = y0.wrapping_add(Self::PRIME_Y);
let z1 = z0.wrapping_add(Self::PRIME_Z);
let xf00 = Self::lerp(
Self::val_coord_3d(seed, x0, y0, z0),
Self::val_coord_3d(seed, x1, y0, z0),
xs,
);
let xf10 = Self::lerp(
Self::val_coord_3d(seed, x0, y1, z0),
Self::val_coord_3d(seed, x1, y1, z0),
xs,
);
let xf01 = Self::lerp(
Self::val_coord_3d(seed, x0, y0, z1),
Self::val_coord_3d(seed, x1, y0, z1),
xs,
);
let xf11 = Self::lerp(
Self::val_coord_3d(seed, x0, y1, z1),
Self::val_coord_3d(seed, x1, y1, z1),
xs,
);
let yf0 = Self::lerp(xf00, xf10, ys);
let yf1 = Self::lerp(xf01, xf11, ys);
Self::lerp(yf0, yf1, zs)
}
// Domain Warp
#[allow(clippy::too_many_arguments)]
fn do_single_domain_warp_2d(
&self,
seed: i32,
amp: f32,
freq: f32,
x: Float,
y: Float,
xr: Float,
yr: Float,
) -> (Float, Float) {
match self.domain_warp_type {
DomainWarpType::OpenSimplex2 => self.single_domain_warp_simplex_gradient_2d(
seed,
amp * 38.283687591552734375,
freq,
x,
y,
xr,
yr,
false,
),
DomainWarpType::OpenSimplex2Reduced => self.single_domain_warp_simplex_gradient_2d(
seed,
amp * 16.,
freq,
x,
y,
xr,
yr,
true,
),
DomainWarpType::BasicGrid => {
self.single_domain_warp_basic_grid_2d(seed, amp, freq, x, y, xr, yr)
}
}
}
#[allow(clippy::too_many_arguments)]
fn do_single_domain_warp_3d(
&self,
seed: i32,
amp: f32,
freq: f32,
x: Float,
y: Float,
z: Float,
xr: Float,
yr: Float,
zr: Float,
) -> (Float, Float, Float) {
match self.domain_warp_type {
DomainWarpType::OpenSimplex2 => self.single_domain_warp_open_simplex_2_gradient(
seed,
amp * 32.69428253173828125,
freq,
x,
y,
z,
xr,
yr,
zr,
false,
),
DomainWarpType::OpenSimplex2Reduced => self.single_domain_warp_open_simplex_2_gradient(
seed,
amp * 7.71604938271605,
freq,
x,
y,
z,
xr,
yr,
zr,
true,
),
DomainWarpType::BasicGrid => {
self.single_domain_warp_basic_grid_3d(seed, amp, freq, x, y, z, xr, yr, zr)
}
}
}
// Domain Warp Single Wrapper
fn domain_warp_single_2d(&self, x: Float, y: Float) -> (Float, Float) {
let seed = self.seed;
let amp = self.domain_warp_amp * self.fractal_bounding;
let freq = self.frequency;
let (xs, ys) = self.transform_domain_warp_coordinate_2d(x, y);
self.do_single_domain_warp_2d(seed, amp, freq, xs, ys, x, y)
}
fn domain_warp_single_3d(&self, x: Float, y: Float, z: Float) -> (Float, Float, Float) {
let seed = self.seed;
let amp = self.domain_warp_amp * self.fractal_bounding;
let freq = self.frequency;
let (xs, ys, zs) = self.transform_domain_warp_coordinate_3d(x, y, z);
self.do_single_domain_warp_3d(seed, amp, freq, xs, ys, zs, x, y, z)
}
// Domain Warp Fractal Progressive
fn domain_warp_fractal_progressive_2d(&self, x: Float, y: Float) -> (Float, Float) {
let mut x = x;
let mut y = y;
let mut seed = self.seed;
let mut amp = self.domain_warp_amp * self.fractal_bounding;
let mut freq = self.frequency;
for _ in 0..self.octaves {
let (xs, ys) = self.transform_domain_warp_coordinate_2d(x, y);
(x, y) = self.do_single_domain_warp_2d(seed, amp, freq, xs, ys, x, y);
seed += 1;
amp *= self.gain;
freq *= self.lacunarity;
}
(x, y)
}
fn domain_warp_fractal_progressive_3d(
&self,
x: Float,
y: Float,
z: Float,
) -> (Float, Float, Float) {
let mut x = x;
let mut y = y;
let mut z = z;
let mut seed = self.seed;
let mut amp = self.domain_warp_amp * self.fractal_bounding;
let mut freq = self.frequency;
for _ in 0..self.octaves {
let (xs, ys, zs) = self.transform_domain_warp_coordinate_3d(x, y, z);
(x, y, z) = self.do_single_domain_warp_3d(seed, amp, freq, xs, ys, zs, x, y, z);
seed += 1;
amp *= self.gain;
freq *= self.lacunarity;
}
(x, y, z)
}
// Domain Warp Fractal Independant
fn domain_warp_fractal_independent_2d(&self, x: Float, y: Float) -> (Float, Float) {
let mut x = x;
let mut y = y;
let (xs, ys) = self.transform_domain_warp_coordinate_2d(x, y);
let mut seed = self.seed;
let mut amp = self.domain_warp_amp * self.fractal_bounding;
let mut freq = self.frequency;
for _ in 0..self.octaves {
(x, y) = self.do_single_domain_warp_2d(seed, amp, freq, xs, ys, x, y);
seed += 1;
amp *= self.gain;
freq *= self.lacunarity;
}
(x, y)
}
fn domain_warp_fractal_independent_3d(
&self,
x: Float,
y: Float,
z: Float,
) -> (Float, Float, Float) {
let mut x = x;
let mut y = y;
let mut z = z;
let (xs, ys, zs) = self.transform_domain_warp_coordinate_3d(x, y, z);
let mut seed = self.seed;
let mut amp = self.domain_warp_amp * self.fractal_bounding;
let mut freq = self.frequency;
for _ in 0..self.octaves {
(x, y, z) = self.do_single_domain_warp_3d(seed, amp, freq, xs, ys, zs, x, y, z);
seed += 1;
amp *= self.gain;
freq *= self.lacunarity;
}
(x, y, z)
}
// Domain Warp Basic Grid
#[allow(clippy::too_many_arguments)]
fn single_domain_warp_basic_grid_2d(
&self,
seed: i32,
warp_amp: f32,
frequency: f32,
x: Float,
y: Float,
xr: Float,
yr: Float,
) -> (Float, Float) {
let xf = x * frequency as Float;
let yf = y * frequency as Float;
let x0 = Self::fast_floor(xf);
let y0 = Self::fast_floor(yf);
#[allow(clippy::unnecessary_cast)]
let xs = Self::interp_hermite((xf - x0 as Float) as f32);
#[allow(clippy::unnecessary_cast)]
let ys = Self::interp_hermite((yf - y0 as Float) as f32);
let x0 = x0.wrapping_mul(Self::PRIME_X);
let y0 = y0.wrapping_mul(Self::PRIME_Y);
let x1 = x0.wrapping_add(Self::PRIME_X);
let y1 = y0.wrapping_add(Self::PRIME_Y);
let hash0 = Self::hash_2d(seed, x0, y0) & (255 << 1);
let hash1 = Self::hash_2d(seed, x1, y0) & (255 << 1);
let lx0x = Self::lerp(
Self::RAND_VECS_2D[hash0 as usize],
Self::RAND_VECS_2D[hash1 as usize],
xs,
);
let ly0x = Self::lerp(
Self::RAND_VECS_2D[(hash0 | 1) as usize],
Self::RAND_VECS_2D[(hash1 | 1) as usize],
xs,
);
let hash0 = Self::hash_2d(seed, x0, y1) & (255 << 1);
let hash1 = Self::hash_2d(seed, x1, y1) & (255 << 1);
let lx1x = Self::lerp(
Self::RAND_VECS_2D[hash0 as usize],
Self::RAND_VECS_2D[hash1 as usize],
xs,
);
let ly1x = Self::lerp(
Self::RAND_VECS_2D[(hash0 | 1) as usize],
Self::RAND_VECS_2D[(hash1 | 1) as usize],
xs,
);
let xr = xr + (Self::lerp(lx0x, lx1x, ys) * warp_amp) as Float;
let yr = yr + (Self::lerp(ly0x, ly1x, ys) * warp_amp) as Float;
(xr, yr)
}
#[allow(clippy::too_many_arguments)]
fn single_domain_warp_basic_grid_3d(
&self,
seed: i32,
warp_amp: f32,
frequency: f32,
x: Float,
y: Float,
z: Float,
xr: Float,
yr: Float,
zr: Float,
) -> (Float, Float, Float) {
let xf = x * frequency as Float;
let yf = y * frequency as Float;
let zf = z * frequency as Float;
let x0 = Self::fast_floor(xf);
let y0 = Self::fast_floor(yf);
let z0 = Self::fast_floor(zf);
#[allow(clippy::unnecessary_cast)]
let xs = Self::interp_hermite((xf - x0 as Float) as f32);
#[allow(clippy::unnecessary_cast)]
let ys = Self::interp_hermite((yf - y0 as Float) as f32);
#[allow(clippy::unnecessary_cast)]
let zs = Self::interp_hermite((zf - z0 as Float) as f32);
let x0 = x0.wrapping_mul(Self::PRIME_X);
let y0 = y0.wrapping_mul(Self::PRIME_Y);
let z0 = z0.wrapping_mul(Self::PRIME_Z);
let x1 = x0.wrapping_add(Self::PRIME_X);
let y1 = y0.wrapping_add(Self::PRIME_Y);
let z1 = z0.wrapping_add(Self::PRIME_Z);
let hash0 = Self::hash_3d(seed, x0, y0, z0) & (255 << 2);
let hash1 = Self::hash_3d(seed, x1, y0, z0) & (255 << 2);
let lx0x = Self::lerp(
Self::RAND_VECS_3D[hash0 as usize],
Self::RAND_VECS_3D[hash1 as usize],
xs,
);
let ly0x = Self::lerp(
Self::RAND_VECS_3D[(hash0 | 1) as usize],
Self::RAND_VECS_3D[(hash1 | 1) as usize],
xs,
);
let lz0x = Self::lerp(
Self::RAND_VECS_3D[(hash0 | 2) as usize],
Self::RAND_VECS_3D[(hash1 | 2) as usize],
xs,
);
let hash0 = Self::hash_3d(seed, x0, y1, z0) & (255 << 2);
let hash1 = Self::hash_3d(seed, x1, y1, z0) & (255 << 2);
let lx1x = Self::lerp(
Self::RAND_VECS_3D[hash0 as usize],
Self::RAND_VECS_3D[hash1 as usize],
xs,
);
let ly1x = Self::lerp(
Self::RAND_VECS_3D[(hash0 | 1) as usize],
Self::RAND_VECS_3D[(hash1 | 1) as usize],
xs,
);
let lz1x = Self::lerp(
Self::RAND_VECS_3D[(hash0 | 2) as usize],
Self::RAND_VECS_3D[(hash1 | 2) as usize],
xs,
);
let lx0y = Self::lerp(lx0x, lx1x, ys);
let ly0y = Self::lerp(ly0x, ly1x, ys);
let lz0y = Self::lerp(lz0x, lz1x, ys);
let hash0 = Self::hash_3d(seed, x0, y0, z1) & (255 << 2);
let hash1 = Self::hash_3d(seed, x1, y0, z1) & (255 << 2);
let lx0x = Self::lerp(
Self::RAND_VECS_3D[hash0 as usize],
Self::RAND_VECS_3D[hash1 as usize],
xs,
);
let ly0x = Self::lerp(
Self::RAND_VECS_3D[(hash0 | 1) as usize],
Self::RAND_VECS_3D[(hash1 | 1) as usize],
xs,
);
let lz0x = Self::lerp(
Self::RAND_VECS_3D[(hash0 | 2) as usize],
Self::RAND_VECS_3D[(hash1 | 2) as usize],
xs,
);
let hash0 = Self::hash_3d(seed, x0, y1, z1) & (255 << 2);
let hash1 = Self::hash_3d(seed, x1, y1, z1) & (255 << 2);
let lx1x = Self::lerp(
Self::RAND_VECS_3D[hash0 as usize],
Self::RAND_VECS_3D[hash1 as usize],
xs,
);
let ly1x = Self::lerp(
Self::RAND_VECS_3D[(hash0 | 1) as usize],
Self::RAND_VECS_3D[(hash1 | 1) as usize],
xs,
);
let lz1x = Self::lerp(
Self::RAND_VECS_3D[(hash0 | 2) as usize],
Self::RAND_VECS_3D[(hash1 | 2) as usize],
xs,
);
let xr = xr + (Self::lerp(lx0y, Self::lerp(lx0x, lx1x, ys), zs) * warp_amp) as Float;
let yr = yr + (Self::lerp(ly0y, Self::lerp(ly0x, ly1x, ys), zs) * warp_amp) as Float;
let zr = zr + (Self::lerp(lz0y, Self::lerp(lz0x, lz1x, ys), zs) * warp_amp) as Float;
(xr, yr, zr)
}
// Domain Warp Simplex/OpenSimplex2
#[allow(clippy::too_many_arguments)]
fn single_domain_warp_simplex_gradient_2d(
&self,
seed: i32,
warp_amp: f32,
frequency: f32,
x: Float,
y: Float,
xr: Float,
yr: Float,
out_frad_only: bool,
) -> (Float, Float) {
const SQRT3: f32 = 1.7320508075688772935274463415059;
const G2: f32 = (3. - SQRT3) / 6.;
let x = x * frequency as Float;
let y = y * frequency as Float;
/*
* --- Skew moved to TransformNoiseCoordinateXY method ---
* let f2 = 0.5 * (sqrt3 - 1);
* let s = (x + y) * f2;
* x += s; y += s;
*/
let i = Self::fast_floor(x);
let j = Self::fast_floor(y);
#[allow(clippy::unnecessary_cast)]
let xi = (x - i as Float) as f32;
#[allow(clippy::unnecessary_cast)]
let yi = (y - j as Float) as f32;
let t = (xi + yi) * G2;
let x0 = xi - t;
let y0 = yi - t;
let i = i.wrapping_mul(Self::PRIME_X);
let j = j.wrapping_mul(Self::PRIME_Y);
let mut vx = 0.;
let mut vy = 0.;
let a = 0.5 - x0 * x0 - y0 * y0;
if a > 0. {
let aaaa = (a * a) * (a * a);
let (xo, yo) = if out_frad_only {
Self::grad_coord_out_2d(seed, i, j)
} else {
Self::grad_coord_dual_2d(seed, i, j, x0, y0)
};
vx += aaaa * xo;
vy += aaaa * yo;
}
let c = (2. * (1. - 2. * G2) * (1. / G2 - 2.)) * t
+ ((-2. * (1. - 2. * G2) * (1. - 2. * G2)) + a);
if c > 0. {
let x2 = x0 + (2. * G2 - 1.);
let y2 = y0 + (2. * G2 - 1.);
let cccc = (c * c) * (c * c);
let (xo, yo) = if out_frad_only {
Self::grad_coord_out_2d(
seed,
i.wrapping_add(Self::PRIME_X),
j.wrapping_add(Self::PRIME_Y),
)
} else {
Self::grad_coord_dual_2d(
seed,
i.wrapping_add(Self::PRIME_X),
j.wrapping_add(Self::PRIME_Y),
x2,
y2,
)
};
vx += cccc * xo;
vy += cccc * yo;
}
if y0 > x0 {
let x1 = x0 + G2;
let y1 = y0 + (G2 - 1.);
let b = 0.5 - x1 * x1 - y1 * y1;
if b > 0. {
let bbbb = (b * b) * (b * b);
let (xo, yo) = if out_frad_only {
Self::grad_coord_out_2d(seed, i, j.wrapping_add(Self::PRIME_Y))
} else {
Self::grad_coord_dual_2d(seed, i, j.wrapping_add(Self::PRIME_Y), x1, y1)
};
vx += bbbb * xo;
vy += bbbb * yo;
}
} else {
let x1 = x0 + (G2 - 1.);
let y1 = y0 + G2;
let b = 0.5 - x1 * x1 - y1 * y1;
if b > 0. {
let bbbb = (b * b) * (b * b);
let (xo, yo) = if out_frad_only {
Self::grad_coord_out_2d(seed, i.wrapping_add(Self::PRIME_X), j)
} else {
Self::grad_coord_dual_2d(seed, i.wrapping_add(Self::PRIME_X), j, x1, y1)
};
vx += bbbb * xo;
vy += bbbb * yo;
}
}
let xr = xr + (vx * warp_amp) as Float;
let yr = yr + (vy * warp_amp) as Float;
(xr, yr)
}
#[allow(clippy::too_many_arguments)]
fn single_domain_warp_open_simplex_2_gradient(
&self,
seed: i32,
warp_amp: f32,
frequency: f32,
x: Float,
y: Float,
z: Float,
xr: Float,
yr: Float,
zr: Float,
out_grad_only: bool,
) -> (Float, Float, Float) {
let mut seed = seed;
let x = x * frequency as Float;
let y = y * frequency as Float;
let z = z * frequency as Float;
/*
* --- Rotation moved to TransformDomainWarpCoordinate method ---
* let r3 = 2. / 3.;
* let r = (x + y + z) * r3; // Rotation, not skew
* x = r - x; y = r - y; z = r - z;
*/
let i = Self::fast_round(x);
let j = Self::fast_round(y);
let k = Self::fast_round(z);
#[allow(clippy::unnecessary_cast)]
let mut x0 = (x - i as Float) as f32;
#[allow(clippy::unnecessary_cast)]
let mut y0 = (y - j as Float) as f32;
#[allow(clippy::unnecessary_cast)]
let mut z0 = (z - k as Float) as f32;
let mut x_n_sign = (-x0 - 1.) as i32 | 1;
let mut y_n_sign = (-y0 - 1.) as i32 | 1;
let mut z_n_sign = (-z0 - 1.) as i32 | 1;
let mut ax0 = x_n_sign as f32 * -x0;
let mut ay0 = y_n_sign as f32 * -y0;
let mut az0 = z_n_sign as f32 * -z0;
let mut i = i.wrapping_mul(Self::PRIME_X);
let mut j = j.wrapping_mul(Self::PRIME_Y);
let mut k = k.wrapping_mul(Self::PRIME_Z);
let mut vx = 0.;
let mut vy = 0.;
let mut vz = 0.;
let mut a = (0.6 - x0 * x0) - (y0 * y0 + z0 * z0);
let mut l = 0;
loop {
if a > 0. {
let aaaa = (a * a) * (a * a);
let (xo, yo, zo) = if out_grad_only {
Self::grad_coord_out_3d(seed, i, j, k)
} else {
Self::grad_coord_dual_3d(seed, i, j, k, x0, y0, z0)
};
vx += aaaa * xo;
vy += aaaa * yo;
vz += aaaa * zo;
}
let mut b = a;
let mut i1 = i;
let mut j1 = j;
let mut k1 = k;
let mut x1 = x0;
let mut y1 = y0;
let mut z1 = z0;
if ax0 >= ay0 && ax0 >= az0 {
x1 += x_n_sign as f32;
b = b + ax0 + ax0;
i1 = i1.wrapping_sub(x_n_sign.wrapping_mul(Self::PRIME_X));
} else if ay0 > ax0 && ay0 >= az0 {
y1 += y_n_sign as f32;
b = b + ay0 + ay0;
j1 = j1.wrapping_sub(y_n_sign.wrapping_mul(Self::PRIME_Y));
} else {
z1 += z_n_sign as f32;
b = b + az0 + az0;
k1 = k1.wrapping_sub(z_n_sign.wrapping_mul(Self::PRIME_Z));
}
if b > 1. {
b -= 1.;
let bbbb = (b * b) * (b * b);
let (xo, yo, zo) = if out_grad_only {
Self::grad_coord_out_3d(seed, i1, j1, k1)
} else {
Self::grad_coord_dual_3d(seed, i1, j1, k1, x1, y1, z1)
};
vx += bbbb * xo;
vy += bbbb * yo;
vz += bbbb * zo;
}
if l == 1 {
break;
}
ax0 = 0.5 - ax0;
ay0 = 0.5 - ay0;
az0 = 0.5 - az0;
x0 = x_n_sign as f32 * ax0;
y0 = y_n_sign as f32 * ay0;
z0 = z_n_sign as f32 * az0;
a += (0.75 - ax0) - (ay0 + az0);
i = i.wrapping_add((x_n_sign >> 1) & Self::PRIME_X);
j = j.wrapping_add((y_n_sign >> 1) & Self::PRIME_Y);
k = k.wrapping_add((z_n_sign >> 1) & Self::PRIME_Z);
x_n_sign = -x_n_sign;
y_n_sign = -y_n_sign;
z_n_sign = -z_n_sign;
seed += 1293373;
l += 1;
}
let xr = xr + (vx * warp_amp) as Float;
let yr = yr + (vy * warp_amp) as Float;
let zr = zr + (vz * warp_amp) as Float;
(xr, yr, zr)
}
}
``` | /content/code_sandbox/Rust/src/lib.rs | rust | 2016-03-28T02:35:12 | 2024-08-16T07:09:20 | FastNoiseLite | Auburn/FastNoiseLite | 2,688 | 44,535 |
```glsl
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// .'',;:cldxkO00KKXXNNWWWNNXKOkxdollcc::::::;:::ccllloooolllllllllooollc:,'... ...........',;cldxkO000Okxdlc::;;;,,;;;::cclllllll
// ..',;:ldxO0KXXNNNNNNNNXXK0kxdolcc::::::;;;,,,,,,;;;;;;;;;;:::cclllllc:;'.... ...........',;:ldxO0KXXXK0Okxdolc::;;;;::cllodddddo
// ...',:loxO0KXNNNNNXXKK0Okxdolc::;::::::::;;;,,'''''.....''',;:clllllc:;,'............''''''''',;:loxO0KXNNNNNXK0Okxdollccccllodxxxxxxd
// ....';:ldkO0KXXXKK00Okxdolcc:;;;;;::cclllcc:;;,''..... ....',;clooddolcc:;;;;,,;;;;;::::;;;;;;:cloxk0KXNWWWWWWNXKK0Okxddoooddxxkkkkkxx
// .....';:ldxkOOOOOkxxdolcc:;;;,,,;;:cllooooolcc:;'... ..,:codxkkkxddooollloooooooollcc:::::clodkO0KXNWWWWWWNNXK00Okxxxxxxxxkkkkxxx
// . ....';:cloddddo___________,,,,;;:clooddddoolc:,... ..,:ldx__00OOOkkk___kkkkkkxxdollc::::cclodkO0KXXNNNNNNXXK0OOkxxxxxxxxxxxxddd
// .......',;:cccc:| |,,,;;:cclooddddoll:;'.. ..';cox| \KKK000| |KK00OOkxdocc___;::clldxxkO0KKKKK00Okkxdddddddddddddddoo
// .......'',,,,,''| ________|',,;;::cclloooooolc:;'......___:ldk| \KK000| |XKKK0Okxolc| |;;::cclodxxkkkkxxdoolllcclllooodddooooo
// ''......''''....| | ....'',,,,;;;::cclloooollc:;,''.'| |oxk| \OOO0| |KKK00Oxdoll|___|;;;;;::ccllllllcc::;;,,;;;:cclloooooooo
// ;;,''.......... | |_____',,;;;____:___cllo________.___| |___| \xkk| |KK_______ool___:::;________;;;_______...'',;;:ccclllloo
// c:;,''......... | |:::/ ' |lo/ | | \dx| |0/ \d| |cc/ |'/ \......',,;;:ccllo
// ol:;,'..........| _____|ll/ __ |o/ ______|____ ___| | \o| |/ ___ \| |o/ ______|/ ___ \ .......'',;:clo
// dlc;,...........| |::clooo| / | |x\___ \KXKKK0| |dol| |\ \| | | | | |d\___ \..| | / / ....',:cl
// xoc;'... .....'| |llodddd| \__| |_____\ \KKK0O| |lc:| |'\ | |___| | |_____\ \.| |_/___/... ...',;:c
// dlc;'... ....',;| |oddddddo\ | |Okkx| |::;| |..\ |\ /| | | \ |... ....',;:c
// ol:,'.......',:c|___|xxxddollc\_____,___|_________/ddoll|___|,,,|___|...\_____|:\ ______/l|___|_________/...\________|'........',;::cc
// c:;'.......';:codxxkkkkxxolc::;::clodxkOO0OOkkxdollc::;;,,''''',,,,''''''''''',,'''''',;:loxkkOOkxol:;,'''',,;:ccllcc:;,'''''',;::ccll
// ;,'.......',:codxkOO0OOkxdlc:;,,;;:cldxxkkxxdolc:;;,,''.....'',;;:::;;,,,'''''........,;cldkO0KK0Okdoc::;;::cloodddoolc:;;;;;::ccllooo
// .........',;:lodxOO0000Okdoc:,,',,;:clloddoolc:;,''.......'',;:clooollc:;;,,''.......',:ldkOKXNNXX0Oxdolllloddxxxxxxdolccccccllooodddd
// . .....';:cldxkO0000Okxol:;,''',,;::cccc:;,,'.......'',;:cldxxkkxxdolc:;;,'.......';coxOKXNWWWNXKOkxddddxxkkkkkkxdoollllooddxxxxkkk
// ....',;:codxkO000OOxdoc:;,''',,,;;;;,''.......',,;:clodkO00000Okxolc::;,,''..',;:ldxOKXNWWWNNK0OkkkkkkkkkkkxxddooooodxxkOOOOO000
// ....',;;clodxkkOOOkkdolc:;,,,,,,,,'..........,;:clodxkO0KKXKK0Okxdolcc::;;,,,;;:codkO0XXNNNNXKK0OOOOOkkkkxxdoollloodxkO0KKKXXXXX
//
// VERSION: 1.1.1
// path_to_url
// Switch between using floats or doubles for input position
#define FNLfloat float
//#define FNLfloat double
// Noise Type
#define FNL_NOISE_OPENSIMPLEX2 0
#define FNL_NOISE_OPENSIMPLEX2S 1
#define FNL_NOISE_CELLULAR 2
#define FNL_NOISE_PERLIN 3
#define FNL_NOISE_VALUE_CUBIC 4
#define FNL_NOISE_VALUE 5
#define fnl_noise_type int
// Rotation types
#define FNL_ROTATION_NONE 0
#define FNL_ROTATION_IMPROVE_XY_PLANES 1
#define FNL_ROTATION_IMPROVE_XZ_PLANES 2
#define fnl_rotation_type_3d int
// Fractal types
#define FNL_FRACTAL_NONE 0
#define FNL_FRACTAL_FBM 1
#define FNL_FRACTAL_RIDGED 2
#define FNL_FRACTAL_PINGPONG 3
#define FNL_FRACTAL_DOMAIN_WARP_PROGRESSIVE 4
#define FNL_FRACTAL_DOMAIN_WARP_INDEPENDENT 5
#define fnl_fractal_type int
#define FNL_CELLULAR_DISTANCE_EUCLIDEAN 0
#define FNL_CELLULAR_DISTANCE_EUCLIDEANSQ 1
#define FNL_CELLULAR_DISTANCE_MANHATTAN 2
#define FNL_CELLULAR_DISTANCE_HYBRID 3
#define fnl_cellular_distance_func int
#define FNL_CELLULAR_RETURN_TYPE_CELLVALUE 0
#define FNL_CELLULAR_RETURN_TYPE_DISTANCE 1
#define FNL_CELLULAR_RETURN_TYPE_DISTANCE2 2
#define FNL_CELLULAR_RETURN_TYPE_DISTANCE2ADD 3
#define FNL_CELLULAR_RETURN_TYPE_DISTANCE2SUB 4
#define FNL_CELLULAR_RETURN_TYPE_DISTANCE2MUL 5
#define FNL_CELLULAR_RETURN_TYPE_DISTANCE2DIV 6
#define fnl_cellular_return_type int
#define FNL_DOMAIN_WARP_OPENSIMPLEX2 0
#define FNL_DOMAIN_WARP_OPENSIMPLEX2_REDUCED 1
#define FNL_DOMAIN_WARP_BASICGRID 2
#define fnl_domain_warp_type int
// Structure containing entire noise system state.
// @note Must only be created using fnlCreateState(optional: seed). To ensure defaults are set.
struct fnl_state
{
// Seed used for all noise types.
// @remark Default: 1337
int seed;
// The frequency for all noise types.
// @remark Default: 0.01
float frequency;
// The noise algorithm to be used by GetNoise(...).
// @remark Default: FNL_NOISE_OPENSIMPLEX2
fnl_noise_type noise_type;
// Sets noise rotation type for 3D.
// @remark Default: FNL_ROTATION_NONE
fnl_rotation_type_3d rotation_type_3d;
// The method used for combining octaves for all fractal noise types.
// @remark Default: None
// @remark FNL_FRACTAL_DOMAIN_WARP_... only effects fnlDomainWarp...
fnl_fractal_type fractal_type;
// The octave count for all fractal noise types.
// @remark Default: 3
int octaves;
// The octave lacunarity for all fractal noise types.
// @remark Default: 2.0
float lacunarity;
// The octave gain for all fractal noise types.
// @remark Default: 0.5
float gain;
// The octave weighting for all none Domaain Warp fractal types.
// @remark Default: 0.0
// @remark
float weighted_strength;
// The strength of the fractal ping pong effect.
// @remark Default: 2.0
float ping_pong_strength;
// The distance function used in cellular noise calculations.
// @remark Default: FNL_CELLULAR_DISTANCE_EUCLIDEANSQ
fnl_cellular_distance_func cellular_distance_func;
// The cellular return type from cellular noise calculations.
// @remark Default: FNL_CELLULAR_RETURN_TYPE_DISTANCE
fnl_cellular_return_type cellular_return_type;
// The maximum distance a cellular point can move from it's grid position.
// @remark Default: 1.0
// @note Setting this higher than 1 will cause artifacts.
float cellular_jitter_mod;
// The warp algorithm when using fnlDomainWarp...
// @remark Default: OpenSimplex2
fnl_domain_warp_type domain_warp_type;
// The maximum warp distance from original position when using fnlDomainWarp...
// @remark Default: 1.0
float domain_warp_amp;
};
// From here on, this is private implementation
// Constants
const float GRADIENTS_2D[] =
{
0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, 0.793353340291235f, 0.793353340291235f, 0.608761429008721f,
0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, -0.130526192220051f, 0.923879532511287f, -0.38268343236509f,
0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, -0.923879532511287f, 0.130526192220052f, -0.99144486137381f,
-0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, -0.793353340291235f, -0.793353340291235f, -0.608761429008721f,
-0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, 0.130526192220051f, -0.923879532511287f, 0.38268343236509f,
-0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, 0.923879532511287f, -0.130526192220052f, 0.99144486137381f,
0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, 0.793353340291235f, 0.793353340291235f, 0.608761429008721f,
0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, -0.130526192220051f, 0.923879532511287f, -0.38268343236509f,
0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, -0.923879532511287f, 0.130526192220052f, -0.99144486137381f,
-0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, -0.793353340291235f, -0.793353340291235f, -0.608761429008721f,
-0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, 0.130526192220051f, -0.923879532511287f, 0.38268343236509f,
-0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, 0.923879532511287f, -0.130526192220052f, 0.99144486137381f,
0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, 0.793353340291235f, 0.793353340291235f, 0.608761429008721f,
0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, -0.130526192220051f, 0.923879532511287f, -0.38268343236509f,
0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, -0.923879532511287f, 0.130526192220052f, -0.99144486137381f,
-0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, -0.793353340291235f, -0.793353340291235f, -0.608761429008721f,
-0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, 0.130526192220051f, -0.923879532511287f, 0.38268343236509f,
-0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, 0.923879532511287f, -0.130526192220052f, 0.99144486137381f,
0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, 0.793353340291235f, 0.793353340291235f, 0.608761429008721f,
0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, -0.130526192220051f, 0.923879532511287f, -0.38268343236509f,
0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, -0.923879532511287f, 0.130526192220052f, -0.99144486137381f,
-0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, -0.793353340291235f, -0.793353340291235f, -0.608761429008721f,
-0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, 0.130526192220051f, -0.923879532511287f, 0.38268343236509f,
-0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, 0.923879532511287f, -0.130526192220052f, 0.99144486137381f,
0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, 0.793353340291235f, 0.793353340291235f, 0.608761429008721f,
0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, -0.130526192220051f, 0.923879532511287f, -0.38268343236509f,
0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, -0.923879532511287f, 0.130526192220052f, -0.99144486137381f,
-0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, -0.793353340291235f, -0.793353340291235f, -0.608761429008721f,
-0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, 0.130526192220051f, -0.923879532511287f, 0.38268343236509f,
-0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, 0.923879532511287f, -0.130526192220052f, 0.99144486137381f,
0.38268343236509f, 0.923879532511287f, 0.923879532511287f, 0.38268343236509f, 0.923879532511287f, -0.38268343236509f, 0.38268343236509f, -0.923879532511287f,
-0.38268343236509f, -0.923879532511287f, -0.923879532511287f, -0.38268343236509f, -0.923879532511287f, 0.38268343236509f, -0.38268343236509f, 0.923879532511287f
};
const float RAND_VECS_2D[] =
{
-0.2700222198f, -0.9628540911f, 0.3863092627f, -0.9223693152f, 0.04444859006f, -0.999011673f, -0.5992523158f, -0.8005602176f, -0.7819280288f, 0.6233687174f, 0.9464672271f, 0.3227999196f, -0.6514146797f, -0.7587218957f, 0.9378472289f, 0.347048376f,
-0.8497875957f, -0.5271252623f, -0.879042592f, 0.4767432447f, -0.892300288f, -0.4514423508f, -0.379844434f, -0.9250503802f, -0.9951650832f, 0.0982163789f, 0.7724397808f, -0.6350880136f, 0.7573283322f, -0.6530343002f, -0.9928004525f, -0.119780055f,
-0.0532665713f, 0.9985803285f, 0.9754253726f, -0.2203300762f, -0.7665018163f, 0.6422421394f, 0.991636706f, 0.1290606184f, -0.994696838f, 0.1028503788f, -0.5379205513f, -0.84299554f, 0.5022815471f, -0.8647041387f, 0.4559821461f, -0.8899889226f,
-0.8659131224f, -0.5001944266f, 0.0879458407f, -0.9961252577f, -0.5051684983f, 0.8630207346f, 0.7753185226f, -0.6315704146f, -0.6921944612f, 0.7217110418f, -0.5191659449f, -0.8546734591f, 0.8978622882f, -0.4402764035f, -0.1706774107f, 0.9853269617f,
-0.9353430106f, -0.3537420705f, -0.9992404798f, 0.03896746794f, -0.2882064021f, -0.9575683108f, -0.9663811329f, 0.2571137995f, -0.8759714238f, -0.4823630009f, -0.8303123018f, -0.5572983775f, 0.05110133755f, -0.9986934731f, -0.8558373281f, -0.5172450752f,
0.09887025282f, 0.9951003332f, 0.9189016087f, 0.3944867976f, -0.2439375892f, -0.9697909324f, -0.8121409387f, -0.5834613061f, -0.9910431363f, 0.1335421355f, 0.8492423985f, -0.5280031709f, -0.9717838994f, -0.2358729591f, 0.9949457207f, 0.1004142068f,
0.6241065508f, -0.7813392434f, 0.662910307f, 0.7486988212f, -0.7197418176f, 0.6942418282f, -0.8143370775f, -0.5803922158f, 0.104521054f, -0.9945226741f, -0.1065926113f, -0.9943027784f, 0.445799684f, -0.8951327509f, 0.105547406f, 0.9944142724f,
-0.992790267f, 0.1198644477f, -0.8334366408f, 0.552615025f, 0.9115561563f, -0.4111755999f, 0.8285544909f, -0.5599084351f, 0.7217097654f, -0.6921957921f, 0.4940492677f, -0.8694339084f, -0.3652321272f, -0.9309164803f, -0.9696606758f, 0.2444548501f,
0.08925509731f, -0.996008799f, 0.5354071276f, -0.8445941083f, -0.1053576186f, 0.9944343981f, -0.9890284586f, 0.1477251101f, 0.004856104961f, 0.9999882091f, 0.9885598478f, 0.1508291331f, 0.9286129562f, -0.3710498316f, -0.5832393863f, -0.8123003252f,
0.3015207509f, 0.9534596146f, -0.9575110528f, 0.2883965738f, 0.9715802154f, -0.2367105511f, 0.229981792f, 0.9731949318f, 0.955763816f, -0.2941352207f, 0.740956116f, 0.6715534485f, -0.9971513787f, -0.07542630764f, 0.6905710663f, -0.7232645452f,
-0.290713703f, -0.9568100872f, 0.5912777791f, -0.8064679708f, -0.9454592212f, -0.325740481f, 0.6664455681f, 0.74555369f, 0.6236134912f, 0.7817328275f, 0.9126993851f, -0.4086316587f, -0.8191762011f, 0.5735419353f, -0.8812745759f, -0.4726046147f,
0.9953313627f, 0.09651672651f, 0.9855650846f, -0.1692969699f, -0.8495980887f, 0.5274306472f, 0.6174853946f, -0.7865823463f, 0.8508156371f, 0.52546432f, 0.9985032451f, -0.05469249926f, 0.1971371563f, -0.9803759185f, 0.6607855748f, -0.7505747292f,
-0.03097494063f, 0.9995201614f, -0.6731660801f, 0.739491331f, -0.7195018362f, -0.6944905383f, 0.9727511689f, 0.2318515979f, 0.9997059088f, -0.0242506907f, 0.4421787429f, -0.8969269532f, 0.9981350961f, -0.061043673f, -0.9173660799f, -0.3980445648f,
-0.8150056635f, -0.5794529907f, -0.8789331304f, 0.4769450202f, 0.0158605829f, 0.999874213f, -0.8095464474f, 0.5870558317f, -0.9165898907f, -0.3998286786f, -0.8023542565f, 0.5968480938f, -0.5176737917f, 0.8555780767f, -0.8154407307f, -0.5788405779f,
0.4022010347f, -0.9155513791f, -0.9052556868f, -0.4248672045f, 0.7317445619f, 0.6815789728f, -0.5647632201f, -0.8252529947f, -0.8403276335f, -0.5420788397f, -0.9314281527f, 0.363925262f, 0.5238198472f, 0.8518290719f, 0.7432803869f, -0.6689800195f,
-0.985371561f, -0.1704197369f, 0.4601468731f, 0.88784281f, 0.825855404f, 0.5638819483f, 0.6182366099f, 0.7859920446f, 0.8331502863f, -0.553046653f, 0.1500307506f, 0.9886813308f, -0.662330369f, -0.7492119075f, -0.668598664f, 0.743623444f,
0.7025606278f, 0.7116238924f, -0.5419389763f, -0.8404178401f, -0.3388616456f, 0.9408362159f, 0.8331530315f, 0.5530425174f, -0.2989720662f, -0.9542618632f, 0.2638522993f, 0.9645630949f, 0.124108739f, -0.9922686234f, -0.7282649308f, -0.6852956957f,
0.6962500149f, 0.7177993569f, -0.9183535368f, 0.3957610156f, -0.6326102274f, -0.7744703352f, -0.9331891859f, -0.359385508f, -0.1153779357f, -0.9933216659f, 0.9514974788f, -0.3076565421f, -0.08987977445f, -0.9959526224f, 0.6678496916f, 0.7442961705f,
0.7952400393f, -0.6062947138f, -0.6462007402f, -0.7631674805f, -0.2733598753f, 0.9619118351f, 0.9669590226f, -0.254931851f, -0.9792894595f, 0.2024651934f, -0.5369502995f, -0.8436138784f, -0.270036471f, -0.9628500944f, -0.6400277131f, 0.7683518247f,
-0.7854537493f, -0.6189203566f, 0.06005905383f, -0.9981948257f, -0.02455770378f, 0.9996984141f, -0.65983623f, 0.751409442f, -0.6253894466f, -0.7803127835f, -0.6210408851f, -0.7837781695f, 0.8348888491f, 0.5504185768f, -0.1592275245f, 0.9872419133f,
0.8367622488f, 0.5475663786f, -0.8675753916f, -0.4973056806f, -0.2022662628f, -0.9793305667f, 0.9399189937f, 0.3413975472f, 0.9877404807f, -0.1561049093f, -0.9034455656f, 0.4287028224f, 0.1269804218f, -0.9919052235f, -0.3819600854f, 0.924178821f,
0.9754625894f, 0.2201652486f, -0.3204015856f, -0.9472818081f, -0.9874760884f, 0.1577687387f, 0.02535348474f, -0.9996785487f, 0.4835130794f, -0.8753371362f, -0.2850799925f, -0.9585037287f, -0.06805516006f, -0.99768156f, -0.7885244045f, -0.6150034663f,
0.3185392127f, -0.9479096845f, 0.8880043089f, 0.4598351306f, 0.6476921488f, -0.7619021462f, 0.9820241299f, 0.1887554194f, 0.9357275128f, -0.3527237187f, -0.8894895414f, 0.4569555293f, 0.7922791302f, 0.6101588153f, 0.7483818261f, 0.6632681526f,
-0.7288929755f, -0.6846276581f, 0.8729032783f, -0.4878932944f, 0.8288345784f, 0.5594937369f, 0.08074567077f, 0.9967347374f, 0.9799148216f, -0.1994165048f, -0.580730673f, -0.8140957471f, -0.4700049791f, -0.8826637636f, 0.2409492979f, 0.9705377045f,
0.9437816757f, -0.3305694308f, -0.8927998638f, -0.4504535528f, -0.8069622304f, 0.5906030467f, 0.06258973166f, 0.9980393407f, -0.9312597469f, 0.3643559849f, 0.5777449785f, 0.8162173362f, -0.3360095855f, -0.941858566f, 0.697932075f, -0.7161639607f,
-0.002008157227f, -0.9999979837f, -0.1827294312f, -0.9831632392f, -0.6523911722f, 0.7578824173f, -0.4302626911f, -0.9027037258f, -0.9985126289f, -0.05452091251f, -0.01028102172f, -0.9999471489f, -0.4946071129f, 0.8691166802f, -0.2999350194f, 0.9539596344f,
0.8165471961f, 0.5772786819f, 0.2697460475f, 0.962931498f, -0.7306287391f, -0.6827749597f, -0.7590952064f, -0.6509796216f, -0.907053853f, 0.4210146171f, -0.5104861064f, -0.8598860013f, 0.8613350597f, 0.5080373165f, 0.5007881595f, -0.8655698812f,
-0.654158152f, 0.7563577938f, -0.8382755311f, -0.545246856f, 0.6940070834f, 0.7199681717f, 0.06950936031f, 0.9975812994f, 0.1702942185f, -0.9853932612f, 0.2695973274f, 0.9629731466f, 0.5519612192f, -0.8338697815f, 0.225657487f, -0.9742067022f,
0.4215262855f, -0.9068161835f, 0.4881873305f, -0.8727388672f, -0.3683854996f, -0.9296731273f, -0.9825390578f, 0.1860564427f, 0.81256471f, 0.5828709909f, 0.3196460933f, -0.9475370046f, 0.9570913859f, 0.2897862643f, -0.6876655497f, -0.7260276109f,
-0.9988770922f, -0.047376731f, -0.1250179027f, 0.992154486f, -0.8280133617f, 0.560708367f, 0.9324863769f, -0.3612051451f, 0.6394653183f, 0.7688199442f, -0.01623847064f, -0.9998681473f, -0.9955014666f, -0.09474613458f, -0.81453315f, 0.580117012f,
0.4037327978f, -0.9148769469f, 0.9944263371f, 0.1054336766f, -0.1624711654f, 0.9867132919f, -0.9949487814f, -0.100383875f, -0.6995302564f, 0.7146029809f, 0.5263414922f, -0.85027327f, -0.5395221479f, 0.841971408f, 0.6579370318f, 0.7530729462f,
0.01426758847f, -0.9998982128f, -0.6734383991f, 0.7392433447f, 0.639412098f, -0.7688642071f, 0.9211571421f, 0.3891908523f, -0.146637214f, -0.9891903394f, -0.782318098f, 0.6228791163f, -0.5039610839f, -0.8637263605f, -0.7743120191f, -0.6328039957f
};
const float GRADIENTS_3D[] =
{
0.f, 1.f, 1.f, 0.f, 0.f,-1.f, 1.f, 0.f, 0.f, 1.f,-1.f, 0.f, 0.f,-1.f,-1.f, 0.f,
1.f, 0.f, 1.f, 0.f, -1.f, 0.f, 1.f, 0.f, 1.f, 0.f,-1.f, 0.f, -1.f, 0.f,-1.f, 0.f,
1.f, 1.f, 0.f, 0.f, -1.f, 1.f, 0.f, 0.f, 1.f,-1.f, 0.f, 0.f, -1.f,-1.f, 0.f, 0.f,
0.f, 1.f, 1.f, 0.f, 0.f,-1.f, 1.f, 0.f, 0.f, 1.f,-1.f, 0.f, 0.f,-1.f,-1.f, 0.f,
1.f, 0.f, 1.f, 0.f, -1.f, 0.f, 1.f, 0.f, 1.f, 0.f,-1.f, 0.f, -1.f, 0.f,-1.f, 0.f,
1.f, 1.f, 0.f, 0.f, -1.f, 1.f, 0.f, 0.f, 1.f,-1.f, 0.f, 0.f, -1.f,-1.f, 0.f, 0.f,
0.f, 1.f, 1.f, 0.f, 0.f,-1.f, 1.f, 0.f, 0.f, 1.f,-1.f, 0.f, 0.f,-1.f,-1.f, 0.f,
1.f, 0.f, 1.f, 0.f, -1.f, 0.f, 1.f, 0.f, 1.f, 0.f,-1.f, 0.f, -1.f, 0.f,-1.f, 0.f,
1.f, 1.f, 0.f, 0.f, -1.f, 1.f, 0.f, 0.f, 1.f,-1.f, 0.f, 0.f, -1.f,-1.f, 0.f, 0.f,
0.f, 1.f, 1.f, 0.f, 0.f,-1.f, 1.f, 0.f, 0.f, 1.f,-1.f, 0.f, 0.f,-1.f,-1.f, 0.f,
1.f, 0.f, 1.f, 0.f, -1.f, 0.f, 1.f, 0.f, 1.f, 0.f,-1.f, 0.f, -1.f, 0.f,-1.f, 0.f,
1.f, 1.f, 0.f, 0.f, -1.f, 1.f, 0.f, 0.f, 1.f,-1.f, 0.f, 0.f, -1.f,-1.f, 0.f, 0.f,
0.f, 1.f, 1.f, 0.f, 0.f,-1.f, 1.f, 0.f, 0.f, 1.f,-1.f, 0.f, 0.f,-1.f,-1.f, 0.f,
1.f, 0.f, 1.f, 0.f, -1.f, 0.f, 1.f, 0.f, 1.f, 0.f,-1.f, 0.f, -1.f, 0.f,-1.f, 0.f,
1.f, 1.f, 0.f, 0.f, -1.f, 1.f, 0.f, 0.f, 1.f,-1.f, 0.f, 0.f, -1.f,-1.f, 0.f, 0.f,
1.f, 1.f, 0.f, 0.f, 0.f,-1.f, 1.f, 0.f, -1.f, 1.f, 0.f, 0.f, 0.f,-1.f,-1.f, 0.f
};
const float RAND_VECS_3D[] =
{
-0.7292736885f, -0.6618439697f, 0.1735581948f, 0.f, 0.790292081f, -0.5480887466f, -0.2739291014f, 0.f, 0.7217578935f, 0.6226212466f, -0.3023380997f, 0.f, 0.565683137f, -0.8208298145f, -0.0790000257f, 0.f, 0.760049034f, -0.5555979497f, -0.3370999617f, 0.f, 0.3713945616f, 0.5011264475f, 0.7816254623f, 0.f, -0.1277062463f, -0.4254438999f, -0.8959289049f, 0.f, -0.2881560924f, -0.5815838982f, 0.7607405838f, 0.f,
0.5849561111f, -0.662820239f, -0.4674352136f, 0.f, 0.3307171178f, 0.0391653737f, 0.94291689f, 0.f, 0.8712121778f, -0.4113374369f, -0.2679381538f, 0.f, 0.580981015f, 0.7021915846f, 0.4115677815f, 0.f, 0.503756873f, 0.6330056931f, -0.5878203852f, 0.f, 0.4493712205f, 0.601390195f, 0.6606022552f, 0.f, -0.6878403724f, 0.09018890807f, -0.7202371714f, 0.f, -0.5958956522f, -0.6469350577f, 0.475797649f, 0.f,
-0.5127052122f, 0.1946921978f, -0.8361987284f, 0.f, -0.9911507142f, -0.05410276466f, -0.1212153153f, 0.f, -0.2149721042f, 0.9720882117f, -0.09397607749f, 0.f, -0.7518650936f, -0.5428057603f, 0.3742469607f, 0.f, 0.5237068895f, 0.8516377189f, -0.02107817834f, 0.f, 0.6333504779f, 0.1926167129f, -0.7495104896f, 0.f, -0.06788241606f, 0.3998305789f, 0.9140719259f, 0.f, -0.5538628599f, -0.4729896695f, -0.6852128902f, 0.f,
-0.7261455366f, -0.5911990757f, 0.3509933228f, 0.f, -0.9229274737f, -0.1782808786f, 0.3412049336f, 0.f, -0.6968815002f, 0.6511274338f, 0.3006480328f, 0.f, 0.9608044783f, -0.2098363234f, -0.1811724921f, 0.f, 0.06817146062f, -0.9743405129f, 0.2145069156f, 0.f, -0.3577285196f, -0.6697087264f, -0.6507845481f, 0.f, -0.1868621131f, 0.7648617052f, -0.6164974636f, 0.f, -0.6541697588f, 0.3967914832f, 0.6439087246f, 0.f,
0.6993340405f, -0.6164538506f, 0.3618239211f, 0.f, -0.1546665739f, 0.6291283928f, 0.7617583057f, 0.f, -0.6841612949f, -0.2580482182f, -0.6821542638f, 0.f, 0.5383980957f, 0.4258654885f, 0.7271630328f, 0.f, -0.5026987823f, -0.7939832935f, -0.3418836993f, 0.f, 0.3202971715f, 0.2834415347f, 0.9039195862f, 0.f, 0.8683227101f, -0.0003762656404f, -0.4959995258f, 0.f, 0.791120031f, -0.08511045745f, 0.6057105799f, 0.f,
-0.04011016052f, -0.4397248749f, 0.8972364289f, 0.f, 0.9145119872f, 0.3579346169f, -0.1885487608f, 0.f, -0.9612039066f, -0.2756484276f, 0.01024666929f, 0.f, 0.6510361721f, -0.2877799159f, -0.7023778346f, 0.f, -0.2041786351f, 0.7365237271f, 0.644859585f, 0.f, -0.7718263711f, 0.3790626912f, 0.5104855816f, 0.f, -0.3060082741f, -0.7692987727f, 0.5608371729f, 0.f, 0.454007341f, -0.5024843065f, 0.7357899537f, 0.f,
0.4816795475f, 0.6021208291f, -0.6367380315f, 0.f, 0.6961980369f, -0.3222197429f, 0.641469197f, 0.f, -0.6532160499f, -0.6781148932f, 0.3368515753f, 0.f, 0.5089301236f, -0.6154662304f, -0.6018234363f, 0.f, -0.1635919754f, -0.9133604627f, -0.372840892f, 0.f, 0.52408019f, -0.8437664109f, 0.1157505864f, 0.f, 0.5902587356f, 0.4983817807f, -0.6349883666f, 0.f, 0.5863227872f, 0.494764745f, 0.6414307729f, 0.f,
0.6779335087f, 0.2341345225f, 0.6968408593f, 0.f, 0.7177054546f, -0.6858979348f, 0.120178631f, 0.f, -0.5328819713f, -0.5205125012f, 0.6671608058f, 0.f, -0.8654874251f, -0.0700727088f, -0.4960053754f, 0.f, -0.2861810166f, 0.7952089234f, 0.5345495242f, 0.f, -0.04849529634f, 0.9810836427f, -0.1874115585f, 0.f, -0.6358521667f, 0.6058348682f, 0.4781800233f, 0.f, 0.6254794696f, -0.2861619734f, 0.7258696564f, 0.f,
-0.2585259868f, 0.5061949264f, -0.8227581726f, 0.f, 0.02136306781f, 0.5064016808f, -0.8620330371f, 0.f, 0.200111773f, 0.8599263484f, 0.4695550591f, 0.f, 0.4743561372f, 0.6014985084f, -0.6427953014f, 0.f, 0.6622993731f, -0.5202474575f, -0.5391679918f, 0.f, 0.08084972818f, -0.6532720452f, 0.7527940996f, 0.f, -0.6893687501f, 0.0592860349f, 0.7219805347f, 0.f, -0.1121887082f, -0.9673185067f, 0.2273952515f, 0.f,
0.7344116094f, 0.5979668656f, -0.3210532909f, 0.f, 0.5789393465f, -0.2488849713f, 0.7764570201f, 0.f, 0.6988182827f, 0.3557169806f, -0.6205791146f, 0.f, -0.8636845529f, -0.2748771249f, -0.4224826141f, 0.f, -0.4247027957f, -0.4640880967f, 0.777335046f, 0.f, 0.5257722489f, -0.8427017621f, 0.1158329937f, 0.f, 0.9343830603f, 0.316302472f, -0.1639543925f, 0.f, -0.1016836419f, -0.8057303073f, -0.5834887393f, 0.f,
-0.6529238969f, 0.50602126f, -0.5635892736f, 0.f, -0.2465286165f, -0.9668205684f, -0.06694497494f, 0.f, -0.9776897119f, -0.2099250524f, -0.007368825344f, 0.f, 0.7736893337f, 0.5734244712f, 0.2694238123f, 0.f, -0.6095087895f, 0.4995678998f, 0.6155736747f, 0.f, 0.5794535482f, 0.7434546771f, 0.3339292269f, 0.f, -0.8226211154f, 0.08142581855f, 0.5627293636f, 0.f, -0.510385483f, 0.4703667658f, 0.7199039967f, 0.f,
-0.5764971849f, -0.07231656274f, -0.8138926898f, 0.f, 0.7250628871f, 0.3949971505f, -0.5641463116f, 0.f, -0.1525424005f, 0.4860840828f, -0.8604958341f, 0.f, -0.5550976208f, -0.4957820792f, 0.667882296f, 0.f, -0.1883614327f, 0.9145869398f, 0.357841725f, 0.f, 0.7625556724f, -0.5414408243f, -0.3540489801f, 0.f, -0.5870231946f, -0.3226498013f, -0.7424963803f, 0.f, 0.3051124198f, 0.2262544068f, -0.9250488391f, 0.f,
0.6379576059f, 0.577242424f, -0.5097070502f, 0.f, -0.5966775796f, 0.1454852398f, -0.7891830656f, 0.f, -0.658330573f, 0.6555487542f, -0.3699414651f, 0.f, 0.7434892426f, 0.2351084581f, 0.6260573129f, 0.f, 0.5562114096f, 0.8264360377f, -0.0873632843f, 0.f, -0.3028940016f, -0.8251527185f, 0.4768419182f, 0.f, 0.1129343818f, -0.985888439f, -0.1235710781f, 0.f, 0.5937652891f, -0.5896813806f, 0.5474656618f, 0.f,
0.6757964092f, -0.5835758614f, -0.4502648413f, 0.f, 0.7242302609f, -0.1152719764f, 0.6798550586f, 0.f, -0.9511914166f, 0.0753623979f, -0.2992580792f, 0.f, 0.2539470961f, -0.1886339355f, 0.9486454084f, 0.f, 0.571433621f, -0.1679450851f, -0.8032795685f, 0.f, -0.06778234979f, 0.3978269256f, 0.9149531629f, 0.f, 0.6074972649f, 0.733060024f, -0.3058922593f, 0.f, -0.5435478392f, 0.1675822484f, 0.8224791405f, 0.f,
-0.5876678086f, -0.3380045064f, -0.7351186982f, 0.f, -0.7967562402f, 0.04097822706f, -0.6029098428f, 0.f, -0.1996350917f, 0.8706294745f, 0.4496111079f, 0.f, -0.02787660336f, -0.9106232682f, -0.4122962022f, 0.f, -0.7797625996f, -0.6257634692f, 0.01975775581f, 0.f, -0.5211232846f, 0.7401644346f, -0.4249554471f, 0.f, 0.8575424857f, 0.4053272873f, -0.3167501783f, 0.f, 0.1045223322f, 0.8390195772f, -0.5339674439f, 0.f,
0.3501822831f, 0.9242524096f, -0.1520850155f, 0.f, 0.1987849858f, 0.07647613266f, 0.9770547224f, 0.f, 0.7845996363f, 0.6066256811f, -0.1280964233f, 0.f, 0.09006737436f, -0.9750989929f, -0.2026569073f, 0.f, -0.8274343547f, -0.542299559f, 0.1458203587f, 0.f, -0.3485797732f, -0.415802277f, 0.840000362f, 0.f, -0.2471778936f, -0.7304819962f, -0.6366310879f, 0.f, -0.3700154943f, 0.8577948156f, 0.3567584454f, 0.f,
0.5913394901f, -0.548311967f, -0.5913303597f, 0.f, 0.1204873514f, -0.7626472379f, -0.6354935001f, 0.f, 0.616959265f, 0.03079647928f, 0.7863922953f, 0.f, 0.1258156836f, -0.6640829889f, -0.7369967419f, 0.f, -0.6477565124f, -0.1740147258f, -0.7417077429f, 0.f, 0.6217889313f, -0.7804430448f, -0.06547655076f, 0.f, 0.6589943422f, -0.6096987708f, 0.4404473475f, 0.f, -0.2689837504f, -0.6732403169f, -0.6887635427f, 0.f,
-0.3849775103f, 0.5676542638f, 0.7277093879f, 0.f, 0.5754444408f, 0.8110471154f, -0.1051963504f, 0.f, 0.9141593684f, 0.3832947817f, 0.131900567f, 0.f, -0.107925319f, 0.9245493968f, 0.3654593525f, 0.f, 0.377977089f, 0.3043148782f, 0.8743716458f, 0.f, -0.2142885215f, -0.8259286236f, 0.5214617324f, 0.f, 0.5802544474f, 0.4148098596f, -0.7008834116f, 0.f, -0.1982660881f, 0.8567161266f, -0.4761596756f, 0.f,
-0.03381553704f, 0.3773180787f, -0.9254661404f, 0.f, -0.6867922841f, -0.6656597827f, 0.2919133642f, 0.f, 0.7731742607f, -0.2875793547f, -0.5652430251f, 0.f, -0.09655941928f, 0.9193708367f, -0.3813575004f, 0.f, 0.2715702457f, -0.9577909544f, -0.09426605581f, 0.f, 0.2451015704f, -0.6917998565f, -0.6792188003f, 0.f, 0.977700782f, -0.1753855374f, 0.1155036542f, 0.f, -0.5224739938f, 0.8521606816f, 0.02903615945f, 0.f,
-0.7734880599f, -0.5261292347f, 0.3534179531f, 0.f, -0.7134492443f, -0.269547243f, 0.6467878011f, 0.f, 0.1644037271f, 0.5105846203f, -0.8439637196f, 0.f, 0.6494635788f, 0.05585611296f, 0.7583384168f, 0.f, -0.4711970882f, 0.5017280509f, -0.7254255765f, 0.f, -0.6335764307f, -0.2381686273f, -0.7361091029f, 0.f, -0.9021533097f, -0.270947803f, -0.3357181763f, 0.f, -0.3793711033f, 0.872258117f, 0.3086152025f, 0.f,
-0.6855598966f, -0.3250143309f, 0.6514394162f, 0.f, 0.2900942212f, -0.7799057743f, -0.5546100667f, 0.f, -0.2098319339f, 0.85037073f, 0.4825351604f, 0.f, -0.4592603758f, 0.6598504336f, -0.5947077538f, 0.f, 0.8715945488f, 0.09616365406f, -0.4807031248f, 0.f, -0.6776666319f, 0.7118504878f, -0.1844907016f, 0.f, 0.7044377633f, 0.312427597f, 0.637304036f, 0.f, -0.7052318886f, -0.2401093292f, -0.6670798253f, 0.f,
0.081921007f, -0.7207336136f, -0.6883545647f, 0.f, -0.6993680906f, -0.5875763221f, -0.4069869034f, 0.f, -0.1281454481f, 0.6419895885f, 0.7559286424f, 0.f, -0.6337388239f, -0.6785471501f, -0.3714146849f, 0.f, 0.5565051903f, -0.2168887573f, -0.8020356851f, 0.f, -0.5791554484f, 0.7244372011f, -0.3738578718f, 0.f, 0.1175779076f, -0.7096451073f, 0.6946792478f, 0.f, -0.6134619607f, 0.1323631078f, 0.7785527795f, 0.f,
0.6984635305f, -0.02980516237f, -0.715024719f, 0.f, 0.8318082963f, -0.3930171956f, 0.3919597455f, 0.f, 0.1469576422f, 0.05541651717f, -0.9875892167f, 0.f, 0.708868575f, -0.2690503865f, 0.6520101478f, 0.f, 0.2726053183f, 0.67369766f, -0.68688995f, 0.f, -0.6591295371f, 0.3035458599f, -0.6880466294f, 0.f, 0.4815131379f, -0.7528270071f, 0.4487723203f, 0.f, 0.9430009463f, 0.1675647412f, -0.2875261255f, 0.f,
0.434802957f, 0.7695304522f, -0.4677277752f, 0.f, 0.3931996188f, 0.594473625f, 0.7014236729f, 0.f, 0.7254336655f, -0.603925654f, 0.3301814672f, 0.f, 0.7590235227f, -0.6506083235f, 0.02433313207f, 0.f, -0.8552768592f, -0.3430042733f, 0.3883935666f, 0.f, -0.6139746835f, 0.6981725247f, 0.3682257648f, 0.f, -0.7465905486f, -0.5752009504f, 0.3342849376f, 0.f, 0.5730065677f, 0.810555537f, -0.1210916791f, 0.f,
-0.9225877367f, -0.3475211012f, -0.167514036f, 0.f, -0.7105816789f, -0.4719692027f, -0.5218416899f, 0.f, -0.08564609717f, 0.3583001386f, 0.929669703f, 0.f, -0.8279697606f, -0.2043157126f, 0.5222271202f, 0.f, 0.427944023f, 0.278165994f, 0.8599346446f, 0.f, 0.5399079671f, -0.7857120652f, -0.3019204161f, 0.f, 0.5678404253f, -0.5495413974f, -0.6128307303f, 0.f, -0.9896071041f, 0.1365639107f, -0.04503418428f, 0.f,
-0.6154342638f, -0.6440875597f, 0.4543037336f, 0.f, 0.1074204368f, -0.7946340692f, 0.5975094525f, 0.f, -0.3595449969f, -0.8885529948f, 0.28495784f, 0.f, -0.2180405296f, 0.1529888965f, 0.9638738118f, 0.f, -0.7277432317f, -0.6164050508f, -0.3007234646f, 0.f, 0.7249729114f, -0.00669719484f, 0.6887448187f, 0.f, -0.5553659455f, -0.5336586252f, 0.6377908264f, 0.f, 0.5137558015f, 0.7976208196f, -0.3160000073f, 0.f,
-0.3794024848f, 0.9245608561f, -0.03522751494f, 0.f, 0.8229248658f, 0.2745365933f, -0.4974176556f, 0.f, -0.5404114394f, 0.6091141441f, 0.5804613989f, 0.f, 0.8036581901f, -0.2703029469f, 0.5301601931f, 0.f, 0.6044318879f, 0.6832968393f, 0.4095943388f, 0.f, 0.06389988817f, 0.9658208605f, -0.2512108074f, 0.f, 0.1087113286f, 0.7402471173f, -0.6634877936f, 0.f, -0.713427712f, -0.6926784018f, 0.1059128479f, 0.f,
0.6458897819f, -0.5724548511f, -0.5050958653f, 0.f, -0.6553931414f, 0.7381471625f, 0.159995615f, 0.f, 0.3910961323f, 0.9188871375f, -0.05186755998f, 0.f, -0.4879022471f, -0.5904376907f, 0.6429111375f, 0.f, 0.6014790094f, 0.7707441366f, -0.2101820095f, 0.f, -0.5677173047f, 0.7511360995f, 0.3368851762f, 0.f, 0.7858573506f, 0.226674665f, 0.5753666838f, 0.f, -0.4520345543f, -0.604222686f, -0.6561857263f, 0.f,
0.002272116345f, 0.4132844051f, -0.9105991643f, 0.f, -0.5815751419f, -0.5162925989f, 0.6286591339f, 0.f, -0.03703704785f, 0.8273785755f, 0.5604221175f, 0.f, -0.5119692504f, 0.7953543429f, -0.3244980058f, 0.f, -0.2682417366f, -0.9572290247f, -0.1084387619f, 0.f, -0.2322482736f, -0.9679131102f, -0.09594243324f, 0.f, 0.3554328906f, -0.8881505545f, 0.2913006227f, 0.f, 0.7346520519f, -0.4371373164f, 0.5188422971f, 0.f,
0.9985120116f, 0.04659011161f, -0.02833944577f, 0.f, -0.3727687496f, -0.9082481361f, 0.1900757285f, 0.f, 0.91737377f, -0.3483642108f, 0.1925298489f, 0.f, 0.2714911074f, 0.4147529736f, -0.8684886582f, 0.f, 0.5131763485f, -0.7116334161f, 0.4798207128f, 0.f, -0.8737353606f, 0.18886992f, -0.4482350644f, 0.f, 0.8460043821f, -0.3725217914f, 0.3814499973f, 0.f, 0.8978727456f, -0.1780209141f, -0.4026575304f, 0.f,
0.2178065647f, -0.9698322841f, -0.1094789531f, 0.f, -0.1518031304f, -0.7788918132f, -0.6085091231f, 0.f, -0.2600384876f, -0.4755398075f, -0.8403819825f, 0.f, 0.572313509f, -0.7474340931f, -0.3373418503f, 0.f, -0.7174141009f, 0.1699017182f, -0.6756111411f, 0.f, -0.684180784f, 0.02145707593f, -0.7289967412f, 0.f, -0.2007447902f, 0.06555605789f, -0.9774476623f, 0.f, -0.1148803697f, -0.8044887315f, 0.5827524187f, 0.f,
-0.7870349638f, 0.03447489231f, 0.6159443543f, 0.f, -0.2015596421f, 0.6859872284f, 0.6991389226f, 0.f, -0.08581082512f, -0.10920836f, -0.9903080513f, 0.f, 0.5532693395f, 0.7325250401f, -0.396610771f, 0.f, -0.1842489331f, -0.9777375055f, -0.1004076743f, 0.f, 0.0775473789f, -0.9111505856f, 0.4047110257f, 0.f, 0.1399838409f, 0.7601631212f, -0.6344734459f, 0.f, 0.4484419361f, -0.845289248f, 0.2904925424f, 0.f
};
// Utilities
float _fnlFastMin(float x, float y) { return min(x, y); }
float _fnlFastMax(float x, float y) { return max(x, y); }
float _fnlFastAbs(float f) { return abs(f); }
float _fnlFastSqrt(float a) { return sqrt(a); }
int _fnlFastFloor(FNLfloat f) { return int(floor(f)); }
int _fnlFastRound(FNLfloat f) { return int(round(f)); }
float _fnlLerp(float a, float b, float t) { return mix(a, b, t); }
float _fnlInterpHermite(float t) { return t * t * (3.f - 2.f * t); }
float _fnlInterpQuintic(float t) { return t * t * t * (t * (t * 6.f - 15.f) + 10.f); }
float _fnlCubicLerp(float a, float b, float c, float d, float t)
{
float p = (d - c) - (a - b);
return t * t * t * p + t * t * ((a - b) - p) + t * (c - a) + b;
}
float _fnlPingPong(float t)
{
t -= float(int(t * 0.5f)) * 2.f;
return t < 1.f ? t : 2.f - t;
}
float _fnlCalculateFractalBounding(fnl_state state)
{
float gain = _fnlFastAbs(state.gain);
float amp = gain;
float ampFractal = 1.f;
for (int i = 1; i < state.octaves; i++)
{
ampFractal += amp;
amp *= gain;
}
return 1.f / ampFractal;
}
// Hashing
const int PRIME_X = 501125321;
const int PRIME_Y = 1136930381;
const int PRIME_Z = 1720413743;
int _fnlHash2D(int seed, int xPrimed, int yPrimed)
{
int hash = seed ^ xPrimed ^ yPrimed;
hash *= 0x27d4eb2d;
return hash;
}
int _fnlHash3D(int seed, int xPrimed, int yPrimed, int zPrimed)
{
int hash = seed ^ xPrimed ^ yPrimed ^ zPrimed;
hash *= 0x27d4eb2d;
return hash;
}
float _fnlValCoord2D(int seed, int xPrimed, int yPrimed)
{
int hash = _fnlHash2D(seed, xPrimed, yPrimed);
hash *= hash;
hash ^= hash << 19;
return float(hash) * (1.f / 2147483648.f);
}
float _fnlValCoord3D(int seed, int xPrimed, int yPrimed, int zPrimed)
{
int hash = _fnlHash3D(seed, xPrimed, yPrimed, zPrimed);
hash *= hash;
hash ^= hash << 19;
return float(hash) * (1.f / 2147483648.f);
}
float _fnlGradCoord2D(int seed, int xPrimed, int yPrimed, float xd, float yd)
{
int hash = _fnlHash2D(seed, xPrimed, yPrimed);
hash ^= hash >> 15;
hash &= 127 << 1;
return xd * GRADIENTS_2D[hash] + yd * GRADIENTS_2D[hash | 1];
}
float _fnlGradCoord3D(int seed, int xPrimed, int yPrimed, int zPrimed, float xd, float yd, float zd)
{
int hash = _fnlHash3D(seed, xPrimed, yPrimed, zPrimed);
hash ^= hash >> 15;
hash &= 63 << 2;
return xd * GRADIENTS_3D[hash] + yd * GRADIENTS_3D[hash | 1] + zd * GRADIENTS_3D[hash | 2];
}
void _fnlGradCoordOut2D(int seed, int xPrimed, int yPrimed, out float xo, out float yo)
{
int hash = _fnlHash2D(seed, xPrimed, yPrimed) & (255 << 1);
xo = RAND_VECS_2D[hash];
yo = RAND_VECS_2D[hash | 1];
}
void _fnlGradCoordOut3D(int seed, int xPrimed, int yPrimed, int zPrimed, out float xo, out float yo, out float zo)
{
int hash = _fnlHash3D(seed, xPrimed, yPrimed, zPrimed) & (255 << 2);
xo = RAND_VECS_3D[hash];
yo = RAND_VECS_3D[hash | 1];
zo = RAND_VECS_3D[hash | 2];
}
void _fnlGradCoordDual2D(int seed, int xPrimed, int yPrimed, float xd, float yd, out float xo, out float yo)
{
int hash = _fnlHash2D(seed, xPrimed, yPrimed);
int index1 = hash & (127 << 1);
int index2 = (hash >> 7) & (255 << 1);
float xg = GRADIENTS_2D[index1];
float yg = GRADIENTS_2D[index1 | 1];
float value = xd * xg + yd * yg;
float xgo = RAND_VECS_2D[index2];
float ygo = RAND_VECS_2D[index2 | 1];
xo = value * xgo;
yo = value * ygo;
}
void _fnlGradCoordDual3D(int seed, int xPrimed, int yPrimed, int zPrimed, float xd, float yd, float zd, out float xo, out float yo, out float zo)
{
int hash = _fnlHash3D(seed, xPrimed, yPrimed, zPrimed);
int index1 = hash & (63 << 2);
int index2 = (hash >> 6) & (255 << 2);
float xg = GRADIENTS_3D[index1];
float yg = GRADIENTS_3D[index1 | 1];
float zg = GRADIENTS_3D[index1 | 2];
float value = xd * xg + yd * yg + zd * zg;
float xgo = RAND_VECS_3D[index2];
float ygo = RAND_VECS_3D[index2 | 1];
float zgo = RAND_VECS_3D[index2 | 2];
xo = value * xgo;
yo = value * ygo;
zo = value * zgo;
}
// Noise Coordinate Transforms (frequency, and possible skew or rotation)
void _fnlTransformNoiseCoordinate2D(fnl_state state, inout FNLfloat x, inout FNLfloat y)
{
x *= state.frequency;
y *= state.frequency;
switch (state.noise_type)
{
case FNL_NOISE_OPENSIMPLEX2:
case FNL_NOISE_OPENSIMPLEX2S:
{
const FNLfloat SQRT3 = FNLfloat(1.7320508075688772935274463415059);
const FNLfloat F2 = 0.5f * (SQRT3 - 1.f);
FNLfloat t = (x + y) * F2;
x += t;
y += t;
}
break;
default:
break;
}
}
void _fnlTransformNoiseCoordinate3D(fnl_state state, inout FNLfloat x, inout FNLfloat y, inout FNLfloat z)
{
x *= state.frequency;
y *= state.frequency;
z *= state.frequency;
switch (state.rotation_type_3d)
{
case FNL_ROTATION_IMPROVE_XY_PLANES:
{
FNLfloat xy = x + y;
FNLfloat s2 = xy * -FNLfloat(0.211324865405187);
z *= FNLfloat(0.577350269189626);
x += s2 - z;
y = y + s2 - z;
z += xy * FNLfloat(0.577350269189626);
}
break;
case FNL_ROTATION_IMPROVE_XZ_PLANES:
{
FNLfloat xz = x + z;
FNLfloat s2 = xz * -FNLfloat(0.211324865405187);
y *= FNLfloat(0.577350269189626);
x += s2 - y;
z += s2 - y;
y += xz * FNLfloat(0.577350269189626);
}
break;
default:
switch (state.noise_type)
{
case FNL_NOISE_OPENSIMPLEX2:
case FNL_NOISE_OPENSIMPLEX2S:
{
const FNLfloat R3 = FNLfloat(2.f / 3.f);
FNLfloat r = (x + y + z) * R3; // Rotation, not skew
x = r - x;
y = r - y;
z = r - z;
}
break;
default:
break;
}
break;
}
}
// Domain Warp Coordinate Transforms
void _fnlTransformDomainWarpCoordinate2D(fnl_state state, inout FNLfloat x, inout FNLfloat y)
{
switch (state.domain_warp_type)
{
case FNL_DOMAIN_WARP_OPENSIMPLEX2:
case FNL_DOMAIN_WARP_OPENSIMPLEX2_REDUCED:
{
const FNLfloat SQRT3 = FNLfloat(1.7320508075688772935274463415059);
const FNLfloat F2 = 0.5f * (SQRT3 - 1.f);
FNLfloat t = (x + y) * F2;
x += t;
y += t;
}
break;
default:
break;
}
}
void _fnlTransformDomainWarpCoordinate3D(fnl_state state, inout FNLfloat x, inout FNLfloat y, inout FNLfloat z)
{
switch (state.rotation_type_3d)
{
case FNL_ROTATION_IMPROVE_XY_PLANES:
{
FNLfloat xy = x + y;
FNLfloat s2 = xy * -FNLfloat(0.211324865405187);
z *= FNLfloat(0.577350269189626);
x += s2 - z;
y = y + s2 - z;
z += xy * FNLfloat(0.577350269189626);
}
break;
case FNL_ROTATION_IMPROVE_XZ_PLANES:
{
FNLfloat xz = x + z;
FNLfloat s2 = xz * -FNLfloat(0.211324865405187);
y *= FNLfloat(0.577350269189626);
x += s2 - y;
z += s2 - y;
y += xz * FNLfloat(0.577350269189626);
}
break;
default:
switch (state.domain_warp_type)
{
case FNL_DOMAIN_WARP_OPENSIMPLEX2:
case FNL_DOMAIN_WARP_OPENSIMPLEX2_REDUCED:
{
const FNLfloat R3 = FNLfloat(2.f / 3.f);
FNLfloat r = (x + y + z) * R3; // Rotation, not skew
x = r - x;
y = r - y;
z = r - z;
}
break;
default:
break;
}
break;
}
}
// Simplex/OpenSimplex2 Noise
float _fnlSingleSimplex2D(int seed, FNLfloat x, FNLfloat y)
{
// 2D OpenSimplex2 case uses the same algorithm as ordinary Simplex.
const float SQRT3 = 1.7320508075688772935274463415059;
const float G2 = (3.f - SQRT3) / 6.f;
// --- Skew moved to TransformNoiseCoordinate method ---
// const FNLfloat F2 = 0.5f * (SQRT3 - 1);
// FNLfloat s = (x + y) * F2;
// x += s; y += s;
int i = _fnlFastFloor(x);
int j = _fnlFastFloor(y);
float xi = x - float(i);
float yi = y - float(j);
float t = (xi + yi) * G2;
float x0 = xi - t;
float y0 = yi - t;
i *= PRIME_X;
j *= PRIME_Y;
float n0, n1, n2;
float a = 0.5f - x0 * x0 - y0 * y0;
if (a <= 0.f)
{
n0 = 0.f;
}
else
{
n0 = (a * a) * (a * a) * _fnlGradCoord2D(seed, i, j, x0, y0);
}
float c = (2.f * (1.f - 2.f * G2) * (1.f / G2 - 2.f)) * t + ((-2.f * (1.f - 2.f * G2) * (1.f - 2.f * G2)) + a);
if (c <= 0.f)
{
n2 = 0.f;
}
else
{
float x2 = x0 + (2.f * G2 - 1.f);
float y2 = y0 + (2.f * G2 - 1.f);
n2 = (c * c) * (c * c) * _fnlGradCoord2D(seed, i + PRIME_X, j + PRIME_Y, x2, y2);
}
if (y0 > x0)
{
float x1 = x0 + G2;
float y1 = y0 + G2 - 1.f;
float b = 0.5f - x1 * x1 - y1 * y1;
if (b <= 0.f)
{
n1 = 0.f;
}
else
{
n1 = (b * b) * (b * b) * _fnlGradCoord2D(seed, i, j + PRIME_Y, x1, y1);
}
}
else
{
float x1 = x0 + (G2 - 1.f);
float y1 = y0 + G2;
float b = 0.5f - x1 * x1 - y1 * y1;
if (b <= 0.f)
{
n1 = 0.f;
}
else
{
n1 = (b * b) * (b * b) * _fnlGradCoord2D(seed, i + PRIME_X, j, x1, y1);
}
}
return (n0 + n1 + n2) * 99.83685446303647;
}
float _fnlSingleOpenSimplex23D(int seed, FNLfloat x, FNLfloat y, FNLfloat z)
{
// 3D OpenSimplex2 case uses two offset rotated cube grids.
// --- Rotation moved to TransformNoiseCoordinate method ---
// const FNLfloat R3 = (FNLfloat)(2.f / 3.f);
// FNLfloat r = (x + y + z) * R3; // Rotation, not skew
// x = r - x; y = r - y; z = r - z;
int i = _fnlFastRound(x);
int j = _fnlFastRound(y);
int k = _fnlFastRound(z);
float x0 = x - float(i);
float y0 = y - float(j);
float z0 = z - float(k);
int xNSign = int(-1.f - x0) | 1;
int yNSign = int(-1.f - y0) | 1;
int zNSign = int(-1.f - z0) | 1;
float ax0 = float(xNSign) * -x0;
float ay0 = float(yNSign) * -y0;
float az0 = float(zNSign) * -z0;
i *= PRIME_X;
j *= PRIME_Y;
k *= PRIME_Z;
float value = 0.f;
float a = (0.6f - x0 * x0) - (y0 * y0 + z0 * z0);
for (int l = 0; ; l++)
{
if (a > 0.f)
{
value += (a * a) * (a * a) * _fnlGradCoord3D(seed, i, j, k, x0, y0, z0);
}
float b = a + 1.f;
int i1 = i;
int j1 = j;
int k1 = k;
float x1 = x0;
float y1 = y0;
float z1 = z0;
if (ax0 >= ay0 && ax0 >= az0)
{
x1 += float(xNSign);
b -= float(xNSign) * 2.f * x1;
i1 -= xNSign * PRIME_X;
}
else if (ay0 > ax0 && ay0 >= az0)
{
y1 += float(yNSign);
b -= float(yNSign) * 2.f * y1;
j1 -= yNSign * PRIME_Y;
}
else
{
z1 += float(zNSign);
b -= float(zNSign) * 2.f * z1;
k1 -= zNSign * PRIME_Z;
}
if (b > 0.f)
{
value += (b * b) * (b * b) * _fnlGradCoord3D(seed, i1, j1, k1, x1, y1, z1);
}
if (l == 1) break;
ax0 = 0.5f - ax0;
ay0 = 0.5f - ay0;
az0 = 0.5f - az0;
x0 = float(xNSign) * ax0;
y0 = float(yNSign) * ay0;
z0 = float(zNSign) * az0;
a += (0.75f - ax0) - (ay0 + az0);
i += (xNSign >> 1) & PRIME_X;
j += (yNSign >> 1) & PRIME_Y;
k += (zNSign >> 1) & PRIME_Z;
xNSign = -xNSign;
yNSign = -yNSign;
zNSign = -zNSign;
seed = ~seed;
}
return value * 32.69428253173828125;
}
// OpenSimplex2S Noise
float _fnlSingleOpenSimplex2S2D(int seed, FNLfloat x, FNLfloat y)
{
// 2D OpenSimplex2S case is a modified 2D simplex noise.
const FNLfloat SQRT3 = FNLfloat(1.7320508075688772935274463415059);
const FNLfloat G2 = (3.f - SQRT3) / 6.f;
// --- Skew moved to TransformNoiseCoordinate method ---
// const FNLfloat F2 = 0.5f * (SQRT3 - 1);
// FNLfloat s = (x + y) * F2;
// x += s; y += s;
int i = _fnlFastFloor(x);
int j = _fnlFastFloor(y);
float xi = x - float(i);
float yi = y - float(j);
i *= PRIME_X;
j *= PRIME_Y;
int i1 = i + PRIME_X;
int j1 = j + PRIME_Y;
float t = (xi + yi) * G2;
float x0 = xi - t;
float y0 = yi - t;
int aMask = int((xi + yi + 1.f) * -0.5f);
int bMask = int((xi - (float(aMask) + 2.f)) * 0.5f - yi);
int cMask = int((yi - (float(aMask) + 2.f)) * 0.5f - xi);
float a0 = (2.f / 3.f) - x0 * x0 - y0 * y0;
float value = (a0 * a0) * (a0 * a0) * _fnlGradCoord2D(seed, i, j, x0, y0);
float a1 = (2.f * (1.f - 2.f * G2) * (1.f / G2 - 2.f)) * t + ((-2.f * (1.f - 2.f * G2) * (1.f - 2.f * G2)) + a0);
float x1 = x0 - (1.f - 2.f * G2);
float y1 = y0 - (1.f - 2.f * G2);
value += (a1 * a1) * (a1 * a1) * _fnlGradCoord2D(seed, i1, j1, x1, y1);
int di2 = ~(aMask | cMask) | 1;
int ndj2 = (aMask & bMask) << 1;
float t2 = float(di2 - ndj2) * G2;
float x2 = x0 - float(di2) + t2;
float y2 = y0 + float(ndj2) + t2;
float a2 = (2.f / 3.f) - x2 * x2 - y2 * y2;
if (a2 > 0.f)
{
value += (a2 * a2) * (a2 * a2) * _fnlGradCoord2D(seed, i1 + (di2 & (-PRIME_X << 1)), j + (ndj2 & (PRIME_Y << 1)), x2, y2);
}
int ndi3 = (aMask & cMask) << 1;
int dj3 = ~(aMask | bMask) | 1;
float t3 = float(dj3 - ndi3) * G2;
float x3 = x0 + float(ndi3) + t3;
float y3 = y0 - float(dj3) + t3;
float a3 = (2.f / 3.f) - x3 * x3 - y3 * y3;
if (a3 > 0.f)
{
value += (a3 * a3) * (a3 * a3) * _fnlGradCoord2D(seed, i + (ndi3 & (PRIME_X << 1)), j1 + (dj3 & (-PRIME_Y << 1)), x3, y3);
}
return value * 18.24196194486065;
}
float _fnlSingleOpenSimplex2S3D(int seed, FNLfloat x, FNLfloat y, FNLfloat z)
{
// 3D OpenSimplex2S case uses two offset rotated cube grids.
// --- Rotation moved to TransformNoiseCoordinate method ---
// const FNLfloat R3 = (FNLfloat)(2.f / 3.f);
// FNLfloat r = (x + y + z) * R3; // Rotation, not skew
// x = r - x; y = r - y; z = r - z;
int i = _fnlFastFloor(x);
int j = _fnlFastFloor(y);
int k = _fnlFastFloor(z);
float xi = x - float(i);
float yi = y - float(j);
float zi = z - float(k);
i *= PRIME_X;
j *= PRIME_Y;
k *= PRIME_Z;
int seed2 = seed + 1293373;
int xNMask = int(-0.5f - xi);
int yNMask = int(-0.5f - yi);
int zNMask = int(-0.5f - zi);
float x0 = xi + float(xNMask);
float y0 = yi + float(yNMask);
float z0 = zi + float(zNMask);
float a0 = 0.75f - x0 * x0 - y0 * y0 - z0 * z0;
float value = (a0 * a0) * (a0 * a0) * _fnlGradCoord3D(seed,
i + (xNMask & PRIME_X), j + (yNMask & PRIME_Y), k + (zNMask & PRIME_Z), x0, y0, z0);
float x1 = xi - 0.5f;
float y1 = yi - 0.5f;
float z1 = zi - 0.5f;
float a1 = 0.75f - x1 * x1 - y1 * y1 - z1 * z1;
value += (a1 * a1) * (a1 * a1) * _fnlGradCoord3D(seed2,
i + PRIME_X, j + PRIME_Y, k + PRIME_Z, x1, y1, z1);
float xAFlipMask0 = float((xNMask | 1) << 1) * x1;
float yAFlipMask0 = float((yNMask | 1) << 1) * y1;
float zAFlipMask0 = float((zNMask | 1) << 1) * z1;
float xAFlipMask1 = float(-2 - (xNMask << 2)) * x1 - 1.f;
float yAFlipMask1 = float(-2 - (yNMask << 2)) * y1 - 1.f;
float zAFlipMask1 = float(-2 - (zNMask << 2)) * z1 - 1.f;
bool skip5 = false;
float a2 = xAFlipMask0 + a0;
if (a2 > 0.f)
{
float x2 = x0 - float(xNMask | 1);
float y2 = y0;
float z2 = z0;
value += (a2 * a2) * (a2 * a2) * _fnlGradCoord3D(seed,
i + (~xNMask & PRIME_X), j + (yNMask & PRIME_Y), k + (zNMask & PRIME_Z), x2, y2, z2);
}
else
{
float a3 = yAFlipMask0 + zAFlipMask0 + a0;
if (a3 > 0.f)
{
float x3 = x0;
float y3 = y0 - float(yNMask | 1);
float z3 = z0 - float(zNMask | 1);
value += (a3 * a3) * (a3 * a3) * _fnlGradCoord3D(seed,
i + (xNMask & PRIME_X), j + (~yNMask & PRIME_Y), k + (~zNMask & PRIME_Z), x3, y3, z3);
}
float a4 = xAFlipMask1 + a1;
if (a4 > 0.f)
{
float x4 = float(xNMask | 1) + x1;
float y4 = y1;
float z4 = z1;
value += (a4 * a4) * (a4 * a4) * _fnlGradCoord3D(seed2,
i + (xNMask & (PRIME_X * 2)), j + PRIME_Y, k + PRIME_Z, x4, y4, z4);
skip5 = true;
}
}
bool skip9 = false;
float a6 = yAFlipMask0 + a0;
if (a6 > 0.f)
{
float x6 = x0;
float y6 = y0 - float(yNMask | 1);
float z6 = z0;
value += (a6 * a6) * (a6 * a6) * _fnlGradCoord3D(seed,
i + (xNMask & PRIME_X), j + (~yNMask & PRIME_Y), k + (zNMask & PRIME_Z), x6, y6, z6);
}
else
{
float a7 = xAFlipMask0 + zAFlipMask0 + a0;
if (a7 > 0.f)
{
float x7 = x0 - float(xNMask | 1);
float y7 = y0;
float z7 = z0 - float(zNMask | 1);
value += (a7 * a7) * (a7 * a7) * _fnlGradCoord3D(seed,
i + (~xNMask & PRIME_X), j + (yNMask & PRIME_Y), k + (~zNMask & PRIME_Z), x7, y7, z7);
}
float a8 = yAFlipMask1 + a1;
if (a8 > 0.f)
{
float x8 = x1;
float y8 = float(yNMask | 1) + y1;
float z8 = z1;
value += (a8 * a8) * (a8 * a8) * _fnlGradCoord3D(seed2,
i + PRIME_X, j + (yNMask & (PRIME_Y << 1)), k + PRIME_Z, x8, y8, z8);
skip9 = true;
}
}
bool skipD = false;
float aA = zAFlipMask0 + a0;
if (aA > 0.f)
{
float xA = x0;
float yA = y0;
float zA = z0 - float(zNMask | 1);
value += (aA * aA) * (aA * aA) * _fnlGradCoord3D(seed,
i + (xNMask & PRIME_X), j + (yNMask & PRIME_Y), k + (~zNMask & PRIME_Z), xA, yA, zA);
}
else
{
float aB = xAFlipMask0 + yAFlipMask0 + a0;
if (aB > 0.f)
{
float xB = x0 - float(xNMask | 1);
float yB = y0 - float(yNMask | 1);
float zB = z0;
value += (aB * aB) * (aB * aB) * _fnlGradCoord3D(seed,
i + (~xNMask & PRIME_X), j + (~yNMask & PRIME_Y), k + (zNMask & PRIME_Z), xB, yB, zB);
}
float aC = zAFlipMask1 + a1;
if (aC > 0.f)
{
float xC = x1;
float yC = y1;
float zC = float(zNMask | 1) + z1;
value += (aC * aC) * (aC * aC) * _fnlGradCoord3D(seed2,
i + PRIME_X, j + PRIME_Y, k + (zNMask & (PRIME_Z << 1)), xC, yC, zC);
skipD = true;
}
}
if (!skip5)
{
float a5 = yAFlipMask1 + zAFlipMask1 + a1;
if (a5 > 0.f)
{
float x5 = x1;
float y5 = float(yNMask | 1) + y1;
float z5 = float(zNMask | 1) + z1;
value += (a5 * a5) * (a5 * a5) * _fnlGradCoord3D(seed2,
i + PRIME_X, j + (yNMask & (PRIME_Y << 1)), k + (zNMask & (PRIME_Z << 1)), x5, y5, z5);
}
}
if (!skip9)
{
float a9 = xAFlipMask1 + zAFlipMask1 + a1;
if (a9 > 0.f)
{
float x9 = float(xNMask | 1) + x1;
float y9 = y1;
float z9 = float(zNMask | 1) + z1;
value += (a9 * a9) * (a9 * a9) * _fnlGradCoord3D(seed2,
i + (xNMask & (PRIME_X * 2)), j + PRIME_Y, k + (zNMask & (PRIME_Z << 1)), x9, y9, z9);
}
}
if (!skipD)
{
float aD = xAFlipMask1 + yAFlipMask1 + a1;
if (aD > 0.f)
{
float xD = float(xNMask | 1) + x1;
float yD = float(yNMask | 1) + y1;
float zD = z1;
value += (aD * aD) * (aD * aD) * _fnlGradCoord3D(seed2,
i + (xNMask & (PRIME_X << 1)), j + (yNMask & (PRIME_Y << 1)), k + PRIME_Z, xD, yD, zD);
}
}
return value * 9.046026385208288;
}
// Cellular Noise
float _fnlSingleCellular2D(fnl_state state, int seed, FNLfloat x, FNLfloat y)
{
int xr = _fnlFastRound(x);
int yr = _fnlFastRound(y);
float distance0 = 1e10f;
float distance1 = 1e10f;
int closestHash = 0;
float cellularJitter = 0.43701595f * state.cellular_jitter_mod;
int xPrimed = (xr - 1) * PRIME_X;
int yPrimedBase = (yr - 1) * PRIME_Y;
switch (state.cellular_distance_func)
{
case FNL_CELLULAR_DISTANCE_MANHATTAN:
{
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int hash = _fnlHash2D(seed, xPrimed, yPrimed);
int idx = hash & (255 << 1);
float vecX = float(xi) - x + RAND_VECS_2D[idx] * cellularJitter;
float vecY = float(yi) - y + RAND_VECS_2D[idx | 1] * cellularJitter;
float newDistance = _fnlFastAbs(vecX) + _fnlFastAbs(vecY);
distance1 = _fnlFastMax(_fnlFastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
yPrimed += PRIME_Y;
}
xPrimed += PRIME_X;
}
break;
}
case FNL_CELLULAR_DISTANCE_HYBRID:
{
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int hash = _fnlHash2D(seed, xPrimed, yPrimed);
int idx = hash & (255 << 1);
float vecX = float(xi) - x + RAND_VECS_2D[idx] * cellularJitter;
float vecY = float(yi) - y + RAND_VECS_2D[idx | 1] * cellularJitter;
float newDistance = (_fnlFastAbs(vecX) + _fnlFastAbs(vecY)) + (vecX * vecX + vecY * vecY);
distance1 = _fnlFastMax(_fnlFastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
yPrimed += PRIME_Y;
}
xPrimed += PRIME_X;
}
break;
}
case FNL_CELLULAR_DISTANCE_EUCLIDEAN:
case FNL_CELLULAR_DISTANCE_EUCLIDEANSQ:
default:
{
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int hash = _fnlHash2D(seed, xPrimed, yPrimed);
int idx = hash & (255 << 1);
float vecX = float(xi) - x + RAND_VECS_2D[idx] * cellularJitter;
float vecY = float(yi) - y + RAND_VECS_2D[idx | 1] * cellularJitter;
float newDistance = vecX * vecX + vecY * vecY;
distance1 = _fnlFastMax(_fnlFastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
yPrimed += PRIME_Y;
}
xPrimed += PRIME_X;
}
break;
}
}
if (state.cellular_distance_func == FNL_CELLULAR_DISTANCE_EUCLIDEAN && state.cellular_return_type >= FNL_CELLULAR_RETURN_TYPE_DISTANCE)
{
distance0 = _fnlFastSqrt(distance0);
if (state.cellular_return_type >= FNL_CELLULAR_RETURN_TYPE_DISTANCE2)
{
distance1 = _fnlFastSqrt(distance1);
}
}
switch (state.cellular_return_type)
{
case FNL_CELLULAR_RETURN_TYPE_CELLVALUE:
return float(closestHash) * (1.f / 2147483648.f);
case FNL_CELLULAR_RETURN_TYPE_DISTANCE:
return distance0 - 1.f;
case FNL_CELLULAR_RETURN_TYPE_DISTANCE2:
return distance1 - 1.f;
case FNL_CELLULAR_RETURN_TYPE_DISTANCE2ADD:
return (distance1 + distance0) * 0.5f - 1.f;
case FNL_CELLULAR_RETURN_TYPE_DISTANCE2SUB:
return distance1 - distance0 - 1.f;
case FNL_CELLULAR_RETURN_TYPE_DISTANCE2MUL:
return distance1 * distance0 * 0.5f - 1.f;
case FNL_CELLULAR_RETURN_TYPE_DISTANCE2DIV:
return distance0 / distance1 - 1.f;
default:
return 0.f;
}
}
float _fnlSingleCellular3D(fnl_state state, int seed, FNLfloat x, FNLfloat y, FNLfloat z)
{
int xr = _fnlFastRound(x);
int yr = _fnlFastRound(y);
int zr = _fnlFastRound(z);
float distance0 = 1e10f;
float distance1 = 1e10f;
int closestHash = 0;
float cellularJitter = 0.39614353 * state.cellular_jitter_mod;
int xPrimed = (xr - 1) * PRIME_X;
int yPrimedBase = (yr - 1) * PRIME_Y;
int zPrimedBase = (zr - 1) * PRIME_Z;
switch (state.cellular_distance_func)
{
case FNL_CELLULAR_DISTANCE_MANHATTAN:
{
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int zPrimed = zPrimedBase;
for (int zi = zr - 1; zi <= zr + 1; zi++)
{
int hash = _fnlHash3D(seed, xPrimed, yPrimed, zPrimed);
int idx = hash & (255 << 2);
float vecX = float(xi) - x + RAND_VECS_3D[idx] * cellularJitter;
float vecY = float(yi) - y + RAND_VECS_3D[idx | 1] * cellularJitter;
float vecZ = float(zi) - z + RAND_VECS_3D[idx | 2] * cellularJitter;
float newDistance = _fnlFastAbs(vecX) + _fnlFastAbs(vecY) + _fnlFastAbs(vecZ);
distance1 = _fnlFastMax(_fnlFastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
zPrimed += PRIME_Z;
}
yPrimed += PRIME_Y;
}
xPrimed += PRIME_X;
}
break;
}
case FNL_CELLULAR_DISTANCE_HYBRID:
{
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int zPrimed = zPrimedBase;
for (int zi = zr - 1; zi <= zr + 1; zi++)
{
int hash = _fnlHash3D(seed, xPrimed, yPrimed, zPrimed);
int idx = hash & (255 << 2);
float vecX = float(xi) - x + RAND_VECS_3D[idx] * cellularJitter;
float vecY = float(yi) - y + RAND_VECS_3D[idx | 1] * cellularJitter;
float vecZ = float(zi) - z + RAND_VECS_3D[idx | 2] * cellularJitter;
float newDistance = (_fnlFastAbs(vecX) + _fnlFastAbs(vecY) + _fnlFastAbs(vecZ)) + (vecX * vecX + vecY * vecY + vecZ * vecZ);
distance1 = _fnlFastMax(_fnlFastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
zPrimed += PRIME_Z;
}
yPrimed += PRIME_Y;
}
xPrimed += PRIME_X;
}
break;
}
case FNL_CELLULAR_DISTANCE_EUCLIDEAN:
case FNL_CELLULAR_DISTANCE_EUCLIDEANSQ:
default:
{
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int zPrimed = zPrimedBase;
for (int zi = zr - 1; zi <= zr + 1; zi++)
{
int hash = _fnlHash3D(seed, xPrimed, yPrimed, zPrimed);
int idx = hash & (255 << 2);
float vecX = float(xi) - x + RAND_VECS_3D[idx] * cellularJitter;
float vecY = float(yi) - y + RAND_VECS_3D[idx | 1] * cellularJitter;
float vecZ = float(zi) - z + RAND_VECS_3D[idx | 2] * cellularJitter;
float newDistance = vecX * vecX + vecY * vecY + vecZ * vecZ;
distance1 = _fnlFastMax(_fnlFastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
zPrimed += PRIME_Z;
}
yPrimed += PRIME_Y;
}
xPrimed += PRIME_X;
}
break;
}
}
if (state.cellular_distance_func == FNL_CELLULAR_DISTANCE_EUCLIDEAN && state.cellular_return_type >= FNL_CELLULAR_RETURN_TYPE_DISTANCE)
{
distance0 = _fnlFastSqrt(distance0);
if (state.cellular_return_type >= FNL_CELLULAR_RETURN_TYPE_DISTANCE2)
{
distance1 = _fnlFastSqrt(distance1);
}
}
switch (state.cellular_return_type)
{
case FNL_CELLULAR_RETURN_TYPE_CELLVALUE:
return float(closestHash) * (1.f / 2147483648.f);
case FNL_CELLULAR_RETURN_TYPE_DISTANCE:
return distance0 - 1.f;
case FNL_CELLULAR_RETURN_TYPE_DISTANCE2:
return distance1 - 1.f;
case FNL_CELLULAR_RETURN_TYPE_DISTANCE2ADD:
return (distance1 + distance0) * 0.5f - 1.f;
case FNL_CELLULAR_RETURN_TYPE_DISTANCE2SUB:
return distance1 - distance0 - 1.f;
case FNL_CELLULAR_RETURN_TYPE_DISTANCE2MUL:
return distance1 * distance0 * 0.5f - 1.f;
case FNL_CELLULAR_RETURN_TYPE_DISTANCE2DIV:
return distance0 / distance1 - 1.f;
default:
return 0.f;
}
}
// Perlin Noise
float _fnlSinglePerlin2D(int seed, FNLfloat x, FNLfloat y)
{
int x0 = _fnlFastFloor(x);
int y0 = _fnlFastFloor(y);
float xd0 = x - float(x0);
float yd0 = y - float(y0);
float xd1 = xd0 - 1.f;
float yd1 = yd0 - 1.f;
float xs = _fnlInterpQuintic(xd0);
float ys = _fnlInterpQuintic(yd0);
x0 *= PRIME_X;
y0 *= PRIME_Y;
int x1 = x0 + PRIME_X;
int y1 = y0 + PRIME_Y;
float xf0 = _fnlLerp(_fnlGradCoord2D(seed, x0, y0, xd0, yd0), _fnlGradCoord2D(seed, x1, y0, xd1, yd0), xs);
float xf1 = _fnlLerp(_fnlGradCoord2D(seed, x0, y1, xd0, yd1), _fnlGradCoord2D(seed, x1, y1, xd1, yd1), xs);
return _fnlLerp(xf0, xf1, ys) * 1.4247691104677813;
}
float _fnlSinglePerlin3D(int seed, FNLfloat x, FNLfloat y, FNLfloat z)
{
int x0 = _fnlFastFloor(x);
int y0 = _fnlFastFloor(y);
int z0 = _fnlFastFloor(z);
float xd0 = x - float(x0);
float yd0 = y - float(y0);
float zd0 = z - float(z0);
float xd1 = xd0 - 1.f;
float yd1 = yd0 - 1.f;
float zd1 = zd0 - 1.f;
float xs = _fnlInterpQuintic(xd0);
float ys = _fnlInterpQuintic(yd0);
float zs = _fnlInterpQuintic(zd0);
x0 *= PRIME_X;
y0 *= PRIME_Y;
z0 *= PRIME_Z;
int x1 = x0 + PRIME_X;
int y1 = y0 + PRIME_Y;
int z1 = z0 + PRIME_Z;
float xf00 = _fnlLerp(_fnlGradCoord3D(seed, x0, y0, z0, xd0, yd0, zd0), _fnlGradCoord3D(seed, x1, y0, z0, xd1, yd0, zd0), xs);
float xf10 = _fnlLerp(_fnlGradCoord3D(seed, x0, y1, z0, xd0, yd1, zd0), _fnlGradCoord3D(seed, x1, y1, z0, xd1, yd1, zd0), xs);
float xf01 = _fnlLerp(_fnlGradCoord3D(seed, x0, y0, z1, xd0, yd0, zd1), _fnlGradCoord3D(seed, x1, y0, z1, xd1, yd0, zd1), xs);
float xf11 = _fnlLerp(_fnlGradCoord3D(seed, x0, y1, z1, xd0, yd1, zd1), _fnlGradCoord3D(seed, x1, y1, z1, xd1, yd1, zd1), xs);
float yf0 = _fnlLerp(xf00, xf10, ys);
float yf1 = _fnlLerp(xf01, xf11, ys);
return _fnlLerp(yf0, yf1, zs) * 0.964921414852142333984375;
}
// Value Cubic
float _fnlSingleValueCubic2D(int seed, FNLfloat x, FNLfloat y)
{
int x1 = _fnlFastFloor(x);
int y1 = _fnlFastFloor(y);
float xs = x - float(x1);
float ys = y - float(y1);
x1 *= PRIME_X;
y1 *= PRIME_Y;
int x0 = x1 - PRIME_X;
int y0 = y1 - PRIME_Y;
int x2 = x1 + PRIME_X;
int y2 = y1 + PRIME_Y;
int x3 = x1 + PRIME_X * 2;
int y3 = y1 + PRIME_Y * 2;
return _fnlCubicLerp(
_fnlCubicLerp(_fnlValCoord2D(seed, x0, y0), _fnlValCoord2D(seed, x1, y0), _fnlValCoord2D(seed, x2, y0), _fnlValCoord2D(seed, x3, y0),
xs),
_fnlCubicLerp(_fnlValCoord2D(seed, x0, y1), _fnlValCoord2D(seed, x1, y1), _fnlValCoord2D(seed, x2, y1), _fnlValCoord2D(seed, x3, y1),
xs),
_fnlCubicLerp(_fnlValCoord2D(seed, x0, y2), _fnlValCoord2D(seed, x1, y2), _fnlValCoord2D(seed, x2, y2), _fnlValCoord2D(seed, x3, y2),
xs),
_fnlCubicLerp(_fnlValCoord2D(seed, x0, y3), _fnlValCoord2D(seed, x1, y3), _fnlValCoord2D(seed, x2, y3), _fnlValCoord2D(seed, x3, y3),
xs),
ys) * (1.f / (1.5f * 1.5f));
}
float _fnlSingleValueCubic3D(int seed, FNLfloat x, FNLfloat y, FNLfloat z)
{
int x1 = _fnlFastFloor(x);
int y1 = _fnlFastFloor(y);
int z1 = _fnlFastFloor(z);
float xs = x - float(x1);
float ys = y - float(y1);
float zs = z - float(z1);
x1 *= PRIME_X;
y1 *= PRIME_Y;
z1 *= PRIME_Z;
int x0 = x1 - PRIME_X;
int y0 = y1 - PRIME_Y;
int z0 = z1 - PRIME_Z;
int x2 = x1 + PRIME_X;
int y2 = y1 + PRIME_Y;
int z2 = z1 + PRIME_Z;
int x3 = x1 + PRIME_X * 2;
int y3 = y1 + PRIME_Y * 2;
int z3 = z1 + PRIME_Z * 2;
return _fnlCubicLerp(
_fnlCubicLerp(
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y0, z0), _fnlValCoord3D(seed, x1, y0, z0), _fnlValCoord3D(seed, x2, y0, z0), _fnlValCoord3D(seed, x3, y0, z0), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y1, z0), _fnlValCoord3D(seed, x1, y1, z0), _fnlValCoord3D(seed, x2, y1, z0), _fnlValCoord3D(seed, x3, y1, z0), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y2, z0), _fnlValCoord3D(seed, x1, y2, z0), _fnlValCoord3D(seed, x2, y2, z0), _fnlValCoord3D(seed, x3, y2, z0), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y3, z0), _fnlValCoord3D(seed, x1, y3, z0), _fnlValCoord3D(seed, x2, y3, z0), _fnlValCoord3D(seed, x3, y3, z0), xs),
ys),
_fnlCubicLerp(
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y0, z1), _fnlValCoord3D(seed, x1, y0, z1), _fnlValCoord3D(seed, x2, y0, z1), _fnlValCoord3D(seed, x3, y0, z1), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y1, z1), _fnlValCoord3D(seed, x1, y1, z1), _fnlValCoord3D(seed, x2, y1, z1), _fnlValCoord3D(seed, x3, y1, z1), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y2, z1), _fnlValCoord3D(seed, x1, y2, z1), _fnlValCoord3D(seed, x2, y2, z1), _fnlValCoord3D(seed, x3, y2, z1), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y3, z1), _fnlValCoord3D(seed, x1, y3, z1), _fnlValCoord3D(seed, x2, y3, z1), _fnlValCoord3D(seed, x3, y3, z1), xs),
ys),
_fnlCubicLerp(
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y0, z2), _fnlValCoord3D(seed, x1, y0, z2), _fnlValCoord3D(seed, x2, y0, z2), _fnlValCoord3D(seed, x3, y0, z2), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y1, z2), _fnlValCoord3D(seed, x1, y1, z2), _fnlValCoord3D(seed, x2, y1, z2), _fnlValCoord3D(seed, x3, y1, z2), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y2, z2), _fnlValCoord3D(seed, x1, y2, z2), _fnlValCoord3D(seed, x2, y2, z2), _fnlValCoord3D(seed, x3, y2, z2), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y3, z2), _fnlValCoord3D(seed, x1, y3, z2), _fnlValCoord3D(seed, x2, y3, z2), _fnlValCoord3D(seed, x3, y3, z2), xs),
ys),
_fnlCubicLerp(
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y0, z3), _fnlValCoord3D(seed, x1, y0, z3), _fnlValCoord3D(seed, x2, y0, z3), _fnlValCoord3D(seed, x3, y0, z3), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y1, z3), _fnlValCoord3D(seed, x1, y1, z3), _fnlValCoord3D(seed, x2, y1, z3), _fnlValCoord3D(seed, x3, y1, z3), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y2, z3), _fnlValCoord3D(seed, x1, y2, z3), _fnlValCoord3D(seed, x2, y2, z3), _fnlValCoord3D(seed, x3, y2, z3), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y3, z3), _fnlValCoord3D(seed, x1, y3, z3), _fnlValCoord3D(seed, x2, y3, z3), _fnlValCoord3D(seed, x3, y3, z3), xs),
ys),
zs) * (1.f / (1.5f * 1.5f * 1.5f));
}
// Value noise
float _fnlSingleValue2D(int seed, FNLfloat x, FNLfloat y)
{
int x0 = _fnlFastFloor(x);
int y0 = _fnlFastFloor(y);
float xs = _fnlInterpHermite(x - float(x0));
float ys = _fnlInterpHermite(y - float(y0));
x0 *= PRIME_X;
y0 *= PRIME_Y;
int x1 = x0 + PRIME_X;
int y1 = y0 + PRIME_Y;
float xf0 = _fnlLerp(_fnlValCoord2D(seed, x0, y0), _fnlValCoord2D(seed, x1, y0), xs);
float xf1 = _fnlLerp(_fnlValCoord2D(seed, x0, y1), _fnlValCoord2D(seed, x1, y1), xs);
return _fnlLerp(xf0, xf1, ys);
}
float _fnlSingleValue3D(int seed, FNLfloat x, FNLfloat y, FNLfloat z)
{
int x0 = _fnlFastFloor(x);
int y0 = _fnlFastFloor(y);
int z0 = _fnlFastFloor(z);
float xs = _fnlInterpHermite(x - float(x0));
float ys = _fnlInterpHermite(y - float(y0));
float zs = _fnlInterpHermite(z - float(z0));
x0 *= PRIME_X;
y0 *= PRIME_Y;
z0 *= PRIME_Z;
int x1 = x0 + PRIME_X;
int y1 = y0 + PRIME_Y;
int z1 = z0 + PRIME_Z;
float xf00 = _fnlLerp(_fnlValCoord3D(seed, x0, y0, z0), _fnlValCoord3D(seed, x1, y0, z0), xs);
float xf10 = _fnlLerp(_fnlValCoord3D(seed, x0, y1, z0), _fnlValCoord3D(seed, x1, y1, z0), xs);
float xf01 = _fnlLerp(_fnlValCoord3D(seed, x0, y0, z1), _fnlValCoord3D(seed, x1, y0, z1), xs);
float xf11 = _fnlLerp(_fnlValCoord3D(seed, x0, y1, z1), _fnlValCoord3D(seed, x1, y1, z1), xs);
float yf0 = _fnlLerp(xf00, xf10, ys);
float yf1 = _fnlLerp(xf01, xf11, ys);
return _fnlLerp(yf0, yf1, zs);
}
// Generic Noise Gen
float _fnlGenNoiseSingle2D(fnl_state state, int seed, FNLfloat x, FNLfloat y)
{
switch (state.noise_type)
{
case FNL_NOISE_OPENSIMPLEX2:
return _fnlSingleSimplex2D(seed, x, y);
case FNL_NOISE_OPENSIMPLEX2S:
return _fnlSingleOpenSimplex2S2D(seed, x, y);
case FNL_NOISE_CELLULAR:
return _fnlSingleCellular2D(state, seed, x, y);
case FNL_NOISE_PERLIN:
return _fnlSinglePerlin2D(seed, x, y);
case FNL_NOISE_VALUE_CUBIC:
return _fnlSingleValueCubic2D(seed, x, y);
case FNL_NOISE_VALUE:
return _fnlSingleValue2D(seed, x, y);
default:
return 0.f;
}
}
float _fnlGenNoiseSingle3D(fnl_state state, int seed, FNLfloat x, FNLfloat y, FNLfloat z)
{
switch (state.noise_type)
{
case FNL_NOISE_OPENSIMPLEX2:
return _fnlSingleOpenSimplex23D(seed, x, y, z);
case FNL_NOISE_OPENSIMPLEX2S:
return _fnlSingleOpenSimplex2S3D(seed, x, y, z);
case FNL_NOISE_CELLULAR:
return _fnlSingleCellular3D(state, seed, x, y, z);
case FNL_NOISE_PERLIN:
return _fnlSinglePerlin3D(seed, x, y, z);
case FNL_NOISE_VALUE_CUBIC:
return _fnlSingleValueCubic3D(seed, x, y, z);
case FNL_NOISE_VALUE:
return _fnlSingleValue3D(seed, x, y, z);
default:
return 0.f;
}
}
// Fractal FBm
float _fnlGenFractalFBM2D(fnl_state state, FNLfloat x, FNLfloat y)
{
int seed = state.seed;
float sum = 0.f;
float amp = _fnlCalculateFractalBounding(state);
for (int i = 0; i < state.octaves; i++)
{
float noise = _fnlGenNoiseSingle2D(state, seed++, x, y);
sum += noise * amp;
amp *= _fnlLerp(1.f, _fnlFastMin(noise + 1.f, 2.f) * 0.5f, state.weighted_strength);
x *= state.lacunarity;
y *= state.lacunarity;
amp *= state.gain;
}
return sum;
}
float _fnlGenFractalFBM3D(fnl_state state, FNLfloat x, FNLfloat y, FNLfloat z)
{
int seed = state.seed;
float sum = 0.f;
float amp = _fnlCalculateFractalBounding(state);
for (int i = 0; i < state.octaves; i++)
{
float noise = _fnlGenNoiseSingle3D(state, seed++, x, y, z);
sum += noise * amp;
amp *= _fnlLerp(1.f, (noise + 1.f) * 0.5f, state.weighted_strength);
x *= state.lacunarity;
y *= state.lacunarity;
z *= state.lacunarity;
amp *= state.gain;
}
return sum;
}
// Fractal Ridged
float _fnlGenFractalRidged2D(fnl_state state, FNLfloat x, FNLfloat y)
{
int seed = state.seed;
float sum = 0.f;
float amp = _fnlCalculateFractalBounding(state);
for (int i = 0; i < state.octaves; i++)
{
float noise = _fnlFastAbs(_fnlGenNoiseSingle2D(state, seed++, x, y));
sum += (noise * -2.f + 1.f) * amp;
amp *= _fnlLerp(1.f, 1.f - noise, state.weighted_strength);
x *= state.lacunarity;
y *= state.lacunarity;
amp *= state.gain;
}
return sum;
}
float _fnlGenFractalRidged3D(fnl_state state, FNLfloat x, FNLfloat y, FNLfloat z)
{
int seed = state.seed;
float sum = 0.f;
float amp = _fnlCalculateFractalBounding(state);
for (int i = 0; i < state.octaves; i++)
{
float noise = _fnlFastAbs(_fnlGenNoiseSingle3D(state, seed++, x, y, z));
sum += (noise * -2.f + 1.f) * amp;
amp *= _fnlLerp(1.f, 1.f - noise, state.weighted_strength);
x *= state.lacunarity;
y *= state.lacunarity;
z *= state.lacunarity;
amp *= state.gain;
}
return sum;
}
// Fractal PingPong
float _fnlGenFractalPingPong2D(fnl_state state, FNLfloat x, FNLfloat y)
{
int seed = state.seed;
float sum = 0.f;
float amp = _fnlCalculateFractalBounding(state);
for (int i = 0; i < state.octaves; i++)
{
float noise = _fnlPingPong((_fnlGenNoiseSingle2D(state, seed++, x, y) + 1.f) * state.ping_pong_strength);
sum += (noise - 0.5f) * 2.f * amp;
amp *= _fnlLerp(1.f, noise, state.weighted_strength);
x *= state.lacunarity;
y *= state.lacunarity;
amp *= state.gain;
}
return sum;
}
float _fnlGenFractalPingPong3D(fnl_state state, FNLfloat x, FNLfloat y, FNLfloat z)
{
int seed = state.seed;
float sum = 0.f;
float amp = _fnlCalculateFractalBounding(state);
for (int i = 0; i < state.octaves; i++)
{
float noise = _fnlPingPong((_fnlGenNoiseSingle3D(state, seed++, x, y, z) + 1.f) * state.ping_pong_strength);
sum += (noise - 0.5f) * 2.f * amp;
amp *= _fnlLerp(1.f, noise, state.weighted_strength);
x *= state.lacunarity;
y *= state.lacunarity;
z *= state.lacunarity;
amp *= state.gain;
}
return sum;
}
// Domain Warp Simplex/OpenSimplex2
void _fnlSingleDomainWarpSimplexGradient(int seed, float warpAmp, float frequency, FNLfloat x, FNLfloat y, inout FNLfloat xr, inout FNLfloat yr, bool outGradOnly)
{
const float SQRT3 = 1.7320508075688772935274463415059;
const float G2 = (3.f - SQRT3) / 6.f;
x *= frequency;
y *= frequency;
// --- Skew moved to TransformNoiseCoordinate method ---
// const FNLfloat F2 = 0.5f * (SQRT3 - 1);
// FNLfloat s = (x + y) * F2;
// x += s; y += s;
int i = _fnlFastFloor(x);
int j = _fnlFastFloor(y);
float xi = x - float(i);
float yi = y - float(j);
float t = (xi + yi) * G2;
float x0 = xi - t;
float y0 = yi - t;
i *= PRIME_X;
j *= PRIME_Y;
float vx, vy;
vx = vy = 0.f;
float a = 0.5f - x0 * x0 - y0 * y0;
if (a > 0.f)
{
float aaaa = (a * a) * (a * a);
float xo, yo;
if (outGradOnly)
{
_fnlGradCoordOut2D(seed, i, j, xo, yo);
}
else
{
_fnlGradCoordDual2D(seed, i, j, x0, y0, xo, yo);
}
vx += aaaa * xo;
vy += aaaa * yo;
}
float c = (2.f * (1.f - 2.f * G2) * (1.f / G2 - 2.f)) * t + ((-2.f * (1.f - 2.f * G2) * (1.f - 2.f * G2)) + a);
if (c > 0.f)
{
float x2 = x0 + (2.f * G2 - 1.f);
float y2 = y0 + (2.f * G2 - 1.f);
float cccc = (c * c) * (c * c);
float xo, yo;
if (outGradOnly)
{
_fnlGradCoordOut2D(seed, i + PRIME_X, j + PRIME_Y, xo, yo);
}
else
{
_fnlGradCoordDual2D(seed, i + PRIME_X, j + PRIME_Y, x2, y2, xo, yo);
}
vx += cccc * xo;
vy += cccc * yo;
}
if (y0 > x0)
{
float x1 = x0 + G2;
float y1 = y0 + (G2 - 1.f);
float b = 0.5f - x1 * x1 - y1 * y1;
if (b > 0.f)
{
float bbbb = (b * b) * (b * b);
float xo, yo;
if (outGradOnly)
{
_fnlGradCoordOut2D(seed, i, j + PRIME_Y, xo, yo);
}
else
{
_fnlGradCoordDual2D(seed, i, j + PRIME_Y, x1, y1, xo, yo);
}
vx += bbbb * xo;
vy += bbbb * yo;
}
}
else
{
float x1 = x0 + (G2 - 1.f);
float y1 = y0 + G2;
float b = 0.5f - x1 * x1 - y1 * y1;
if (b > 0.f)
{
float bbbb = (b * b) * (b * b);
float xo, yo;
if (outGradOnly)
{
_fnlGradCoordOut2D(seed, i + PRIME_X, j, xo, yo);
}
else
{
_fnlGradCoordDual2D(seed, i + PRIME_X, j, x1, y1, xo, yo);
}
vx += bbbb * xo;
vy += bbbb * yo;
}
}
xr += vx * warpAmp;
yr += vy * warpAmp;
}
void _fnlSingleDomainWarpOpenSimplex2Gradient(int seed, float warpAmp, float frequency, FNLfloat x, FNLfloat y, FNLfloat z, inout FNLfloat xr, inout FNLfloat yr, inout FNLfloat zr, bool outGradOnly)
{
x *= frequency;
y *= frequency;
z *= frequency;
// --- Rotation moved to TransformDomainWarpCoordinate method ---
// const FNLfloat R3 = (FNLfloat)(2.f / 3.f);
// FNLfloat r = (x + y + z) * R3; // Rotation, not skew
// x = r - x; y = r - y; z = r - z;
int i = _fnlFastRound(x);
int j = _fnlFastRound(y);
int k = _fnlFastRound(z);
float x0 = x - float(i);
float y0 = y - float(j);
float z0 = z - float(k);
int xNSign = int(-x0 - 1.f) | 1;
int yNSign = int(-y0 - 1.f) | 1;
int zNSign = int(-z0 - 1.f) | 1;
float ax0 = float(xNSign) * -x0;
float ay0 = float(yNSign) * -y0;
float az0 = float(zNSign) * -z0;
i *= PRIME_X;
j *= PRIME_Y;
k *= PRIME_Z;
float vx, vy, vz;
vx = vy = vz = 0.f;
float a = (0.6f - x0 * x0) - (y0 * y0 + z0 * z0);
for (int l = 0; l < 2; l++)
{
if (a > 0.f)
{
float aaaa = (a * a) * (a * a);
float xo, yo, zo;
if (outGradOnly)
{
_fnlGradCoordOut3D(seed, i, j, k, xo, yo, zo);
}
else
{
_fnlGradCoordDual3D(seed, i, j, k, x0, y0, z0, xo, yo, zo);
}
vx += aaaa * xo;
vy += aaaa * yo;
vz += aaaa * zo;
}
float b = a + 1.f;
int i1 = i;
int j1 = j;
int k1 = k;
float x1 = x0;
float y1 = y0;
float z1 = z0;
if (ax0 >= ay0 && ax0 >= az0)
{
x1 += float(xNSign);
b -= float(xNSign) * 2.f * x1;
i1 -= xNSign * PRIME_X;
}
else if (ay0 > ax0 && ay0 >= az0)
{
y1 += float(yNSign);
b -= float(yNSign) * 2.f * y1;
j1 -= yNSign * PRIME_Y;
}
else
{
z1 += float(zNSign);
b -= float(zNSign) * 2.f * z1;
k1 -= zNSign * PRIME_Z;
}
if (b > 0.f)
{
float bbbb = (b * b) * (b * b);
float xo, yo, zo;
if (outGradOnly)
{
_fnlGradCoordOut3D(seed, i1, j1, k1, xo, yo, zo);
}
else
{
_fnlGradCoordDual3D(seed, i1, j1, k1, x1, y1, z1, xo, yo, zo);
}
vx += bbbb * xo;
vy += bbbb * yo;
vz += bbbb * zo;
}
if (l == 1) break;
ax0 = 0.5f - ax0;
ay0 = 0.5f - ay0;
az0 = 0.5f - az0;
x0 = float(xNSign) * ax0;
y0 = float(yNSign) * ay0;
z0 = float(zNSign) * az0;
a += (0.75f - ax0) - (ay0 + az0);
i += (xNSign >> 1) & PRIME_X;
j += (yNSign >> 1) & PRIME_Y;
k += (zNSign >> 1) & PRIME_Z;
xNSign = -xNSign;
yNSign = -yNSign;
zNSign = -zNSign;
seed += 1293373;
}
xr += vx * warpAmp;
yr += vy * warpAmp;
zr += vz * warpAmp;
}
// Domain Warp Basic Grid
void _fnlSingleDomainWarpBasicGrid2D(int seed, float warpAmp, float frequency, FNLfloat x, FNLfloat y, inout FNLfloat xp, inout FNLfloat yp)
{
FNLfloat xf = x * frequency;
FNLfloat yf = y * frequency;
int x0 = _fnlFastFloor(xf);
int y0 = _fnlFastFloor(yf);
float xs = _fnlInterpHermite(xf - float(x0));
float ys = _fnlInterpHermite(yf - float(y0));
x0 *= PRIME_X;
y0 *= PRIME_Y;
int x1 = x0 + PRIME_X;
int y1 = y0 + PRIME_Y;
int idx0 = _fnlHash2D(seed, x0, y0) & (255 << 1);
int idx1 = _fnlHash2D(seed, x1, y0) & (255 << 1);
float lx0x = _fnlLerp(RAND_VECS_2D[idx0], RAND_VECS_2D[idx1], xs);
float ly0x = _fnlLerp(RAND_VECS_2D[idx0 | 1], RAND_VECS_2D[idx1 | 1], xs);
idx0 = _fnlHash2D(seed, x0, y1) & (255 << 1);
idx1 = _fnlHash2D(seed, x1, y1) & (255 << 1);
float lx1x = _fnlLerp(RAND_VECS_2D[idx0], RAND_VECS_2D[idx1], xs);
float ly1x = _fnlLerp(RAND_VECS_2D[idx0 | 1], RAND_VECS_2D[idx1 | 1], xs);
xp += _fnlLerp(lx0x, lx1x, ys) * warpAmp;
yp += _fnlLerp(ly0x, ly1x, ys) * warpAmp;
}
void _fnlSingleDomainWarpBasicGrid3D(int seed, float warpAmp, float frequency, FNLfloat x, FNLfloat y, FNLfloat z, inout FNLfloat xp, inout FNLfloat yp, inout FNLfloat zp)
{
FNLfloat xf = x * frequency;
FNLfloat yf = y * frequency;
FNLfloat zf = z * frequency;
int x0 = _fnlFastFloor(xf);
int y0 = _fnlFastFloor(yf);
int z0 = _fnlFastFloor(zf);
float xs = _fnlInterpHermite(xf - float(x0));
float ys = _fnlInterpHermite(yf - float(y0));
float zs = _fnlInterpHermite(zf - float(z0));
x0 *= PRIME_X;
y0 *= PRIME_Y;
z0 *= PRIME_Z;
int x1 = x0 + PRIME_X;
int y1 = y0 + PRIME_Y;
int z1 = z0 + PRIME_Z;
int idx0 = _fnlHash3D(seed, x0, y0, z0) & (255 << 2);
int idx1 = _fnlHash3D(seed, x1, y0, z0) & (255 << 2);
float lx0x = _fnlLerp(RAND_VECS_3D[idx0], RAND_VECS_3D[idx1], xs);
float ly0x = _fnlLerp(RAND_VECS_3D[idx0 | 1], RAND_VECS_3D[idx1 | 1], xs);
float lz0x = _fnlLerp(RAND_VECS_3D[idx0 | 2], RAND_VECS_3D[idx1 | 2], xs);
idx0 = _fnlHash3D(seed, x0, y1, z0) & (255 << 2);
idx1 = _fnlHash3D(seed, x1, y1, z0) & (255 << 2);
float lx1x = _fnlLerp(RAND_VECS_3D[idx0], RAND_VECS_3D[idx1], xs);
float ly1x = _fnlLerp(RAND_VECS_3D[idx0 | 1], RAND_VECS_3D[idx1 | 1], xs);
float lz1x = _fnlLerp(RAND_VECS_3D[idx0 | 2], RAND_VECS_3D[idx1 | 2], xs);
float lx0y = _fnlLerp(lx0x, lx1x, ys);
float ly0y = _fnlLerp(ly0x, ly1x, ys);
float lz0y = _fnlLerp(lz0x, lz1x, ys);
idx0 = _fnlHash3D(seed, x0, y0, z1) & (255 << 2);
idx1 = _fnlHash3D(seed, x1, y0, z1) & (255 << 2);
lx0x = _fnlLerp(RAND_VECS_3D[idx0], RAND_VECS_3D[idx1], xs);
ly0x = _fnlLerp(RAND_VECS_3D[idx0 | 1], RAND_VECS_3D[idx1 | 1], xs);
lz0x = _fnlLerp(RAND_VECS_3D[idx0 | 2], RAND_VECS_3D[idx1 | 2], xs);
idx0 = _fnlHash3D(seed, x0, y1, z1) & (255 << 2);
idx1 = _fnlHash3D(seed, x1, y1, z1) & (255 << 2);
lx1x = _fnlLerp(RAND_VECS_3D[idx0], RAND_VECS_3D[idx1], xs);
ly1x = _fnlLerp(RAND_VECS_3D[idx0 | 1], RAND_VECS_3D[idx1 | 1], xs);
lz1x = _fnlLerp(RAND_VECS_3D[idx0 | 2], RAND_VECS_3D[idx1 | 2], xs);
xp += _fnlLerp(lx0y, _fnlLerp(lx0x, lx1x, ys), zs) * warpAmp;
yp += _fnlLerp(ly0y, _fnlLerp(ly0x, ly1x, ys), zs) * warpAmp;
zp += _fnlLerp(lz0y, _fnlLerp(lz0x, lz1x, ys), zs) * warpAmp;
}
// Domain Warp
void _fnlDoSingleDomainWarp2D(fnl_state state, int seed, float amp, float freq, FNLfloat x, FNLfloat y, inout FNLfloat xp, inout FNLfloat yp)
{
switch (state.domain_warp_type)
{
case FNL_DOMAIN_WARP_OPENSIMPLEX2:
_fnlSingleDomainWarpSimplexGradient(seed, amp * 38.283687591552734375, freq, x, y, xp, yp, false);
break;
case FNL_DOMAIN_WARP_OPENSIMPLEX2_REDUCED:
_fnlSingleDomainWarpSimplexGradient(seed, amp * 16.f, freq, x, y, xp, yp, true);
break;
case FNL_DOMAIN_WARP_BASICGRID:
_fnlSingleDomainWarpBasicGrid2D(seed, amp, freq, x, y, xp, yp);
break;
}
}
void _fnlDoSingleDomainWarp3D(fnl_state state, int seed, float amp, float freq, FNLfloat x, FNLfloat y, FNLfloat z, inout FNLfloat xp, inout FNLfloat yp, inout FNLfloat zp)
{
switch (state.domain_warp_type)
{
case FNL_DOMAIN_WARP_OPENSIMPLEX2:
_fnlSingleDomainWarpOpenSimplex2Gradient(seed, amp * 32.69428253173828125, freq, x, y, z, xp, yp, zp, false);
break;
case FNL_DOMAIN_WARP_OPENSIMPLEX2_REDUCED:
_fnlSingleDomainWarpOpenSimplex2Gradient(seed, amp * 7.71604938271605, freq, x, y, z, xp, yp, zp, true);
break;
case FNL_DOMAIN_WARP_BASICGRID:
_fnlSingleDomainWarpBasicGrid3D(seed, amp, freq, x, y, z, xp, yp, zp);
break;
}
}
// Domain Warp Single Wrapper
void _fnlDomainWarpSingle2D(fnl_state state, inout FNLfloat x, inout FNLfloat y)
{
int seed = state.seed;
float amp = state.domain_warp_amp * _fnlCalculateFractalBounding(state);
float freq = state.frequency;
FNLfloat xs = x;
FNLfloat ys = y;
_fnlTransformDomainWarpCoordinate2D(state, xs, ys);
_fnlDoSingleDomainWarp2D(state, seed, amp, freq, xs, ys, x, y);
}
void _fnlDomainWarpSingle3D(fnl_state state, inout FNLfloat x, inout FNLfloat y, inout FNLfloat z)
{
int seed = state.seed;
float amp = state.domain_warp_amp * _fnlCalculateFractalBounding(state);
float freq = state.frequency;
FNLfloat xs = x;
FNLfloat ys = y;
FNLfloat zs = z;
_fnlTransformDomainWarpCoordinate3D(state, xs, ys, zs);
_fnlDoSingleDomainWarp3D(state, seed, amp, freq, xs, ys, zs, x, y, z);
}
// Domain Warp Fractal Progressive
void _fnlDomainWarpFractalProgressive2D(fnl_state state, inout FNLfloat x, inout FNLfloat y)
{
int seed = state.seed;
float amp = state.domain_warp_amp * _fnlCalculateFractalBounding(state);
float freq = state.frequency;
for (int i = 0; i < state.octaves; i++)
{
FNLfloat xs = x;
FNLfloat ys = y;
_fnlTransformDomainWarpCoordinate2D(state, xs, ys);
_fnlDoSingleDomainWarp2D(state, seed, amp, freq, xs, ys, x, y);
seed++;
amp *= state.gain;
freq *= state.lacunarity;
}
}
void _fnlDomainWarpFractalProgressive3D(fnl_state state, inout FNLfloat x, inout FNLfloat y, inout FNLfloat z)
{
int seed = state.seed;
float amp = state.domain_warp_amp * _fnlCalculateFractalBounding(state);
float freq = state.frequency;
for (int i = 0; i < state.octaves; i++)
{
FNLfloat xs = x;
FNLfloat ys = y;
FNLfloat zs = z;
_fnlTransformDomainWarpCoordinate3D(state, xs, ys, zs);
_fnlDoSingleDomainWarp3D(state, seed, amp, freq, xs, ys, zs, x, y, z);
seed++;
amp *= state.gain;
freq *= state.lacunarity;
}
}
// Domain Warp Fractal Independent
void _fnlDomainWarpFractalIndependent2D(fnl_state state, inout FNLfloat x, inout FNLfloat y)
{
FNLfloat xs = x;
FNLfloat ys = y;
_fnlTransformDomainWarpCoordinate2D(state, xs, ys);
int seed = state.seed;
float amp = state.domain_warp_amp * _fnlCalculateFractalBounding(state);
float freq = state.frequency;
for (int i = 0; i < state.octaves; i++)
{
_fnlDoSingleDomainWarp2D(state, seed, amp, freq, xs, ys, x, y);
seed++;
amp *= state.gain;
freq *= state.lacunarity;
}
}
void _fnlDomainWarpFractalIndependent3D(fnl_state state, inout FNLfloat x, inout FNLfloat y, inout FNLfloat z)
{
FNLfloat xs = x;
FNLfloat ys = y;
FNLfloat zs = z;
_fnlTransformDomainWarpCoordinate3D(state, xs, ys, zs);
int seed = state.seed;
float amp = state.domain_warp_amp * _fnlCalculateFractalBounding(state);
float freq = state.frequency;
for (int i = 0; i < state.octaves; i++)
{
_fnlDoSingleDomainWarp3D(state, seed, amp, freq, xs, ys, zs, x, y, z);
seed++;
amp *= state.gain;
freq *= state.lacunarity;
}
}
// ====================
// Public API
// ====================
// Creates a noise state with default values.
// @param seed Optionally set the state seed.
fnl_state fnlCreateState(int seed)
{
fnl_state newState;
newState.seed = seed;
newState.frequency = 0.01f;
newState.noise_type = FNL_NOISE_OPENSIMPLEX2;
newState.rotation_type_3d = FNL_ROTATION_NONE;
newState.fractal_type = FNL_FRACTAL_NONE;
newState.octaves = 3;
newState.lacunarity = 2.f;
newState.gain = 0.5f;
newState.weighted_strength = 0.f;
newState.ping_pong_strength = 2.f;
newState.cellular_distance_func = FNL_CELLULAR_DISTANCE_EUCLIDEANSQ;
newState.cellular_return_type = FNL_CELLULAR_RETURN_TYPE_DISTANCE;
newState.cellular_jitter_mod = 1.f;
newState.domain_warp_amp = 30.f;
newState.domain_warp_type = FNL_DOMAIN_WARP_OPENSIMPLEX2;
return newState;
}
// 2D noise at given position using the state settings
// @returns Noise output bounded between -1 and 1.
float fnlGetNoise2D(fnl_state state, FNLfloat x, FNLfloat y)
{
_fnlTransformNoiseCoordinate2D(state, x, y);
switch (state.fractal_type)
{
default:
return _fnlGenNoiseSingle2D(state, state.seed, x, y);
case FNL_FRACTAL_FBM:
return _fnlGenFractalFBM2D(state, x, y);
case FNL_FRACTAL_RIDGED:
return _fnlGenFractalRidged2D(state, x, y);
case FNL_FRACTAL_PINGPONG:
return _fnlGenFractalPingPong2D(state, x, y);
}
}
// 3D noise at given position using the state settings
// @returns Noise output bounded between -1 and 1.
float fnlGetNoise3D(fnl_state state, FNLfloat x, FNLfloat y, FNLfloat z)
{
_fnlTransformNoiseCoordinate3D(state, x, y, z);
// Select a noise type
switch (state.fractal_type)
{
default:
return _fnlGenNoiseSingle3D(state, state.seed, x, y, z);
case FNL_FRACTAL_FBM:
return _fnlGenFractalFBM3D(state, x, y, z);
case FNL_FRACTAL_RIDGED:
return _fnlGenFractalRidged3D(state, x, y, z);
case FNL_FRACTAL_PINGPONG:
return _fnlGenFractalPingPong3D(state, x, y, z);
}
}
// 2D warps the input position using current domain warp settings.
//
// Example usage with fnlGetNoise2D:
// ```
// fnlDomainWarp2D(state, x, y);
// noise = fnlGetNoise2D(state, x, y);
// ```
void fnlDomainWarp2D(fnl_state state, inout FNLfloat x, inout FNLfloat y)
{
switch (state.fractal_type)
{
default:
_fnlDomainWarpSingle2D(state, x, y);
break;
case FNL_FRACTAL_DOMAIN_WARP_PROGRESSIVE:
_fnlDomainWarpFractalProgressive2D(state, x, y);
break;
case FNL_FRACTAL_DOMAIN_WARP_INDEPENDENT:
_fnlDomainWarpFractalIndependent2D(state, x, y);
break;
}
}
// 3D warps the input position using current domain warp settings.
//
// Example usage with fnlGetNoise3D:
// ```
// fnlDomainWarp3D(state, x, y, z);
// noise = fnlGetNoise3D(state, x, y, z);
// ```
void fnlDomainWarp3D(fnl_state state, inout FNLfloat x, inout FNLfloat y, inout FNLfloat z)
{
switch (state.fractal_type)
{
default:
_fnlDomainWarpSingle3D(state, x, y, z);
break;
case FNL_FRACTAL_DOMAIN_WARP_PROGRESSIVE:
_fnlDomainWarpFractalProgressive3D(state, x, y, z);
break;
case FNL_FRACTAL_DOMAIN_WARP_INDEPENDENT:
_fnlDomainWarpFractalIndependent3D(state, x, y, z);
break;
}
}
``` | /content/code_sandbox/GLSL/FastNoiseLite.glsl | glsl | 2016-03-28T02:35:12 | 2024-08-16T07:09:20 | FastNoiseLite | Auburn/FastNoiseLite | 2,688 | 40,675 |
```c++
#include <algorithm>
#include <chrono>
#include <cstdint>
#include <sstream>
#include <imgui_app/ImGui_Application.hpp>
#include <imgui_internal.h>
#include <EGL/egl.h>
#include <GLES2/gl2.h>
#include <emscripten.h>
#include <emscripten_browser_file.h>
#include "../Cpp/FastNoiseLite.h"
#include "FastNoiseLite.h"
class FastNoiseLitePreviewApp : public ImGui_Application
{
public:
bool init() override
{
bool success = ImGui_Application::init();
set_window_title("FastNoise Lite GUI");
ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_DockingEnable;
return success;
}
uint32_t noiseTex = 0;
ImVec2 noiseTexSize;
int noiseTexSizeGenX;
int noiseTexSizeGenY;
float noiseTexMin = -1;
float noiseTexMax = 1;
int previewSize[2] = { 768, 768 };
bool preview3d = false;
float previewScroll = 0;
double previewPosZ = 0;
bool previewDomainWarp = false;
bool previewAutoSize = false;
float previewGenTime = 0;
float previewGenTimeFinal = 0;
float previewMin = 0;
float previewMinFinal = 0;
float previewMax = 0;
float previewMaxFinal = 0;
float previewMean = 0;
float previewMeanFinal = 0;
bool previewTriggerSave = false;
int previewPixelY = 0;
unsigned char* previewPixelArray = nullptr;
FastNoiseLite fnl;
FastNoiseLite fnlWarp;
int fnlNoiseType = 0;
int fnlRotationType = 0;
int fnlSeed = 1337;
float fnlFrequency = 0.01f;
int fnlFractalType = 0;
int fnlFractalOctaves = 3;
float fnlFractalLacunarity = 2.0f;
float fnlFractalGain = 0.5f;
float fnlFractalWeightedStrength = 0.0f;
float fnlFractalPingPongStrength = 2.0f;
int fnlCellularType = 1;
int fnlCellularReturnType = 1;
float fnlCellularJitter = 1.0f;
int fnlDomainWarpSeed = 1337;
float fnlDomainWarpFrequency = 0.01f;
int fnlDomainWarpType = 0;
int fnlDomainWarpRotationType = 0;
float fnlDomainWarpAmplitude = 1.0f;
int fnlDomainWarpFractalType = 0;
int fnlDomainWarpFractalOctaves = 3;
float fnlDomainWarpFractalLacunarity = 2.0f;
float fnlDomainWarpFractalGain = 0.5f;
void draw_ui() override
{
static const char* enumNoiseType[] = { "OpenSimplex2", "OpenSimplex2S", "Cellular", "Perlin", "Value Cubic", "Value" };
static const char* enumRotationType[] = { "None", "Improve XY Planes", "Improve XZ Planes" };
static const char* enumFractalType[] = { "None", "FBm", "Ridged", "Ping Pong" };
static const char* enumCellularType[] = { "Euclidean", "Euclidean Sq", "Manhattan", "Hybrid" };
static const char* enumCellularReturnType[] = { "Cell Value", "Distance", "Distance 2", "Distance 2 Add", "Distance 2 Sub", "Distance 2 Mul", "Distance 2 Div" };
static const char* enumDomainWarpType[] = { "None", "OpenSimplex2", "OpenSimplex2 Reduced", "Basic Grid" };
static const char* enumDomainWarpFractalType[] = { "None", "Progressive", "Independent" };
SetupDocking();
// ImGui::ShowDemoWindow();
bool texUpdate = false;
ImGui::Begin("Settings");
ImGui::PushItemWidth(120);
ImGui::BeginTabBar("Tabs");
if (ImGui::BeginTabItem("FastNoise Lite"))
{
/// General
ImGui::TextUnformatted("General");
if (ImGui::Combo("Noise Type", &fnlNoiseType, enumNoiseType, IM_ARRAYSIZE(enumNoiseType)))
{
fnl.SetNoiseType((FastNoiseLite::NoiseType)fnlNoiseType);
texUpdate = true;
}
ImGui::BeginDisabled(!preview3d);
if (ImGui::Combo("Rotation Type 3D", &fnlRotationType, enumRotationType, IM_ARRAYSIZE(enumRotationType)))
{
fnl.SetRotationType3D((FastNoiseLite::RotationType3D)fnlRotationType);
texUpdate = true;
}
ImGui::EndDisabled();
if (ImGui::DragInt("Seed", &fnlSeed))
{
fnl.SetSeed(fnlSeed);
texUpdate = true;
}
if (ImGui::DragFloat("Frequency", &fnlFrequency, 0.0002f))
{
fnl.SetFrequency(fnlFrequency);
texUpdate = true;
}
/// Fractal
ImGui::TextUnformatted("Fractal");
if (ImGui::Combo("Type", &fnlFractalType, enumFractalType, IM_ARRAYSIZE(enumFractalType)))
{
fnl.SetFractalType((FastNoiseLite::FractalType)fnlFractalType);
texUpdate = true;
}
ImGui::BeginDisabled(fnlFractalType == 0);
if (ImGui::DragInt("Octaves", &fnlFractalOctaves, 0.1f, 1, 20))
{
fnl.SetFractalOctaves(fnlFractalOctaves);
texUpdate = true;
}
if (ImGui::DragFloat("Lacunarity", &fnlFractalLacunarity, 0.01f))
{
fnl.SetFractalLacunarity(fnlFractalLacunarity);
texUpdate = true;
}
if (ImGui::DragFloat("Gain", &fnlFractalGain, 0.01f))
{
fnl.SetFractalGain(fnlFractalGain);
texUpdate = true;
}
if (ImGui::DragFloat("Weighted Strength", &fnlFractalWeightedStrength, 0.01f))
{
fnl.SetFractalWeightedStrength(fnlFractalWeightedStrength);
texUpdate = true;
}
ImGui::BeginDisabled(fnlFractalType != (int)FastNoiseLite::FractalType_PingPong);
if (ImGui::DragFloat("Ping Pong Strength", &fnlFractalPingPongStrength, 0.01f))
{
fnl.SetFractalPingPongStrength(fnlFractalPingPongStrength);
texUpdate = true;
}
ImGui::EndDisabled();
ImGui::EndDisabled();
/// Cellular
ImGui::TextUnformatted("Cellular");
ImGui::BeginDisabled(fnlNoiseType != (int)FastNoiseLite::NoiseType_Cellular);
if (ImGui::Combo("Distance Function", &fnlCellularType, enumCellularType, IM_ARRAYSIZE(enumCellularType)))
{
fnl.SetCellularDistanceFunction((FastNoiseLite::CellularDistanceFunction)fnlCellularType);
texUpdate = true;
}
if (ImGui::Combo("Return Type", &fnlCellularReturnType, enumCellularReturnType, IM_ARRAYSIZE(enumCellularReturnType)))
{
fnl.SetCellularReturnType((FastNoiseLite::CellularReturnType)fnlCellularReturnType);
texUpdate = true;
}
if (ImGui::DragFloat("Jitter", &fnlCellularJitter, 0.01f))
{
fnl.SetCellularJitter(fnlCellularJitter);
texUpdate = true;
}
ImGui::EndDisabled();
/// Domain Warp
ImGui::PushID("Domain Warp");
ImGui::TextUnformatted("Domain Warp");
if (ImGui::Combo("Type", &fnlDomainWarpType, enumDomainWarpType, IM_ARRAYSIZE(enumDomainWarpType)))
{
fnlWarp.SetDomainWarpType((FastNoiseLite::DomainWarpType)(fnlDomainWarpType - 1));
texUpdate = true;
}
ImGui::BeginDisabled(fnlDomainWarpType == 0);
ImGui::BeginDisabled(!preview3d);
if (ImGui::Combo("Rotation Type 3D", &fnlDomainWarpRotationType, enumRotationType, IM_ARRAYSIZE(enumRotationType)))
{
fnlWarp.SetRotationType3D((FastNoiseLite::RotationType3D)fnlDomainWarpRotationType);
texUpdate = true;
}
ImGui::EndDisabled();
if (ImGui::DragFloat("Amplitude", &fnlDomainWarpAmplitude, 0.5f))
{
fnlWarp.SetDomainWarpAmp(fnlDomainWarpAmplitude);
texUpdate = true;
}
if (ImGui::DragInt("Seed", &fnlDomainWarpSeed))
{
fnlWarp.SetSeed(fnlDomainWarpSeed);
texUpdate = true;
}
if (ImGui::DragFloat("Frequency", &fnlDomainWarpFrequency, 0.001f))
{
fnlWarp.SetFrequency(fnlDomainWarpFrequency);
texUpdate = true;
}
/// Domain Warp Fractal
ImGui::PushID("Domain Warp Fractal");
ImGui::TextUnformatted("Domain Warp Fractal");
if (ImGui::Combo("Type", &fnlDomainWarpFractalType, enumDomainWarpFractalType, IM_ARRAYSIZE(enumDomainWarpFractalType)))
{
fnlWarp.SetFractalType((FastNoiseLite::FractalType)(fnlDomainWarpFractalType ? fnlDomainWarpFractalType + 3 : 0));
texUpdate = true;
}
ImGui::BeginDisabled(fnlDomainWarpFractalType == 0);
if (ImGui::DragInt("Octaves", &fnlDomainWarpFractalOctaves, 0.1f, 1, 20))
{
fnlWarp.SetFractalOctaves(fnlDomainWarpFractalOctaves);
texUpdate = true;
}
if (ImGui::DragFloat("Lacunarity", &fnlDomainWarpFractalLacunarity, 0.01f))
{
fnlWarp.SetFractalLacunarity(fnlDomainWarpFractalLacunarity);
texUpdate = true;
}
if (ImGui::DragFloat("Gain", &fnlDomainWarpFractalGain, 0.01f))
{
fnlWarp.SetFractalGain(fnlDomainWarpFractalGain);
texUpdate = true;
}
ImGui::EndDisabled();
ImGui::EndDisabled();
ImGui::PopID();
ImGui::PopID();
ImGui::NewLine();
ImGui::TextUnformatted(FNL_VERSION);
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Preview Settings"))
{
int sizeXY[] = { (int)noiseTexSize.x, (int)noiseTexSize.y };
ImGui::Checkbox("Auto Size", &previewAutoSize);
ImGui::BeginDisabled(previewAutoSize);
ImGui::DragInt2("Size", previewSize, 1, 32, 4096);
ImGui::EndDisabled();
if (ImGui::DragFloat("Black Point", &noiseTexMin, 0.01f))
{
texUpdate = true;
}
if (ImGui::DragFloat("White Point", &noiseTexMax, 0.01f))
{
texUpdate = true;
}
if (ImGui::Checkbox("3D", &preview3d))
{
texUpdate = true;
}
if (preview3d)
{
ImGui::Indent();
ImGui::DragFloat("Scroll Speed", &previewScroll, 0.02f);
ImGui::BeginDisabled(previewScroll != 0);
float floatPosZ = (float)previewPosZ;
if (ImGui::DragFloat("Z Position", &floatPosZ))
{
previewPosZ = floatPosZ;
texUpdate = true;
}
ImGui::EndDisabled();
ImGui::Unindent();
}
ImGui::NewLine();
if (ImGui::Button("Save Preview"))
{
previewTriggerSave = true;
}
ImGui::EndTabItem();
}
ImGui::EndTabBar();
ImGui::PopItemWidth();
ImGui::End();
ImGui::Begin("Noise Texture");
if (previewAutoSize)
{
ImVec2 autoSize = ImGui::GetContentRegionAvail();
previewSize[0] = autoSize.x;
previewSize[1] = autoSize.y;
}
if (previewPixelY == 0)
{
if (noiseTexSizeGenX != previewSize[0] || noiseTexSizeGenY != previewSize[1])
{
texUpdate = true;
}
if (preview3d && previewScroll != 0)
{
previewPosZ += previewScroll;
texUpdate = true;
}
}
UpdateTexture(texUpdate);
if (previewTriggerSave && previewPixelArray && previewPixelY == 0)
{
previewTriggerSave = false;
std::string bmpFile = EncodeBMP((int)noiseTexSize.x, (int)noiseTexSize.y, previewPixelArray).str();
emscripten_browser_file::download("FastNoiseLite.bmp", "image/bmp", bmpFile);
}
ImGui::Image((void*)(intptr_t)noiseTex, noiseTexSize);
ImGui::End();
ImGui::BeginViewportSideBar("status", ImGui::GetMainViewport(), ImGuiDir_Down, 32, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);
float textOffset = 0;
ImGui::Text("Preview Stats: %0.02fms", previewGenTimeFinal);
ImGui::SameLine(textOffset += 200);
ImGui::Text("Min: %0.04f", previewMinFinal);
ImGui::SameLine(textOffset += 100);
ImGui::Text("Max: %0.04f", previewMaxFinal);
ImGui::SameLine(textOffset += 100);
ImGui::Text("Mean: %0.04f", previewMeanFinal);
ImGui::SameLine(ImGui::GetWindowWidth() - ImGui::CalcTextSize("GitHub").x - 15);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() - 2);
if (ImGui::Button("GitHub"))
{
emscripten_run_script("window.open('path_to_url '_blank').focus();");
}
ImGui::PopStyleVar();
ImGui::End();
}
void SetupDocking()
{
static ImGuiDockNodeFlags dockspace_flags = ImGuiDockNodeFlags_PassthruCentralNode;
// We are using the ImGuiWindowFlags_NoDocking flag to make the parent window not dockable into,
// because it would be confusing to have two docking targets within each others.
ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDocking;
ImGuiViewport* viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(viewport->Pos);
ImGui::SetNextWindowSize(viewport->Size);
ImGui::SetNextWindowViewport(viewport->ID);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
window_flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove;
window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus;
// When using ImGuiDockNodeFlags_PassthruCentralNode, DockSpace() will render our background and handle the pass-thru hole, so we ask Begin() to not render a background.
if (dockspace_flags & ImGuiDockNodeFlags_PassthruCentralNode)
window_flags |= ImGuiWindowFlags_NoBackground;
// Important: note that we proceed even if Begin() returns false (aka window is collapsed).
// This is because we want to keep our DockSpace() active. If a DockSpace() is inactive,
// all active windows docked into it will lose their parent and become undocked.
// We cannot preserve the docking relationship between an active window and an inactive docking, otherwise
// any change of dockspace/settings would lead to windows being stuck in limbo and never being visible.
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
ImGui::Begin("DockSpace", nullptr, window_flags);
ImGui::PopStyleVar();
ImGui::PopStyleVar(2);
// DockSpace
ImGuiIO& io = ImGui::GetIO();
if (io.ConfigFlags & ImGuiConfigFlags_DockingEnable)
{
ImGuiID dockspace_id = ImGui::GetID("MyDockSpace");
ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags);
static auto first_time = true;
if (first_time)
{
first_time = false;
ImGui::DockBuilderRemoveNode(dockspace_id); // clear any previous layout
ImGui::DockBuilderAddNode(dockspace_id, dockspace_flags | ImGuiDockNodeFlags_DockSpace);
ImGui::DockBuilderSetNodeSize(dockspace_id, viewport->Size);
float split = 280 / viewport->Size.x;
// split the dockspace into 2 nodes -- DockBuilderSplitNode takes in the following args in the following order
// window ID to split, direction, fraction (between 0 and 1), the final two setting let's us choose which id we want (which ever one we DON'T set as NULL, will be returned by the function)
// out_id_at_dir is the id of the node in the direction we specified earlier, out_id_at_opposite_dir is in the opposite direction
auto dock_id_left = ImGui::DockBuilderSplitNode(dockspace_id, ImGuiDir_Left, split, nullptr, &dockspace_id);
// we now dock our windows into the docking node we made above
ImGui::DockBuilderDockWindow("Noise Texture", dockspace_id);
ImGui::DockBuilderDockWindow("Settings", dock_id_left);
ImGui::DockBuilderGetNode(dockspace_id)->SetLocalFlags(ImGuiDockNodeFlags_NoTabBar);
ImGui::DockBuilderGetNode(dock_id_left)->SetLocalFlags(ImGuiDockNodeFlags_NoTabBar);
ImGui::DockBuilderFinish(dockspace_id);
}
}
ImGui::End();
}
std::stringstream EncodeBMP(size_t width, size_t height, unsigned char* data)
{
std::stringstream file;
struct BmpHeader
{
// File header (14)
// char b = 'B';
// char m = 'M';
uint32_t fileSize;
uint32_t reserved = 0;
uint32_t dataOffset = 14u + 12u + (256u * 3u);
// Bmp Info Header (12)
uint32_t headerSize = 12u;
uint16_t sizeX;
uint16_t sizeY;
uint16_t colorPlanes = 1u;
uint16_t bitDepth = 8u;
};
int paddedSizeX = (int)width;
int padding = paddedSizeX % 4;
if (padding)
{
padding = 4 - padding;
paddedSizeX += padding;
}
BmpHeader header;
header.fileSize = header.dataOffset + (uint32_t)(paddedSizeX * height);
header.sizeX = (uint16_t)width;
header.sizeY = (uint16_t)height;
file << 'B' << 'M';
file.write(reinterpret_cast<char*>(&header), sizeof(BmpHeader));
// Colour map
for (int i = 0; i < 256; i++)
{
char b3[] = { (char)i, (char)i, (char)i };
file.write(b3, 3);
}
int idx = 0;
for (size_t y = 0; y < height; y++)
{
for (size_t x = 0; x < height; x++)
{
file.write(reinterpret_cast<char*>(data + idx), 1);
idx += 4;
}
if (padding)
{
int zero = 0;
file.write(reinterpret_cast<char*>(&zero), padding);
}
}
return file;
}
void UpdateTexture(bool newPreview)
{
if (previewPixelY == 0 && !newPreview)
{
return;
}
if (newPreview)
{
if (previewPixelArray)
{
delete[] previewPixelArray;
}
previewPixelY = 0;
previewGenTime = 0;
noiseTexSizeGenX = previewSize[0];
noiseTexSizeGenY = previewSize[1];
previewMin = INFINITY;
previewMax = -INFINITY;
previewMean = 0;
previewPixelArray = new unsigned char[noiseTexSizeGenX * noiseTexSizeGenY * 4];
}
int index = noiseTexSizeGenX * previewPixelY * 4;
float scale = 255 / (noiseTexMax - noiseTexMin);
auto timer = std::chrono::high_resolution_clock::now();
for (int y = previewPixelY; y < noiseTexSizeGenY; y++)
{
previewPixelY = y + 1;
for (int x = 0; x < noiseTexSizeGenX; x++)
{
float noise;
double posX = (double)(x - noiseTexSizeGenX / 2);
double posY = (double)(y - noiseTexSizeGenY / 2);
if (preview3d)
{
double posZ = previewPosZ;
if (fnlDomainWarpType > 0)
{
fnlWarp.DomainWarp(posX, posY, posZ);
}
noise = fnl.GetNoise(posX, posY, posZ);
}
else
{
if (fnlDomainWarpType > 0)
{
fnlWarp.DomainWarp(posX, posY);
}
noise = fnl.GetNoise(posX, posY);
}
unsigned char cNoise = (unsigned char)std::max(0.0f, std::min(255.0f, (noise - noiseTexMin) * scale));
previewPixelArray[index++] = cNoise;
previewPixelArray[index++] = cNoise;
previewPixelArray[index++] = cNoise;
previewPixelArray[index++] = 255;
previewMin = std::min(previewMin, noise);
previewMax = std::max(previewMax, noise);
previewMean += noise;
}
if ((y % 8) == 0 && std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - timer).count() >= 80)
{
break;
}
}
previewGenTime += std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now() - timer).count() / 1000000.f;
if (previewPixelY >= noiseTexSizeGenY)
{
noiseTexSize.x = noiseTexSizeGenX;
noiseTexSize.y = noiseTexSizeGenY;
previewPixelY = 0;
previewMeanFinal = previewMean / (noiseTexSize.x * noiseTexSize.y);
previewMinFinal = previewMin;
previewMaxFinal = previewMax;
previewGenTimeFinal = previewGenTime;
if (noiseTex != 0)
{
glDeleteTextures(1, &noiseTex);
}
// Create a OpenGL texture identifier
glGenTextures(1, &noiseTex);
glBindTexture(GL_TEXTURE_2D, noiseTex);
// Setup filtering parameters for display
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // This is required on WebGL for non power-of-two textures
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // Same
// Upload pixels into texture
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, noiseTexSizeGenX, noiseTexSizeGenY, 0, GL_RGBA, GL_UNSIGNED_BYTE, previewPixelArray);
}
}
};
int main()
{
FastNoiseLitePreviewApp app;
if (!app.init())
return 1;
app.run_main_loop();
return 0;
}
``` | /content/code_sandbox/WebPreviewApp/main.cpp | c++ | 2016-03-28T02:35:12 | 2024-08-16T07:09:20 | FastNoiseLite | Auburn/FastNoiseLite | 2,688 | 5,587 |
```powershell
$scriptPath = $PSScriptRoot
$emsdkVer = "3.1.52"
$emsdkPath = Join-Path -Path $PSScriptRoot -ChildPath "emsdk" | Join-Path -ChildPath $emsdkVer
if (Test-Path -Path $emsdkPath -PathType Container) {
Write-Host "Found existing emsdk"
& "$emsdkPath\emsdk_env.ps1"
} else {
Write-Host "Building emsdk"
git clone --branch $emsdkVer "path_to_url" $emsdkPath
& "$emsdkPath\emsdk.ps1" install $emsdkVer
& "$emsdkPath\emsdk.ps1" activate $emsdkVer
}
emcc --version
emcmake cmake -Bbuild -DCMAKE_BUILD_TYPE=Release
cmake --build build
``` | /content/code_sandbox/WebPreviewApp/build.ps1 | powershell | 2016-03-28T02:35:12 | 2024-08-16T07:09:20 | FastNoiseLite | Auburn/FastNoiseLite | 2,688 | 191 |
```hlsl
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// .'',;:cldxkO00KKXXNNWWWNNXKOkxdollcc::::::;:::ccllloooolllllllllooollc:,'... ...........',;cldxkO000Okxdlc::;;;,,;;;::cclllllll
// ..',;:ldxO0KXXNNNNNNNNXXK0kxdolcc::::::;;;,,,,,,;;;;;;;;;;:::cclllllc:;'.... ...........',;:ldxO0KXXXK0Okxdolc::;;;;::cllodddddo
// ...',:loxO0KXNNNNNXXKK0Okxdolc::;::::::::;;;,,'''''.....''',;:clllllc:;,'............''''''''',;:loxO0KXNNNNNXK0Okxdollccccllodxxxxxxd
// ....';:ldkO0KXXXKK00Okxdolcc:;;;;;::cclllcc:;;,''..... ....',;clooddolcc:;;;;,,;;;;;::::;;;;;;:cloxk0KXNWWWWWWNXKK0Okxddoooddxxkkkkkxx
// .....';:ldxkOOOOOkxxdolcc:;;;,,,;;:cllooooolcc:;'... ..,:codxkkkxddooollloooooooollcc:::::clodkO0KXNWWWWWWNNXK00Okxxxxxxxxkkkkxxx
// . ....';:cloddddo___________,,,,;;:clooddddoolc:,... ..,:ldx__00OOOkkk___kkkkkkxxdollc::::cclodkO0KXXNNNNNNXXK0OOkxxxxxxxxxxxxddd
// .......',;:cccc:| |,,,;;:cclooddddoll:;'.. ..';cox| \KKK000| |KK00OOkxdocc___;::clldxxkO0KKKKK00Okkxdddddddddddddddoo
// .......'',,,,,''| ________|',,;;::cclloooooolc:;'......___:ldk| \KK000| |XKKK0Okxolc| |;;::cclodxxkkkkxxdoolllcclllooodddooooo
// ''......''''....| | ....'',,,,;;;::cclloooollc:;,''.'| |oxk| \OOO0| |KKK00Oxdoll|___|;;;;;::ccllllllcc::;;,,;;;:cclloooooooo
// ;;,''.......... | |_____',,;;;____:___cllo________.___| |___| \xkk| |KK_______ool___:::;________;;;_______...'',;;:ccclllloo
// c:;,''......... | |:::/ ' |lo/ | | \dx| |0/ \d| |cc/ |'/ \......',,;;:ccllo
// ol:;,'..........| _____|ll/ __ |o/ ______|____ ___| | \o| |/ ___ \| |o/ ______|/ ___ \ .......'',;:clo
// dlc;,...........| |::clooo| / | |x\___ \KXKKK0| |dol| |\ \| | | | | |d\___ \..| | / / ....',:cl
// xoc;'... .....'| |llodddd| \__| |_____\ \KKK0O| |lc:| |'\ | |___| | |_____\ \.| |_/___/... ...',;:c
// dlc;'... ....',;| |oddddddo\ | |Okkx| |::;| |..\ |\ /| | | \ |... ....',;:c
// ol:,'.......',:c|___|xxxddollc\_____,___|_________/ddoll|___|,,,|___|...\_____|:\ ______/l|___|_________/...\________|'........',;::cc
// c:;'.......';:codxxkkkkxxolc::;::clodxkOO0OOkkxdollc::;;,,''''',,,,''''''''''',,'''''',;:loxkkOOkxol:;,'''',,;:ccllcc:;,'''''',;::ccll
// ;,'.......',:codxkOO0OOkxdlc:;,,;;:cldxxkkxxdolc:;;,,''.....'',;;:::;;,,,'''''........,;cldkO0KK0Okdoc::;;::cloodddoolc:;;;;;::ccllooo
// .........',;:lodxOO0000Okdoc:,,',,;:clloddoolc:;,''.......'',;:clooollc:;;,,''.......',:ldkOKXNNXX0Oxdolllloddxxxxxxdolccccccllooodddd
// . .....';:cldxkO0000Okxol:;,''',,;::cccc:;,,'.......'',;:cldxxkkxxdolc:;;,'.......';coxOKXNWWWNXKOkxddddxxkkkkkkxdoollllooddxxxxkkk
// ....',;:codxkO000OOxdoc:;,''',,,;;;;,''.......',,;:clodkO00000Okxolc::;,,''..',;:ldxOKXNWWWNNK0OkkkkkkkkkkkxxddooooodxxkOOOOO000
// ....',;;clodxkkOOOkkdolc:;,,,,,,,,'..........,;:clodxkO0KKXKK0Okxdolcc::;;,,,;;:codkO0XXNNNNXKK0OOOOOkkkkxxdoollloodxkO0KKKXXXXX
//
// VERSION: 1.1.1
// path_to_url
// Switch between using floats or doubles for input position
typedef float FNLfloat;
//typedef double FNLfloat;
// Noise Type
#define FNL_NOISE_OPENSIMPLEX2 0
#define FNL_NOISE_OPENSIMPLEX2S 1
#define FNL_NOISE_CELLULAR 2
#define FNL_NOISE_PERLIN 3
#define FNL_NOISE_VALUE_CUBIC 4
#define FNL_NOISE_VALUE 5
typedef int fnl_noise_type;
// Rotation types
#define FNL_ROTATION_NONE 0
#define FNL_ROTATION_IMPROVE_XY_PLANES 1
#define FNL_ROTATION_IMPROVE_XZ_PLANES 2
typedef int fnl_rotation_type_3d;
// Fractal types
#define FNL_FRACTAL_NONE 0
#define FNL_FRACTAL_FBM 1
#define FNL_FRACTAL_RIDGED 2
#define FNL_FRACTAL_PINGPONG 3
#define FNL_FRACTAL_DOMAIN_WARP_PROGRESSIVE 4
#define FNL_FRACTAL_DOMAIN_WARP_INDEPENDENT 5
typedef int fnl_fractal_type;
#define FNL_CELLULAR_DISTANCE_EUCLIDEAN 0
#define FNL_CELLULAR_DISTANCE_EUCLIDEANSQ 1
#define FNL_CELLULAR_DISTANCE_MANHATTAN 2
#define FNL_CELLULAR_DISTANCE_HYBRID 3
typedef int fnl_cellular_distance_func;
#define FNL_CELLULAR_RETURN_TYPE_CELLVALUE 0
#define FNL_CELLULAR_RETURN_TYPE_DISTANCE 1
#define FNL_CELLULAR_RETURN_TYPE_DISTANCE2 2
#define FNL_CELLULAR_RETURN_TYPE_DISTANCE2ADD 3
#define FNL_CELLULAR_RETURN_TYPE_DISTANCE2SUB 4
#define FNL_CELLULAR_RETURN_TYPE_DISTANCE2MUL 5
#define FNL_CELLULAR_RETURN_TYPE_DISTANCE2DIV 6
typedef int fnl_cellular_return_type;
#define FNL_DOMAIN_WARP_OPENSIMPLEX2 0
#define FNL_DOMAIN_WARP_OPENSIMPLEX2_REDUCED 1
#define FNL_DOMAIN_WARP_BASICGRID 2
typedef int fnl_domain_warp_type;
// Removes [0x80004005 - unknown error] 'internal error: no storage type for block output'
#if UNITY_VERSION
#define FNL_FLATTEN [flatten]
#define FNL_UNROLL [unroll(1)]
#else
#define FNL_FLATTEN
#define FNL_UNROLL
#endif
/**
* Structure containing entire noise system state.
* @note Must only be created using fnlCreateState(optional: seed). To ensure defaults are set.
*/
struct fnl_state
{
/**
* Seed used for all noise types.
* @remark Default: 1337
*/
int seed;
/**
* The frequency for all noise types.
* @remark Default: 0.01
*/
float frequency;
/**
* The noise algorithm to be used by GetNoise(...).
* @remark Default: FNL_NOISE_OPENSIMPLEX2
*/
fnl_noise_type noise_type;
/**
* Sets noise rotation type for 3D.
* @remark Default: FNL_ROTATION_NONE
*/
fnl_rotation_type_3d rotation_type_3d;
/**
* The method used for combining octaves for all fractal noise types.
* @remark Default: None
* @remark FNL_FRACTAL_DOMAIN_WARP_... only effects fnlDomainWarp...
*/
fnl_fractal_type fractal_type;
/**
* The octave count for all fractal noise types.
* @remark Default: 3
*/
int octaves;
/**
* The octave lacunarity for all fractal noise types.
* @remark Default: 2.0
*/
float lacunarity;
/**
* The octave gain for all fractal noise types.
* @remark Default: 0.5
*/
float gain;
/**
* The octave weighting for all none Domaain Warp fractal types.
* @remark Default: 0.0
* @remark
*/
float weighted_strength;
/**
* The strength of the fractal ping pong effect.
* @remark Default: 2.0
*/
float ping_pong_strength;
/**
* The distance function used in cellular noise calculations.
* @remark Default: FNL_CELLULAR_DISTANCE_EUCLIDEANSQ
*/
fnl_cellular_distance_func cellular_distance_func;
/**
* The cellular return type from cellular noise calculations.
* @remark Default: FNL_CELLULAR_RETURN_TYPE_DISTANCE
*/
fnl_cellular_return_type cellular_return_type;
/**
* The maximum distance a cellular point can move from it's grid position.
* @remark Default: 1.0
* @note Setting this higher than 1 will cause artifacts.
*/
float cellular_jitter_mod;
/**
* The warp algorithm when using fnlDomainWarp...
* @remark Default: OpenSimplex2
*/
fnl_domain_warp_type domain_warp_type;
/**
* The maximum warp distance from original position when using fnlDomainWarp...
* @remark Default: 1.0
*/
float domain_warp_amp;
};
/**
* Creates a noise state with default values.
* @param seed Optionally set the state seed.
*/
fnl_state fnlCreateState(int seed = 1337);
/**
* 2D noise at given position using the state settings
* @returns Noise output bounded between -1 and 1.
*/
float fnlGetNoise2D(fnl_state state, FNLfloat x, FNLfloat y);
/**
* 3D noise at given position using the state settings
* @returns Noise output bounded between -1 and 1.
*/
float fnlGetNoise3D(fnl_state state, FNLfloat x, FNLfloat y, FNLfloat z);
/**
* 2D warps the input position using current domain warp settings.
*
* Example usage with fnlGetNoise2D:
* ```
* fnlDomainWarp2D(state, x, y);
* noise = fnlGetNoise2D(state, x, y);
* ```
*/
void fnlDomainWarp2D(fnl_state state, inout FNLfloat x, inout FNLfloat y);
/**
* 3D warps the input position using current domain warp settings.
*
* Example usage with fnlGetNoise3D:
* ```
* fnlDomainWarp3D(state, x, y, z);
* noise = fnlGetNoise3D(state, x, y, z);
* ```
*/
void fnlDomainWarp3D(fnl_state state, inout FNLfloat x, inout FNLfloat y, inout FNLfloat z);
// From here on, this is private implementation
// Constants
static const float GRADIENTS_2D[] =
{
0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, 0.793353340291235f, 0.793353340291235f, 0.608761429008721f,
0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, -0.130526192220051f, 0.923879532511287f, -0.38268343236509f,
0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, -0.923879532511287f, 0.130526192220052f, -0.99144486137381f,
-0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, -0.793353340291235f, -0.793353340291235f, -0.608761429008721f,
-0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, 0.130526192220051f, -0.923879532511287f, 0.38268343236509f,
-0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, 0.923879532511287f, -0.130526192220052f, 0.99144486137381f,
0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, 0.793353340291235f, 0.793353340291235f, 0.608761429008721f,
0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, -0.130526192220051f, 0.923879532511287f, -0.38268343236509f,
0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, -0.923879532511287f, 0.130526192220052f, -0.99144486137381f,
-0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, -0.793353340291235f, -0.793353340291235f, -0.608761429008721f,
-0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, 0.130526192220051f, -0.923879532511287f, 0.38268343236509f,
-0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, 0.923879532511287f, -0.130526192220052f, 0.99144486137381f,
0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, 0.793353340291235f, 0.793353340291235f, 0.608761429008721f,
0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, -0.130526192220051f, 0.923879532511287f, -0.38268343236509f,
0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, -0.923879532511287f, 0.130526192220052f, -0.99144486137381f,
-0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, -0.793353340291235f, -0.793353340291235f, -0.608761429008721f,
-0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, 0.130526192220051f, -0.923879532511287f, 0.38268343236509f,
-0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, 0.923879532511287f, -0.130526192220052f, 0.99144486137381f,
0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, 0.793353340291235f, 0.793353340291235f, 0.608761429008721f,
0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, -0.130526192220051f, 0.923879532511287f, -0.38268343236509f,
0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, -0.923879532511287f, 0.130526192220052f, -0.99144486137381f,
-0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, -0.793353340291235f, -0.793353340291235f, -0.608761429008721f,
-0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, 0.130526192220051f, -0.923879532511287f, 0.38268343236509f,
-0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, 0.923879532511287f, -0.130526192220052f, 0.99144486137381f,
0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, 0.793353340291235f, 0.793353340291235f, 0.608761429008721f,
0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, -0.130526192220051f, 0.923879532511287f, -0.38268343236509f,
0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, -0.923879532511287f, 0.130526192220052f, -0.99144486137381f,
-0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, -0.793353340291235f, -0.793353340291235f, -0.608761429008721f,
-0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, 0.130526192220051f, -0.923879532511287f, 0.38268343236509f,
-0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, 0.923879532511287f, -0.130526192220052f, 0.99144486137381f,
0.38268343236509f, 0.923879532511287f, 0.923879532511287f, 0.38268343236509f, 0.923879532511287f, -0.38268343236509f, 0.38268343236509f, -0.923879532511287f,
-0.38268343236509f, -0.923879532511287f, -0.923879532511287f, -0.38268343236509f, -0.923879532511287f, 0.38268343236509f, -0.38268343236509f, 0.923879532511287f,
};
static const float RAND_VECS_2D[] =
{
-0.2700222198f, -0.9628540911f, 0.3863092627f, -0.9223693152f, 0.04444859006f, -0.999011673f, -0.5992523158f, -0.8005602176f, -0.7819280288f, 0.6233687174f, 0.9464672271f, 0.3227999196f, -0.6514146797f, -0.7587218957f, 0.9378472289f, 0.347048376f,
-0.8497875957f, -0.5271252623f, -0.879042592f, 0.4767432447f, -0.892300288f, -0.4514423508f, -0.379844434f, -0.9250503802f, -0.9951650832f, 0.0982163789f, 0.7724397808f, -0.6350880136f, 0.7573283322f, -0.6530343002f, -0.9928004525f, -0.119780055f,
-0.0532665713f, 0.9985803285f, 0.9754253726f, -0.2203300762f, -0.7665018163f, 0.6422421394f, 0.991636706f, 0.1290606184f, -0.994696838f, 0.1028503788f, -0.5379205513f, -0.84299554f, 0.5022815471f, -0.8647041387f, 0.4559821461f, -0.8899889226f,
-0.8659131224f, -0.5001944266f, 0.0879458407f, -0.9961252577f, -0.5051684983f, 0.8630207346f, 0.7753185226f, -0.6315704146f, -0.6921944612f, 0.7217110418f, -0.5191659449f, -0.8546734591f, 0.8978622882f, -0.4402764035f, -0.1706774107f, 0.9853269617f,
-0.9353430106f, -0.3537420705f, -0.9992404798f, 0.03896746794f, -0.2882064021f, -0.9575683108f, -0.9663811329f, 0.2571137995f, -0.8759714238f, -0.4823630009f, -0.8303123018f, -0.5572983775f, 0.05110133755f, -0.9986934731f, -0.8558373281f, -0.5172450752f,
0.09887025282f, 0.9951003332f, 0.9189016087f, 0.3944867976f, -0.2439375892f, -0.9697909324f, -0.8121409387f, -0.5834613061f, -0.9910431363f, 0.1335421355f, 0.8492423985f, -0.5280031709f, -0.9717838994f, -0.2358729591f, 0.9949457207f, 0.1004142068f,
0.6241065508f, -0.7813392434f, 0.662910307f, 0.7486988212f, -0.7197418176f, 0.6942418282f, -0.8143370775f, -0.5803922158f, 0.104521054f, -0.9945226741f, -0.1065926113f, -0.9943027784f, 0.445799684f, -0.8951327509f, 0.105547406f, 0.9944142724f,
-0.992790267f, 0.1198644477f, -0.8334366408f, 0.552615025f, 0.9115561563f, -0.4111755999f, 0.8285544909f, -0.5599084351f, 0.7217097654f, -0.6921957921f, 0.4940492677f, -0.8694339084f, -0.3652321272f, -0.9309164803f, -0.9696606758f, 0.2444548501f,
0.08925509731f, -0.996008799f, 0.5354071276f, -0.8445941083f, -0.1053576186f, 0.9944343981f, -0.9890284586f, 0.1477251101f, 0.004856104961f, 0.9999882091f, 0.9885598478f, 0.1508291331f, 0.9286129562f, -0.3710498316f, -0.5832393863f, -0.8123003252f,
0.3015207509f, 0.9534596146f, -0.9575110528f, 0.2883965738f, 0.9715802154f, -0.2367105511f, 0.229981792f, 0.9731949318f, 0.955763816f, -0.2941352207f, 0.740956116f, 0.6715534485f, -0.9971513787f, -0.07542630764f, 0.6905710663f, -0.7232645452f,
-0.290713703f, -0.9568100872f, 0.5912777791f, -0.8064679708f, -0.9454592212f, -0.325740481f, 0.6664455681f, 0.74555369f, 0.6236134912f, 0.7817328275f, 0.9126993851f, -0.4086316587f, -0.8191762011f, 0.5735419353f, -0.8812745759f, -0.4726046147f,
0.9953313627f, 0.09651672651f, 0.9855650846f, -0.1692969699f, -0.8495980887f, 0.5274306472f, 0.6174853946f, -0.7865823463f, 0.8508156371f, 0.52546432f, 0.9985032451f, -0.05469249926f, 0.1971371563f, -0.9803759185f, 0.6607855748f, -0.7505747292f,
-0.03097494063f, 0.9995201614f, -0.6731660801f, 0.739491331f, -0.7195018362f, -0.6944905383f, 0.9727511689f, 0.2318515979f, 0.9997059088f, -0.0242506907f, 0.4421787429f, -0.8969269532f, 0.9981350961f, -0.061043673f, -0.9173660799f, -0.3980445648f,
-0.8150056635f, -0.5794529907f, -0.8789331304f, 0.4769450202f, 0.0158605829f, 0.999874213f, -0.8095464474f, 0.5870558317f, -0.9165898907f, -0.3998286786f, -0.8023542565f, 0.5968480938f, -0.5176737917f, 0.8555780767f, -0.8154407307f, -0.5788405779f,
0.4022010347f, -0.9155513791f, -0.9052556868f, -0.4248672045f, 0.7317445619f, 0.6815789728f, -0.5647632201f, -0.8252529947f, -0.8403276335f, -0.5420788397f, -0.9314281527f, 0.363925262f, 0.5238198472f, 0.8518290719f, 0.7432803869f, -0.6689800195f,
-0.985371561f, -0.1704197369f, 0.4601468731f, 0.88784281f, 0.825855404f, 0.5638819483f, 0.6182366099f, 0.7859920446f, 0.8331502863f, -0.553046653f, 0.1500307506f, 0.9886813308f, -0.662330369f, -0.7492119075f, -0.668598664f, 0.743623444f,
0.7025606278f, 0.7116238924f, -0.5419389763f, -0.8404178401f, -0.3388616456f, 0.9408362159f, 0.8331530315f, 0.5530425174f, -0.2989720662f, -0.9542618632f, 0.2638522993f, 0.9645630949f, 0.124108739f, -0.9922686234f, -0.7282649308f, -0.6852956957f,
0.6962500149f, 0.7177993569f, -0.9183535368f, 0.3957610156f, -0.6326102274f, -0.7744703352f, -0.9331891859f, -0.359385508f, -0.1153779357f, -0.9933216659f, 0.9514974788f, -0.3076565421f, -0.08987977445f, -0.9959526224f, 0.6678496916f, 0.7442961705f,
0.7952400393f, -0.6062947138f, -0.6462007402f, -0.7631674805f, -0.2733598753f, 0.9619118351f, 0.9669590226f, -0.254931851f, -0.9792894595f, 0.2024651934f, -0.5369502995f, -0.8436138784f, -0.270036471f, -0.9628500944f, -0.6400277131f, 0.7683518247f,
-0.7854537493f, -0.6189203566f, 0.06005905383f, -0.9981948257f, -0.02455770378f, 0.9996984141f, -0.65983623f, 0.751409442f, -0.6253894466f, -0.7803127835f, -0.6210408851f, -0.7837781695f, 0.8348888491f, 0.5504185768f, -0.1592275245f, 0.9872419133f,
0.8367622488f, 0.5475663786f, -0.8675753916f, -0.4973056806f, -0.2022662628f, -0.9793305667f, 0.9399189937f, 0.3413975472f, 0.9877404807f, -0.1561049093f, -0.9034455656f, 0.4287028224f, 0.1269804218f, -0.9919052235f, -0.3819600854f, 0.924178821f,
0.9754625894f, 0.2201652486f, -0.3204015856f, -0.9472818081f, -0.9874760884f, 0.1577687387f, 0.02535348474f, -0.9996785487f, 0.4835130794f, -0.8753371362f, -0.2850799925f, -0.9585037287f, -0.06805516006f, -0.99768156f, -0.7885244045f, -0.6150034663f,
0.3185392127f, -0.9479096845f, 0.8880043089f, 0.4598351306f, 0.6476921488f, -0.7619021462f, 0.9820241299f, 0.1887554194f, 0.9357275128f, -0.3527237187f, -0.8894895414f, 0.4569555293f, 0.7922791302f, 0.6101588153f, 0.7483818261f, 0.6632681526f,
-0.7288929755f, -0.6846276581f, 0.8729032783f, -0.4878932944f, 0.8288345784f, 0.5594937369f, 0.08074567077f, 0.9967347374f, 0.9799148216f, -0.1994165048f, -0.580730673f, -0.8140957471f, -0.4700049791f, -0.8826637636f, 0.2409492979f, 0.9705377045f,
0.9437816757f, -0.3305694308f, -0.8927998638f, -0.4504535528f, -0.8069622304f, 0.5906030467f, 0.06258973166f, 0.9980393407f, -0.9312597469f, 0.3643559849f, 0.5777449785f, 0.8162173362f, -0.3360095855f, -0.941858566f, 0.697932075f, -0.7161639607f,
-0.002008157227f, -0.9999979837f, -0.1827294312f, -0.9831632392f, -0.6523911722f, 0.7578824173f, -0.4302626911f, -0.9027037258f, -0.9985126289f, -0.05452091251f, -0.01028102172f, -0.9999471489f, -0.4946071129f, 0.8691166802f, -0.2999350194f, 0.9539596344f,
0.8165471961f, 0.5772786819f, 0.2697460475f, 0.962931498f, -0.7306287391f, -0.6827749597f, -0.7590952064f, -0.6509796216f, -0.907053853f, 0.4210146171f, -0.5104861064f, -0.8598860013f, 0.8613350597f, 0.5080373165f, 0.5007881595f, -0.8655698812f,
-0.654158152f, 0.7563577938f, -0.8382755311f, -0.545246856f, 0.6940070834f, 0.7199681717f, 0.06950936031f, 0.9975812994f, 0.1702942185f, -0.9853932612f, 0.2695973274f, 0.9629731466f, 0.5519612192f, -0.8338697815f, 0.225657487f, -0.9742067022f,
0.4215262855f, -0.9068161835f, 0.4881873305f, -0.8727388672f, -0.3683854996f, -0.9296731273f, -0.9825390578f, 0.1860564427f, 0.81256471f, 0.5828709909f, 0.3196460933f, -0.9475370046f, 0.9570913859f, 0.2897862643f, -0.6876655497f, -0.7260276109f,
-0.9988770922f, -0.047376731f, -0.1250179027f, 0.992154486f, -0.8280133617f, 0.560708367f, 0.9324863769f, -0.3612051451f, 0.6394653183f, 0.7688199442f, -0.01623847064f, -0.9998681473f, -0.9955014666f, -0.09474613458f, -0.81453315f, 0.580117012f,
0.4037327978f, -0.9148769469f, 0.9944263371f, 0.1054336766f, -0.1624711654f, 0.9867132919f, -0.9949487814f, -0.100383875f, -0.6995302564f, 0.7146029809f, 0.5263414922f, -0.85027327f, -0.5395221479f, 0.841971408f, 0.6579370318f, 0.7530729462f,
0.01426758847f, -0.9998982128f, -0.6734383991f, 0.7392433447f, 0.639412098f, -0.7688642071f, 0.9211571421f, 0.3891908523f, -0.146637214f, -0.9891903394f, -0.782318098f, 0.6228791163f, -0.5039610839f, -0.8637263605f, -0.7743120191f, -0.6328039957f,
};
static const float GRADIENTS_3D[] =
{
0, 1, 1, 0, 0,-1, 1, 0, 0, 1,-1, 0, 0,-1,-1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0,-1, 0, -1, 0,-1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1,-1, 0, 0, -1,-1, 0, 0,
0, 1, 1, 0, 0,-1, 1, 0, 0, 1,-1, 0, 0,-1,-1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0,-1, 0, -1, 0,-1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1,-1, 0, 0, -1,-1, 0, 0,
0, 1, 1, 0, 0,-1, 1, 0, 0, 1,-1, 0, 0,-1,-1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0,-1, 0, -1, 0,-1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1,-1, 0, 0, -1,-1, 0, 0,
0, 1, 1, 0, 0,-1, 1, 0, 0, 1,-1, 0, 0,-1,-1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0,-1, 0, -1, 0,-1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1,-1, 0, 0, -1,-1, 0, 0,
0, 1, 1, 0, 0,-1, 1, 0, 0, 1,-1, 0, 0,-1,-1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0,-1, 0, -1, 0,-1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1,-1, 0, 0, -1,-1, 0, 0,
1, 1, 0, 0, 0,-1, 1, 0, -1, 1, 0, 0, 0,-1,-1, 0
};
static const float RAND_VECS_3D[] =
{
-0.7292736885f, -0.6618439697f, 0.1735581948f, 0, 0.790292081f, -0.5480887466f, -0.2739291014f, 0, 0.7217578935f, 0.6226212466f, -0.3023380997f, 0, 0.565683137f, -0.8208298145f, -0.0790000257f, 0, 0.760049034f, -0.5555979497f, -0.3370999617f, 0, 0.3713945616f, 0.5011264475f, 0.7816254623f, 0, -0.1277062463f, -0.4254438999f, -0.8959289049f, 0, -0.2881560924f, -0.5815838982f, 0.7607405838f, 0,
0.5849561111f, -0.662820239f, -0.4674352136f, 0, 0.3307171178f, 0.0391653737f, 0.94291689f, 0, 0.8712121778f, -0.4113374369f, -0.2679381538f, 0, 0.580981015f, 0.7021915846f, 0.4115677815f, 0, 0.503756873f, 0.6330056931f, -0.5878203852f, 0, 0.4493712205f, 0.601390195f, 0.6606022552f, 0, -0.6878403724f, 0.09018890807f, -0.7202371714f, 0, -0.5958956522f, -0.6469350577f, 0.475797649f, 0,
-0.5127052122f, 0.1946921978f, -0.8361987284f, 0, -0.9911507142f, -0.05410276466f, -0.1212153153f, 0, -0.2149721042f, 0.9720882117f, -0.09397607749f, 0, -0.7518650936f, -0.5428057603f, 0.3742469607f, 0, 0.5237068895f, 0.8516377189f, -0.02107817834f, 0, 0.6333504779f, 0.1926167129f, -0.7495104896f, 0, -0.06788241606f, 0.3998305789f, 0.9140719259f, 0, -0.5538628599f, -0.4729896695f, -0.6852128902f, 0,
-0.7261455366f, -0.5911990757f, 0.3509933228f, 0, -0.9229274737f, -0.1782808786f, 0.3412049336f, 0, -0.6968815002f, 0.6511274338f, 0.3006480328f, 0, 0.9608044783f, -0.2098363234f, -0.1811724921f, 0, 0.06817146062f, -0.9743405129f, 0.2145069156f, 0, -0.3577285196f, -0.6697087264f, -0.6507845481f, 0, -0.1868621131f, 0.7648617052f, -0.6164974636f, 0, -0.6541697588f, 0.3967914832f, 0.6439087246f, 0,
0.6993340405f, -0.6164538506f, 0.3618239211f, 0, -0.1546665739f, 0.6291283928f, 0.7617583057f, 0, -0.6841612949f, -0.2580482182f, -0.6821542638f, 0, 0.5383980957f, 0.4258654885f, 0.7271630328f, 0, -0.5026987823f, -0.7939832935f, -0.3418836993f, 0, 0.3202971715f, 0.2834415347f, 0.9039195862f, 0, 0.8683227101f, -0.0003762656404f, -0.4959995258f, 0, 0.791120031f, -0.08511045745f, 0.6057105799f, 0,
-0.04011016052f, -0.4397248749f, 0.8972364289f, 0, 0.9145119872f, 0.3579346169f, -0.1885487608f, 0, -0.9612039066f, -0.2756484276f, 0.01024666929f, 0, 0.6510361721f, -0.2877799159f, -0.7023778346f, 0, -0.2041786351f, 0.7365237271f, 0.644859585f, 0, -0.7718263711f, 0.3790626912f, 0.5104855816f, 0, -0.3060082741f, -0.7692987727f, 0.5608371729f, 0, 0.454007341f, -0.5024843065f, 0.7357899537f, 0,
0.4816795475f, 0.6021208291f, -0.6367380315f, 0, 0.6961980369f, -0.3222197429f, 0.641469197f, 0, -0.6532160499f, -0.6781148932f, 0.3368515753f, 0, 0.5089301236f, -0.6154662304f, -0.6018234363f, 0, -0.1635919754f, -0.9133604627f, -0.372840892f, 0, 0.52408019f, -0.8437664109f, 0.1157505864f, 0, 0.5902587356f, 0.4983817807f, -0.6349883666f, 0, 0.5863227872f, 0.494764745f, 0.6414307729f, 0,
0.6779335087f, 0.2341345225f, 0.6968408593f, 0, 0.7177054546f, -0.6858979348f, 0.120178631f, 0, -0.5328819713f, -0.5205125012f, 0.6671608058f, 0, -0.8654874251f, -0.0700727088f, -0.4960053754f, 0, -0.2861810166f, 0.7952089234f, 0.5345495242f, 0, -0.04849529634f, 0.9810836427f, -0.1874115585f, 0, -0.6358521667f, 0.6058348682f, 0.4781800233f, 0, 0.6254794696f, -0.2861619734f, 0.7258696564f, 0,
-0.2585259868f, 0.5061949264f, -0.8227581726f, 0, 0.02136306781f, 0.5064016808f, -0.8620330371f, 0, 0.200111773f, 0.8599263484f, 0.4695550591f, 0, 0.4743561372f, 0.6014985084f, -0.6427953014f, 0, 0.6622993731f, -0.5202474575f, -0.5391679918f, 0, 0.08084972818f, -0.6532720452f, 0.7527940996f, 0, -0.6893687501f, 0.0592860349f, 0.7219805347f, 0, -0.1121887082f, -0.9673185067f, 0.2273952515f, 0,
0.7344116094f, 0.5979668656f, -0.3210532909f, 0, 0.5789393465f, -0.2488849713f, 0.7764570201f, 0, 0.6988182827f, 0.3557169806f, -0.6205791146f, 0, -0.8636845529f, -0.2748771249f, -0.4224826141f, 0, -0.4247027957f, -0.4640880967f, 0.777335046f, 0, 0.5257722489f, -0.8427017621f, 0.1158329937f, 0, 0.9343830603f, 0.316302472f, -0.1639543925f, 0, -0.1016836419f, -0.8057303073f, -0.5834887393f, 0,
-0.6529238969f, 0.50602126f, -0.5635892736f, 0, -0.2465286165f, -0.9668205684f, -0.06694497494f, 0, -0.9776897119f, -0.2099250524f, -0.007368825344f, 0, 0.7736893337f, 0.5734244712f, 0.2694238123f, 0, -0.6095087895f, 0.4995678998f, 0.6155736747f, 0, 0.5794535482f, 0.7434546771f, 0.3339292269f, 0, -0.8226211154f, 0.08142581855f, 0.5627293636f, 0, -0.510385483f, 0.4703667658f, 0.7199039967f, 0,
-0.5764971849f, -0.07231656274f, -0.8138926898f, 0, 0.7250628871f, 0.3949971505f, -0.5641463116f, 0, -0.1525424005f, 0.4860840828f, -0.8604958341f, 0, -0.5550976208f, -0.4957820792f, 0.667882296f, 0, -0.1883614327f, 0.9145869398f, 0.357841725f, 0, 0.7625556724f, -0.5414408243f, -0.3540489801f, 0, -0.5870231946f, -0.3226498013f, -0.7424963803f, 0, 0.3051124198f, 0.2262544068f, -0.9250488391f, 0,
0.6379576059f, 0.577242424f, -0.5097070502f, 0, -0.5966775796f, 0.1454852398f, -0.7891830656f, 0, -0.658330573f, 0.6555487542f, -0.3699414651f, 0, 0.7434892426f, 0.2351084581f, 0.6260573129f, 0, 0.5562114096f, 0.8264360377f, -0.0873632843f, 0, -0.3028940016f, -0.8251527185f, 0.4768419182f, 0, 0.1129343818f, -0.985888439f, -0.1235710781f, 0, 0.5937652891f, -0.5896813806f, 0.5474656618f, 0,
0.6757964092f, -0.5835758614f, -0.4502648413f, 0, 0.7242302609f, -0.1152719764f, 0.6798550586f, 0, -0.9511914166f, 0.0753623979f, -0.2992580792f, 0, 0.2539470961f, -0.1886339355f, 0.9486454084f, 0, 0.571433621f, -0.1679450851f, -0.8032795685f, 0, -0.06778234979f, 0.3978269256f, 0.9149531629f, 0, 0.6074972649f, 0.733060024f, -0.3058922593f, 0, -0.5435478392f, 0.1675822484f, 0.8224791405f, 0,
-0.5876678086f, -0.3380045064f, -0.7351186982f, 0, -0.7967562402f, 0.04097822706f, -0.6029098428f, 0, -0.1996350917f, 0.8706294745f, 0.4496111079f, 0, -0.02787660336f, -0.9106232682f, -0.4122962022f, 0, -0.7797625996f, -0.6257634692f, 0.01975775581f, 0, -0.5211232846f, 0.7401644346f, -0.4249554471f, 0, 0.8575424857f, 0.4053272873f, -0.3167501783f, 0, 0.1045223322f, 0.8390195772f, -0.5339674439f, 0,
0.3501822831f, 0.9242524096f, -0.1520850155f, 0, 0.1987849858f, 0.07647613266f, 0.9770547224f, 0, 0.7845996363f, 0.6066256811f, -0.1280964233f, 0, 0.09006737436f, -0.9750989929f, -0.2026569073f, 0, -0.8274343547f, -0.542299559f, 0.1458203587f, 0, -0.3485797732f, -0.415802277f, 0.840000362f, 0, -0.2471778936f, -0.7304819962f, -0.6366310879f, 0, -0.3700154943f, 0.8577948156f, 0.3567584454f, 0,
0.5913394901f, -0.548311967f, -0.5913303597f, 0, 0.1204873514f, -0.7626472379f, -0.6354935001f, 0, 0.616959265f, 0.03079647928f, 0.7863922953f, 0, 0.1258156836f, -0.6640829889f, -0.7369967419f, 0, -0.6477565124f, -0.1740147258f, -0.7417077429f, 0, 0.6217889313f, -0.7804430448f, -0.06547655076f, 0, 0.6589943422f, -0.6096987708f, 0.4404473475f, 0, -0.2689837504f, -0.6732403169f, -0.6887635427f, 0,
-0.3849775103f, 0.5676542638f, 0.7277093879f, 0, 0.5754444408f, 0.8110471154f, -0.1051963504f, 0, 0.9141593684f, 0.3832947817f, 0.131900567f, 0, -0.107925319f, 0.9245493968f, 0.3654593525f, 0, 0.377977089f, 0.3043148782f, 0.8743716458f, 0, -0.2142885215f, -0.8259286236f, 0.5214617324f, 0, 0.5802544474f, 0.4148098596f, -0.7008834116f, 0, -0.1982660881f, 0.8567161266f, -0.4761596756f, 0,
-0.03381553704f, 0.3773180787f, -0.9254661404f, 0, -0.6867922841f, -0.6656597827f, 0.2919133642f, 0, 0.7731742607f, -0.2875793547f, -0.5652430251f, 0, -0.09655941928f, 0.9193708367f, -0.3813575004f, 0, 0.2715702457f, -0.9577909544f, -0.09426605581f, 0, 0.2451015704f, -0.6917998565f, -0.6792188003f, 0, 0.977700782f, -0.1753855374f, 0.1155036542f, 0, -0.5224739938f, 0.8521606816f, 0.02903615945f, 0,
-0.7734880599f, -0.5261292347f, 0.3534179531f, 0, -0.7134492443f, -0.269547243f, 0.6467878011f, 0, 0.1644037271f, 0.5105846203f, -0.8439637196f, 0, 0.6494635788f, 0.05585611296f, 0.7583384168f, 0, -0.4711970882f, 0.5017280509f, -0.7254255765f, 0, -0.6335764307f, -0.2381686273f, -0.7361091029f, 0, -0.9021533097f, -0.270947803f, -0.3357181763f, 0, -0.3793711033f, 0.872258117f, 0.3086152025f, 0,
-0.6855598966f, -0.3250143309f, 0.6514394162f, 0, 0.2900942212f, -0.7799057743f, -0.5546100667f, 0, -0.2098319339f, 0.85037073f, 0.4825351604f, 0, -0.4592603758f, 0.6598504336f, -0.5947077538f, 0, 0.8715945488f, 0.09616365406f, -0.4807031248f, 0, -0.6776666319f, 0.7118504878f, -0.1844907016f, 0, 0.7044377633f, 0.312427597f, 0.637304036f, 0, -0.7052318886f, -0.2401093292f, -0.6670798253f, 0,
0.081921007f, -0.7207336136f, -0.6883545647f, 0, -0.6993680906f, -0.5875763221f, -0.4069869034f, 0, -0.1281454481f, 0.6419895885f, 0.7559286424f, 0, -0.6337388239f, -0.6785471501f, -0.3714146849f, 0, 0.5565051903f, -0.2168887573f, -0.8020356851f, 0, -0.5791554484f, 0.7244372011f, -0.3738578718f, 0, 0.1175779076f, -0.7096451073f, 0.6946792478f, 0, -0.6134619607f, 0.1323631078f, 0.7785527795f, 0,
0.6984635305f, -0.02980516237f, -0.715024719f, 0, 0.8318082963f, -0.3930171956f, 0.3919597455f, 0, 0.1469576422f, 0.05541651717f, -0.9875892167f, 0, 0.708868575f, -0.2690503865f, 0.6520101478f, 0, 0.2726053183f, 0.67369766f, -0.68688995f, 0, -0.6591295371f, 0.3035458599f, -0.6880466294f, 0, 0.4815131379f, -0.7528270071f, 0.4487723203f, 0, 0.9430009463f, 0.1675647412f, -0.2875261255f, 0,
0.434802957f, 0.7695304522f, -0.4677277752f, 0, 0.3931996188f, 0.594473625f, 0.7014236729f, 0, 0.7254336655f, -0.603925654f, 0.3301814672f, 0, 0.7590235227f, -0.6506083235f, 0.02433313207f, 0, -0.8552768592f, -0.3430042733f, 0.3883935666f, 0, -0.6139746835f, 0.6981725247f, 0.3682257648f, 0, -0.7465905486f, -0.5752009504f, 0.3342849376f, 0, 0.5730065677f, 0.810555537f, -0.1210916791f, 0,
-0.9225877367f, -0.3475211012f, -0.167514036f, 0, -0.7105816789f, -0.4719692027f, -0.5218416899f, 0, -0.08564609717f, 0.3583001386f, 0.929669703f, 0, -0.8279697606f, -0.2043157126f, 0.5222271202f, 0, 0.427944023f, 0.278165994f, 0.8599346446f, 0, 0.5399079671f, -0.7857120652f, -0.3019204161f, 0, 0.5678404253f, -0.5495413974f, -0.6128307303f, 0, -0.9896071041f, 0.1365639107f, -0.04503418428f, 0,
-0.6154342638f, -0.6440875597f, 0.4543037336f, 0, 0.1074204368f, -0.7946340692f, 0.5975094525f, 0, -0.3595449969f, -0.8885529948f, 0.28495784f, 0, -0.2180405296f, 0.1529888965f, 0.9638738118f, 0, -0.7277432317f, -0.6164050508f, -0.3007234646f, 0, 0.7249729114f, -0.00669719484f, 0.6887448187f, 0, -0.5553659455f, -0.5336586252f, 0.6377908264f, 0, 0.5137558015f, 0.7976208196f, -0.3160000073f, 0,
-0.3794024848f, 0.9245608561f, -0.03522751494f, 0, 0.8229248658f, 0.2745365933f, -0.4974176556f, 0, -0.5404114394f, 0.6091141441f, 0.5804613989f, 0, 0.8036581901f, -0.2703029469f, 0.5301601931f, 0, 0.6044318879f, 0.6832968393f, 0.4095943388f, 0, 0.06389988817f, 0.9658208605f, -0.2512108074f, 0, 0.1087113286f, 0.7402471173f, -0.6634877936f, 0, -0.713427712f, -0.6926784018f, 0.1059128479f, 0,
0.6458897819f, -0.5724548511f, -0.5050958653f, 0, -0.6553931414f, 0.7381471625f, 0.159995615f, 0, 0.3910961323f, 0.9188871375f, -0.05186755998f, 0, -0.4879022471f, -0.5904376907f, 0.6429111375f, 0, 0.6014790094f, 0.7707441366f, -0.2101820095f, 0, -0.5677173047f, 0.7511360995f, 0.3368851762f, 0, 0.7858573506f, 0.226674665f, 0.5753666838f, 0, -0.4520345543f, -0.604222686f, -0.6561857263f, 0,
0.002272116345f, 0.4132844051f, -0.9105991643f, 0, -0.5815751419f, -0.5162925989f, 0.6286591339f, 0, -0.03703704785f, 0.8273785755f, 0.5604221175f, 0, -0.5119692504f, 0.7953543429f, -0.3244980058f, 0, -0.2682417366f, -0.9572290247f, -0.1084387619f, 0, -0.2322482736f, -0.9679131102f, -0.09594243324f, 0, 0.3554328906f, -0.8881505545f, 0.2913006227f, 0, 0.7346520519f, -0.4371373164f, 0.5188422971f, 0,
0.9985120116f, 0.04659011161f, -0.02833944577f, 0, -0.3727687496f, -0.9082481361f, 0.1900757285f, 0, 0.91737377f, -0.3483642108f, 0.1925298489f, 0, 0.2714911074f, 0.4147529736f, -0.8684886582f, 0, 0.5131763485f, -0.7116334161f, 0.4798207128f, 0, -0.8737353606f, 0.18886992f, -0.4482350644f, 0, 0.8460043821f, -0.3725217914f, 0.3814499973f, 0, 0.8978727456f, -0.1780209141f, -0.4026575304f, 0,
0.2178065647f, -0.9698322841f, -0.1094789531f, 0, -0.1518031304f, -0.7788918132f, -0.6085091231f, 0, -0.2600384876f, -0.4755398075f, -0.8403819825f, 0, 0.572313509f, -0.7474340931f, -0.3373418503f, 0, -0.7174141009f, 0.1699017182f, -0.6756111411f, 0, -0.684180784f, 0.02145707593f, -0.7289967412f, 0, -0.2007447902f, 0.06555605789f, -0.9774476623f, 0, -0.1148803697f, -0.8044887315f, 0.5827524187f, 0,
-0.7870349638f, 0.03447489231f, 0.6159443543f, 0, -0.2015596421f, 0.6859872284f, 0.6991389226f, 0, -0.08581082512f, -0.10920836f, -0.9903080513f, 0, 0.5532693395f, 0.7325250401f, -0.396610771f, 0, -0.1842489331f, -0.9777375055f, -0.1004076743f, 0, 0.0775473789f, -0.9111505856f, 0.4047110257f, 0, 0.1399838409f, 0.7601631212f, -0.6344734459f, 0, 0.4484419361f, -0.845289248f, 0.2904925424f, 0
};
// Utilities
static inline float _fnlFastMin(float x, float y) { return x < y ? x : y; }
static inline float _fnlFastMax(float x, float y) { return x > y ? x : y; }
static inline float _fnlFastAbs(float f) { return f < 0 ? -f : f; }
static inline float _fnlFastSqrt(float a) { return sqrt(a); }
static inline int _fnlFastFloor(FNLfloat f) { return (f >= 0 ? (int)f : (int)f - 1); }
static inline int _fnlFastRound(FNLfloat f) { return (f >= 0) ? (int)(f + 0.5f) : (int)(f - 0.5f); }
static inline float _fnlLerp(float a, float b, float t) { return a + t * (b - a); }
static inline float _fnlInterpHermite(float t) { return t * t * (3 - 2 * t); }
static inline float _fnlInterpQuintic(float t) { return t * t * t * (t * (t * 6 - 15) + 10); }
static inline float _fnlCubicLerp(float a, float b, float c, float d, float t)
{
float p = (d - c) - (a - b);
return t * t * t * p + t * t * ((a - b) - p) + t * (c - a) + b;
}
static inline float _fnlPingPong(float t)
{
t -= (int)(t * 0.5f) * 2;
return t < 1 ? t : 2 - t;
}
static float _fnlCalculateFractalBounding(fnl_state state)
{
float gain = _fnlFastAbs(state.gain);
float amp = gain;
float ampFractal = 1.0f;
for (int i = 1; i < state.octaves; i++)
{
ampFractal += amp;
amp *= gain;
}
return 1.0f / ampFractal;
}
// Hashing
static const int PRIME_X = 501125321;
static const int PRIME_Y = 1136930381;
static const int PRIME_Z = 1720413743;
static inline int _fnlHash2D(int seed, int xPrimed, int yPrimed)
{
int hash = seed ^ xPrimed ^ yPrimed;
hash *= 0x27d4eb2d;
return hash;
}
static inline int _fnlHash3D(int seed, int xPrimed, int yPrimed, int zPrimed)
{
int hash = seed ^ xPrimed ^ yPrimed ^ zPrimed;
hash *= 0x27d4eb2d;
return hash;
}
static inline float _fnlValCoord2D(int seed, int xPrimed, int yPrimed)
{
int hash = _fnlHash2D(seed, xPrimed, yPrimed);
hash *= hash;
hash ^= hash << 19;
return hash * (1 / 2147483648.0f);
}
static inline float _fnlValCoord3D(int seed, int xPrimed, int yPrimed, int zPrimed)
{
int hash = _fnlHash3D(seed, xPrimed, yPrimed, zPrimed);
hash *= hash;
hash ^= hash << 19;
return hash * (1 / 2147483648.0f);
}
static inline float _fnlGradCoord2D(int seed, int xPrimed, int yPrimed, float xd, float yd)
{
int hash = _fnlHash2D(seed, xPrimed, yPrimed);
hash ^= hash >> 15;
hash &= 127 << 1;
return xd * GRADIENTS_2D[hash] + yd * GRADIENTS_2D[hash | 1];
}
static inline float _fnlGradCoord3D(int seed, int xPrimed, int yPrimed, int zPrimed, float xd, float yd, float zd)
{
int hash = _fnlHash3D(seed, xPrimed, yPrimed, zPrimed);
hash ^= hash >> 15;
hash &= 63 << 2;
return xd * GRADIENTS_3D[hash] + yd * GRADIENTS_3D[hash | 1] + zd * GRADIENTS_3D[hash | 2];
}
static inline void _fnlGradCoordOut2D(int seed, int xPrimed, int yPrimed, out float xo, out float yo)
{
int hash = _fnlHash2D(seed, xPrimed, yPrimed) & (255 << 1);
xo = RAND_VECS_2D[hash];
yo = RAND_VECS_2D[hash | 1];
}
static inline void _fnlGradCoordOut3D(int seed, int xPrimed, int yPrimed, int zPrimed, out float xo, out float yo, out float zo)
{
int hash = _fnlHash3D(seed, xPrimed, yPrimed, zPrimed) & (255 << 2);
xo = RAND_VECS_3D[hash];
yo = RAND_VECS_3D[hash | 1];
zo = RAND_VECS_3D[hash | 2];
}
static inline void _fnlGradCoordDual2D(int seed, int xPrimed, int yPrimed, float xd, float yd, out float xo, out float yo)
{
int hash = _fnlHash2D(seed, xPrimed, yPrimed);
int index1 = hash & (127 << 1);
int index2 = (hash >> 7) & (255 << 1);
float xg = GRADIENTS_2D[index1];
float yg = GRADIENTS_2D[index1 | 1];
float value = xd * xg + yd * yg;
float xgo = RAND_VECS_2D[index2];
float ygo = RAND_VECS_2D[index2 | 1];
xo = value * xgo;
yo = value * ygo;
}
static inline void _fnlGradCoordDual3D(int seed, int xPrimed, int yPrimed, int zPrimed, float xd, float yd, float zd, out float xo, out float yo, out float zo)
{
int hash = _fnlHash3D(seed, xPrimed, yPrimed, zPrimed);
int index1 = hash & (63 << 2);
int index2 = (hash >> 6) & (255 << 2);
float xg = GRADIENTS_3D[index1];
float yg = GRADIENTS_3D[index1 | 1];
float zg = GRADIENTS_3D[index1 | 2];
float value = xd * xg + yd * yg + zd * zg;
float xgo = RAND_VECS_3D[index2];
float ygo = RAND_VECS_3D[index2 | 1];
float zgo = RAND_VECS_3D[index2 | 2];
xo = value * xgo;
yo = value * ygo;
zo = value * zgo;
}
// Generic Noise Gen
static float _fnlSingleSimplex2D(int seed, FNLfloat x, FNLfloat y);
static float _fnlSingleOpenSimplex23D(int seed, FNLfloat x, FNLfloat y, FNLfloat z);
static float _fnlSingleOpenSimplex2S2D(int seed, FNLfloat x, FNLfloat y);
static float _fnlSingleOpenSimplex2S3D(int seed, FNLfloat x, FNLfloat y, FNLfloat z);
static float _fnlSingleCellular2D(fnl_state state, int seed, FNLfloat x, FNLfloat y);
static float _fnlSingleCellular3D(fnl_state state, int seed, FNLfloat x, FNLfloat y, FNLfloat z);
static float _fnlSinglePerlin2D(int seed, FNLfloat x, FNLfloat y);
static float _fnlSinglePerlin3D(int seed, FNLfloat x, FNLfloat y, FNLfloat z);
static float _fnlSingleValueCubic2D(int seed, FNLfloat x, FNLfloat y);
static float _fnlSingleValueCubic3D(int seed, FNLfloat x, FNLfloat y, FNLfloat z);
static float _fnlSingleValue2D(int seed, FNLfloat x, FNLfloat y);
static float _fnlSingleValue3D(int seed, FNLfloat x, FNLfloat y, FNLfloat z);
static float _fnlGenNoiseSingle2D(fnl_state state, int seed, FNLfloat x, FNLfloat y)
{
FNL_FLATTEN switch (state.noise_type)
{
case FNL_NOISE_OPENSIMPLEX2:
return _fnlSingleSimplex2D(seed, x, y);
case FNL_NOISE_OPENSIMPLEX2S:
return _fnlSingleOpenSimplex2S2D(seed, x, y);
case FNL_NOISE_CELLULAR:
return _fnlSingleCellular2D(state, seed, x, y);
case FNL_NOISE_PERLIN:
return _fnlSinglePerlin2D(seed, x, y);
case FNL_NOISE_VALUE_CUBIC:
return _fnlSingleValueCubic2D(seed, x, y);
case FNL_NOISE_VALUE:
return _fnlSingleValue2D(seed, x, y);
default:
return 0;
}
}
static float _fnlGenNoiseSingle3D(fnl_state state, int seed, FNLfloat x, FNLfloat y, FNLfloat z)
{
FNL_FLATTEN switch (state.noise_type)
{
case FNL_NOISE_OPENSIMPLEX2:
return _fnlSingleOpenSimplex23D(seed, x, y, z);
case FNL_NOISE_OPENSIMPLEX2S:
return _fnlSingleOpenSimplex2S3D(seed, x, y, z);
case FNL_NOISE_CELLULAR:
return _fnlSingleCellular3D(state, seed, x, y, z);
case FNL_NOISE_PERLIN:
return _fnlSinglePerlin3D(seed, x, y, z);
case FNL_NOISE_VALUE_CUBIC:
return _fnlSingleValueCubic3D(seed, x, y, z);
case FNL_NOISE_VALUE:
return _fnlSingleValue3D(seed, x, y, z);
default:
return 0;
}
}
// Noise Coordinate Transforms (frequency, and possible skew or rotation)
static void _fnlTransformNoiseCoordinate2D(fnl_state state, inout FNLfloat x, inout FNLfloat y)
{
x *= state.frequency;
y *= state.frequency;
switch (state.noise_type)
{
case FNL_NOISE_OPENSIMPLEX2:
case FNL_NOISE_OPENSIMPLEX2S:
{
const FNLfloat SQRT3 = (FNLfloat)1.7320508075688772935274463415059;
const FNLfloat F2 = 0.5f * (SQRT3 - 1);
FNLfloat t = (x + y) * F2;
x += t;
y += t;
}
break;
default:
break;
}
}
static void _fnlTransformNoiseCoordinate3D(fnl_state state, inout FNLfloat x, inout FNLfloat y, inout FNLfloat z)
{
x *= state.frequency;
y *= state.frequency;
z *= state.frequency;
switch (state.rotation_type_3d)
{
case FNL_ROTATION_IMPROVE_XY_PLANES:
{
FNLfloat xy = x + y;
FNLfloat s2 = xy * -(FNLfloat)0.211324865405187;
z *= (FNLfloat)0.577350269189626;
x += s2 - z;
y = y + s2 - z;
z += xy * (FNLfloat)0.577350269189626;
}
break;
case FNL_ROTATION_IMPROVE_XZ_PLANES:
{
FNLfloat xz = x + z;
FNLfloat s2 = xz * -(FNLfloat)0.211324865405187;
y *= (FNLfloat)0.577350269189626;
x += s2 - y;
z += s2 - y;
y += xz * (FNLfloat)0.577350269189626;
}
break;
default:
switch (state.noise_type)
{
case FNL_NOISE_OPENSIMPLEX2:
case FNL_NOISE_OPENSIMPLEX2S:
{
const FNLfloat R3 = (FNLfloat)(2.0 / 3.0);
FNLfloat r = (x + y + z) * R3; // Rotation, not skew
x = r - x;
y = r - y;
z = r - z;
}
break;
default:
break;
}
break;
}
}
// Domain Warp Coordinate Transforms
static void _fnlTransformDomainWarpCoordinate2D(fnl_state state, inout FNLfloat x, inout FNLfloat y)
{
switch (state.domain_warp_type)
{
case FNL_DOMAIN_WARP_OPENSIMPLEX2:
case FNL_DOMAIN_WARP_OPENSIMPLEX2_REDUCED:
{
const FNLfloat SQRT3 = (FNLfloat)1.7320508075688772935274463415059;
const FNLfloat F2 = 0.5f * (SQRT3 - 1);
FNLfloat t = (x + y) * F2;
x += t;
y += t;
}
break;
default:
break;
}
}
static void _fnlTransformDomainWarpCoordinate3D(fnl_state state, inout FNLfloat x, inout FNLfloat y, inout FNLfloat z)
{
switch (state.rotation_type_3d)
{
case FNL_ROTATION_IMPROVE_XY_PLANES:
{
FNLfloat xy = x + y;
FNLfloat s2 = xy * -(FNLfloat)0.211324865405187;
z *= (FNLfloat)0.577350269189626;
x += s2 - z;
y = y + s2 - z;
z += xy * (FNLfloat)0.577350269189626;
}
break;
case FNL_ROTATION_IMPROVE_XZ_PLANES:
{
FNLfloat xz = x + z;
FNLfloat s2 = xz * -(FNLfloat)0.211324865405187;
y *= (FNLfloat)0.577350269189626;
x += s2 - y;
z += s2 - y;
y += xz * (FNLfloat)0.577350269189626;
}
break;
default:
switch (state.domain_warp_type)
{
case FNL_DOMAIN_WARP_OPENSIMPLEX2:
case FNL_DOMAIN_WARP_OPENSIMPLEX2_REDUCED:
{
const FNLfloat R3 = (FNLfloat)(2.0 / 3.0);
FNLfloat r = (x + y + z) * R3; // Rotation, not skew
x = r - x;
y = r - y;
z = r - z;
}
break;
default:
break;
}
break;
}
}
// Fractal FBm
static float _fnlGenFractalFBM2D(fnl_state state, FNLfloat x, FNLfloat y)
{
int seed = state.seed;
float sum = 0;
float amp = _fnlCalculateFractalBounding(state);
for (int i = 0; i < state.octaves; i++)
{
float noise = _fnlGenNoiseSingle2D(state, seed++, x, y);
sum += noise * amp;
amp *= _fnlLerp(1.0f, _fnlFastMin(noise + 1, 2) * 0.5f, state.weighted_strength);
x *= state.lacunarity;
y *= state.lacunarity;
amp *= state.gain;
}
return sum;
}
static float _fnlGenFractalFBM3D(fnl_state state, FNLfloat x, FNLfloat y, FNLfloat z)
{
int seed = state.seed;
float sum = 0;
float amp = _fnlCalculateFractalBounding(state);
for (int i = 0; i < state.octaves; i++)
{
float noise = _fnlGenNoiseSingle3D(state, seed++, x, y, z);
sum += noise * amp;
amp *= _fnlLerp(1.0f, (noise + 1) * 0.5f, state.weighted_strength);
x *= state.lacunarity;
y *= state.lacunarity;
z *= state.lacunarity;
amp *= state.gain;
}
return sum;
}
// Fractal Ridged
static float _fnlGenFractalRidged2D(fnl_state state, FNLfloat x, FNLfloat y)
{
int seed = state.seed;
float sum = 0;
float amp = _fnlCalculateFractalBounding(state);
for (int i = 0; i < state.octaves; i++)
{
float noise = _fnlFastAbs(_fnlGenNoiseSingle2D(state, seed++, x, y));
sum += (noise * -2 + 1) * amp;
amp *= _fnlLerp(1.0f, 1 - noise, state.weighted_strength);
x *= state.lacunarity;
y *= state.lacunarity;
amp *= state.gain;
}
return sum;
}
static float _fnlGenFractalRidged3D(fnl_state state, FNLfloat x, FNLfloat y, FNLfloat z)
{
int seed = state.seed;
float sum = 0;
float amp = _fnlCalculateFractalBounding(state);
for (int i = 0; i < state.octaves; i++)
{
float noise = _fnlFastAbs(_fnlGenNoiseSingle3D(state, seed++, x, y, z));
sum += (noise * -2 + 1) * amp;
amp *= _fnlLerp(1.0f, 1 - noise, state.weighted_strength);
x *= state.lacunarity;
y *= state.lacunarity;
z *= state.lacunarity;
amp *= state.gain;
}
return sum;
}
// Fractal PingPong
static float _fnlGenFractalPingPong2D(fnl_state state, FNLfloat x, FNLfloat y)
{
int seed = state.seed;
float sum = 0;
float amp = _fnlCalculateFractalBounding(state);
for (int i = 0; i < state.octaves; i++)
{
float noise = _fnlPingPong((_fnlGenNoiseSingle2D(state, seed++, x, y) + 1) * state.ping_pong_strength);
sum += (noise - 0.5f) * 2 * amp;
amp *= _fnlLerp(1.0f, noise, state.weighted_strength);
x *= state.lacunarity;
y *= state.lacunarity;
amp *= state.gain;
}
return sum;
}
static float _fnlGenFractalPingPong3D(fnl_state state, FNLfloat x, FNLfloat y, FNLfloat z)
{
int seed = state.seed;
float sum = 0;
float amp = _fnlCalculateFractalBounding(state);
for (int i = 0; i < state.octaves; i++)
{
float noise = _fnlPingPong((_fnlGenNoiseSingle3D(state, seed++, x, y, z) + 1) * state.ping_pong_strength);
sum += (noise - 0.5f) * 2 * amp;
amp *= _fnlLerp(1.0f, noise, state.weighted_strength);
x *= state.lacunarity;
y *= state.lacunarity;
z *= state.lacunarity;
amp *= state.gain;
}
return sum;
}
// Simplex/OpenSimplex2 Noise
static float _fnlSingleSimplex2D(int seed, FNLfloat x, FNLfloat y)
{
// 2D OpenSimplex2 case uses the same algorithm as ordinary Simplex.
const float SQRT3 = 1.7320508075688772935274463415059f;
const float G2 = (3 - SQRT3) / 6;
/*
* --- Skew moved to TransformNoiseCoordinate method ---
* const FNLfloat F2 = 0.5f * (SQRT3 - 1);
* FNLfloat s = (x + y) * F2;
* x += s; y += s;
*/
int i = _fnlFastFloor(x);
int j = _fnlFastFloor(y);
float xi = (float)(x - i);
float yi = (float)(y - j);
float t = (xi + yi) * G2;
float x0 = (float)(xi - t);
float y0 = (float)(yi - t);
i *= PRIME_X;
j *= PRIME_Y;
float n0, n1, n2;
float a = 0.5f - x0 * x0 - y0 * y0;
if (a <= 0)
n0 = 0;
else
{
n0 = (a * a) * (a * a) * _fnlGradCoord2D(seed, i, j, x0, y0);
}
float c = (float)(2 * (1 - 2 * G2) * (1 / G2 - 2)) * t + ((float)(-2 * (1 - 2 * G2) * (1 - 2 * G2)) + a);
if (c <= 0)
n2 = 0;
else
{
float x2 = x0 + (2 * (float)G2 - 1);
float y2 = y0 + (2 * (float)G2 - 1);
n2 = (c * c) * (c * c) * _fnlGradCoord2D(seed, i + PRIME_X, j + PRIME_Y, x2, y2);
}
if (y0 > x0)
{
float x1 = x0 + (float)G2;
float y1 = y0 + ((float)G2 - 1);
float b = 0.5f - x1 * x1 - y1 * y1;
if (b <= 0)
n1 = 0;
else
{
n1 = (b * b) * (b * b) * _fnlGradCoord2D(seed, i, j + PRIME_Y, x1, y1);
}
}
else
{
float x1 = x0 + ((float)G2 - 1);
float y1 = y0 + (float)G2;
float b = 0.5f - x1 * x1 - y1 * y1;
if (b <= 0)
n1 = 0;
else
{
n1 = (b * b) * (b * b) * _fnlGradCoord2D(seed, i + PRIME_X, j, x1, y1);
}
}
return (n0 + n1 + n2) * 99.83685446303647f;
}
static float _fnlSingleOpenSimplex23D(int seed, FNLfloat x, FNLfloat y, FNLfloat z)
{
// 3D OpenSimplex2 case uses two offset rotated cube grids.
/*
* --- Rotation moved to TransformNoiseCoordinate method ---
* const FNLfloat R3 = (FNLfloat)(2.0 / 3.0);
* FNLfloat r = (x + y + z) * R3; // Rotation, not skew
* x = r - x; y = r - y; z = r - z;
*/
int i = _fnlFastRound(x);
int j = _fnlFastRound(y);
int k = _fnlFastRound(z);
float x0 = (float)(x - i);
float y0 = (float)(y - j);
float z0 = (float)(z - k);
int xNSign = (int)(-1.0f - x0) | 1;
int yNSign = (int)(-1.0f - y0) | 1;
int zNSign = (int)(-1.0f - z0) | 1;
float ax0 = xNSign * -x0;
float ay0 = yNSign * -y0;
float az0 = zNSign * -z0;
i *= PRIME_X;
j *= PRIME_Y;
k *= PRIME_Z;
float value = 0;
float a = (0.6f - x0 * x0) - (y0 * y0 + z0 * z0);
FNL_UNROLL for (int l = 0; ; l++)
{
if (a > 0)
{
value += (a * a) * (a * a) * _fnlGradCoord3D(seed, i, j, k, x0, y0, z0);
}
float b = a + 1;
int i1 = i;
int j1 = j;
int k1 = k;
float x1 = x0;
float y1 = y0;
float z1 = z0;
if (ax0 >= ay0 && ax0 >= az0)
{
x1 += xNSign;
b -= xNSign * 2 * x1;
i1 -= xNSign * PRIME_X;
}
else if (ay0 > ax0 && ay0 >= az0)
{
y1 += yNSign;
b -= yNSign * 2 * y1;
j1 -= yNSign * PRIME_Y;
}
else
{
z1 += zNSign;
b -= zNSign * 2 * z1;
k1 -= zNSign * PRIME_Z;
}
if (b > 0)
{
value += (b * b) * (b * b) * _fnlGradCoord3D(seed, i1, j1, k1, x1, y1, z1);
}
if (l == 1) break;
ax0 = 0.5f - ax0;
ay0 = 0.5f - ay0;
az0 = 0.5f - az0;
x0 = xNSign * ax0;
y0 = yNSign * ay0;
z0 = zNSign * az0;
a += (0.75f - ax0) - (ay0 + az0);
i += (xNSign >> 1) & PRIME_X;
j += (yNSign >> 1) & PRIME_Y;
k += (zNSign >> 1) & PRIME_Z;
xNSign = -xNSign;
yNSign = -yNSign;
zNSign = -zNSign;
seed = ~seed;
}
return value * 32.69428253173828125f;
}
// OpenSimplex2S Noise
static float _fnlSingleOpenSimplex2S2D(int seed, FNLfloat x, FNLfloat y)
{
// 2D OpenSimplex2S case is a modified 2D simplex noise.
const FNLfloat SQRT3 = (FNLfloat)1.7320508075688772935274463415059;
const FNLfloat G2 = (3 - SQRT3) / 6;
/*
* --- Skew moved to TransformNoiseCoordinate method ---
* const FNLfloat F2 = 0.5f * (SQRT3 - 1);
* FNLfloat s = (x + y) * F2;
* x += s; y += s;
*/
int i = _fnlFastFloor(x);
int j = _fnlFastFloor(y);
float xi = (float)(x - i);
float yi = (float)(y - j);
i *= PRIME_X;
j *= PRIME_Y;
int i1 = i + PRIME_X;
int j1 = j + PRIME_Y;
float t = (xi + yi) * (float)G2;
float x0 = xi - t;
float y0 = yi - t;
int aMask = (int)((xi + yi + 1) * -0.5f);
int bMask = (int)((xi - (aMask + 2)) * 0.5f - yi);
int cMask = (int)((yi - (aMask + 2)) * 0.5f - xi);
float a0 = (2.0f / 3.0f) - x0 * x0 - y0 * y0;
float value = (a0 * a0) * (a0 * a0) * _fnlGradCoord2D(seed, i, j, x0, y0);
float a1 = (float)(2 * (1 - 2 * G2) * (1 / G2 - 2)) * t + ((float)(-2 * (1 - 2 * G2) * (1 - 2 * G2)) + a0);
float x1 = x0 - (float)(1 - 2 * G2);
float y1 = y0 - (float)(1 - 2 * G2);
value += (a1 * a1) * (a1 * a1) * _fnlGradCoord2D(seed, i1, j1, x1, y1);
int di2 = ~(aMask | cMask) | 1;
int ndj2 = (aMask & bMask) << 1;
float t2 = (di2 - ndj2) * (float)G2;
float x2 = x0 - di2 + t2;
float y2 = y0 + ndj2 + t2;
float a2 = (2.0f / 3.0f) - x2 * x2 - y2 * y2;
if (a2 > 0)
{
value += (a2 * a2) * (a2 * a2) * _fnlGradCoord2D(seed, i1 + (di2 & (-PRIME_X << 1)), j + (ndj2 & (PRIME_Y << 1)), x2, y2);
}
int ndi3 = (aMask & cMask) << 1;
int dj3 = ~(aMask | bMask) | 1;
float t3 = (dj3 - ndi3) * (float)G2;
float x3 = x0 + ndi3 + t3;
float y3 = y0 - dj3 + t3;
float a3 = (2.0f / 3.0f) - x3 * x3 - y3 * y3;
if (a3 > 0)
{
value += (a3 * a3) * (a3 * a3) * _fnlGradCoord2D(seed, i + (ndi3 & (PRIME_X << 1)), j1 + (dj3 & (-PRIME_Y << 1)), x3, y3);
}
return value * 18.24196194486065f;
}
static float _fnlSingleOpenSimplex2S3D(int seed, FNLfloat x, FNLfloat y, FNLfloat z)
{
// 3D OpenSimplex2S case uses two offset rotated cube grids.
/*
* --- Rotation moved to TransformNoiseCoordinate method ---
* const FNLfloat R3 = (FNLfloat)(2.0 / 3.0);
* FNLfloat r = (x + y + z) * R3; // Rotation, not skew
* x = r - x; y = r - y; z = r - z;
*/
int i = _fnlFastFloor(x);
int j = _fnlFastFloor(y);
int k = _fnlFastFloor(z);
float xi = (float)(x - i);
float yi = (float)(y - j);
float zi = (float)(z - k);
i *= PRIME_X;
j *= PRIME_Y;
k *= PRIME_Z;
int seed2 = seed + 1293373;
int xNMask = (int)(-0.5f - xi);
int yNMask = (int)(-0.5f - yi);
int zNMask = (int)(-0.5f - zi);
float x0 = xi + xNMask;
float y0 = yi + yNMask;
float z0 = zi + zNMask;
float a0 = 0.75f - x0 * x0 - y0 * y0 - z0 * z0;
float value = (a0 * a0) * (a0 * a0) * _fnlGradCoord3D(seed,
i + (xNMask & PRIME_X), j + (yNMask & PRIME_Y), k + (zNMask & PRIME_Z), x0, y0, z0);
float x1 = xi - 0.5f;
float y1 = yi - 0.5f;
float z1 = zi - 0.5f;
float a1 = 0.75f - x1 * x1 - y1 * y1 - z1 * z1;
value += (a1 * a1) * (a1 * a1) * _fnlGradCoord3D(seed2,
i + PRIME_X, j + PRIME_Y, k + PRIME_Z, x1, y1, z1);
float xAFlipMask0 = ((xNMask | 1) << 1) * x1;
float yAFlipMask0 = ((yNMask | 1) << 1) * y1;
float zAFlipMask0 = ((zNMask | 1) << 1) * z1;
float xAFlipMask1 = (-2 - (xNMask << 2)) * x1 - 1.0f;
float yAFlipMask1 = (-2 - (yNMask << 2)) * y1 - 1.0f;
float zAFlipMask1 = (-2 - (zNMask << 2)) * z1 - 1.0f;
bool skip5 = false;
float a2 = xAFlipMask0 + a0;
if (a2 > 0)
{
float x2 = x0 - (xNMask | 1);
float y2 = y0;
float z2 = z0;
value += (a2 * a2) * (a2 * a2) * _fnlGradCoord3D(seed,
i + (~xNMask & PRIME_X), j + (yNMask & PRIME_Y), k + (zNMask & PRIME_Z), x2, y2, z2);
}
else
{
float a3 = yAFlipMask0 + zAFlipMask0 + a0;
if (a3 > 0)
{
float x3 = x0;
float y3 = y0 - (yNMask | 1);
float z3 = z0 - (zNMask | 1);
value += (a3 * a3) * (a3 * a3) * _fnlGradCoord3D(seed,
i + (xNMask & PRIME_X), j + (~yNMask & PRIME_Y), k + (~zNMask & PRIME_Z), x3, y3, z3);
}
float a4 = xAFlipMask1 + a1;
if (a4 > 0)
{
float x4 = (xNMask | 1) + x1;
float y4 = y1;
float z4 = z1;
value += (a4 * a4) * (a4 * a4) * _fnlGradCoord3D(seed2,
i + (xNMask & (PRIME_X * 2)), j + PRIME_Y, k + PRIME_Z, x4, y4, z4);
skip5 = true;
}
}
bool skip9 = false;
float a6 = yAFlipMask0 + a0;
if (a6 > 0)
{
float x6 = x0;
float y6 = y0 - (yNMask | 1);
float z6 = z0;
value += (a6 * a6) * (a6 * a6) * _fnlGradCoord3D(seed,
i + (xNMask & PRIME_X), j + (~yNMask & PRIME_Y), k + (zNMask & PRIME_Z), x6, y6, z6);
}
else
{
float a7 = xAFlipMask0 + zAFlipMask0 + a0;
if (a7 > 0)
{
float x7 = x0 - (xNMask | 1);
float y7 = y0;
float z7 = z0 - (zNMask | 1);
value += (a7 * a7) * (a7 * a7) * _fnlGradCoord3D(seed,
i + (~xNMask & PRIME_X), j + (yNMask & PRIME_Y), k + (~zNMask & PRIME_Z), x7, y7, z7);
}
float a8 = yAFlipMask1 + a1;
if (a8 > 0)
{
float x8 = x1;
float y8 = (yNMask | 1) + y1;
float z8 = z1;
value += (a8 * a8) * (a8 * a8) * _fnlGradCoord3D(seed2,
i + PRIME_X, j + (yNMask & (PRIME_Y << 1)), k + PRIME_Z, x8, y8, z8);
skip9 = true;
}
}
bool skipD = false;
float aA = zAFlipMask0 + a0;
if (aA > 0)
{
float xA = x0;
float yA = y0;
float zA = z0 - (zNMask | 1);
value += (aA * aA) * (aA * aA) * _fnlGradCoord3D(seed,
i + (xNMask & PRIME_X), j + (yNMask & PRIME_Y), k + (~zNMask & PRIME_Z), xA, yA, zA);
}
else
{
float aB = xAFlipMask0 + yAFlipMask0 + a0;
if (aB > 0)
{
float xB = x0 - (xNMask | 1);
float yB = y0 - (yNMask | 1);
float zB = z0;
value += (aB * aB) * (aB * aB) * _fnlGradCoord3D(seed,
i + (~xNMask & PRIME_X), j + (~yNMask & PRIME_Y), k + (zNMask & PRIME_Z), xB, yB, zB);
}
float aC = zAFlipMask1 + a1;
if (aC > 0)
{
float xC = x1;
float yC = y1;
float zC = (zNMask | 1) + z1;
value += (aC * aC) * (aC * aC) * _fnlGradCoord3D(seed2,
i + PRIME_X, j + PRIME_Y, k + (zNMask & (PRIME_Z << 1)), xC, yC, zC);
skipD = true;
}
}
if (!skip5)
{
float a5 = yAFlipMask1 + zAFlipMask1 + a1;
if (a5 > 0)
{
float x5 = x1;
float y5 = (yNMask | 1) + y1;
float z5 = (zNMask | 1) + z1;
value += (a5 * a5) * (a5 * a5) * _fnlGradCoord3D(seed2,
i + PRIME_X, j + (yNMask & (PRIME_Y << 1)), k + (zNMask & (PRIME_Z << 1)), x5, y5, z5);
}
}
if (!skip9)
{
float a9 = xAFlipMask1 + zAFlipMask1 + a1;
if (a9 > 0)
{
float x9 = (xNMask | 1) + x1;
float y9 = y1;
float z9 = (zNMask | 1) + z1;
value += (a9 * a9) * (a9 * a9) * _fnlGradCoord3D(seed2,
i + (xNMask & (PRIME_X * 2)), j + PRIME_Y, k + (zNMask & (PRIME_Z << 1)), x9, y9, z9);
}
}
if (!skipD)
{
float aD = xAFlipMask1 + yAFlipMask1 + a1;
if (aD > 0)
{
float xD = (xNMask | 1) + x1;
float yD = (yNMask | 1) + y1;
float zD = z1;
value += (aD * aD) * (aD * aD) * _fnlGradCoord3D(seed2,
i + (xNMask & (PRIME_X << 1)), j + (yNMask & (PRIME_Y << 1)), k + PRIME_Z, xD, yD, zD);
}
}
return value * 9.046026385208288f;
}
// Cellular Noise
static float _fnlSingleCellular2D(fnl_state state, int seed, FNLfloat x, FNLfloat y)
{
int xr = _fnlFastRound(x);
int yr = _fnlFastRound(y);
float distance0 = 1e10f;
float distance1 = 1e10f;
int closestHash = 0;
float cellularJitter = 0.43701595f * state.cellular_jitter_mod;
int xPrimed = (xr - 1) * PRIME_X;
int yPrimedBase = (yr - 1) * PRIME_Y;
FNL_FLATTEN switch (state.cellular_distance_func)
{
default:
case FNL_CELLULAR_DISTANCE_EUCLIDEAN:
case FNL_CELLULAR_DISTANCE_EUCLIDEANSQ:
{
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int hash = _fnlHash2D(seed, xPrimed, yPrimed);
int idx = hash & (255 << 1);
float vecX = (float)(xi - x) + RAND_VECS_2D[idx] * cellularJitter;
float vecY = (float)(yi - y) + RAND_VECS_2D[idx | 1] * cellularJitter;
float newDistance = vecX * vecX + vecY * vecY;
distance1 = _fnlFastMax(_fnlFastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
yPrimed += PRIME_Y;
}
xPrimed += PRIME_X;
}
break;
}
case FNL_CELLULAR_DISTANCE_MANHATTAN:
{
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int hash = _fnlHash2D(seed, xPrimed, yPrimed);
int idx = hash & (255 << 1);
float vecX = (float)(xi - x) + RAND_VECS_2D[idx] * cellularJitter;
float vecY = (float)(yi - y) + RAND_VECS_2D[idx | 1] * cellularJitter;
float newDistance = _fnlFastAbs(vecX) + _fnlFastAbs(vecY);
distance1 = _fnlFastMax(_fnlFastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
yPrimed += PRIME_Y;
}
xPrimed += PRIME_X;
}
break;
}
case FNL_CELLULAR_DISTANCE_HYBRID:
{
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int hash = _fnlHash2D(seed, xPrimed, yPrimed);
int idx = hash & (255 << 1);
float vecX = (float)(xi - x) + RAND_VECS_2D[idx] * cellularJitter;
float vecY = (float)(yi - y) + RAND_VECS_2D[idx | 1] * cellularJitter;
float newDistance = (_fnlFastAbs(vecX) + _fnlFastAbs(vecY)) + (vecX * vecX + vecY * vecY);
distance1 = _fnlFastMax(_fnlFastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
yPrimed += PRIME_Y;
}
xPrimed += PRIME_X;
}
break;
}
}
FNL_FLATTEN if (state.cellular_distance_func == FNL_CELLULAR_DISTANCE_EUCLIDEAN && state.cellular_return_type >= FNL_CELLULAR_RETURN_TYPE_DISTANCE)
{
distance0 = _fnlFastSqrt(distance0);
if (state.cellular_return_type >= FNL_CELLULAR_RETURN_TYPE_DISTANCE2)
distance1 = _fnlFastSqrt(distance1);
}
switch (state.cellular_return_type)
{
case FNL_CELLULAR_RETURN_TYPE_CELLVALUE:
return closestHash * (1 / 2147483648.0f);
case FNL_CELLULAR_RETURN_TYPE_DISTANCE:
return distance0 - 1;
case FNL_CELLULAR_RETURN_TYPE_DISTANCE2:
return distance1 - 1;
case FNL_CELLULAR_RETURN_TYPE_DISTANCE2ADD:
return (distance1 + distance0) * 0.5f - 1;
case FNL_CELLULAR_RETURN_TYPE_DISTANCE2SUB:
return distance1 - distance0 - 1;
case FNL_CELLULAR_RETURN_TYPE_DISTANCE2MUL:
return distance1 * distance0 * 0.5f - 1;
case FNL_CELLULAR_RETURN_TYPE_DISTANCE2DIV:
return distance0 / distance1 - 1;
default:
return 0;
}
}
static float _fnlSingleCellular3D(fnl_state state, int seed, FNLfloat x, FNLfloat y, FNLfloat z)
{
int xr = _fnlFastRound(x);
int yr = _fnlFastRound(y);
int zr = _fnlFastRound(z);
float distance0 = 1e10f;
float distance1 = 1e10f;
int closestHash = 0;
float cellularJitter = 0.39614353f * state.cellular_jitter_mod;
int xPrimed = (xr - 1) * PRIME_X;
int yPrimedBase = (yr - 1) * PRIME_Y;
int zPrimedBase = (zr - 1) * PRIME_Z;
switch (state.cellular_distance_func)
{
default:
case FNL_CELLULAR_DISTANCE_EUCLIDEAN:
case FNL_CELLULAR_DISTANCE_EUCLIDEANSQ:
{
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int zPrimed = zPrimedBase;
for (int zi = zr - 1; zi <= zr + 1; zi++)
{
int hash = _fnlHash3D(seed, xPrimed, yPrimed, zPrimed);
int idx = hash & (255 << 2);
float vecX = (float)(xi - x) + RAND_VECS_3D[idx] * cellularJitter;
float vecY = (float)(yi - y) + RAND_VECS_3D[idx | 1] * cellularJitter;
float vecZ = (float)(zi - z) + RAND_VECS_3D[idx | 2] * cellularJitter;
float newDistance = vecX * vecX + vecY * vecY + vecZ * vecZ;
distance1 = _fnlFastMax(_fnlFastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
zPrimed += PRIME_Z;
}
yPrimed += PRIME_Y;
}
xPrimed += PRIME_X;
}
break;
}
case FNL_CELLULAR_DISTANCE_MANHATTAN:
{
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int zPrimed = zPrimedBase;
for (int zi = zr - 1; zi <= zr + 1; zi++)
{
int hash = _fnlHash3D(seed, xPrimed, yPrimed, zPrimed);
int idx = hash & (255 << 2);
float vecX = (float)(xi - x) + RAND_VECS_3D[idx] * cellularJitter;
float vecY = (float)(yi - y) + RAND_VECS_3D[idx | 1] * cellularJitter;
float vecZ = (float)(zi - z) + RAND_VECS_3D[idx | 2] * cellularJitter;
float newDistance = _fnlFastAbs(vecX) + _fnlFastAbs(vecY) + _fnlFastAbs(vecZ);
distance1 = _fnlFastMax(_fnlFastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
zPrimed += PRIME_Z;
}
yPrimed += PRIME_Y;
}
xPrimed += PRIME_X;
}
break;
}
case FNL_CELLULAR_DISTANCE_HYBRID:
{
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int zPrimed = zPrimedBase;
for (int zi = zr - 1; zi <= zr + 1; zi++)
{
int hash = _fnlHash3D(seed, xPrimed, yPrimed, zPrimed);
int idx = hash & (255 << 2);
float vecX = (float)(xi - x) + RAND_VECS_3D[idx] * cellularJitter;
float vecY = (float)(yi - y) + RAND_VECS_3D[idx | 1] * cellularJitter;
float vecZ = (float)(zi - z) + RAND_VECS_3D[idx | 2] * cellularJitter;
float newDistance = (_fnlFastAbs(vecX) + _fnlFastAbs(vecY) + _fnlFastAbs(vecZ)) + (vecX * vecX + vecY * vecY + vecZ * vecZ);
distance1 = _fnlFastMax(_fnlFastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
zPrimed += PRIME_Z;
}
yPrimed += PRIME_Y;
}
xPrimed += PRIME_X;
}
break;
}
}
if (state.cellular_distance_func == FNL_CELLULAR_DISTANCE_EUCLIDEAN && state.cellular_return_type >= FNL_CELLULAR_RETURN_TYPE_DISTANCE)
{
distance0 = _fnlFastSqrt(distance0);
if (state.cellular_return_type >= FNL_CELLULAR_RETURN_TYPE_DISTANCE2)
distance1 = _fnlFastSqrt(distance1);
}
switch (state.cellular_return_type)
{
case FNL_CELLULAR_RETURN_TYPE_CELLVALUE:
return closestHash * (1 / 2147483648.0f);
case FNL_CELLULAR_RETURN_TYPE_DISTANCE:
return distance0 - 1;
case FNL_CELLULAR_RETURN_TYPE_DISTANCE2:
return distance1 - 1;
case FNL_CELLULAR_RETURN_TYPE_DISTANCE2ADD:
return (distance1 + distance0) * 0.5f - 1;
case FNL_CELLULAR_RETURN_TYPE_DISTANCE2SUB:
return distance1 - distance0 - 1;
case FNL_CELLULAR_RETURN_TYPE_DISTANCE2MUL:
return distance1 * distance0 * 0.5f - 1;
case FNL_CELLULAR_RETURN_TYPE_DISTANCE2DIV:
return distance0 / distance1 - 1;
default:
return 0;
}
}
// Perlin Noise
static float _fnlSinglePerlin2D(int seed, FNLfloat x, FNLfloat y)
{
int x0 = _fnlFastFloor(x);
int y0 = _fnlFastFloor(y);
float xd0 = (float)(x - x0);
float yd0 = (float)(y - y0);
float xd1 = xd0 - 1;
float yd1 = yd0 - 1;
float xs = _fnlInterpQuintic(xd0);
float ys = _fnlInterpQuintic(yd0);
x0 *= PRIME_X;
y0 *= PRIME_Y;
int x1 = x0 + PRIME_X;
int y1 = y0 + PRIME_Y;
float xf0 = _fnlLerp(_fnlGradCoord2D(seed, x0, y0, xd0, yd0), _fnlGradCoord2D(seed, x1, y0, xd1, yd0), xs);
float xf1 = _fnlLerp(_fnlGradCoord2D(seed, x0, y1, xd0, yd1), _fnlGradCoord2D(seed, x1, y1, xd1, yd1), xs);
return _fnlLerp(xf0, xf1, ys) * 1.4247691104677813f;
}
static float _fnlSinglePerlin3D(int seed, FNLfloat x, FNLfloat y, FNLfloat z)
{
int x0 = _fnlFastFloor(x);
int y0 = _fnlFastFloor(y);
int z0 = _fnlFastFloor(z);
float xd0 = (float)(x - x0);
float yd0 = (float)(y - y0);
float zd0 = (float)(z - z0);
float xd1 = xd0 - 1;
float yd1 = yd0 - 1;
float zd1 = zd0 - 1;
float xs = _fnlInterpQuintic(xd0);
float ys = _fnlInterpQuintic(yd0);
float zs = _fnlInterpQuintic(zd0);
x0 *= PRIME_X;
y0 *= PRIME_Y;
z0 *= PRIME_Z;
int x1 = x0 + PRIME_X;
int y1 = y0 + PRIME_Y;
int z1 = z0 + PRIME_Z;
float xf00 = _fnlLerp(_fnlGradCoord3D(seed, x0, y0, z0, xd0, yd0, zd0), _fnlGradCoord3D(seed, x1, y0, z0, xd1, yd0, zd0), xs);
float xf10 = _fnlLerp(_fnlGradCoord3D(seed, x0, y1, z0, xd0, yd1, zd0), _fnlGradCoord3D(seed, x1, y1, z0, xd1, yd1, zd0), xs);
float xf01 = _fnlLerp(_fnlGradCoord3D(seed, x0, y0, z1, xd0, yd0, zd1), _fnlGradCoord3D(seed, x1, y0, z1, xd1, yd0, zd1), xs);
float xf11 = _fnlLerp(_fnlGradCoord3D(seed, x0, y1, z1, xd0, yd1, zd1), _fnlGradCoord3D(seed, x1, y1, z1, xd1, yd1, zd1), xs);
float yf0 = _fnlLerp(xf00, xf10, ys);
float yf1 = _fnlLerp(xf01, xf11, ys);
return _fnlLerp(yf0, yf1, zs) * 0.964921414852142333984375f;
}
// Value Cubic
static float _fnlSingleValueCubic2D(int seed, FNLfloat x, FNLfloat y)
{
int x1 = _fnlFastFloor(x);
int y1 = _fnlFastFloor(y);
float xs = x - (float)x1;
float ys = y - (float)y1;
x1 *= PRIME_X;
y1 *= PRIME_Y;
int x0 = x1 - PRIME_X;
int y0 = y1 - PRIME_Y;
int x2 = x1 + PRIME_X;
int y2 = y1 + PRIME_Y;
int x3 = x1 + PRIME_X * 2;
int y3 = y1 + PRIME_Y * 2;
return _fnlCubicLerp(
_fnlCubicLerp(_fnlValCoord2D(seed, x0, y0), _fnlValCoord2D(seed, x1, y0), _fnlValCoord2D(seed, x2, y0), _fnlValCoord2D(seed, x3, y0),
xs),
_fnlCubicLerp(_fnlValCoord2D(seed, x0, y1), _fnlValCoord2D(seed, x1, y1), _fnlValCoord2D(seed, x2, y1), _fnlValCoord2D(seed, x3, y1),
xs),
_fnlCubicLerp(_fnlValCoord2D(seed, x0, y2), _fnlValCoord2D(seed, x1, y2), _fnlValCoord2D(seed, x2, y2), _fnlValCoord2D(seed, x3, y2),
xs),
_fnlCubicLerp(_fnlValCoord2D(seed, x0, y3), _fnlValCoord2D(seed, x1, y3), _fnlValCoord2D(seed, x2, y3), _fnlValCoord2D(seed, x3, y3),
xs),
ys) * (1 / (1.5f * 1.5f));
}
static float _fnlSingleValueCubic3D(int seed, FNLfloat x, FNLfloat y, FNLfloat z)
{
int x1 = _fnlFastFloor(x);
int y1 = _fnlFastFloor(y);
int z1 = _fnlFastFloor(z);
float xs = x - (float)x1;
float ys = y - (float)y1;
float zs = z - (float)z1;
x1 *= PRIME_X;
y1 *= PRIME_Y;
z1 *= PRIME_Z;
int x0 = x1 - PRIME_X;
int y0 = y1 - PRIME_Y;
int z0 = z1 - PRIME_Z;
int x2 = x1 + PRIME_X;
int y2 = y1 + PRIME_Y;
int z2 = z1 + PRIME_Z;
int x3 = x1 + PRIME_X * 2;
int y3 = y1 + PRIME_Y * 2;
int z3 = z1 + PRIME_Z * 2;
return _fnlCubicLerp(
_fnlCubicLerp(
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y0, z0), _fnlValCoord3D(seed, x1, y0, z0), _fnlValCoord3D(seed, x2, y0, z0), _fnlValCoord3D(seed, x3, y0, z0), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y1, z0), _fnlValCoord3D(seed, x1, y1, z0), _fnlValCoord3D(seed, x2, y1, z0), _fnlValCoord3D(seed, x3, y1, z0), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y2, z0), _fnlValCoord3D(seed, x1, y2, z0), _fnlValCoord3D(seed, x2, y2, z0), _fnlValCoord3D(seed, x3, y2, z0), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y3, z0), _fnlValCoord3D(seed, x1, y3, z0), _fnlValCoord3D(seed, x2, y3, z0), _fnlValCoord3D(seed, x3, y3, z0), xs),
ys),
_fnlCubicLerp(
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y0, z1), _fnlValCoord3D(seed, x1, y0, z1), _fnlValCoord3D(seed, x2, y0, z1), _fnlValCoord3D(seed, x3, y0, z1), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y1, z1), _fnlValCoord3D(seed, x1, y1, z1), _fnlValCoord3D(seed, x2, y1, z1), _fnlValCoord3D(seed, x3, y1, z1), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y2, z1), _fnlValCoord3D(seed, x1, y2, z1), _fnlValCoord3D(seed, x2, y2, z1), _fnlValCoord3D(seed, x3, y2, z1), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y3, z1), _fnlValCoord3D(seed, x1, y3, z1), _fnlValCoord3D(seed, x2, y3, z1), _fnlValCoord3D(seed, x3, y3, z1), xs),
ys),
_fnlCubicLerp(
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y0, z2), _fnlValCoord3D(seed, x1, y0, z2), _fnlValCoord3D(seed, x2, y0, z2), _fnlValCoord3D(seed, x3, y0, z2), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y1, z2), _fnlValCoord3D(seed, x1, y1, z2), _fnlValCoord3D(seed, x2, y1, z2), _fnlValCoord3D(seed, x3, y1, z2), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y2, z2), _fnlValCoord3D(seed, x1, y2, z2), _fnlValCoord3D(seed, x2, y2, z2), _fnlValCoord3D(seed, x3, y2, z2), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y3, z2), _fnlValCoord3D(seed, x1, y3, z2), _fnlValCoord3D(seed, x2, y3, z2), _fnlValCoord3D(seed, x3, y3, z2), xs),
ys),
_fnlCubicLerp(
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y0, z3), _fnlValCoord3D(seed, x1, y0, z3), _fnlValCoord3D(seed, x2, y0, z3), _fnlValCoord3D(seed, x3, y0, z3), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y1, z3), _fnlValCoord3D(seed, x1, y1, z3), _fnlValCoord3D(seed, x2, y1, z3), _fnlValCoord3D(seed, x3, y1, z3), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y2, z3), _fnlValCoord3D(seed, x1, y2, z3), _fnlValCoord3D(seed, x2, y2, z3), _fnlValCoord3D(seed, x3, y2, z3), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y3, z3), _fnlValCoord3D(seed, x1, y3, z3), _fnlValCoord3D(seed, x2, y3, z3), _fnlValCoord3D(seed, x3, y3, z3), xs),
ys),
zs) * (1 / (1.5f * 1.5f * 1.5f));
}
// Value noise
static float _fnlSingleValue2D(int seed, FNLfloat x, FNLfloat y)
{
int x0 = _fnlFastFloor(x);
int y0 = _fnlFastFloor(y);
float xs = _fnlInterpHermite((float)(x - x0));
float ys = _fnlInterpHermite((float)(y - y0));
x0 *= PRIME_X;
y0 *= PRIME_Y;
int x1 = x0 + PRIME_X;
int y1 = y0 + PRIME_Y;
float xf0 = _fnlLerp(_fnlValCoord2D(seed, x0, y0), _fnlValCoord2D(seed, x1, y0), xs);
float xf1 = _fnlLerp(_fnlValCoord2D(seed, x0, y1), _fnlValCoord2D(seed, x1, y1), xs);
return _fnlLerp(xf0, xf1, ys);
}
static float _fnlSingleValue3D(int seed, FNLfloat x, FNLfloat y, FNLfloat z)
{
int x0 = _fnlFastFloor(x);
int y0 = _fnlFastFloor(y);
int z0 = _fnlFastFloor(z);
float xs = _fnlInterpHermite((float)(x - x0));
float ys = _fnlInterpHermite((float)(y - y0));
float zs = _fnlInterpHermite((float)(z - z0));
x0 *= PRIME_X;
y0 *= PRIME_Y;
z0 *= PRIME_Z;
int x1 = x0 + PRIME_X;
int y1 = y0 + PRIME_Y;
int z1 = z0 + PRIME_Z;
float xf00 = _fnlLerp(_fnlValCoord3D(seed, x0, y0, z0), _fnlValCoord3D(seed, x1, y0, z0), xs);
float xf10 = _fnlLerp(_fnlValCoord3D(seed, x0, y1, z0), _fnlValCoord3D(seed, x1, y1, z0), xs);
float xf01 = _fnlLerp(_fnlValCoord3D(seed, x0, y0, z1), _fnlValCoord3D(seed, x1, y0, z1), xs);
float xf11 = _fnlLerp(_fnlValCoord3D(seed, x0, y1, z1), _fnlValCoord3D(seed, x1, y1, z1), xs);
float yf0 = _fnlLerp(xf00, xf10, ys);
float yf1 = _fnlLerp(xf01, xf11, ys);
return _fnlLerp(yf0, yf1, zs);
}
// Domain Warp
// Forward declare
static void _fnlSingleDomainWarpBasicGrid2D(int seed, float warpAmp, float frequency, FNLfloat x, FNLfloat y, inout FNLfloat xp, inout FNLfloat yp);
static void _fnlSingleDomainWarpBasicGrid3D(int seed, float warpAmp, float frequency, FNLfloat x, FNLfloat y, FNLfloat z, inout FNLfloat xp, inout FNLfloat yp, inout FNLfloat zp);
static void _fnlSingleDomainWarpSimplexGradient(int seed, float warpAmp, float frequency, FNLfloat x, FNLfloat y, inout FNLfloat xr, inout FNLfloat yr, bool outGradOnly);
static void _fnlSingleDomainWarpOpenSimplex2Gradient(int seed, float warpAmp, float frequency, FNLfloat x, FNLfloat y, FNLfloat z, inout FNLfloat xr, inout FNLfloat yr, inout FNLfloat zr, bool outGradOnly);
static void _fnlDoSingleDomainWarp2D(fnl_state state, int seed, float amp, float freq, FNLfloat x, FNLfloat y, inout FNLfloat xp, inout FNLfloat yp)
{
FNL_FLATTEN switch (state.domain_warp_type)
{
case FNL_DOMAIN_WARP_OPENSIMPLEX2:
_fnlSingleDomainWarpSimplexGradient(seed, amp * 38.283687591552734375f, freq, x, y, xp, yp, false);
break;
case FNL_DOMAIN_WARP_OPENSIMPLEX2_REDUCED:
_fnlSingleDomainWarpSimplexGradient(seed, amp * 16.0f, freq, x, y, xp, yp, true);
break;
case FNL_DOMAIN_WARP_BASICGRID:
_fnlSingleDomainWarpBasicGrid2D(seed, amp, freq, x, y, xp, yp);
break;
}
}
static void _fnlDoSingleDomainWarp3D(fnl_state state, int seed, float amp, float freq, FNLfloat x, FNLfloat y, FNLfloat z, inout FNLfloat xp, inout FNLfloat yp, inout FNLfloat zp)
{
FNL_FLATTEN switch (state.domain_warp_type)
{
case FNL_DOMAIN_WARP_OPENSIMPLEX2:
_fnlSingleDomainWarpOpenSimplex2Gradient(seed, amp * 32.69428253173828125f, freq, x, y, z, xp, yp, zp, false);
break;
case FNL_DOMAIN_WARP_OPENSIMPLEX2_REDUCED:
_fnlSingleDomainWarpOpenSimplex2Gradient(seed, amp * 7.71604938271605f, freq, x, y, z, xp, yp, zp, true);
break;
case FNL_DOMAIN_WARP_BASICGRID:
_fnlSingleDomainWarpBasicGrid3D(seed, amp, freq, x, y, z, xp, yp, zp);
break;
}
}
// Domain Warp Single Wrapper
static void _fnlDomainWarpSingle2D(fnl_state state, inout FNLfloat x, inout FNLfloat y)
{
int seed = state.seed;
float amp = state.domain_warp_amp * _fnlCalculateFractalBounding(state);
float freq = state.frequency;
FNLfloat xs = x;
FNLfloat ys = y;
_fnlTransformDomainWarpCoordinate2D(state, xs, ys);
_fnlDoSingleDomainWarp2D(state, seed, amp, freq, xs, ys, x, y);
}
static void _fnlDomainWarpSingle3D(fnl_state state, inout FNLfloat x, inout FNLfloat y, inout FNLfloat z)
{
int seed = state.seed;
float amp = state.domain_warp_amp * _fnlCalculateFractalBounding(state);
float freq = state.frequency;
FNLfloat xs = x;
FNLfloat ys = y;
FNLfloat zs = z;
_fnlTransformDomainWarpCoordinate3D(state, xs, ys, zs);
_fnlDoSingleDomainWarp3D(state, seed, amp, freq, xs, ys, zs, x, y, z);
}
// Domain Warp Fractal Progressive
static void _fnlDomainWarpFractalProgressive2D(fnl_state state, inout FNLfloat x, inout FNLfloat y)
{
int seed = state.seed;
float amp = state.domain_warp_amp * _fnlCalculateFractalBounding(state);
float freq = state.frequency;
for (int i = 0; i < state.octaves; i++)
{
FNLfloat xs = x;
FNLfloat ys = y;
_fnlTransformDomainWarpCoordinate2D(state, xs, ys);
_fnlDoSingleDomainWarp2D(state, seed, amp, freq, xs, ys, x, y);
seed++;
amp *= state.gain;
freq *= state.lacunarity;
}
}
static void _fnlDomainWarpFractalProgressive3D(fnl_state state, inout FNLfloat x, inout FNLfloat y, inout FNLfloat z)
{
int seed = state.seed;
float amp = state.domain_warp_amp * _fnlCalculateFractalBounding(state);
float freq = state.frequency;
for (int i = 0; i < state.octaves; i++)
{
FNLfloat xs = x;
FNLfloat ys = y;
FNLfloat zs = z;
_fnlTransformDomainWarpCoordinate3D(state, xs, ys, zs);
_fnlDoSingleDomainWarp3D(state, seed, amp, freq, xs, ys, zs, x, y, z);
seed++;
amp *= state.gain;
freq *= state.lacunarity;
}
}
// Domain Warp Fractal Independent
static void _fnlDomainWarpFractalIndependent2D(fnl_state state, inout FNLfloat x, inout FNLfloat y)
{
FNLfloat xs = x;
FNLfloat ys = y;
_fnlTransformDomainWarpCoordinate2D(state, xs, ys);
int seed = state.seed;
float amp = state.domain_warp_amp * _fnlCalculateFractalBounding(state);
float freq = state.frequency;
for (int i = 0; i < state.octaves; i++)
{
_fnlDoSingleDomainWarp2D(state, seed, amp, freq, xs, ys, x, y);
seed++;
amp *= state.gain;
freq *= state.lacunarity;
}
}
static void _fnlDomainWarpFractalIndependent3D(fnl_state state, inout FNLfloat x, inout FNLfloat y, inout FNLfloat z)
{
FNLfloat xs = x;
FNLfloat ys = y;
FNLfloat zs = z;
_fnlTransformDomainWarpCoordinate3D(state, xs, ys, zs);
int seed = state.seed;
float amp = state.domain_warp_amp * _fnlCalculateFractalBounding(state);
float freq = state.frequency;
for (int i = 0; i < state.octaves; i++)
{
_fnlDoSingleDomainWarp3D(state, seed, amp, freq, xs, ys, zs, x, y, z);
seed++;
amp *= state.gain;
freq *= state.lacunarity;
}
}
// Domain Warp Basic Grid
static void _fnlSingleDomainWarpBasicGrid2D(int seed, float warpAmp, float frequency, FNLfloat x, FNLfloat y, inout FNLfloat xp, inout FNLfloat yp)
{
FNLfloat xf = x * frequency;
FNLfloat yf = y * frequency;
int x0 = _fnlFastFloor(xf);
int y0 = _fnlFastFloor(yf);
float xs = _fnlInterpHermite((float)(xf - x0));
float ys = _fnlInterpHermite((float)(yf - y0));
x0 *= PRIME_X;
y0 *= PRIME_Y;
int x1 = x0 + PRIME_X;
int y1 = y0 + PRIME_Y;
int idx0 = _fnlHash2D(seed, x0, y0) & (255 << 1);
int idx1 = _fnlHash2D(seed, x1, y0) & (255 << 1);
float lx0x = _fnlLerp(RAND_VECS_2D[idx0], RAND_VECS_2D[idx1], xs);
float ly0x = _fnlLerp(RAND_VECS_2D[idx0 | 1], RAND_VECS_2D[idx1 | 1], xs);
idx0 = _fnlHash2D(seed, x0, y1) & (255 << 1);
idx1 = _fnlHash2D(seed, x1, y1) & (255 << 1);
float lx1x = _fnlLerp(RAND_VECS_2D[idx0], RAND_VECS_2D[idx1], xs);
float ly1x = _fnlLerp(RAND_VECS_2D[idx0 | 1], RAND_VECS_2D[idx1 | 1], xs);
xp += _fnlLerp(lx0x, lx1x, ys) * warpAmp;
yp += _fnlLerp(ly0x, ly1x, ys) * warpAmp;
}
static void _fnlSingleDomainWarpBasicGrid3D(int seed, float warpAmp, float frequency, FNLfloat x, FNLfloat y, FNLfloat z, inout FNLfloat xp, inout FNLfloat yp, inout FNLfloat zp)
{
FNLfloat xf = x * frequency;
FNLfloat yf = y * frequency;
FNLfloat zf = z * frequency;
int x0 = _fnlFastFloor(xf);
int y0 = _fnlFastFloor(yf);
int z0 = _fnlFastFloor(zf);
float xs = _fnlInterpHermite((float)(xf - x0));
float ys = _fnlInterpHermite((float)(yf - y0));
float zs = _fnlInterpHermite((float)(zf - z0));
x0 *= PRIME_X;
y0 *= PRIME_Y;
z0 *= PRIME_Z;
int x1 = x0 + PRIME_X;
int y1 = y0 + PRIME_Y;
int z1 = z0 + PRIME_Z;
int idx0 = _fnlHash3D(seed, x0, y0, z0) & (255 << 2);
int idx1 = _fnlHash3D(seed, x1, y0, z0) & (255 << 2);
float lx0x = _fnlLerp(RAND_VECS_3D[idx0], RAND_VECS_3D[idx1], xs);
float ly0x = _fnlLerp(RAND_VECS_3D[idx0 | 1], RAND_VECS_3D[idx1 | 1], xs);
float lz0x = _fnlLerp(RAND_VECS_3D[idx0 | 2], RAND_VECS_3D[idx1 | 2], xs);
idx0 = _fnlHash3D(seed, x0, y1, z0) & (255 << 2);
idx1 = _fnlHash3D(seed, x1, y1, z0) & (255 << 2);
float lx1x = _fnlLerp(RAND_VECS_3D[idx0], RAND_VECS_3D[idx1], xs);
float ly1x = _fnlLerp(RAND_VECS_3D[idx0 | 1], RAND_VECS_3D[idx1 | 1], xs);
float lz1x = _fnlLerp(RAND_VECS_3D[idx0 | 2], RAND_VECS_3D[idx1 | 2], xs);
float lx0y = _fnlLerp(lx0x, lx1x, ys);
float ly0y = _fnlLerp(ly0x, ly1x, ys);
float lz0y = _fnlLerp(lz0x, lz1x, ys);
idx0 = _fnlHash3D(seed, x0, y0, z1) & (255 << 2);
idx1 = _fnlHash3D(seed, x1, y0, z1) & (255 << 2);
lx0x = _fnlLerp(RAND_VECS_3D[idx0], RAND_VECS_3D[idx1], xs);
ly0x = _fnlLerp(RAND_VECS_3D[idx0 | 1], RAND_VECS_3D[idx1 | 1], xs);
lz0x = _fnlLerp(RAND_VECS_3D[idx0 | 2], RAND_VECS_3D[idx1 | 2], xs);
idx0 = _fnlHash3D(seed, x0, y1, z1) & (255 << 2);
idx1 = _fnlHash3D(seed, x1, y1, z1) & (255 << 2);
lx1x = _fnlLerp(RAND_VECS_3D[idx0], RAND_VECS_3D[idx1], xs);
ly1x = _fnlLerp(RAND_VECS_3D[idx0 | 1], RAND_VECS_3D[idx1 | 1], xs);
lz1x = _fnlLerp(RAND_VECS_3D[idx0 | 2], RAND_VECS_3D[idx1 | 2], xs);
xp += _fnlLerp(lx0y, _fnlLerp(lx0x, lx1x, ys), zs) * warpAmp;
yp += _fnlLerp(ly0y, _fnlLerp(ly0x, ly1x, ys), zs) * warpAmp;
zp += _fnlLerp(lz0y, _fnlLerp(lz0x, lz1x, ys), zs) * warpAmp;
}
// Domain Warp Simplex/OpenSimplex2
static void _fnlSingleDomainWarpSimplexGradient(int seed, float warpAmp, float frequency, FNLfloat x, FNLfloat y, inout FNLfloat xr, inout FNLfloat yr, bool outGradOnly)
{
const float SQRT3 = 1.7320508075688772935274463415059f;
const float G2 = (3 - SQRT3) / 6;
x *= frequency;
y *= frequency;
/*
* --- Skew moved to TransformNoiseCoordinate method ---
* const FNLfloat F2 = 0.5f * (SQRT3 - 1);
* FNLfloat s = (x + y) * F2;
* x += s; y += s;
*/
int i = _fnlFastFloor(x);
int j = _fnlFastFloor(y);
float xi = (float)(x - i);
float yi = (float)(y - j);
float t = (xi + yi) * G2;
float x0 = (float)(xi - t);
float y0 = (float)(yi - t);
i *= PRIME_X;
j *= PRIME_Y;
float vx, vy;
vx = vy = 0;
float a = 0.5f - x0 * x0 - y0 * y0;
if (a > 0)
{
float aaaa = (a * a) * (a * a);
float xo, yo;
if (outGradOnly)
_fnlGradCoordOut2D(seed, i, j, xo, yo);
else
_fnlGradCoordDual2D(seed, i, j, x0, y0, xo, yo);
vx += aaaa * xo;
vy += aaaa * yo;
}
float c = (float)(2 * (1 - 2 * G2) * (1 / G2 - 2)) * t + ((float)(-2 * (1 - 2 * G2) * (1 - 2 * G2)) + a);
if (c > 0)
{
float x2 = x0 + (2 * (float)G2 - 1);
float y2 = y0 + (2 * (float)G2 - 1);
float cccc = (c * c) * (c * c);
float xo, yo;
if (outGradOnly)
_fnlGradCoordOut2D(seed, i + PRIME_X, j + PRIME_Y, xo, yo);
else
_fnlGradCoordDual2D(seed, i + PRIME_X, j + PRIME_Y, x2, y2, xo, yo);
vx += cccc * xo;
vy += cccc * yo;
}
if (y0 > x0)
{
float x1 = x0 + (float)G2;
float y1 = y0 + ((float)G2 - 1);
float b = 0.5f - x1 * x1 - y1 * y1;
if (b > 0)
{
float bbbb = (b * b) * (b * b);
float xo, yo;
if (outGradOnly)
_fnlGradCoordOut2D(seed, i, j + PRIME_Y, xo, yo);
else
_fnlGradCoordDual2D(seed, i, j + PRIME_Y, x1, y1, xo, yo);
vx += bbbb * xo;
vy += bbbb * yo;
}
}
else
{
float x1 = x0 + ((float)G2 - 1);
float y1 = y0 + (float)G2;
float b = 0.5f - x1 * x1 - y1 * y1;
if (b > 0)
{
float bbbb = (b * b) * (b * b);
float xo, yo;
if (outGradOnly)
_fnlGradCoordOut2D(seed, i + PRIME_X, j, xo, yo);
else
_fnlGradCoordDual2D(seed, i + PRIME_X, j, x1, y1, xo, yo);
vx += bbbb * xo;
vy += bbbb * yo;
}
}
xr += vx * warpAmp;
yr += vy * warpAmp;
}
static void _fnlSingleDomainWarpOpenSimplex2Gradient(int seed, float warpAmp, float frequency, FNLfloat x, FNLfloat y, FNLfloat z, inout FNLfloat xr, inout FNLfloat yr, inout FNLfloat zr, bool outGradOnly)
{
x *= frequency;
y *= frequency;
z *= frequency;
/*
* --- Rotation moved to TransformDomainWarpCoordinate method ---
* const FNLfloat R3 = (FNLfloat)(2.0 / 3.0);
* FNLfloat r = (x + y + z) * R3; // Rotation, not skew
* x = r - x; y = r - y; z = r - z;
*/
int i = _fnlFastRound(x);
int j = _fnlFastRound(y);
int k = _fnlFastRound(z);
float x0 = (float)x - i;
float y0 = (float)y - j;
float z0 = (float)z - k;
int xNSign = (int)(-x0 - 1.0f) | 1;
int yNSign = (int)(-y0 - 1.0f) | 1;
int zNSign = (int)(-z0 - 1.0f) | 1;
float ax0 = xNSign * -x0;
float ay0 = yNSign * -y0;
float az0 = zNSign * -z0;
i *= PRIME_X;
j *= PRIME_Y;
k *= PRIME_Z;
float vx, vy, vz;
vx = vy = vz = 0;
float a = (0.6f - x0 * x0) - (y0 * y0 + z0 * z0);
for (int l = 0; l < 2; l++)
{
if (a > 0)
{
float aaaa = (a * a) * (a * a);
float xo, yo, zo;
if (outGradOnly)
_fnlGradCoordOut3D(seed, i, j, k, xo, yo, zo);
else
_fnlGradCoordDual3D(seed, i, j, k, x0, y0, z0, xo, yo, zo);
vx += aaaa * xo;
vy += aaaa * yo;
vz += aaaa * zo;
}
float b = a + 1;
int i1 = i;
int j1 = j;
int k1 = k;
float x1 = x0;
float y1 = y0;
float z1 = z0;
if (ax0 >= ay0 && ax0 >= az0)
{
x1 += xNSign;
b -= xNSign * 2 * x1;
i1 -= xNSign * PRIME_X;
}
else if (ay0 > ax0 && ay0 >= az0)
{
y1 += yNSign;
b -= yNSign * 2 * y1;
j1 -= yNSign * PRIME_Y;
}
else
{
z1 += zNSign;
b -= zNSign * 2 * z1;
k1 -= zNSign * PRIME_Z;
}
if (b > 0)
{
float bbbb = (b * b) * (b * b);
float xo, yo, zo;
if (outGradOnly)
_fnlGradCoordOut3D(seed, i1, j1, k1, xo, yo, zo);
else
_fnlGradCoordDual3D(seed, i1, j1, k1, x1, y1, z1, xo, yo, zo);
vx += bbbb * xo;
vy += bbbb * yo;
vz += bbbb * zo;
}
if (l == 1)
break;
ax0 = 0.5f - ax0;
ay0 = 0.5f - ay0;
az0 = 0.5f - az0;
x0 = xNSign * ax0;
y0 = yNSign * ay0;
z0 = zNSign * az0;
a += (0.75f - ax0) - (ay0 + az0);
i += (xNSign >> 1) & PRIME_X;
j += (yNSign >> 1) & PRIME_Y;
k += (zNSign >> 1) & PRIME_Z;
xNSign = -xNSign;
yNSign = -yNSign;
zNSign = -zNSign;
seed += 1293373;
}
xr += vx * warpAmp;
yr += vy * warpAmp;
zr += vz * warpAmp;
}
// ====================
// Public API
// ====================
fnl_state fnlCreateState(int seed)
{
fnl_state newState;
newState.seed = seed;
newState.frequency = 0.01f;
newState.noise_type = FNL_NOISE_OPENSIMPLEX2;
newState.rotation_type_3d = FNL_ROTATION_NONE;
newState.fractal_type = FNL_FRACTAL_NONE;
newState.octaves = 3;
newState.lacunarity = 2.0f;
newState.gain = 0.5f;
newState.weighted_strength = 0.0f;
newState.ping_pong_strength = 2.0f;
newState.cellular_distance_func = FNL_CELLULAR_DISTANCE_EUCLIDEANSQ;
newState.cellular_return_type = FNL_CELLULAR_RETURN_TYPE_DISTANCE;
newState.cellular_jitter_mod = 1.0f;
newState.domain_warp_amp = 30.0f;
newState.domain_warp_type = FNL_DOMAIN_WARP_OPENSIMPLEX2;
return newState;
}
float fnlGetNoise2D(fnl_state state, FNLfloat x, FNLfloat y)
{
_fnlTransformNoiseCoordinate2D(state, x, y);
FNL_FLATTEN switch (state.fractal_type)
{
default:
return _fnlGenNoiseSingle2D(state, state.seed, x, y);
case FNL_FRACTAL_FBM:
return _fnlGenFractalFBM2D(state, x, y);
case FNL_FRACTAL_RIDGED:
return _fnlGenFractalRidged2D(state, x, y);
case FNL_FRACTAL_PINGPONG:
return _fnlGenFractalPingPong2D(state, x, y);
}
}
float fnlGetNoise3D(fnl_state state, FNLfloat x, FNLfloat y, FNLfloat z)
{
_fnlTransformNoiseCoordinate3D(state, x, y, z);
// Select a noise type
FNL_FLATTEN switch (state.fractal_type)
{
default:
return _fnlGenNoiseSingle3D(state, state.seed, x, y, z);
case FNL_FRACTAL_FBM:
return _fnlGenFractalFBM3D(state, x, y, z);
case FNL_FRACTAL_RIDGED:
return _fnlGenFractalRidged3D(state, x, y, z);
case FNL_FRACTAL_PINGPONG:
return _fnlGenFractalPingPong3D(state, x, y, z);
}
}
void fnlDomainWarp2D(fnl_state state, inout FNLfloat x, inout FNLfloat y)
{
FNL_FLATTEN switch (state.fractal_type)
{
default:
_fnlDomainWarpSingle2D(state, x, y);
break;
case FNL_FRACTAL_DOMAIN_WARP_PROGRESSIVE:
_fnlDomainWarpFractalProgressive2D(state, x, y);
break;
case FNL_FRACTAL_DOMAIN_WARP_INDEPENDENT:
_fnlDomainWarpFractalIndependent2D(state, x, y);
break;
}
}
void fnlDomainWarp3D(fnl_state state, inout FNLfloat x, inout FNLfloat y, inout FNLfloat z)
{
FNL_FLATTEN switch (state.fractal_type)
{
default:
_fnlDomainWarpSingle3D(state, x, y, z);
break;
case FNL_FRACTAL_DOMAIN_WARP_PROGRESSIVE:
_fnlDomainWarpFractalProgressive3D(state, x, y, z);
break;
case FNL_FRACTAL_DOMAIN_WARP_INDEPENDENT:
_fnlDomainWarpFractalIndependent3D(state, x, y, z);
break;
}
}
``` | /content/code_sandbox/HLSL/FastNoiseLite.hlsl | hlsl | 2016-03-28T02:35:12 | 2024-08-16T07:09:20 | FastNoiseLite | Auburn/FastNoiseLite | 2,688 | 41,132 |
```javascript
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// .'',;:cldxkO00KKXXNNWWWNNXKOkxdollcc::::::;:::ccllloooolllllllllooollc:,'... ...........',;cldxkO000Okxdlc::;;;,,;;;::cclllllll
// ..',;:ldxO0KXXNNNNNNNNXXK0kxdolcc::::::;;;,,,,,,;;;;;;;;;;:::cclllllc:;'.... ...........',;:ldxO0KXXXK0Okxdolc::;;;;::cllodddddo
// ...',:loxO0KXNNNNNXXKK0Okxdolc::;::::::::;;;,,'''''.....''',;:clllllc:;,'............''''''''',;:loxO0KXNNNNNXK0Okxdollccccllodxxxxxxd
// ....';:ldkO0KXXXKK00Okxdolcc:;;;;;::cclllcc:;;,''..... ....',;clooddolcc:;;;;,,;;;;;::::;;;;;;:cloxk0KXNWWWWWWNXKK0Okxddoooddxxkkkkkxx
// .....';:ldxkOOOOOkxxdolcc:;;;,,,;;:cllooooolcc:;'... ..,:codxkkkxddooollloooooooollcc:::::clodkO0KXNWWWWWWNNXK00Okxxxxxxxxkkkkxxx
// . ....';:cloddddo___________,,,,;;:clooddddoolc:,... ..,:ldx__00OOOkkk___kkkkkkxxdollc::::cclodkO0KXXNNNNNNXXK0OOkxxxxxxxxxxxxddd
// .......',;:cccc:| |,,,;;:cclooddddoll:;'.. ..';cox| \KKK000| |KK00OOkxdocc___;::clldxxkO0KKKKK00Okkxdddddddddddddddoo
// .......'',,,,,''| ________|',,;;::cclloooooolc:;'......___:ldk| \KK000| |XKKK0Okxolc| |;;::cclodxxkkkkxxdoolllcclllooodddooooo
// ''......''''....| | ....'',,,,;;;::cclloooollc:;,''.'| |oxk| \OOO0| |KKK00Oxdoll|___|;;;;;::ccllllllcc::;;,,;;;:cclloooooooo
// ;;,''.......... | |_____',,;;;____:___cllo________.___| |___| \xkk| |KK_______ool___:::;________;;;_______...'',;;:ccclllloo
// c:;,''......... | |:::/ ' |lo/ | | \dx| |0/ \d| |cc/ |'/ \......',,;;:ccllo
// ol:;,'..........| _____|ll/ __ |o/ ______|____ ___| | \o| |/ ___ \| |o/ ______|/ ___ \ .......'',;:clo
// dlc;,...........| |::clooo| / | |x\___ \KXKKK0| |dol| |\ \| | | | | |d\___ \..| | / / ....',:cl
// xoc;'... .....'| |llodddd| \__| |_____\ \KKK0O| |lc:| |'\ | |___| | |_____\ \.| |_/___/... ...',;:c
// dlc;'... ....',;| |oddddddo\ | |Okkx| |::;| |..\ |\ /| | | \ |... ....',;:c
// ol:,'.......',:c|___|xxxddollc\_____,___|_________/ddoll|___|,,,|___|...\_____|:\ ______/l|___|_________/...\________|'........',;::cc
// c:;'.......';:codxxkkkkxxolc::;::clodxkOO0OOkkxdollc::;;,,''''',,,,''''''''''',,'''''',;:loxkkOOkxol:;,'''',,;:ccllcc:;,'''''',;::ccll
// ;,'.......',:codxkOO0OOkxdlc:;,,;;:cldxxkkxxdolc:;;,,''.....'',;;:::;;,,,'''''........,;cldkO0KK0Okdoc::;;::cloodddoolc:;;;;;::ccllooo
// .........',;:lodxOO0000Okdoc:,,',,;:clloddoolc:;,''.......'',;:clooollc:;;,,''.......',:ldkOKXNNXX0Oxdolllloddxxxxxxdolccccccllooodddd
// . .....';:cldxkO0000Okxol:;,''',,;::cccc:;,,'.......'',;:cldxxkkxxdolc:;;,'.......';coxOKXNWWWNXKOkxddddxxkkkkkkxdoollllooddxxxxkkk
// ....',;:codxkO000OOxdoc:;,''',,,;;;;,''.......',,;:clodkO00000Okxolc::;,,''..',;:ldxOKXNWWWNNK0OkkkkkkkkkkkxxddooooodxxkOOOOO000
// ....',;;clodxkkOOOkkdolc:;,,,,,,,,'..........,;:clodxkO0KKXKK0Okxdolcc::;;,,,;;:codkO0XXNNNNXKK0OOOOOkkkkxxdoollloodxkO0KKKXXXXX
//
// VERSION: 1.1.1
// path_to_url
// path_to_url
//
// Ported to JavaScript by snowfoxsh (Patrick U):
// Discord: dev_storm (preferred) | Email: storm1surge@gmail.com | GitHub: snowfoxsh (path_to_url
//
/**
* @description FastNoise Lite is an extremely portable open source noise generation library with a large selection of noise algorithms
* @author Jordan Peck, snowfoxsh
* @version 1.1.1
* @license MIT
* @git path_to_url
* @npm path_to_url
* @example
// Import from npm (if you used npm)
import FastNoiseLite from "fastnoise-lite";
// Create and configure FastNoiseLite object
let noise = new FastNoiseLite();
noise.SetNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
// Gather noise data
let noiseData = [];
for (let x = 0; x < 128; x++) {
noiseData[x] = [];
for (let y = 0; y < 128; y++) {
noiseData[x][y] = noise.GetNoise(x,y);
}
}
// Do something with this data...
*/
export default class FastNoiseLite {
/**
* @static
* @enum {string}
* @type {Readonly<{Cellular: string, OpenSimplex2: string, Value: string, ValueCubic: string, Perlin: string, OpenSimplex2S: string}>}
*/
static NoiseType = Object.freeze({
OpenSimplex2: "OpenSimplex2",
OpenSimplex2S: "OpenSimplex2S",
Cellular: "Cellular",
Perlin: "Perlin",
ValueCubic: "ValueCubic",
Value: "Value",
});
/**
* @static
* @enum {string}
* @type {Readonly<{ImproveXYPlanes: string, ImproveXZPlanes: string, None: string}>}
*/
static RotationType3D = Object.freeze({
None: "None",
ImproveXYPlanes: "ImproveXYPlanes",
ImproveXZPlanes: "ImproveXZPlanes",
});
/**
* @static
* @enum {string}
* @type {Readonly<{FBm: string, DomainWarpIndependent: string, PingPong: string, None: string, Ridged: string, DomainWarpProgressive: string}>}
*/
static FractalType = Object.freeze({
None: "None",
FBm: "FBm",
Ridged: "Ridged",
PingPong: "PingPong",
DomainWarpProgressive: "DomainWarpProgressive",
DomainWarpIndependent: "DomainWarpIndependent",
});
/**
* @static
* @enum {string}
* @type {Readonly<{EuclideanSq: string, Euclidean: string, Hybrid: string, Manhattan: string}>}
*/
static CellularDistanceFunction = Object.freeze({
Euclidean: "Euclidean",
EuclideanSq: "EuclideanSq",
Manhattan: "Manhattan",
Hybrid: "Hybrid",
});
/**
* @static
* @enum {string}
* @type {Readonly<{Distance2Sub: string, Distance2Mul: string, Distance2Add: string, Distance2Div: string, CellValue: string, Distance: string, Distance2: string}>}
*/
static CellularReturnType = Object.freeze({
CellValue: "CellValue",
Distance: "Distance",
Distance2: "Distance2",
Distance2Add: "Distance2Add",
Distance2Sub: "Distance2Sub",
Distance2Mul: "Distance2Mul",
Distance2Div: "Distance2Div",
});
/**
* @static
* @enum {string}
* @type {Readonly<{BasicGrid: string, OpenSimplex2Reduced: string, OpenSimplex2: string}>}
*/
static DomainWarpType = Object.freeze({
OpenSimplex2: "OpenSimplex2",
OpenSimplex2Reduced: "OpenSimplex2Reduced",
BasicGrid: "BasicGrid",
});
/**
* @static
* @enum {string}
* @type {Readonly<{ImproveXYPlanes: string, ImproveXZPlanes: string, None: string, DefaultOpenSimplex2: string}>}
*/
static TransformType3D = Object.freeze({
None: "None",
ImproveXYPlanes: "ImproveXYPlanes",
ImproveXZPlanes: "ImproveXZPlanes",
DefaultOpenSimplex2: "DefaultOpenSimplex2",
});
/* Private */
_Seed = 1337;
_Frequency = 0.01;
_NoiseType = FastNoiseLite.NoiseType.OpenSimplex2;
_RotationType3D = FastNoiseLite.RotationType3D.None;
_TransformType3D = FastNoiseLite.TransformType3D.DefaultOpenSimplex2;
_DomainWarpAmp = 1.0;
_FractalType = FastNoiseLite.FractalType.None;
_Octaves = 3;
_Lacunarity = 2.0;
_Gain = 0.5;
_WeightedStrength = 0.0;
_PingPongStrength = 2.0;
_FractalBounding = 1 / 1.75;
_CellularDistanceFunction = FastNoiseLite.CellularDistanceFunction.EuclideanSq;
_CellularReturnType = FastNoiseLite.CellularReturnType.Distance;
_CellularJitterModifier = 1.0;
_DomainWarpType = FastNoiseLite.DomainWarpType.OpenSimplex2;
_WarpTransformType3D = FastNoiseLite.TransformType3D.DefaultOpenSimplex2;
/**
* @description Create new FastNoiseLite object with optional seed
* @param {number} [seed]
* @constructor
*/
constructor(seed) {
if (seed !== undefined) {
this._Seed = seed;
}
}
/**
* @description Sets seed used for all noise types
* @remarks Default: 1337
* @default 1337
* @param {number} seed
*/
SetSeed(seed) {
this._Seed = seed;
}
/**
* @description Sets frequency for all noise types
* @remarks Default: 0.01
* @default 0.01
* @param {number} frequency
*/
SetFrequency(frequency) {
this._Frequency = frequency;
}
/**
* @description Sets noise algorithm used for GetNoise(...)
* @remarks Default: OpenSimplex2
* @default FastNoiseLite.NoiseType.OpenSimplex2
* @param {FastNoiseLite.NoiseType} noiseType
*/
SetNoiseType(noiseType) {
this._NoiseType = noiseType;
this._UpdateTransformType3D();
}
/**
* @description Sets domain rotation type for 3D Noise and 3D DomainWarp.
* @description Can aid in reducing directional artifacts when sampling a 2D plane in 3D
* @remarks Default: None
* @default FastNoiseLite.RotationType3D.None
* @param {FastNoiseLite.RotationType3D} rotationType3D
*/
SetRotationType3D(rotationType3D) {
this._RotationType3D = rotationType3D;
this._UpdateTransformType3D();
this._UpdateWarpTransformType3D();
}
/**
* @description Sets method for combining octaves in all fractal noise types
* @remarks Default: None
* @default FastNoiseLite.FractalType.None
* @param {FastNoiseLite.FractalType} fractalType
*/
SetFractalType(fractalType) {
this._FractalType = fractalType;
}
/**
* @description Sets octave count for all fractal noise types
* @remarks Default: 3
* @default 3
* @param {number} octaves
*/
SetFractalOctaves(octaves) {
this._Octaves = octaves;
this._CalculateFractalBounding();
}
/**
* @description Sets octave lacunarity for all fractal noise types
* @remarks Default: 2.0
* @default 2.0
* @param {number} lacunarity
*/
SetFractalLacunarity(lacunarity) {
this._Lacunarity = lacunarity;
}
/**
* @description Sets octave gain for all fractal noise types
* @remarks Default: 0.5
* @default 0.5
* @param {number} gain
*/
SetFractalGain(gain) {
this._Gain = gain;
this._CalculateFractalBounding();
}
/**
* @description Sets octave weighting for all none DomainWarp fratal types
* @remarks Default: 0.0 | Keep between 0...1 to maintain -1...1 output bounding
* @default 0.5
* @param {number} weightedStrength
*/
SetFractalWeightedStrength(weightedStrength) {
this._WeightedStrength = weightedStrength;
}
/**
* @description Sets strength of the fractal ping pong effect
* @remarks Default: 2.0
* @default 2.0
* @param {number} pingPongStrength
*/
SetFractalPingPongStrength(pingPongStrength) {
this._PingPongStrength = pingPongStrength;
}
/**
* @description Sets distance function used in cellular noise calculations
* @remarks Default: EuclideanSq
* @default FastNoiseLite.CellularDistanceFunction.EuclideanSq
* @param {FastNoiseLite.CellularDistanceFunction} cellularDistanceFunction
*/
SetCellularDistanceFunction(cellularDistanceFunction) {
this._CellularDistanceFunction = cellularDistanceFunction;
}
/**
* @description Sets return type from cellular noise calculations
* @remarks Default: Distance
* @default FastNoiseLite.CellularReturnType.Distance
* @param {FastNoiseLite.CellularReturnType} cellularReturnType
*/
SetCellularReturnType(cellularReturnType) {
this._CellularReturnType = cellularReturnType;
}
/**
* @description Sets the maximum distance a cellular point can move from it's grid position
* @remarks Default: 1.0
* @default 1.0
* @param {number} cellularJitter
*/
SetCellularJitter(cellularJitter) {
this._CellularJitterModifier = cellularJitter;
}
/**
* @description Sets the warp algorithm when using DomainWarp(...)
* @remarks Default: OpenSimplex2
* @default FastNoiseLite.DomainWarpType.OpenSimplex2
* @param {FastNoiseLite.DomainWarpType} domainWarpType
*/
SetDomainWarpType(domainWarpType) {
this._DomainWarpType = domainWarpType;
this._UpdateWarpTransformType3D();
}
/**
* @description Sets the maximum warp distance from original position when using DomainWarp(...)
* @remarks Default: 1.0
* @default 1.0
* @param {number} domainWarpAmp
*/
SetDomainWarpAmp(domainWarpAmp) {
this._DomainWarpAmp = domainWarpAmp;
}
/**
* @description 2D/3D noise at given position using current settings
* @param {number} x X coordinate
* @param {number} y Y coordinate
* @param {number} [z] Z coordinate
* @return {number} Noise output bounded between -1...1
*/
GetNoise(x, y, z) {
/**
* @description 2D noise at given position using current settings
* @param {number} x
* @param {number} y
* @return {number} Noise output bounded between -1...1
*/
let R2 = (x, y) => {
x *= this._Frequency;
y *= this._Frequency;
switch (this._NoiseType) {
case FastNoiseLite.NoiseType.OpenSimplex2:
case FastNoiseLite.NoiseType.OpenSimplex2S:
const SQRT3 = 1.7320508075688772935274463415059;
const F2 = 0.5 * (SQRT3 - 1);
let t = (x + y) * F2;
x += t;
y += t;
break;
default:
break;
}
switch (this._FractalType) {
default:
return this._GenNoiseSingleR2(this._Seed, x, y);
case FastNoiseLite.FractalType.FBm:
return this._GenFractalFBmR2(x, y);
case FastNoiseLite.FractalType.Ridged:
return this._GenFractalRidgedR2(x, y);
case FastNoiseLite.FractalType.PingPong:
return this._GenFractalPingPongR2(x, y);
}
};
/**
* @description 3D noise at given position using current settings
* @param {number} x
* @param {number} y
* @param {number} z
* @return {number} Noise output bounded between -1...1
*/
let R3 = (x, y, z) => {
x *= this._Frequency;
y *= this._Frequency;
z *= this._Frequency;
switch (this._TransformType3D) {
case FastNoiseLite.TransformType3D.ImproveXYPlanes: {
let xy = x + y;
let s2 = xy * -0.211324865405187;
z *= 0.577350269189626;
x += s2 - z;
y += s2 - z;
z += xy * 0.577350269189626;
break;
}
case FastNoiseLite.TransformType3D.ImproveXZPlanes: {
let xz = x + z;
let s2 = xz * -0.211324865405187;
y *= 0.577350269189626;
x += s2 - y;
z += s2 - y;
y += xz * 0.577350269189626;
break;
}
case FastNoiseLite.TransformType3D.DefaultOpenSimplex2:
const R3 = 2.0 / 3.0;
let r = (x + y + z) * R3;
x = r - x;
y = r - y;
z = r - z;
break;
default:
break;
}
switch (this._FractalType) {
default:
return this._GenNoiseSingleR3(this._Seed, x, y, z);
case FastNoiseLite.FractalType.FBm:
return this._GenFractalFBmR3(x, y, z);
case FastNoiseLite.FractalType.Ridged:
return this._GenFractalRidgedR3(x, y, z);
case FastNoiseLite.FractalType.PingPong:
return this._GenFractalPingPongR3(x, y, z);
}
};
if (arguments.length === 2) {
return R2(x, y);
}
if (arguments.length === 3) {
return R3(x, y, z);
}
}
/**
* @description 2D/3D warps the input position using current domain warp settings
* @param {Vector2|Vector3} coord
*/
DomainWrap(coord) {
switch (this._FractalType) {
default:
this._DomainWarpSingle(coord);
break;
case FastNoiseLite.FractalType.DomainWarpProgressive:
this._DomainWarpFractalProgressive(coord);
break;
case FastNoiseLite.FractalType.DomainWarpIndependent:
this._DomainWarpFractalIndependent(coord);
break;
}
}
// prettier-ignore
_Gradients2D = [
0.130526192220052, 0.99144486137381, 0.38268343236509, 0.923879532511287, 0.608761429008721, 0.793353340291235, 0.793353340291235, 0.608761429008721,
0.923879532511287, 0.38268343236509, 0.99144486137381, 0.130526192220051, 0.99144486137381, -0.130526192220051, 0.923879532511287, -0.38268343236509,
0.793353340291235, -0.60876142900872, 0.608761429008721, -0.793353340291235, 0.38268343236509, -0.923879532511287, 0.130526192220052, -0.99144486137381,
-0.130526192220052, -0.99144486137381, -0.38268343236509, -0.923879532511287, -0.608761429008721, -0.793353340291235, -0.793353340291235, -0.608761429008721,
-0.923879532511287, -0.38268343236509, -0.99144486137381, -0.130526192220052, -0.99144486137381, 0.130526192220051, -0.923879532511287, 0.38268343236509,
-0.793353340291235, 0.608761429008721, -0.608761429008721, 0.793353340291235, -0.38268343236509, 0.923879532511287, -0.130526192220052, 0.99144486137381,
0.130526192220052, 0.99144486137381, 0.38268343236509, 0.923879532511287, 0.608761429008721, 0.793353340291235, 0.793353340291235, 0.608761429008721,
0.923879532511287, 0.38268343236509, 0.99144486137381, 0.130526192220051, 0.99144486137381, -0.130526192220051, 0.923879532511287, -0.38268343236509,
0.793353340291235, -0.60876142900872, 0.608761429008721, -0.793353340291235, 0.38268343236509, -0.923879532511287, 0.130526192220052, -0.99144486137381,
-0.130526192220052, -0.99144486137381, -0.38268343236509, -0.923879532511287, -0.608761429008721, -0.793353340291235, -0.793353340291235, -0.608761429008721,
-0.923879532511287, -0.38268343236509, -0.99144486137381, -0.130526192220052, -0.99144486137381, 0.130526192220051, -0.923879532511287, 0.38268343236509,
-0.793353340291235, 0.608761429008721, -0.608761429008721, 0.793353340291235, -0.38268343236509, 0.923879532511287, -0.130526192220052, 0.99144486137381,
0.130526192220052, 0.99144486137381, 0.38268343236509, 0.923879532511287, 0.608761429008721, 0.793353340291235, 0.793353340291235, 0.608761429008721,
0.923879532511287, 0.38268343236509, 0.99144486137381, 0.130526192220051, 0.99144486137381, -0.130526192220051, 0.923879532511287, -0.38268343236509,
0.793353340291235, -0.60876142900872, 0.608761429008721, -0.793353340291235, 0.38268343236509, -0.923879532511287, 0.130526192220052, -0.99144486137381,
-0.130526192220052, -0.99144486137381, -0.38268343236509, -0.923879532511287, -0.608761429008721, -0.793353340291235, -0.793353340291235, -0.608761429008721,
-0.923879532511287, -0.38268343236509, -0.99144486137381, -0.130526192220052, -0.99144486137381, 0.130526192220051, -0.923879532511287, 0.38268343236509,
-0.793353340291235, 0.608761429008721, -0.608761429008721, 0.793353340291235, -0.38268343236509, 0.923879532511287, -0.130526192220052, 0.99144486137381,
0.130526192220052, 0.99144486137381, 0.38268343236509, 0.923879532511287, 0.608761429008721, 0.793353340291235, 0.793353340291235, 0.608761429008721,
0.923879532511287, 0.38268343236509, 0.99144486137381, 0.130526192220051, 0.99144486137381, -0.130526192220051, 0.923879532511287, -0.38268343236509,
0.793353340291235, -0.60876142900872, 0.608761429008721, -0.793353340291235, 0.38268343236509, -0.923879532511287, 0.130526192220052, -0.99144486137381,
-0.130526192220052, -0.99144486137381, -0.38268343236509, -0.923879532511287, -0.608761429008721, -0.793353340291235, -0.793353340291235, -0.608761429008721,
-0.923879532511287, -0.38268343236509, -0.99144486137381, -0.130526192220052, -0.99144486137381, 0.130526192220051, -0.923879532511287, 0.38268343236509,
-0.793353340291235, 0.608761429008721, -0.608761429008721, 0.793353340291235, -0.38268343236509, 0.923879532511287, -0.130526192220052, 0.99144486137381,
0.130526192220052, 0.99144486137381, 0.38268343236509, 0.923879532511287, 0.608761429008721, 0.793353340291235, 0.793353340291235, 0.608761429008721,
0.923879532511287, 0.38268343236509, 0.99144486137381, 0.130526192220051, 0.99144486137381, -0.130526192220051, 0.923879532511287, -0.38268343236509,
0.793353340291235, -0.60876142900872, 0.608761429008721, -0.793353340291235, 0.38268343236509, -0.923879532511287, 0.130526192220052, -0.99144486137381,
-0.130526192220052, -0.99144486137381, -0.38268343236509, -0.923879532511287, -0.608761429008721, -0.793353340291235, -0.793353340291235, -0.608761429008721,
-0.923879532511287, -0.38268343236509, -0.99144486137381, -0.130526192220052, -0.99144486137381, 0.130526192220051, -0.923879532511287, 0.38268343236509,
-0.793353340291235, 0.608761429008721, -0.608761429008721, 0.793353340291235, -0.38268343236509, 0.923879532511287, -0.130526192220052, 0.99144486137381,
0.38268343236509, 0.923879532511287, 0.923879532511287, 0.38268343236509, 0.923879532511287, -0.38268343236509, 0.38268343236509, -0.923879532511287,
-0.38268343236509, -0.923879532511287, -0.923879532511287, -0.38268343236509, -0.923879532511287, 0.38268343236509, -0.38268343236509, 0.923879532511287,
];
// prettier-ignore
_RandVecs2D = [
-0.2700222198, -0.9628540911, 0.3863092627, -0.9223693152, 0.04444859006, -0.999011673, -0.5992523158, -0.8005602176, -0.7819280288, 0.6233687174, 0.9464672271, 0.3227999196, -0.6514146797, -0.7587218957, 0.9378472289, 0.347048376,
-0.8497875957, -0.5271252623, -0.879042592, 0.4767432447, -0.892300288, -0.4514423508, -0.379844434, -0.9250503802, -0.9951650832, 0.0982163789, 0.7724397808, -0.6350880136, 0.7573283322, -0.6530343002, -0.9928004525, -0.119780055,
-0.0532665713, 0.9985803285, 0.9754253726, -0.2203300762, -0.7665018163, 0.6422421394, 0.991636706, 0.1290606184, -0.994696838, 0.1028503788, -0.5379205513, -0.84299554, 0.5022815471, -0.8647041387, 0.4559821461, -0.8899889226,
-0.8659131224, -0.5001944266, 0.0879458407, -0.9961252577, -0.5051684983, 0.8630207346, 0.7753185226, -0.6315704146, -0.6921944612, 0.7217110418, -0.5191659449, -0.8546734591, 0.8978622882, -0.4402764035, -0.1706774107, 0.9853269617,
-0.9353430106, -0.3537420705, -0.9992404798, 0.03896746794, -0.2882064021, -0.9575683108, -0.9663811329, 0.2571137995, -0.8759714238, -0.4823630009, -0.8303123018, -0.5572983775, 0.05110133755, -0.9986934731, -0.8558373281, -0.5172450752,
0.09887025282, 0.9951003332, 0.9189016087, 0.3944867976, -0.2439375892, -0.9697909324, -0.8121409387, -0.5834613061, -0.9910431363, 0.1335421355, 0.8492423985, -0.5280031709, -0.9717838994, -0.2358729591, 0.9949457207, 0.1004142068,
0.6241065508, -0.7813392434, 0.662910307, 0.7486988212, -0.7197418176, 0.6942418282, -0.8143370775, -0.5803922158, 0.104521054, -0.9945226741, -0.1065926113, -0.9943027784, 0.445799684, -0.8951327509, 0.105547406, 0.9944142724,
-0.992790267, 0.1198644477, -0.8334366408, 0.552615025, 0.9115561563, -0.4111755999, 0.8285544909, -0.5599084351, 0.7217097654, -0.6921957921, 0.4940492677, -0.8694339084, -0.3652321272, -0.9309164803, -0.9696606758, 0.2444548501,
0.08925509731, -0.996008799, 0.5354071276, -0.8445941083, -0.1053576186, 0.9944343981, -0.9890284586, 0.1477251101, 0.004856104961, 0.9999882091, 0.9885598478, 0.1508291331, 0.9286129562, -0.3710498316, -0.5832393863, -0.8123003252,
0.3015207509, 0.9534596146, -0.9575110528, 0.2883965738, 0.9715802154, -0.2367105511, 0.229981792, 0.9731949318, 0.955763816, -0.2941352207, 0.740956116, 0.6715534485, -0.9971513787, -0.07542630764, 0.6905710663, -0.7232645452,
-0.290713703, -0.9568100872, 0.5912777791, -0.8064679708, -0.9454592212, -0.325740481, 0.6664455681, 0.74555369, 0.6236134912, 0.7817328275, 0.9126993851, -0.4086316587, -0.8191762011, 0.5735419353, -0.8812745759, -0.4726046147,
0.9953313627, 0.09651672651, 0.9855650846, -0.1692969699, -0.8495980887, 0.5274306472, 0.6174853946, -0.7865823463, 0.8508156371, 0.52546432, 0.9985032451, -0.05469249926, 0.1971371563, -0.9803759185, 0.6607855748, -0.7505747292,
-0.03097494063, 0.9995201614, -0.6731660801, 0.739491331, -0.7195018362, -0.6944905383, 0.9727511689, 0.2318515979, 0.9997059088, -0.0242506907, 0.4421787429, -0.8969269532, 0.9981350961, -0.061043673, -0.9173660799, -0.3980445648,
-0.8150056635, -0.5794529907, -0.8789331304, 0.4769450202, 0.0158605829, 0.999874213, -0.8095464474, 0.5870558317, -0.9165898907, -0.3998286786, -0.8023542565, 0.5968480938, -0.5176737917, 0.8555780767, -0.8154407307, -0.5788405779,
0.4022010347, -0.9155513791, -0.9052556868, -0.4248672045, 0.7317445619, 0.6815789728, -0.5647632201, -0.8252529947, -0.8403276335, -0.5420788397, -0.9314281527, 0.363925262, 0.5238198472, 0.8518290719, 0.7432803869, -0.6689800195,
-0.985371561, -0.1704197369, 0.4601468731, 0.88784281, 0.825855404, 0.5638819483, 0.6182366099, 0.7859920446, 0.8331502863, -0.553046653, 0.1500307506, 0.9886813308, -0.662330369, -0.7492119075, -0.668598664, 0.743623444,
0.7025606278, 0.7116238924, -0.5419389763, -0.8404178401, -0.3388616456, 0.9408362159, 0.8331530315, 0.5530425174, -0.2989720662, -0.9542618632, 0.2638522993, 0.9645630949, 0.124108739, -0.9922686234, -0.7282649308, -0.6852956957,
0.6962500149, 0.7177993569, -0.9183535368, 0.3957610156, -0.6326102274, -0.7744703352, -0.9331891859, -0.359385508, -0.1153779357, -0.9933216659, 0.9514974788, -0.3076565421, -0.08987977445, -0.9959526224, 0.6678496916, 0.7442961705,
0.7952400393, -0.6062947138, -0.6462007402, -0.7631674805, -0.2733598753, 0.9619118351, 0.9669590226, -0.254931851, -0.9792894595, 0.2024651934, -0.5369502995, -0.8436138784, -0.270036471, -0.9628500944, -0.6400277131, 0.7683518247,
-0.7854537493, -0.6189203566, 0.06005905383, -0.9981948257, -0.02455770378, 0.9996984141, -0.65983623, 0.751409442, -0.6253894466, -0.7803127835, -0.6210408851, -0.7837781695, 0.8348888491, 0.5504185768, -0.1592275245, 0.9872419133,
0.8367622488, 0.5475663786, -0.8675753916, -0.4973056806, -0.2022662628, -0.9793305667, 0.9399189937, 0.3413975472, 0.9877404807, -0.1561049093, -0.9034455656, 0.4287028224, 0.1269804218, -0.9919052235, -0.3819600854, 0.924178821,
0.9754625894, 0.2201652486, -0.3204015856, -0.9472818081, -0.9874760884, 0.1577687387, 0.02535348474, -0.9996785487, 0.4835130794, -0.8753371362, -0.2850799925, -0.9585037287, -0.06805516006, -0.99768156, -0.7885244045, -0.6150034663,
0.3185392127, -0.9479096845, 0.8880043089, 0.4598351306, 0.6476921488, -0.7619021462, 0.9820241299, 0.1887554194, 0.9357275128, -0.3527237187, -0.8894895414, 0.4569555293, 0.7922791302, 0.6101588153, 0.7483818261, 0.6632681526,
-0.7288929755, -0.6846276581, 0.8729032783, -0.4878932944, 0.8288345784, 0.5594937369, 0.08074567077, 0.9967347374, 0.9799148216, -0.1994165048, -0.580730673, -0.8140957471, -0.4700049791, -0.8826637636, 0.2409492979, 0.9705377045,
0.9437816757, -0.3305694308, -0.8927998638, -0.4504535528, -0.8069622304, 0.5906030467, 0.06258973166, 0.9980393407, -0.9312597469, 0.3643559849, 0.5777449785, 0.8162173362, -0.3360095855, -0.941858566, 0.697932075, -0.7161639607,
-0.002008157227, -0.9999979837, -0.1827294312, -0.9831632392, -0.6523911722, 0.7578824173, -0.4302626911, -0.9027037258, -0.9985126289, -0.05452091251, -0.01028102172, -0.9999471489, -0.4946071129, 0.8691166802, -0.2999350194, 0.9539596344,
0.8165471961, 0.5772786819, 0.2697460475, 0.962931498, -0.7306287391, -0.6827749597, -0.7590952064, -0.6509796216, -0.907053853, 0.4210146171, -0.5104861064, -0.8598860013, 0.8613350597, 0.5080373165, 0.5007881595, -0.8655698812,
-0.654158152, 0.7563577938, -0.8382755311, -0.545246856, 0.6940070834, 0.7199681717, 0.06950936031, 0.9975812994, 0.1702942185, -0.9853932612, 0.2695973274, 0.9629731466, 0.5519612192, -0.8338697815, 0.225657487, -0.9742067022,
0.4215262855, -0.9068161835, 0.4881873305, -0.8727388672, -0.3683854996, -0.9296731273, -0.9825390578, 0.1860564427, 0.81256471, 0.5828709909, 0.3196460933, -0.9475370046, 0.9570913859, 0.2897862643, -0.6876655497, -0.7260276109,
-0.9988770922, -0.047376731, -0.1250179027, 0.992154486, -0.8280133617, 0.560708367, 0.9324863769, -0.3612051451, 0.6394653183, 0.7688199442, -0.01623847064, -0.9998681473, -0.9955014666, -0.09474613458, -0.81453315, 0.580117012,
0.4037327978, -0.9148769469, 0.9944263371, 0.1054336766, -0.1624711654, 0.9867132919, -0.9949487814, -0.100383875, -0.6995302564, 0.7146029809, 0.5263414922, -0.85027327, -0.5395221479, 0.841971408, 0.6579370318, 0.7530729462,
0.01426758847, -0.9998982128, -0.6734383991, 0.7392433447, 0.639412098, -0.7688642071, 0.9211571421, 0.3891908523, -0.146637214, -0.9891903394, -0.782318098, 0.6228791163, -0.5039610839, -0.8637263605, -0.7743120191, -0.6328039957,
];
// prettier-ignore
_Gradients3D = [
0, 1, 1, 0, 0, -1, 1, 0, 0, 1, -1, 0, 0, -1, -1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0, -1, 0, -1, 0, -1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1, -1, 0, 0, -1, -1, 0, 0,
0, 1, 1, 0, 0, -1, 1, 0, 0, 1, -1, 0, 0, -1, -1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0, -1, 0, -1, 0, -1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1, -1, 0, 0, -1, -1, 0, 0,
0, 1, 1, 0, 0, -1, 1, 0, 0, 1, -1, 0, 0, -1, -1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0, -1, 0, -1, 0, -1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1, -1, 0, 0, -1, -1, 0, 0,
0, 1, 1, 0, 0, -1, 1, 0, 0, 1, -1, 0, 0, -1, -1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0, -1, 0, -1, 0, -1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1, -1, 0, 0, -1, -1, 0, 0,
0, 1, 1, 0, 0, -1, 1, 0, 0, 1, -1, 0, 0, -1, -1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0, -1, 0, -1, 0, -1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1, -1, 0, 0, -1, -1, 0, 0,
1, 1, 0, 0, 0, -1, 1, 0, -1, 1, 0, 0, 0, -1, -1, 0
];
// prettier-ignore
_RandVecs3D = [
-0.7292736885, -0.6618439697, 0.1735581948, 0, 0.790292081, -0.5480887466, -0.2739291014, 0, 0.7217578935, 0.6226212466, -0.3023380997, 0, 0.565683137, -0.8208298145, -0.0790000257, 0, 0.760049034, -0.5555979497, -0.3370999617, 0, 0.3713945616, 0.5011264475, 0.7816254623, 0, -0.1277062463, -0.4254438999, -0.8959289049, 0, -0.2881560924, -0.5815838982, 0.7607405838, 0,
0.5849561111, -0.662820239, -0.4674352136, 0, 0.3307171178, 0.0391653737, 0.94291689, 0, 0.8712121778, -0.4113374369, -0.2679381538, 0, 0.580981015, 0.7021915846, 0.4115677815, 0, 0.503756873, 0.6330056931, -0.5878203852, 0, 0.4493712205, 0.601390195, 0.6606022552, 0, -0.6878403724, 0.09018890807, -0.7202371714, 0, -0.5958956522, -0.6469350577, 0.475797649, 0,
-0.5127052122, 0.1946921978, -0.8361987284, 0, -0.9911507142, -0.05410276466, -0.1212153153, 0, -0.2149721042, 0.9720882117, -0.09397607749, 0, -0.7518650936, -0.5428057603, 0.3742469607, 0, 0.5237068895, 0.8516377189, -0.02107817834, 0, 0.6333504779, 0.1926167129, -0.7495104896, 0, -0.06788241606, 0.3998305789, 0.9140719259, 0, -0.5538628599, -0.4729896695, -0.6852128902, 0,
-0.7261455366, -0.5911990757, 0.3509933228, 0, -0.9229274737, -0.1782808786, 0.3412049336, 0, -0.6968815002, 0.6511274338, 0.3006480328, 0, 0.9608044783, -0.2098363234, -0.1811724921, 0, 0.06817146062, -0.9743405129, 0.2145069156, 0, -0.3577285196, -0.6697087264, -0.6507845481, 0, -0.1868621131, 0.7648617052, -0.6164974636, 0, -0.6541697588, 0.3967914832, 0.6439087246, 0,
0.6993340405, -0.6164538506, 0.3618239211, 0, -0.1546665739, 0.6291283928, 0.7617583057, 0, -0.6841612949, -0.2580482182, -0.6821542638, 0, 0.5383980957, 0.4258654885, 0.7271630328, 0, -0.5026987823, -0.7939832935, -0.3418836993, 0, 0.3202971715, 0.2834415347, 0.9039195862, 0, 0.8683227101, -0.0003762656404, -0.4959995258, 0, 0.791120031, -0.08511045745, 0.6057105799, 0,
-0.04011016052, -0.4397248749, 0.8972364289, 0, 0.9145119872, 0.3579346169, -0.1885487608, 0, -0.9612039066, -0.2756484276, 0.01024666929, 0, 0.6510361721, -0.2877799159, -0.7023778346, 0, -0.2041786351, 0.7365237271, 0.644859585, 0, -0.7718263711, 0.3790626912, 0.5104855816, 0, -0.3060082741, -0.7692987727, 0.5608371729, 0, 0.454007341, -0.5024843065, 0.7357899537, 0,
0.4816795475, 0.6021208291, -0.6367380315, 0, 0.6961980369, -0.3222197429, 0.641469197, 0, -0.6532160499, -0.6781148932, 0.3368515753, 0, 0.5089301236, -0.6154662304, -0.6018234363, 0, -0.1635919754, -0.9133604627, -0.372840892, 0, 0.52408019, -0.8437664109, 0.1157505864, 0, 0.5902587356, 0.4983817807, -0.6349883666, 0, 0.5863227872, 0.494764745, 0.6414307729, 0,
0.6779335087, 0.2341345225, 0.6968408593, 0, 0.7177054546, -0.6858979348, 0.120178631, 0, -0.5328819713, -0.5205125012, 0.6671608058, 0, -0.8654874251, -0.0700727088, -0.4960053754, 0, -0.2861810166, 0.7952089234, 0.5345495242, 0, -0.04849529634, 0.9810836427, -0.1874115585, 0, -0.6358521667, 0.6058348682, 0.4781800233, 0, 0.6254794696, -0.2861619734, 0.7258696564, 0,
-0.2585259868, 0.5061949264, -0.8227581726, 0, 0.02136306781, 0.5064016808, -0.8620330371, 0, 0.200111773, 0.8599263484, 0.4695550591, 0, 0.4743561372, 0.6014985084, -0.6427953014, 0, 0.6622993731, -0.5202474575, -0.5391679918, 0, 0.08084972818, -0.6532720452, 0.7527940996, 0, -0.6893687501, 0.0592860349, 0.7219805347, 0, -0.1121887082, -0.9673185067, 0.2273952515, 0,
0.7344116094, 0.5979668656, -0.3210532909, 0, 0.5789393465, -0.2488849713, 0.7764570201, 0, 0.6988182827, 0.3557169806, -0.6205791146, 0, -0.8636845529, -0.2748771249, -0.4224826141, 0, -0.4247027957, -0.4640880967, 0.777335046, 0, 0.5257722489, -0.8427017621, 0.1158329937, 0, 0.9343830603, 0.316302472, -0.1639543925, 0, -0.1016836419, -0.8057303073, -0.5834887393, 0,
-0.6529238969, 0.50602126, -0.5635892736, 0, -0.2465286165, -0.9668205684, -0.06694497494, 0, -0.9776897119, -0.2099250524, -0.007368825344, 0, 0.7736893337, 0.5734244712, 0.2694238123, 0, -0.6095087895, 0.4995678998, 0.6155736747, 0, 0.5794535482, 0.7434546771, 0.3339292269, 0, -0.8226211154, 0.08142581855, 0.5627293636, 0, -0.510385483, 0.4703667658, 0.7199039967, 0,
-0.5764971849, -0.07231656274, -0.8138926898, 0, 0.7250628871, 0.3949971505, -0.5641463116, 0, -0.1525424005, 0.4860840828, -0.8604958341, 0, -0.5550976208, -0.4957820792, 0.667882296, 0, -0.1883614327, 0.9145869398, 0.357841725, 0, 0.7625556724, -0.5414408243, -0.3540489801, 0, -0.5870231946, -0.3226498013, -0.7424963803, 0, 0.3051124198, 0.2262544068, -0.9250488391, 0,
0.6379576059, 0.577242424, -0.5097070502, 0, -0.5966775796, 0.1454852398, -0.7891830656, 0, -0.658330573, 0.6555487542, -0.3699414651, 0, 0.7434892426, 0.2351084581, 0.6260573129, 0, 0.5562114096, 0.8264360377, -0.0873632843, 0, -0.3028940016, -0.8251527185, 0.4768419182, 0, 0.1129343818, -0.985888439, -0.1235710781, 0, 0.5937652891, -0.5896813806, 0.5474656618, 0,
0.6757964092, -0.5835758614, -0.4502648413, 0, 0.7242302609, -0.1152719764, 0.6798550586, 0, -0.9511914166, 0.0753623979, -0.2992580792, 0, 0.2539470961, -0.1886339355, 0.9486454084, 0, 0.571433621, -0.1679450851, -0.8032795685, 0, -0.06778234979, 0.3978269256, 0.9149531629, 0, 0.6074972649, 0.733060024, -0.3058922593, 0, -0.5435478392, 0.1675822484, 0.8224791405, 0,
-0.5876678086, -0.3380045064, -0.7351186982, 0, -0.7967562402, 0.04097822706, -0.6029098428, 0, -0.1996350917, 0.8706294745, 0.4496111079, 0, -0.02787660336, -0.9106232682, -0.4122962022, 0, -0.7797625996, -0.6257634692, 0.01975775581, 0, -0.5211232846, 0.7401644346, -0.4249554471, 0, 0.8575424857, 0.4053272873, -0.3167501783, 0, 0.1045223322, 0.8390195772, -0.5339674439, 0,
0.3501822831, 0.9242524096, -0.1520850155, 0, 0.1987849858, 0.07647613266, 0.9770547224, 0, 0.7845996363, 0.6066256811, -0.1280964233, 0, 0.09006737436, -0.9750989929, -0.2026569073, 0, -0.8274343547, -0.542299559, 0.1458203587, 0, -0.3485797732, -0.415802277, 0.840000362, 0, -0.2471778936, -0.7304819962, -0.6366310879, 0, -0.3700154943, 0.8577948156, 0.3567584454, 0,
0.5913394901, -0.548311967, -0.5913303597, 0, 0.1204873514, -0.7626472379, -0.6354935001, 0, 0.616959265, 0.03079647928, 0.7863922953, 0, 0.1258156836, -0.6640829889, -0.7369967419, 0, -0.6477565124, -0.1740147258, -0.7417077429, 0, 0.6217889313, -0.7804430448, -0.06547655076, 0, 0.6589943422, -0.6096987708, 0.4404473475, 0, -0.2689837504, -0.6732403169, -0.6887635427, 0,
-0.3849775103, 0.5676542638, 0.7277093879, 0, 0.5754444408, 0.8110471154, -0.1051963504, 0, 0.9141593684, 0.3832947817, 0.131900567, 0, -0.107925319, 0.9245493968, 0.3654593525, 0, 0.377977089, 0.3043148782, 0.8743716458, 0, -0.2142885215, -0.8259286236, 0.5214617324, 0, 0.5802544474, 0.4148098596, -0.7008834116, 0, -0.1982660881, 0.8567161266, -0.4761596756, 0,
-0.03381553704, 0.3773180787, -0.9254661404, 0, -0.6867922841, -0.6656597827, 0.2919133642, 0, 0.7731742607, -0.2875793547, -0.5652430251, 0, -0.09655941928, 0.9193708367, -0.3813575004, 0, 0.2715702457, -0.9577909544, -0.09426605581, 0, 0.2451015704, -0.6917998565, -0.6792188003, 0, 0.977700782, -0.1753855374, 0.1155036542, 0, -0.5224739938, 0.8521606816, 0.02903615945, 0,
-0.7734880599, -0.5261292347, 0.3534179531, 0, -0.7134492443, -0.269547243, 0.6467878011, 0, 0.1644037271, 0.5105846203, -0.8439637196, 0, 0.6494635788, 0.05585611296, 0.7583384168, 0, -0.4711970882, 0.5017280509, -0.7254255765, 0, -0.6335764307, -0.2381686273, -0.7361091029, 0, -0.9021533097, -0.270947803, -0.3357181763, 0, -0.3793711033, 0.872258117, 0.3086152025, 0,
-0.6855598966, -0.3250143309, 0.6514394162, 0, 0.2900942212, -0.7799057743, -0.5546100667, 0, -0.2098319339, 0.85037073, 0.4825351604, 0, -0.4592603758, 0.6598504336, -0.5947077538, 0, 0.8715945488, 0.09616365406, -0.4807031248, 0, -0.6776666319, 0.7118504878, -0.1844907016, 0, 0.7044377633, 0.312427597, 0.637304036, 0, -0.7052318886, -0.2401093292, -0.6670798253, 0,
0.081921007, -0.7207336136, -0.6883545647, 0, -0.6993680906, -0.5875763221, -0.4069869034, 0, -0.1281454481, 0.6419895885, 0.7559286424, 0, -0.6337388239, -0.6785471501, -0.3714146849, 0, 0.5565051903, -0.2168887573, -0.8020356851, 0, -0.5791554484, 0.7244372011, -0.3738578718, 0, 0.1175779076, -0.7096451073, 0.6946792478, 0, -0.6134619607, 0.1323631078, 0.7785527795, 0,
0.6984635305, -0.02980516237, -0.715024719, 0, 0.8318082963, -0.3930171956, 0.3919597455, 0, 0.1469576422, 0.05541651717, -0.9875892167, 0, 0.708868575, -0.2690503865, 0.6520101478, 0, 0.2726053183, 0.67369766, -0.68688995, 0, -0.6591295371, 0.3035458599, -0.6880466294, 0, 0.4815131379, -0.7528270071, 0.4487723203, 0, 0.9430009463, 0.1675647412, -0.2875261255, 0,
0.434802957, 0.7695304522, -0.4677277752, 0, 0.3931996188, 0.594473625, 0.7014236729, 0, 0.7254336655, -0.603925654, 0.3301814672, 0, 0.7590235227, -0.6506083235, 0.02433313207, 0, -0.8552768592, -0.3430042733, 0.3883935666, 0, -0.6139746835, 0.6981725247, 0.3682257648, 0, -0.7465905486, -0.5752009504, 0.3342849376, 0, 0.5730065677, 0.810555537, -0.1210916791, 0,
-0.9225877367, -0.3475211012, -0.167514036, 0, -0.7105816789, -0.4719692027, -0.5218416899, 0, -0.08564609717, 0.3583001386, 0.929669703, 0, -0.8279697606, -0.2043157126, 0.5222271202, 0, 0.427944023, 0.278165994, 0.8599346446, 0, 0.5399079671, -0.7857120652, -0.3019204161, 0, 0.5678404253, -0.5495413974, -0.6128307303, 0, -0.9896071041, 0.1365639107, -0.04503418428, 0,
-0.6154342638, -0.6440875597, 0.4543037336, 0, 0.1074204368, -0.7946340692, 0.5975094525, 0, -0.3595449969, -0.8885529948, 0.28495784, 0, -0.2180405296, 0.1529888965, 0.9638738118, 0, -0.7277432317, -0.6164050508, -0.3007234646, 0, 0.7249729114, -0.00669719484, 0.6887448187, 0, -0.5553659455, -0.5336586252, 0.6377908264, 0, 0.5137558015, 0.7976208196, -0.3160000073, 0,
-0.3794024848, 0.9245608561, -0.03522751494, 0, 0.8229248658, 0.2745365933, -0.4974176556, 0, -0.5404114394, 0.6091141441, 0.5804613989, 0, 0.8036581901, -0.2703029469, 0.5301601931, 0, 0.6044318879, 0.6832968393, 0.4095943388, 0, 0.06389988817, 0.9658208605, -0.2512108074, 0, 0.1087113286, 0.7402471173, -0.6634877936, 0, -0.713427712, -0.6926784018, 0.1059128479, 0,
0.6458897819, -0.5724548511, -0.5050958653, 0, -0.6553931414, 0.7381471625, 0.159995615, 0, 0.3910961323, 0.9188871375, -0.05186755998, 0, -0.4879022471, -0.5904376907, 0.6429111375, 0, 0.6014790094, 0.7707441366, -0.2101820095, 0, -0.5677173047, 0.7511360995, 0.3368851762, 0, 0.7858573506, 0.226674665, 0.5753666838, 0, -0.4520345543, -0.604222686, -0.6561857263, 0,
0.002272116345, 0.4132844051, -0.9105991643, 0, -0.5815751419, -0.5162925989, 0.6286591339, 0, -0.03703704785, 0.8273785755, 0.5604221175, 0, -0.5119692504, 0.7953543429, -0.3244980058, 0, -0.2682417366, -0.9572290247, -0.1084387619, 0, -0.2322482736, -0.9679131102, -0.09594243324, 0, 0.3554328906, -0.8881505545, 0.2913006227, 0, 0.7346520519, -0.4371373164, 0.5188422971, 0,
0.9985120116, 0.04659011161, -0.02833944577, 0, -0.3727687496, -0.9082481361, 0.1900757285, 0, 0.91737377, -0.3483642108, 0.1925298489, 0, 0.2714911074, 0.4147529736, -0.8684886582, 0, 0.5131763485, -0.7116334161, 0.4798207128, 0, -0.8737353606, 0.18886992, -0.4482350644, 0, 0.8460043821, -0.3725217914, 0.3814499973, 0, 0.8978727456, -0.1780209141, -0.4026575304, 0,
0.2178065647, -0.9698322841, -0.1094789531, 0, -0.1518031304, -0.7788918132, -0.6085091231, 0, -0.2600384876, -0.4755398075, -0.8403819825, 0, 0.572313509, -0.7474340931, -0.3373418503, 0, -0.7174141009, 0.1699017182, -0.6756111411, 0, -0.684180784, 0.02145707593, -0.7289967412, 0, -0.2007447902, 0.06555605789, -0.9774476623, 0, -0.1148803697, -0.8044887315, 0.5827524187, 0,
-0.7870349638, 0.03447489231, 0.6159443543, 0, -0.2015596421, 0.6859872284, 0.6991389226, 0, -0.08581082512, -0.10920836, -0.9903080513, 0, 0.5532693395, 0.7325250401, -0.396610771, 0, -0.1842489331, -0.9777375055, -0.1004076743, 0, 0.0775473789, -0.9111505856, 0.4047110257, 0, 0.1399838409, 0.7601631212, -0.6344734459, 0, 0.4484419361, -0.845289248, 0.2904925424, 0
];
_PrimeX = 501125321;
_PrimeY = 1136930381;
_PrimeZ = 1720413743;
/**
* @private
* @param {number} a
* @param {number} b
* @param {number} t
* @returns {number}
*/
static _Lerp(a, b, t) {
return a + t * (b - a);
}
/**
* @private
* @param {number} t
* @returns {number}
*/
static _InterpHermite(t) {
return t * t * (3 - 2 * t);
}
/**
* @private
* @param t
* @returns {number}
*/
static _InterpQuintic(t) {
return t * t * t * (t * (t * 6 - 15) + 10);
}
/**
* @private
* @param {number} a
* @param {number} b
* @param {number} c
* @param {number} d
* @param {number} t
* @returns {number}
*/
static _CubicLerp(a, b, c, d, t) {
let p = d - c - (a - b);
return t * t * t * p + t * t * (a - b - p) + t * (c - a) + b;
}
/**
* @private
* @param {number} t
* @returns {number}
*/
static _PingPong(t) {
t -= Math.trunc(t * 0.5) * 2;
return t < 1 ? t : 2 - t;
}
/**
* @private
*/
_CalculateFractalBounding() {
let gain = Math.abs(this._Gain);
let amp = gain;
let ampFractal = 1.0;
for (let i = 1; i < this._Octaves; i++) {
ampFractal += amp;
amp *= gain;
}
this._FractalBounding = 1 / ampFractal;
}
/**
* @private
* @param {number} seed
* @param {number} xPrimed
* @param {number} yPrimed
* @returns {number}
*/
_HashR2(seed, xPrimed, yPrimed) {
let hash = seed ^ xPrimed ^ yPrimed;
hash = Math.imul(hash, 0x27d4eb2d);
return hash;
}
/**
*
* @param {number} seed
* @param {number} xPrimed
* @param {number} yPrimed
* @param {number} zPrimed
* @returns {number}
*/
_HashR3(seed, xPrimed, yPrimed, zPrimed){
let hash = seed ^ xPrimed ^ yPrimed ^ zPrimed;
hash = Math.imul(hash, 0x27d4eb2d);
return hash;
}
/**
* @private
* @param {number} seed
* @param {number} xPrimed
* @param {number} yPrimed
* @returns {number}
*/
_ValCoordR2(seed, xPrimed, yPrimed) {
let hash = this._HashR2(seed, xPrimed, yPrimed);
hash = Math.imul(hash, hash);
hash ^= hash << 19;
return hash * (1 / 2147483648.0);
}
/**
*
* @param {number} seed
* @param {number} xPrimed
* @param {number} yPrimed
* @param {number} zPrimed
* @returns {number}
*/
_ValCoordR3(seed, xPrimed, yPrimed, zPrimed){
let hash = this._HashR3(seed, xPrimed, yPrimed, zPrimed);
hash = Math.imul(hash, hash);
hash ^= hash << 19;
return hash * (1 / 2147483648.0);
}
/**
*
* @param {number} seed
* @param {number} xPrimed
* @param {number} yPrimed
* @param {number} xd
* @param {number} yd
* @returns {number}
*/
_GradCoordR2(seed, xPrimed, yPrimed, xd, yd) {
let hash = this._HashR2(seed, xPrimed, yPrimed);
hash ^= hash >> 15;
hash &= 127 << 1;
let xg = this._Gradients2D[hash];
let yg = this._Gradients2D[hash | 1];
return xd * xg + yd * yg;
}
/**
*
* @param {number} seed
* @param {number} xPrimed
* @param {number} yPrimed
* @param {number} zPrimed
* @param {number} xd
* @param {number} yd
* @param {number} zd
* @returns {number}
*/
_GradCoordR3(seed, xPrimed, yPrimed, zPrimed, xd, yd, zd) {
let hash = this._HashR3(seed, xPrimed, yPrimed, zPrimed);
hash ^= hash >> 15;
hash &= 63 << 2;
let xg = this._Gradients3D[hash];
let yg = this._Gradients3D[hash | 1];
let zg = this._Gradients3D[hash | 2];
return xd * xg + yd * yg + zd * zg;
}
/**
* @private
* @param {number} seed
* @param {number} x
* @param {number} y
* @returns {number}
*/
_GenNoiseSingleR2(seed, x, y) {
switch (this._NoiseType) {
case FastNoiseLite.NoiseType.OpenSimplex2:
return this._SingleOpenSimplex2R2(seed, x, y);
case FastNoiseLite.NoiseType.OpenSimplex2S:
return this._SingleOpenSimplex2SR2(seed, x, y);
case FastNoiseLite.NoiseType.Cellular:
return this._SingleCellularR2(seed, x, y);
case FastNoiseLite.NoiseType.Perlin:
return this._SinglePerlinR2(seed, x, y);
case FastNoiseLite.NoiseType.ValueCubic:
return this._SingleValueCubicR2(seed, x, y);
case FastNoiseLite.NoiseType.Value:
return this._SingleValueR2(seed, x, y);
default:
return 0;
}
}
/**
* @private
* @param {number} seed
* @param {number} x
* @param {number} y
* @param {number} z
* @returns {number}
*/
_GenNoiseSingleR3(seed, x, y, z){
switch (this._NoiseType) {
case FastNoiseLite.NoiseType.OpenSimplex2:
return this._SingleOpenSimplex2R3(seed, x, y, z);
case FastNoiseLite.NoiseType.OpenSimplex2S:
return this._SingleOpenSimplex2SR3(seed, x, y, z);
case FastNoiseLite.NoiseType.Cellular:
return this._SingleCellularR3(seed, x, y, z);
case FastNoiseLite.NoiseType.Perlin:
return this._SinglePerlinR3(seed, x, y, z);
case FastNoiseLite.NoiseType.ValueCubic:
return this._SingleValueCubicR3(seed, x, y, z);
case FastNoiseLite.NoiseType.Value:
return this._SingleValueR3(seed, x, y, z);
default:
return 0;
}
}
/**
* @private
*/
_UpdateTransformType3D() {
switch (this._RotationType3D) {
case FastNoiseLite.RotationType3D.ImproveXYPlanes:
this._TransformType3D = FastNoiseLite.TransformType3D.ImproveXYPlanes;
break;
case FastNoiseLite.RotationType3D.ImproveXZPlanes:
this._TransformType3D = FastNoiseLite.TransformType3D.ImproveXZPlanes;
break;
default:
switch (this._NoiseType) {
case FastNoiseLite.NoiseType.OpenSimplex2:
case FastNoiseLite.NoiseType.OpenSimplex2S:
this._TransformType3D = FastNoiseLite.TransformType3D.DefaultOpenSimplex2;
break;
default:
this._TransformType3D = FastNoiseLite.TransformType3D.None;
break;
}
break;
}
}
/**
* @private
*/
_UpdateWarpTransformType3D() {
switch (this._RotationType3D) {
case FastNoiseLite.RotationType3D.ImproveXYPlanes:
this._WarpTransformType3D = FastNoiseLite.TransformType3D.ImproveXYPlanes;
break;
case FastNoiseLite.RotationType3D.ImproveXZPlanes:
this._WarpTransformType3D = FastNoiseLite.TransformType3D.ImproveXZPlanes;
break;
default:
switch (this._DomainWarpType) {
case FastNoiseLite.DomainWarpType.OpenSimplex2:
case FastNoiseLite.DomainWarpType.OpenSimplex2Reduced:
this._WarpTransformType3D = FastNoiseLite.TransformType3D.DefaultOpenSimplex2;
break;
default:
this._WarpTransformType3D = FastNoiseLite.TransformType3D.None;
break;
}
break;
}
}
/**
* @private
* @param {number} x
* @param {number} y
* @returns {number}
*/
_GenFractalFBmR2(x,y) {
let seed = this._Seed;
let sum = 0;
let amp = this._FractalBounding;
for (let i = 0; i < this._Octaves; i++) {
let noise = this._GenNoiseSingleR2(seed++, x, y);
sum += noise * amp;
amp *= FastNoiseLite._Lerp(1.0, Math.min(noise + 1, 2) * 0.5, this._WeightedStrength);
x *= this._Lacunarity;
y *= this._Lacunarity;
amp *= this._Gain;
}
return sum;
}
/**
* @private
* @param {number} x
* @param {number} y
* @param {number} z
* @returns {number}
*/
_GenFractalFBmR3(x,y,z){
let seed = this._Seed;
let sum = 0;
let amp = this._FractalBounding;
for (let i = 0; i < this._Octaves; i++) {
let noise = this._GenNoiseSingleR3(seed++, x, y, z);
sum += noise * amp;
amp *= FastNoiseLite._Lerp(1.0, (noise + 1) * 0.5, this._WeightedStrength);
x *= this._Lacunarity;
y *= this._Lacunarity;
z *= this._Lacunarity;
amp *= this._Gain;
}
return sum;
}
/**
* @private
* @param {number} x
* @param {number} y
* @returns {number}
*/
_GenFractalRidgedR2(x,y) {
let seed = this._Seed;
let sum = 0;
let amp = this._FractalBounding;
for (let i = 0; i < this._Octaves; i++) {
let noise = Math.abs(this._GenNoiseSingleR2(seed++, x, y));
sum += (noise * -2 + 1) * amp;
amp *= FastNoiseLite._Lerp(1.0, 1 - noise, this._WeightedStrength);
x *= this._Lacunarity;
y *= this._Lacunarity;
amp *= this._Gain;
}
return sum;
}
/**
* @private
* @param {number} x
* @param {number} y
* @param {number} z
* @returns {number}
*/
_GenFractalRidgedR3(x,y,z){
let seed = this._Seed;
let sum = 0;
let amp = this._FractalBounding;
for (let i = 0; i < this._Octaves; i++) {
let noise = Math.abs(this._GenNoiseSingleR3(seed++, x, y, z));
sum += (noise * -2 + 1) * amp;
amp *= FastNoiseLite._Lerp(1.0, 1 - noise, this._WeightedStrength);
x *= this._Lacunarity;
y *= this._Lacunarity;
z *= this._Lacunarity;
amp *= this._Gain;
}
return sum;
}
/**
* @private
* @param {number} x
* @param {number} y
* @returns {number}
*/
_GenFractalPingPongR2(x,y) {
let seed = this._Seed;
let sum = 0;
let amp = this._FractalBounding;
for (let i = 0; i < this._Octaves; i++) {
let noise = FastNoiseLite._PingPong(
(this._GenNoiseSingleR2(seed++, x, y) + 1) * this._PingPongStrength
);
sum += (noise - 0.5) * 2 * amp;
amp *= FastNoiseLite._Lerp(1.0, noise, this._WeightedStrength);
x *= this._Lacunarity;
y *= this._Lacunarity;
amp *= this._Gain;
}
return sum;
}
/**
* @private
* @param {number} x
* @param {number} y
* @param {number} z
* @returns {number}
*/
_GenFractalPingPongR3(x,y,z){
let seed = this._Seed;
let sum = 0;
let amp = this._FractalBounding;
for (let i = 0; i < this._Octaves; i++) {
let noise = FastNoiseLite._PingPong(
(this._GenNoiseSingleR3(seed++, x, y, z) + 1) * this._PingPongStrength
);
sum += (noise - 0.5) * 2 * amp;
amp *= FastNoiseLite._Lerp(1.0, noise, this._WeightedStrength);
x *= this._Lacunarity;
y *= this._Lacunarity;
z *= this._Lacunarity;
amp *= this._Gain;
}
return sum;
}
/**
*
* @param {number} seed
* @param {number} x
* @param {number} y
* @returns {number}
*/
_SingleOpenSimplex2R2(seed,x,y) {
const SQRT3 = 1.7320508075688772935274463415059;
const G2 = (3 - SQRT3) / 6;
let i = Math.floor(x);
let j = Math.floor(y);
let xi = x - i;
let yi = y - j;
let t = (xi + yi) * G2;
let x0 = xi - t;
let y0 = yi - t;
i = Math.imul(i, this._PrimeX);
j = Math.imul(j, this._PrimeY);
let n0, n1, n2;
let a = 0.5 - x0 * x0 - y0 * y0;
if (a <= 0) {
n0 = 0;
} else {
n0 = a * a * (a * a) * this._GradCoordR2(seed, i, j, x0, y0);
}
let c = 2 * (1 - 2 * G2) * (1 / G2 - 2) * t + (-2 * (1 - 2 * G2) * (1 - 2 * G2) + a);
if (c <= 0) {
n2 = 0;
} else {
let x2 = x0 + (2 * G2 - 1);
let y2 = y0 + (2 * G2 - 1);
n2 = c * c * (c * c) * this._GradCoordR2(seed, i + this._PrimeX, j + this._PrimeY, x2, y2);
}
if (y0 > x0) {
let x1 = x0 + G2;
let y1 = y0 + (G2 - 1);
let b = 0.5 - x1 * x1 - y1 * y1;
if (b <= 0) {
n1 = 0;
} else {
n1 = b * b * (b * b) * this._GradCoordR2(seed, i, j + this._PrimeY, x1, y1);
}
} else {
let x1 = x0 + (G2 - 1);
let y1 = y0 + G2;
let b = 0.5 - x1 * x1 - y1 * y1;
if (b <= 0) {
n1 = 0;
} else {
n1 = b * b * (b * b) * this._GradCoordR2(seed, i + this._PrimeX, j, x1, y1);
}
}
return (n0 + n1 + n2) * 99.83685446303647;
}
/**
* @private
* @param {number} seed
* @param {number} x
* @param {number} y
* @param {number} z
* @returns {number}
*/
_SingleOpenSimplex2R3(seed,x,y,z){
let i = Math.round(x);
let j = Math.round(y);
let k = Math.round(z);
let x0 = x - i;
let y0 = y - j;
let z0 = z - k;
let yNSign = Math.trunc((-1.0 - y0) | 1);
let xNSign = Math.trunc((-1.0 - x0) | 1);
let zNSign = Math.trunc((-1.0 - z0) | 1);
let ax0 = xNSign * -x0;
let ay0 = yNSign * -y0;
let az0 = zNSign * -z0;
i = Math.imul(i, this._PrimeX);
j = Math.imul(j, this._PrimeY);
k = Math.imul(k, this._PrimeZ);
let value = 0;
let a = 0.6 - x0 * x0 - (y0 * y0 + z0 * z0);
for (let l = 0; ; l++) {
if (a > 0) {
value += a * a * (a * a) * this._GradCoordR3(seed, i, j, k, x0, y0, z0);
}
if (ax0 >= ay0 && ax0 >= az0) {
let b = a + ax0 + ax0;
if (b > 1) {
b -= 1;
value +=
b *
b *
(b * b) *
this._GradCoordR3(
seed,
i - xNSign * this._PrimeX,
j,
k,
x0 + xNSign,
y0,
z0
);
}
} else if (ay0 > ax0 && ay0 >= az0) {
let b = a + ay0 + ay0;
if (b > 1) {
b -= 1;
value +=
b *
b *
(b * b) *
this._GradCoordR3(
seed,
i,
j - yNSign * this._PrimeY,
k,
x0,
y0 + yNSign,
z0
);
}
} else {
let b = a + az0 + az0;
if (b > 1) {
b -= 1;
value +=
b *
b *
(b * b) *
this._GradCoordR3(
seed,
i,
j,
k - zNSign * this._PrimeZ,
x0,
y0,
z0 + zNSign
);
}
}
if (l === 1) {
break;
}
ax0 = 0.5 - ax0;
ay0 = 0.5 - ay0;
az0 = 0.5 - az0;
x0 = xNSign * ax0;
y0 = yNSign * ay0;
z0 = zNSign * az0;
a += 0.75 - ax0 - (ay0 + az0);
i += (xNSign >> 1) & this._PrimeX;
j += (yNSign >> 1) & this._PrimeY;
k += (zNSign >> 1) & this._PrimeZ;
xNSign = -xNSign;
yNSign = -yNSign;
zNSign = -zNSign;
seed = ~seed;
}
return value * 32.69428253173828125;
}
/**
* @private
* @param {number} seed
* @param {number} x
* @param {number} y
* @returns {number}
*/
_SingleOpenSimplex2SR2(seed,x,y) {
// 2D OpenSimplex2S case is a modified 2D simplex noise.
const SQRT3 = 1.7320508075688772935274463415059;
const G2 = (3 - SQRT3) / 6;
/*
* --- Skew moved to TransformNoiseCoordinate method ---
* final FNLfloat F2 = 0.5f * (SQRT3 - 1);
* FNLfloat s = (x + y) * F2;
* x += s; y += s;
*/
let i = Math.floor(x);
let j = Math.floor(y);
let xi = x - i;
let yi = y - j;
i = Math.imul(i, this._PrimeX);
j = Math.imul(j, this._PrimeY);
let i1 = i + this._PrimeX;
let j1 = j + this._PrimeY;
let t = (xi + yi) * G2;
let x0 = xi - t;
let y0 = yi - t;
let a0 = 2.0 / 3.0 - x0 * x0 - y0 * y0;
let value = a0 * a0 * (a0 * a0) * this._GradCoordR2(seed, i, j, x0, y0);
let a1 = 2 * (1 - 2 * G2) * (1 / G2 - 2) * t + (-2 * (1 - 2 * G2) * (1 - 2 * G2) + a0);
let x1 = x0 - (1 - 2 * G2);
let y1 = y0 - (1 - 2 * G2);
value += a1 * a1 * (a1 * a1) * this._GradCoordR2(seed, i1, j1, x1, y1);
// Nested conditionals were faster than compact bit logic/arithmetic.
let xmyi = xi - yi;
if (t > G2) {
if (xi + xmyi > 1) {
let x2 = x0 + (3 * G2 - 2);
let y2 = y0 + (3 * G2 - 1);
let a2 = 2.0 / 3.0 - x2 * x2 - y2 * y2;
if (a2 > 0) {
value +=
a2 *
a2 *
(a2 * a2) *
this._GradCoordR2(seed, i + (this._PrimeX << 1), j + this._PrimeY, x2, y2);
}
} else {
let x2 = x0 + G2;
let y2 = y0 + (G2 - 1);
let a2 = 2.0 / 3.0 - x2 * x2 - y2 * y2;
if (a2 > 0) {
value +=
a2 * a2 * (a2 * a2) * this._GradCoordR2(seed, i, j + this._PrimeY, x2, y2);
}
}
if (yi - xmyi > 1) {
let x3 = x0 + (3 * G2 - 1);
let y3 = y0 + (3 * G2 - 2);
let a3 = 2.0 / 3.0 - x3 * x3 - y3 * y3;
if (a3 > 0) {
value +=
a3 *
a3 *
(a3 * a3) *
this._GradCoordR2(seed, i + this._PrimeX, j + (this._PrimeY << 1), x3, y3);
}
} else {
let x3 = x0 + (G2 - 1);
let y3 = y0 + G2;
let a3 = 2.0 / 3.0 - x3 * x3 - y3 * y3;
if (a3 > 0) {
value +=
a3 * a3 * (a3 * a3) * this._GradCoordR2(seed, i + this._PrimeX, j, x3, y3);
}
}
} else {
if (xi + xmyi < 0) {
let x2 = x0 + (1 - G2);
let y2 = y0 - G2;
let a2 = 2.0 / 3.0 - x2 * x2 - y2 * y2;
if (a2 > 0) {
value +=
a2 * a2 * (a2 * a2) * this._GradCoordR2(seed, i - this._PrimeX, j, x2, y2);
}
} else {
let x2 = x0 + (G2 - 1);
let y2 = y0 + G2;
let a2 = 2.0 / 3.0 - x2 * x2 - y2 * y2;
if (a2 > 0) {
value +=
a2 * a2 * (a2 * a2) * this._GradCoordR2(seed, i + this._PrimeX, j, x2, y2);
}
}
if (yi < xmyi) {
let x2 = x0 - G2;
let y2 = y0 - (G2 - 1);
let a2 = 2.0 / 3.0 - x2 * x2 - y2 * y2;
if (a2 > 0) {
value +=
a2 * a2 * (a2 * a2) * this._GradCoordR2(seed, i, j - this._PrimeY, x2, y2);
}
} else {
let x2 = x0 + G2;
let y2 = y0 + (G2 - 1);
let a2 = 2.0 / 3.0 - x2 * x2 - y2 * y2;
if (a2 > 0) {
value +=
a2 * a2 * (a2 * a2) * this._GradCoordR2(seed, i, j + this._PrimeY, x2, y2);
}
}
}
return value * 18.24196194486065;
}
/**
* @private
* @param {number} seed
* @param {number} x
* @param {number} y
* @param {number} z
* @returns {number}
*/
_SingleOpenSimplex2SR3 (seed, x, y, z) {
// 3D OpenSimplex2S case uses two offset rotated cube grids.
/*
* --- Rotation moved to TransformNoiseCoordinate method ---
* final FNLfloat R3 = (FNLfloat)(2.0 / 3.0);
* FNLfloat r = (x + y + z) * R3; // Rotation, not skew
* x = r - x; y = r - y; z = r - z;
*/
let i = Math.floor(x);
let j = Math.floor(y);
let k = Math.floor(z);
let xi = x - i;
let yi = y - j;
let zi = z - k;
i = Math.imul(i, this._PrimeX);
j = Math.imul(j, this._PrimeY);
k = Math.imul(k, this._PrimeZ);
let seed2 = seed + 1293373;
let xNMask = Math.trunc(-0.5 - xi);
let yNMask = Math.trunc(-0.5 - yi);
let zNMask = Math.trunc(-0.5 - zi);
let x0 = xi + xNMask;
let y0 = yi + yNMask;
let z0 = zi + zNMask;
let a0 = 0.75 - x0 * x0 - y0 * y0 - z0 * z0;
let value =
a0 *
a0 *
(a0 * a0) *
this._GradCoordR3(
seed,
i + (xNMask & this._PrimeX),
j + (yNMask & this._PrimeY),
k + (zNMask & this._PrimeZ),
x0,
y0,
z0
);
let x1 = xi - 0.5;
let y1 = yi - 0.5;
let z1 = zi - 0.5;
let a1 = 0.75 - x1 * x1 - y1 * y1 - z1 * z1;
value +=
a1 *
a1 *
(a1 * a1) *
this._GradCoordR3(seed2, i + this._PrimeX, j + this._PrimeY, k + this._PrimeZ, x1, y1, z1);
let xAFlipMask0 = ((xNMask | 1) << 1) * x1;
let yAFlipMask0 = ((yNMask | 1) << 1) * y1;
let zAFlipMask0 = ((zNMask | 1) << 1) * z1;
let xAFlipMask1 = (-2 - (xNMask << 2)) * x1 - 1.0;
let yAFlipMask1 = (-2 - (yNMask << 2)) * y1 - 1.0;
let zAFlipMask1 = (-2 - (zNMask << 2)) * z1 - 1.0;
let skip5 = false;
let a2 = xAFlipMask0 + a0;
if (a2 > 0) {
let x2 = x0 - (xNMask | 1);
value +=
a2 *
a2 *
(a2 * a2) *
this._GradCoordR3(
seed,
i + (~xNMask & this._PrimeX),
j + (yNMask & this._PrimeY),
k + (zNMask & this._PrimeZ),
x2,
y0,
z0
);
} else {
let a3 = yAFlipMask0 + zAFlipMask0 + a0;
if (a3 > 0) {
let x3 = x0;
let y3 = y0 - (yNMask | 1);
let z3 = z0 - (zNMask | 1);
value +=
a3 *
a3 *
(a3 * a3) *
this._GradCoordR3(
seed,
i + (xNMask & this._PrimeX),
j + (~yNMask & this._PrimeY),
k + (~zNMask & this._PrimeZ),
x3,
y3,
z3
);
}
let a4 = xAFlipMask1 + a1;
if (a4 > 0) {
let x4 = (xNMask | 1) + x1;
value +=
a4 *
a4 *
(a4 * a4) *
this._GradCoordR3(
seed2,
i + (xNMask & (this._PrimeX * 2)),
j + this._PrimeY,
k + this._PrimeZ,
x4,
y1,
z1
);
skip5 = true;
}
}
let skip9 = false;
let a6 = yAFlipMask0 + a0;
if (a6 > 0) {
let x6 = x0;
let y6 = y0 - (yNMask | 1);
value +=
a6 *
a6 *
(a6 * a6) *
this._GradCoordR3(
seed,
i + (xNMask & this._PrimeX),
j + (~yNMask & this._PrimeY),
k + (zNMask & this._PrimeZ),
x6,
y6,
z0
);
} else {
let a7 = xAFlipMask0 + zAFlipMask0 + a0;
if (a7 > 0) {
let x7 = x0 - (xNMask | 1);
let y7 = y0;
let z7 = z0 - (zNMask | 1);
value +=
a7 *
a7 *
(a7 * a7) *
this._GradCoordR3(
seed,
i + (~xNMask & this._PrimeX),
j + (yNMask & this._PrimeY),
k + (~zNMask & this._PrimeZ),
x7,
y7,
z7
);
}
let a8 = yAFlipMask1 + a1;
if (a8 > 0) {
let x8 = x1;
let y8 = (yNMask | 1) + y1;
value +=
a8 *
a8 *
(a8 * a8) *
this._GradCoordR3(
seed2,
i + this._PrimeX,
j + (yNMask & (this._PrimeY << 1)),
k + this._PrimeZ,
x8,
y8,
z1
);
skip9 = true;
}
}
let skipD = false;
let aA = zAFlipMask0 + a0;
if (aA > 0) {
let xA = x0;
let yA = y0;
let zA = z0 - (zNMask | 1);
value +=
aA *
aA *
(aA * aA) *
this._GradCoordR3(
seed,
i + (xNMask & this._PrimeX),
j + (yNMask & this._PrimeY),
k + (~zNMask & this._PrimeZ),
xA,
yA,
zA
);
} else {
let aB = xAFlipMask0 + yAFlipMask0 + a0;
if (aB > 0) {
let xB = x0 - (xNMask | 1);
let yB = y0 - (yNMask | 1);
value +=
aB *
aB *
(aB * aB) *
this._GradCoordR3(
seed,
i + (~xNMask & this._PrimeX),
j + (~yNMask & this._PrimeY),
k + (zNMask & this._PrimeZ),
xB,
yB,
z0
);
}
let aC = zAFlipMask1 + a1;
if (aC > 0) {
let xC = x1;
let yC = y1;
let zC = (zNMask | 1) + z1;
value +=
aC *
aC *
(aC * aC) *
this._GradCoordR3(
seed2,
i + this._PrimeX,
j + this._PrimeY,
k + (zNMask & (this._PrimeZ << 1)),
xC,
yC,
zC
);
skipD = true;
}
}
if (!skip5) {
let a5 = yAFlipMask1 + zAFlipMask1 + a1;
if (a5 > 0) {
let x5 = x1;
let y5 = (yNMask | 1) + y1;
let z5 = (zNMask | 1) + z1;
value +=
a5 *
a5 *
(a5 * a5) *
this._GradCoordR3(
seed2,
i + this._PrimeX,
j + (yNMask & (this._PrimeY << 1)),
k + (zNMask & (this._PrimeZ << 1)),
x5,
y5,
z5
);
}
}
if (!skip9) {
let a9 = xAFlipMask1 + zAFlipMask1 + a1;
if (a9 > 0) {
let x9 = (xNMask | 1) + x1;
let y9 = y1;
let z9 = (zNMask | 1) + z1;
value +=
a9 *
a9 *
(a9 * a9) *
this._GradCoordR3(
seed2,
i + (xNMask & (this._PrimeX * 2)),
j + this._PrimeY,
k + (zNMask & (this._PrimeZ << 1)),
x9,
y9,
z9
);
}
}
if (!skipD) {
let aD = xAFlipMask1 + yAFlipMask1 + a1;
if (aD > 0) {
let xD = (xNMask | 1) + x1;
let yD = (yNMask | 1) + y1;
value +=
aD *
aD *
(aD * aD) *
this._GradCoordR3(
seed2,
i + (xNMask & (this._PrimeX << 1)),
j + (yNMask & (this._PrimeY << 1)),
k + this._PrimeZ,
xD,
yD,
z1
);
}
}
return value * 9.046026385208288;
}
/**
* @private
* @param {number} seed
* @param {number} x
* @param {number} y
* @returns {number}
*/
_SingleCellularR2(seed,x,y) {
/**
*
* @param {number} seed
* @param {number} x
* @param {number} y
* @returns {number}
*/
let xr = Math.round(x);
let yr = Math.round(y);
let distance0 = Number.MAX_VALUE;
let distance1 = Number.MAX_VALUE;
let closestHash = 0;
let cellularJitter = 0.43701595 * this._CellularJitterModifier;
let xPrimed = (xr - 1) * this._PrimeX;
let yPrimedBase = (yr - 1) * this._PrimeY;
switch (this._CellularDistanceFunction) {
default:
case FastNoiseLite.CellularDistanceFunction.Euclidean:
case FastNoiseLite.CellularDistanceFunction.EuclideanSq:
for (let xi = xr - 1; xi <= xr + 1; xi++) {
let yPrimed = yPrimedBase;
for (let yi = yr - 1; yi <= yr + 1; yi++) {
let hash = this._HashR2(seed, xPrimed, yPrimed);
let idx = hash & (255 << 1);
let vecX = xi - x + this._RandVecs2D[idx] * cellularJitter;
let vecY = yi - y + this._RandVecs2D[idx | 1] * cellularJitter;
let newDistance = vecX * vecX + vecY * vecY;
distance1 = Math.max(Math.min(distance1, newDistance), distance0);
if (newDistance < distance0) {
distance0 = newDistance;
closestHash = hash;
}
yPrimed += this._PrimeY;
}
xPrimed += this._PrimeX;
}
break;
case FastNoiseLite.CellularDistanceFunction.Manhattan:
for (let xi = xr - 1; xi <= xr + 1; xi++) {
let yPrimed = yPrimedBase;
for (let yi = yr - 1; yi <= yr + 1; yi++) {
let hash = this._HashR2(seed, xPrimed, yPrimed);
let idx = hash & (255 << 1);
let vecX = xi - x + this._RandVecs2D[idx] * cellularJitter;
let vecY = yi - y + this._RandVecs2D[idx | 1] * cellularJitter;
let newDistance = Math.abs(vecX) + Math.abs(vecY);
distance1 = Math.max(Math.min(distance1, newDistance), distance0);
if (newDistance < distance0) {
distance0 = newDistance;
closestHash = hash;
}
yPrimed += this._PrimeY;
}
xPrimed += this._PrimeX;
}
break;
case FastNoiseLite.CellularDistanceFunction.Hybrid:
for (let xi = xr - 1; xi <= xr + 1; xi++) {
let yPrimed = yPrimedBase;
for (let yi = yr - 1; yi <= yr + 1; yi++) {
let hash = this._HashR2(seed, xPrimed, yPrimed);
let idx = hash & (255 << 1);
let vecX = xi - x + this._RandVecs2D[idx] * cellularJitter;
let vecY = yi - y + this._RandVecs2D[idx | 1] * cellularJitter;
let newDistance =
Math.abs(vecX) + Math.abs(vecY) + (vecX * vecX + vecY * vecY);
distance1 = Math.max(Math.min(distance1, newDistance), distance0);
if (newDistance < distance0) {
distance0 = newDistance;
closestHash = hash;
}
yPrimed += this._PrimeY;
}
xPrimed += this._PrimeX;
}
break;
}
if (
this._CellularDistanceFunction === FastNoiseLite.CellularDistanceFunction.Euclidean &&
this._CellularReturnType !== FastNoiseLite.CellularReturnType.CellValue
) {
distance0 = Math.sqrt(distance0);
if (this._CellularReturnType !== FastNoiseLite.CellularReturnType.CellValue) {
distance1 = Math.sqrt(distance1);
}
}
switch (this._CellularReturnType) {
case FastNoiseLite.CellularReturnType.CellValue:
return closestHash * (1 / 2147483648.0);
case FastNoiseLite.CellularReturnType.Distance:
return distance0 - 1;
case FastNoiseLite.CellularReturnType.Distance2:
return distance1 - 1;
case FastNoiseLite.CellularReturnType.Distance2Add:
return (distance1 + distance0) * 0.5 - 1;
case FastNoiseLite.CellularReturnType.Distance2Sub:
return distance1 - distance0 - 1;
case FastNoiseLite.CellularReturnType.Distance2Mul:
return distance1 * distance0 * 0.5 - 1;
case FastNoiseLite.CellularReturnType.Distance2Div:
return distance0 / distance1 - 1;
default:
return 0;
}
}
/**
* @private
* @param {number} seed
* @param {number} x
* @param {number} y
* @param {number} z
* @returns {number}
*/
_SingleCellularR3 (seed, x, y, z) {
let xr = Math.round(x);
let yr = Math.round(y);
let zr = Math.round(z);
let distance0 = Number.MAX_VALUE;
let distance1 = Number.MAX_VALUE;
let closestHash = 0;
let cellularJitter = 0.39614353 * this._CellularJitterModifier;
let xPrimed = (xr - 1) * this._PrimeX;
let yPrimedBase = (yr - 1) * this._PrimeY;
let zPrimedBase = (zr - 1) * this._PrimeZ;
switch (this._CellularDistanceFunction) {
case FastNoiseLite.CellularDistanceFunction.Euclidean:
case FastNoiseLite.CellularDistanceFunction.EuclideanSq:
for (let xi = xr - 1; xi <= xr + 1; xi++) {
let yPrimed = yPrimedBase;
for (let yi = yr - 1; yi <= yr + 1; yi++) {
let zPrimed = zPrimedBase;
for (let zi = zr - 1; zi <= zr + 1; zi++) {
let hash = this._HashR3(seed, xPrimed, yPrimed, zPrimed);
let idx = hash & (255 << 2);
let vecX = xi - x + this._RandVecs3D[idx] * cellularJitter;
let vecY = yi - y + this._RandVecs3D[idx | 1] * cellularJitter;
let vecZ = zi - z + this._RandVecs3D[idx | 2] * cellularJitter;
let newDistance = vecX * vecX + vecY * vecY + vecZ * vecZ;
distance1 = Math.max(Math.min(distance1, newDistance), distance0);
if (newDistance < distance0) {
distance0 = newDistance;
closestHash = hash;
}
zPrimed += this._PrimeZ;
}
yPrimed += this._PrimeY;
}
xPrimed += this._PrimeX;
}
break;
case FastNoiseLite.CellularDistanceFunction.Manhattan:
for (let xi = xr - 1; xi <= xr + 1; xi++) {
let yPrimed = yPrimedBase;
for (let yi = yr - 1; yi <= yr + 1; yi++) {
let zPrimed = zPrimedBase;
for (let zi = zr - 1; zi <= zr + 1; zi++) {
let hash = this._HashR3(seed, xPrimed, yPrimed, zPrimed);
let idx = hash & (255 << 2);
let vecX = xi - x + this._RandVecs3D[idx] * cellularJitter;
let vecY = yi - y + this._RandVecs3D[idx | 1] * cellularJitter;
let vecZ = zi - z + this._RandVecs3D[idx | 2] * cellularJitter;
let newDistance = Math.abs(vecX) + Math.abs(vecY) + Math.abs(vecZ);
distance1 = Math.max(Math.min(distance1, newDistance), distance0);
if (newDistance < distance0) {
distance0 = newDistance;
closestHash = hash;
}
zPrimed += this._PrimeZ;
}
yPrimed += this._PrimeY;
}
xPrimed += this._PrimeX;
}
break;
case FastNoiseLite.CellularDistanceFunction.Hybrid:
for (let xi = xr - 1; xi <= xr + 1; xi++) {
let yPrimed = yPrimedBase;
for (let yi = yr - 1; yi <= yr + 1; yi++) {
let zPrimed = zPrimedBase;
for (let zi = zr - 1; zi <= zr + 1; zi++) {
let hash = this._HashR3(seed, xPrimed, yPrimed, zPrimed);
let idx = hash & (255 << 2);
let vecX = xi - x + this._RandVecs3D[idx] * cellularJitter;
let vecY = yi - y + this._RandVecs3D[idx | 1] * cellularJitter;
let vecZ = zi - z + this._RandVecs3D[idx | 2] * cellularJitter;
let newDistance =
Math.abs(vecX) +
Math.abs(vecY) +
Math.abs(vecZ) +
(vecX * vecX + vecY * vecY + vecZ * vecZ);
distance1 = Math.max(Math.min(distance1, newDistance), distance0);
if (newDistance < distance0) {
distance0 = newDistance;
closestHash = hash;
}
zPrimed += this._PrimeZ;
}
yPrimed += this._PrimeY;
}
xPrimed += this._PrimeX;
}
break;
default:
break;
}
if (
this._CellularDistanceFunction === FastNoiseLite.CellularDistanceFunction.Euclidean &&
this._CellularReturnType !== FastNoiseLite.CellularReturnType.CellValue
) {
distance0 = Math.sqrt(distance0);
if (this._CellularReturnType !== FastNoiseLite.CellularReturnType.CellValue) {
distance1 = Math.sqrt(distance1);
}
}
switch (this._CellularReturnType) {
case FastNoiseLite.CellularReturnType.CellValue:
return closestHash * (1 / 2147483648.0);
case FastNoiseLite.CellularReturnType.Distance:
return distance0 - 1;
case FastNoiseLite.CellularReturnType.Distance2:
return distance1 - 1;
case FastNoiseLite.CellularReturnType.Distance2Add:
return (distance1 + distance0) * 0.5 - 1;
case FastNoiseLite.CellularReturnType.Distance2Sub:
return distance1 - distance0 - 1;
case FastNoiseLite.CellularReturnType.Distance2Mul:
return distance1 * distance0 * 0.5 - 1;
case FastNoiseLite.CellularReturnType.Distance2Div:
return distance0 / distance1 - 1;
default:
return 0;
}
}
/**
* @private
* @param {number} seed
* @param {number} x
* @param {number} y
* @returns {number}
*/
_SinglePerlinR2(seed, x, y) {
let x0 = Math.floor(x);
let y0 = Math.floor(y);
let xd0 = x - x0;
let yd0 = y - y0;
let xd1 = xd0 - 1;
let yd1 = yd0 - 1;
let xs = FastNoiseLite._InterpQuintic(xd0);
let ys = FastNoiseLite._InterpQuintic(yd0);
x0 = Math.imul(x0, this._PrimeX);
y0 = Math.imul(y0, this._PrimeY);
let x1 = x0 + this._PrimeX;
let y1 = y0 + this._PrimeY;
let xf0 = FastNoiseLite._Lerp(
this._GradCoordR2(seed, x0, y0, xd0, yd0),
this._GradCoordR2(seed, x1, y0, xd1, yd0),
xs
);
let xf1 = FastNoiseLite._Lerp(
this._GradCoordR2(seed, x0, y1, xd0, yd1),
this._GradCoordR2(seed, x1, y1, xd1, yd1),
xs
);
return FastNoiseLite._Lerp(xf0, xf1, ys) * 1.4247691104677813;
}
/**
* @private
* @param {number} seed
* @param {number} x
* @param {number} y
* @param {number} z
* @returns {number}
*/
_SinglePerlinR3 (seed, x, y, z) {
let x0 = Math.floor(x);
let y0 = Math.floor(y);
let z0 = Math.floor(z);
let xd0 = x - x0;
let yd0 = y - y0;
let zd0 = z - z0;
let xd1 = xd0 - 1;
let yd1 = yd0 - 1;
let zd1 = zd0 - 1;
let xs = FastNoiseLite._InterpQuintic(xd0);
let ys = FastNoiseLite._InterpQuintic(yd0);
let zs = FastNoiseLite._InterpQuintic(zd0);
x0 = Math.imul(x0, this._PrimeX);
y0 = Math.imul(y0, this._PrimeY);
z0 = Math.imul(z0, this._PrimeZ);
let x1 = x0 + this._PrimeX;
let y1 = y0 + this._PrimeY;
let z1 = z0 + this._PrimeZ;
let xf00 = FastNoiseLite._Lerp(
this._GradCoordR3(seed, x0, y0, z0, xd0, yd0, zd0),
this._GradCoordR3(seed, x1, y0, z0, xd1, yd0, zd0),
xs
);
let xf10 = FastNoiseLite._Lerp(
this._GradCoordR3(seed, x0, y1, z0, xd0, yd1, zd0),
this._GradCoordR3(seed, x1, y1, z0, xd1, yd1, zd0),
xs
);
let xf01 = FastNoiseLite._Lerp(
this._GradCoordR3(seed, x0, y0, z1, xd0, yd0, zd1),
this._GradCoordR3(seed, x1, y0, z1, xd1, yd0, zd1),
xs
);
let xf11 = FastNoiseLite._Lerp(
this._GradCoordR3(seed, x0, y1, z1, xd0, yd1, zd1),
this._GradCoordR3(seed, x1, y1, z1, xd1, yd1, zd1),
xs
);
let yf0 = FastNoiseLite._Lerp(xf00, xf10, ys);
let yf1 = FastNoiseLite._Lerp(xf01, xf11, ys);
return FastNoiseLite._Lerp(yf0, yf1, zs) * 0.964921414852142333984375;
}
/**
* @private
* @param {number} seed
* @param {number} x
* @param {number} y
* @returns {number}
*/
_SingleValueCubicR2(seed, x, y) {
let x1 = Math.floor(x);
let y1 = Math.floor(y);
let xs = x - x1;
let ys = y - y1;
x1 = Math.imul(x1, this._PrimeX);
y1 = Math.imul(y1, this._PrimeY);
let x0 = x1 - this._PrimeX;
let y0 = y1 - this._PrimeY;
let x2 = x1 + this._PrimeX;
let y2 = y1 + this._PrimeY;
let x3 = x1 + (this._PrimeX << 1);
let y3 = y1 + (this._PrimeY << 1);
return (
FastNoiseLite._CubicLerp(
FastNoiseLite._CubicLerp(
this._ValCoordR2(seed, x0, y0),
this._ValCoordR2(seed, x1, y0),
this._ValCoordR2(seed, x2, y0),
this._ValCoordR2(seed, x3, y0),
xs
),
FastNoiseLite._CubicLerp(
this._ValCoordR2(seed, x0, y1),
this._ValCoordR2(seed, x1, y1),
this._ValCoordR2(seed, x2, y1),
this._ValCoordR2(seed, x3, y1),
xs
),
FastNoiseLite._CubicLerp(
this._ValCoordR2(seed, x0, y2),
this._ValCoordR2(seed, x1, y2),
this._ValCoordR2(seed, x2, y2),
this._ValCoordR2(seed, x3, y2),
xs
),
FastNoiseLite._CubicLerp(
this._ValCoordR2(seed, x0, y3),
this._ValCoordR2(seed, x1, y3),
this._ValCoordR2(seed, x2, y3),
this._ValCoordR2(seed, x3, y3),
xs
),
ys
) *
(1 / (1.5 * 1.5))
);
}
/**
* @private
* @param {number} seed
* @param {number} x
* @param {number} y
* @param {number} z
* @returns {number}
*/
_SingleValueCubicR3(seed, x, y, z) {
let x1 = Math.floor(x);
let y1 = Math.floor(y);
let z1 = Math.floor(z);
let xs = x - x1;
let ys = y - y1;
let zs = z - z1;
x1 = Math.imul(x1, this._PrimeX);
y1 = Math.imul(y1, this._PrimeY);
z1 = Math.imul(z1, this._PrimeZ);
let x0 = x1 - this._PrimeX;
let y0 = y1 - this._PrimeY;
let z0 = z1 - this._PrimeZ;
let x2 = x1 + this._PrimeX;
let y2 = y1 + this._PrimeY;
let z2 = z1 + this._PrimeZ;
let x3 = x1 + (this._PrimeX << 1);
let y3 = y1 + (this._PrimeY << 1);
let z3 = z1 + (this._PrimeZ << 1);
return (
FastNoiseLite._CubicLerp(
FastNoiseLite._CubicLerp(
FastNoiseLite._CubicLerp(
this._ValCoordR3(seed, x0, y0, z0),
this._ValCoordR3(seed, x1, y0, z0),
this._ValCoordR3(seed, x2, y0, z0),
this._ValCoordR3(seed, x3, y0, z0),
xs
),
FastNoiseLite._CubicLerp(
this._ValCoordR3(seed, x0, y1, z0),
this._ValCoordR3(seed, x1, y1, z0),
this._ValCoordR3(seed, x2, y1, z0),
this._ValCoordR3(seed, x3, y1, z0),
xs
),
FastNoiseLite._CubicLerp(
this._ValCoordR3(seed, x0, y2, z0),
this._ValCoordR3(seed, x1, y2, z0),
this._ValCoordR3(seed, x2, y2, z0),
this._ValCoordR3(seed, x3, y2, z0),
xs
),
FastNoiseLite._CubicLerp(
this._ValCoordR3(seed, x0, y3, z0),
this._ValCoordR3(seed, x1, y3, z0),
this._ValCoordR3(seed, x2, y3, z0),
this._ValCoordR3(seed, x3, y3, z0),
xs
),
ys
),
FastNoiseLite._CubicLerp(
FastNoiseLite._CubicLerp(
this._ValCoordR3(seed, x0, y0, z1),
this._ValCoordR3(seed, x1, y0, z1),
this._ValCoordR3(seed, x2, y0, z1),
this._ValCoordR3(seed, x3, y0, z1),
xs
),
FastNoiseLite._CubicLerp(
this._ValCoordR3(seed, x0, y1, z1),
this._ValCoordR3(seed, x1, y1, z1),
this._ValCoordR3(seed, x2, y1, z1),
this._ValCoordR3(seed, x3, y1, z1),
xs
),
FastNoiseLite._CubicLerp(
this._ValCoordR3(seed, x0, y2, z1),
this._ValCoordR3(seed, x1, y2, z1),
this._ValCoordR3(seed, x2, y2, z1),
this._ValCoordR3(seed, x3, y2, z1),
xs
),
FastNoiseLite._CubicLerp(
this._ValCoordR3(seed, x0, y3, z1),
this._ValCoordR3(seed, x1, y3, z1),
this._ValCoordR3(seed, x2, y3, z1),
this._ValCoordR3(seed, x3, y3, z1),
xs
),
ys
),
FastNoiseLite._CubicLerp(
FastNoiseLite._CubicLerp(
this._ValCoordR3(seed, x0, y0, z2),
this._ValCoordR3(seed, x1, y0, z2),
this._ValCoordR3(seed, x2, y0, z2),
this._ValCoordR3(seed, x3, y0, z2),
xs
),
FastNoiseLite._CubicLerp(
this._ValCoordR3(seed, x0, y1, z2),
this._ValCoordR3(seed, x1, y1, z2),
this._ValCoordR3(seed, x2, y1, z2),
this._ValCoordR3(seed, x3, y1, z2),
xs
),
FastNoiseLite._CubicLerp(
this._ValCoordR3(seed, x0, y2, z2),
this._ValCoordR3(seed, x1, y2, z2),
this._ValCoordR3(seed, x2, y2, z2),
this._ValCoordR3(seed, x3, y2, z2),
xs
),
FastNoiseLite._CubicLerp(
this._ValCoordR3(seed, x0, y3, z2),
this._ValCoordR3(seed, x1, y3, z2),
this._ValCoordR3(seed, x2, y3, z2),
this._ValCoordR3(seed, x3, y3, z2),
xs
),
ys
),
FastNoiseLite._CubicLerp(
FastNoiseLite._CubicLerp(
this._ValCoordR3(seed, x0, y0, z3),
this._ValCoordR3(seed, x1, y0, z3),
this._ValCoordR3(seed, x2, y0, z3),
this._ValCoordR3(seed, x3, y0, z3),
xs
),
FastNoiseLite._CubicLerp(
this._ValCoordR3(seed, x0, y1, z3),
this._ValCoordR3(seed, x1, y1, z3),
this._ValCoordR3(seed, x2, y1, z3),
this._ValCoordR3(seed, x3, y1, z3),
xs
),
FastNoiseLite._CubicLerp(
this._ValCoordR3(seed, x0, y2, z3),
this._ValCoordR3(seed, x1, y2, z3),
this._ValCoordR3(seed, x2, y2, z3),
this._ValCoordR3(seed, x3, y2, z3),
xs
),
FastNoiseLite._CubicLerp(
this._ValCoordR3(seed, x0, y3, z3),
this._ValCoordR3(seed, x1, y3, z3),
this._ValCoordR3(seed, x2, y3, z3),
this._ValCoordR3(seed, x3, y3, z3),
xs
),
ys
),
zs
) *
(1 / (1.5 * 1.5 * 1.5))
);
}
/**
* @private
* @param {number} seed
* @param {number} x
* @param {number} y
* @returns {number}
*/
_SingleValueR2(seed, x, y) {
let x0 = Math.floor(x);
let y0 = Math.floor(y);
let xs = FastNoiseLite._InterpHermite(x - x0);
let ys = FastNoiseLite._InterpHermite(y - y0);
x0 = Math.imul(x0, this._PrimeX);
y0 = Math.imul(y0, this._PrimeY);
let x1 = x0 + this._PrimeX;
let y1 = y0 + this._PrimeY;
let xf0 = FastNoiseLite._Lerp(this._ValCoordR2(seed, x0, y0), this._ValCoordR2(seed, x1, y0), xs);
let xf1 = FastNoiseLite._Lerp(this._ValCoordR2(seed, x0, y1), this._ValCoordR2(seed, x1, y1), xs);
return FastNoiseLite._Lerp(xf0, xf1, ys);
}
/**
* @private
* @param {number} seed
* @param {number} x
* @param {number} y
* @param {number} z
* @returns {number}
*/
_SingleValueR3(seed, x, y, z) {
let x0 = Math.floor(x);
let y0 = Math.floor(y);
let z0 = Math.floor(z);
let xs = FastNoiseLite._InterpHermite(x - x0);
let ys = FastNoiseLite._InterpHermite(y - y0);
let zs = FastNoiseLite._InterpHermite(z - z0);
x0 = Math.imul(x0, this._PrimeX);
y0 = Math.imul(y0, this._PrimeY);
z0 = Math.imul(z0, this._PrimeZ);
let x1 = x0 + this._PrimeX;
let y1 = y0 + this._PrimeY;
let z1 = z0 + this._PrimeZ;
let xf00 = FastNoiseLite._Lerp(
this._ValCoordR3(seed, x0, y0, z0),
this._ValCoordR3(seed, x1, y0, z0),
xs
);
let xf10 = FastNoiseLite._Lerp(
this._ValCoordR3(seed, x0, y1, z0),
this._ValCoordR3(seed, x1, y1, z0),
xs
);
let xf01 = FastNoiseLite._Lerp(
this._ValCoordR3(seed, x0, y0, z1),
this._ValCoordR3(seed, x1, y0, z1),
xs
);
let xf11 = FastNoiseLite._Lerp(
this._ValCoordR3(seed, x0, y1, z1),
this._ValCoordR3(seed, x1, y1, z1),
xs
);
let yf0 = FastNoiseLite._Lerp(xf00, xf10, ys);
let yf1 = FastNoiseLite._Lerp(xf01, xf11, ys);
return FastNoiseLite._Lerp(yf0, yf1, zs);
}
/**
* @private
*/
_DoSingleDomainWarp() {
/**
*
* @param {number} seed
* @param {number} amp
* @param {number} freq
* @param {Vector2} coord
* @param {number} x
* @param {number} y
*/
let R2 = (seed, amp, freq, coord, x, y) => {
switch (this._DomainWarpType) {
case FastNoiseLite.DomainWarpType.OpenSimplex2:
this._SingleDomainWarpOpenSimplex2Gradient(
seed,
amp * 38.283687591552734375,
freq,
coord,
false,
x,
y
);
break;
case FastNoiseLite.DomainWarpType.OpenSimplex2Reduced:
this._SingleDomainWarpOpenSimplex2Gradient(
seed,
amp * 16.0,
freq,
coord,
true,
x,
y
);
break;
case FastNoiseLite.DomainWarpType.BasicGrid:
this._SingleDomainWarpBasicGrid(seed, amp, freq, coord, x, y);
break;
}
};
/**
*
* @param {number} seed
* @param {number} amp
* @param {number} freq
* @param {Vector3} coord
* @param {number} x
* @param {number} y
* @param {number} z
*/
let R3 = (seed, amp, freq, coord, x, y, z) => {
switch (this._DomainWarpType) {
case FastNoiseLite.DomainWarpType.OpenSimplex2:
this._SingleDomainWarpOpenSimplex2Gradient(
seed,
amp * 32.69428253173828125,
freq,
coord,
false,
x,
y,
z
);
break;
case FastNoiseLite.DomainWarpType.OpenSimplex2Reduced:
this._SingleDomainWarpOpenSimplex2Gradient(
seed,
amp * 7.71604938271605,
freq,
coord,
true,
x,
y,
z
);
break;
case FastNoiseLite.DomainWarpType.BasicGrid:
this._SingleDomainWarpBasicGrid(seed, amp, freq, coord, x, y, z);
break;
}
};
if (arguments.length === 6 && arguments[3] instanceof Vector2) {
return R2(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
}
if (arguments.length === 7 && arguments[3] instanceof Vector3) {
return R3(
arguments[0],
arguments[1],
arguments[2],
arguments[3],
arguments[4],
arguments[5],
arguments[6]
);
}
}
/**
* @private
*/
_DomainWarpSingle() {
/**
*
* @param {Vector2} coord
*/
let R2 = coord => {
let seed = this._Seed;
let amp = this._DomainWarpAmp * this._FractalBounding;
let freq = this._Frequency;
let xs = coord.x;
let ys = coord.y;
switch (this._DomainWarpType) {
case FastNoiseLite.DomainWarpType.OpenSimplex2:
case FastNoiseLite.DomainWarpType.OpenSimplex2Reduced:
const SQRT3 = 1.7320508075688772935274463415059;
const F2 = 0.5 * (SQRT3 - 1);
let t = (xs + ys) * F2;
xs += t;
ys += t;
break;
default:
break;
}
this._DoSingleDomainWarp(seed, amp, freq, coord, xs, ys);
};
/**
*
* @param {Vector3} coord
*/
let R3 = coord => {
let seed = this._Seed;
let amp = this._DomainWarpAmp * this._FractalBounding;
let freq = this._Frequency;
let xs = coord.x;
let ys = coord.y;
let zs = coord.z;
switch (this._WarpTransformType3D) {
case FastNoiseLite.TransformType3D.ImproveXYPlanes:
{
let xy = xs + ys;
let s2 = xy * -0.211324865405187;
zs *= 0.577350269189626;
xs += s2 - zs;
ys = ys + s2 - zs;
zs += xy * 0.577350269189626;
}
break;
case FastNoiseLite.TransformType3D.ImproveXZPlanes:
{
let xz = xs + zs;
let s2 = xz * -0.211324865405187;
ys *= 0.577350269189626;
xs += s2 - ys;
zs += s2 - ys;
ys += xz * 0.577350269189626;
}
break;
case FastNoiseLite.TransformType3D.DefaultOpenSimplex2:
const R3 = 2.0 / 3.0;
let r = (xs + ys + zs) * R3; // Rotation, not skew
xs = r - xs;
ys = r - ys;
zs = r - zs;
break;
default:
break;
}
this._DoSingleDomainWarp(seed, amp, freq, coord, xs, ys, zs);
};
if (arguments.length === 1 && arguments[0] instanceof Vector2) {
return R2(arguments[0]);
}
if (arguments.length === 1 && arguments[0] instanceof Vector3) {
return R3(arguments[0]);
}
}
_DomainWarpFractalProgressive() {
/**
*
* @param {Vector2} coord
*/
let R2 = coord => {
let seed = this._Seed;
let amp = this._DomainWarpAmp * this._FractalBounding;
let freq = this._Frequency;
for (let i = 0; i < this._Octaves; i++) {
let xs = coord.x;
let ys = coord.y;
switch (this._DomainWarpType) {
case FastNoiseLite.DomainWarpType.OpenSimplex2:
case FastNoiseLite.DomainWarpType.OpenSimplex2Reduced:
const SQRT3 = 1.7320508075688772935274463415059;
const F2 = 0.5 * (SQRT3 - 1);
let t = (xs + ys) * F2;
xs += t;
ys += t;
break;
default:
break;
}
this._DoSingleDomainWarp(seed, amp, freq, coord, xs, ys);
seed++;
amp *= this._Gain;
freq *= this._Lacunarity;
}
};
/**
*
* @param {Vector3} coord
*/
let R3 = coord => {
let seed = this._Seed;
let amp = this._DomainWarpAmp * this._FractalBounding;
let freq = this._Frequency;
for (let i = 0; i < this._Octaves; i++) {
let xs = coord.x;
let ys = coord.y;
let zs = coord.z;
switch (this._WarpTransformType3D) {
case FastNoiseLite.TransformType3D.ImproveXYPlanes:
{
let xy = xs + ys;
let s2 = xy * -0.211324865405187;
zs *= 0.577350269189626;
xs += s2 - zs;
ys = ys + s2 - zs;
zs += xy * 0.577350269189626;
}
break;
case FastNoiseLite.TransformType3D.ImproveXZPlanes:
{
let xz = xs + zs;
let s2 = xz * -0.211324865405187;
ys *= 0.577350269189626;
xs += s2 - ys;
zs += s2 - ys;
ys += xz * 0.577350269189626;
}
break;
case FastNoiseLite.TransformType3D.DefaultOpenSimplex2:
{
const R3 = 2.0 / 3.0;
let r = (xs + ys + zs) * R3; // Rotation, not skew
xs = r - xs;
ys = r - ys;
zs = r - zs;
}
break;
default:
break;
}
this._DoSingleDomainWarp(seed, amp, freq, coord, xs, ys, zs);
seed++;
amp *= this._Gain;
freq *= this._Lacunarity;
}
};
if (arguments.length === 1 && arguments[0] instanceof Vector2) {
return R2(arguments[0]);
}
if (arguments.length === 1 && arguments[0] instanceof Vector3) {
return R3(arguments[0]);
}
}
/**
* @private
*/
_DomainWarpFractalIndependent() {
/**
*
* @param {Vector2} coord
*/
let R2 = coord => {
let xs = coord.x;
let ys = coord.y;
switch (this._DomainWarpType) {
case FastNoiseLite.DomainWarpType.OpenSimplex2:
case FastNoiseLite.DomainWarpType.OpenSimplex2Reduced:
const SQRT3 = 1.7320508075688772935274463415059;
const F2 = 0.5 * (SQRT3 - 1);
let t = (xs + ys) * F2;
xs += t;
ys += t;
break;
default:
break;
}
let seed = this._Seed;
let amp = this._DomainWarpAmp * this._FractalBounding;
let freq = this._Frequency;
for (let i = 0; i < this._Octaves; i++) {
this._DoSingleDomainWarp(seed, amp, freq, coord, xs, ys);
seed++;
amp *= this._Gain;
freq *= this._Lacunarity;
}
};
/**
*
* @param {Vector3} coord
*/
let R3 = coord => {
let xs = coord.x;
let ys = coord.y;
let zs = coord.z;
switch (this._WarpTransformType3D) {
case FastNoiseLite.TransformType3D.ImproveXYPlanes:
{
let xy = xs + ys;
let s2 = xy * -0.211324865405187;
zs *= 0.577350269189626;
xs += s2 - zs;
ys = ys + s2 - zs;
zs += xy * 0.577350269189626;
}
break;
case FastNoiseLite.TransformType3D.ImproveXZPlanes:
{
let xz = xs + zs;
let s2 = xz * -0.211324865405187;
ys *= 0.577350269189626;
xs += s2 - ys;
zs += s2 - ys;
ys += xz * 0.577350269189626;
}
break;
case FastNoiseLite.TransformType3D.DefaultOpenSimplex2:
{
const R3 = 2.0 / 3.0;
let r = (xs + ys + zs) * R3; // Rotation, not skew
xs = r - xs;
ys = r - ys;
zs = r - zs;
}
break;
default:
break;
}
let seed = this._Seed;
let amp = this._DomainWarpAmp * this._FractalBounding;
let freq = this._Frequency;
for (let i = 0; i < this._Octaves; i++) {
this._DoSingleDomainWarp(seed, amp, freq, coord, xs, ys, zs);
seed++;
amp *= this._Gain;
freq *= this._Lacunarity;
}
};
if (arguments.length === 1 && arguments[0] instanceof Vector2) {
return R2(arguments[0]);
}
if (arguments.length === 1 && arguments[0] instanceof Vector3) {
return R3(arguments[0]);
}
}
/**
* @private
*/
_SingleDomainWarpBasicGrid() {
/**
*
* @param {number} seed
* @param {number} warpAmp
* @param {number} frequency
* @param {Vector2} coord
* @param {number} x
* @param {number} y
*/
let R2 = (seed, warpAmp, frequency, coord, x, y) => {
let xf = x * frequency;
let yf = y * frequency;
let x0 = Math.floor(xf);
let y0 = Math.floor(yf);
let xs = FastNoiseLite._InterpHermite(xf - x0);
let ys = FastNoiseLite._InterpHermite(yf - y0);
x0 = Math.imul(x0, this._PrimeX);
y0 = Math.imul(y0, this._PrimeY);
let x1 = x0 + this._PrimeX;
let y1 = y0 + this._PrimeY;
let hash0 = this._HashR2(seed, x0, y0) & (255 << 1);
let hash1 = this._HashR2(seed, x1, y0) & (255 << 1);
let lx0x = FastNoiseLite._Lerp(this._RandVecs2D[hash0], this._RandVecs2D[hash1], xs);
let ly0x = FastNoiseLite._Lerp(this._RandVecs2D[hash0 | 1], this._RandVecs2D[hash1 | 1], xs);
hash0 = this._HashR2(seed, x0, y1) & (255 << 1);
hash1 = this._HashR2(seed, x1, y1) & (255 << 1);
let lx1x = FastNoiseLite._Lerp(this._RandVecs2D[hash0], this._RandVecs2D[hash1], xs);
let ly1x = FastNoiseLite._Lerp(this._RandVecs2D[hash0 | 1], this._RandVecs2D[hash1 | 1], xs);
coord.x += FastNoiseLite._Lerp(lx0x, lx1x, ys) * warpAmp;
coord.y += FastNoiseLite._Lerp(ly0x, ly1x, ys) * warpAmp;
};
/**
*
* @param {number} seed
* @param {number} warpAmp
* @param {number} frequency
* @param {Vector3} coord
* @param {number} x
* @param {number} y
* @param {number} z
*/
let R3 = (seed, warpAmp, frequency, coord, x, y, z) => {
let xf = x * frequency;
let yf = y * frequency;
let zf = z * frequency;
let x0 = Math.floor(xf);
let y0 = Math.floor(yf);
let z0 = Math.floor(zf);
let xs = FastNoiseLite._InterpHermite(xf - x0);
let ys = FastNoiseLite._InterpHermite(yf - y0);
let zs = FastNoiseLite._InterpHermite(zf - z0);
x0 = Math.imul(x0, this._PrimeX);
y0 = Math.imul(y0, this._PrimeY);
z0 = Math.imul(z0, this._PrimeZ);
let x1 = x0 + this._PrimeX;
let y1 = y0 + this._PrimeY;
let z1 = z0 + this._PrimeZ;
let hash0 = this._HashR3(seed, x0, y0, z0) & (255 << 2);
let hash1 = this._HashR3(seed, x1, y0, z0) & (255 << 2);
let lx0x = FastNoiseLite._Lerp(this._RandVecs3D[hash0], this._RandVecs3D[hash1], xs);
let ly0x = FastNoiseLite._Lerp(this._RandVecs3D[hash0 | 1], this._RandVecs3D[hash1 | 1], xs);
let lz0x = FastNoiseLite._Lerp(this._RandVecs3D[hash0 | 2], this._RandVecs3D[hash1 | 2], xs);
hash0 = this._HashR3(seed, x0, y1, z0) & (255 << 2);
hash1 = this._HashR3(seed, x1, y1, z0) & (255 << 2);
let lx1x = FastNoiseLite._Lerp(this._RandVecs3D[hash0], this._RandVecs3D[hash1], xs);
let ly1x = FastNoiseLite._Lerp(this._RandVecs3D[hash0 | 1], this._RandVecs3D[hash1 | 1], xs);
let lz1x = FastNoiseLite._Lerp(this._RandVecs3D[hash0 | 2], this._RandVecs3D[hash1 | 2], xs);
let lx0y = FastNoiseLite._Lerp(lx0x, lx1x, ys);
let ly0y = FastNoiseLite._Lerp(ly0x, ly1x, ys);
let lz0y = FastNoiseLite._Lerp(lz0x, lz1x, ys);
hash0 = this._HashR3(seed, x0, y0, z1) & (255 << 2);
hash1 = this._HashR3(seed, x1, y0, z1) & (255 << 2);
lx0x = FastNoiseLite._Lerp(this._RandVecs3D[hash0], this._RandVecs3D[hash1], xs);
ly0x = FastNoiseLite._Lerp(this._RandVecs3D[hash0 | 1], this._RandVecs3D[hash1 | 1], xs);
lz0x = FastNoiseLite._Lerp(this._RandVecs3D[hash0 | 2], this._RandVecs3D[hash1 | 2], xs);
hash0 = this._HashR3(seed, x0, y1, z1) & (255 << 2);
hash1 = this._HashR3(seed, x1, y1, z1) & (255 << 2);
lx1x = FastNoiseLite._Lerp(this._RandVecs3D[hash0], this._RandVecs3D[hash1], xs);
ly1x = FastNoiseLite._Lerp(this._RandVecs3D[hash0 | 1], this._RandVecs3D[hash1 | 1], xs);
lz1x = FastNoiseLite._Lerp(this._RandVecs3D[hash0 | 2], this._RandVecs3D[hash1 | 2], xs);
coord.x += FastNoiseLite._Lerp(lx0y, FastNoiseLite._Lerp(lx0x, lx1x, ys), zs) * warpAmp;
coord.y += FastNoiseLite._Lerp(ly0y, FastNoiseLite._Lerp(ly0x, ly1x, ys), zs) * warpAmp;
coord.z += FastNoiseLite._Lerp(lz0y, FastNoiseLite._Lerp(lz0x, lz1x, ys), zs) * warpAmp;
};
if (arguments.length === 6 && arguments[3] instanceof Vector2) {
R2(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
}
if (arguments.length === 7 && arguments[3] instanceof Vector3) {
R3(
arguments[0],
arguments[1],
arguments[2],
arguments[3],
arguments[4],
arguments[5],
arguments[6]
);
}
}
/**
* @private
*/
_SingleDomainWarpOpenSimplex2Gradient() {
/**
*
* @param {number} seed
* @param {number} warpAmp
* @param {number} frequency
* @param {Vector2} coord
* @param {boolean} outGradOnly
* @param {number} x
* @param {number} y
*/
let R2 = (seed, warpAmp, frequency, coord, outGradOnly, x, y) => {
const SQRT3 = 1.7320508075688772935274463415059;
const G2 = (3 - SQRT3) / 6;
x *= frequency;
y *= frequency;
let i = Math.floor(x);
let j = Math.floor(y);
let xi = x - i;
let yi = y - j;
let t = (xi + yi) * G2;
let x0 = xi - t;
let y0 = yi - t;
i = Math.imul(i, this._PrimeX);
j = Math.imul(j, this._PrimeY);
let vx, vy;
vx = vy = 0;
let a = 0.5 - x0 * x0 - y0 * y0;
if (a > 0) {
let aaaa = a * a * (a * a);
let xo, yo;
if (outGradOnly) {
let hash = this._HashR2(seed, i, j) & (255 << 1);
xo = this._RandVecs2D[hash];
yo = this._RandVecs2D[hash | 1];
} else {
let hash = this._HashR2(seed, i, j);
let index1 = hash & (127 << 1);
let index2 = (hash >> 7) & (255 << 1);
let xg = this._Gradients2D[index1];
let yg = this._Gradients2D[index1 | 1];
let value = x0 * xg + y0 * yg;
let xgo = this._RandVecs2D[index2];
let ygo = this._RandVecs2D[index2 | 1];
xo = value * xgo;
yo = value * ygo;
}
vx += aaaa * xo;
vy += aaaa * yo;
}
let c = 2 * (1 - 2 * G2) * (1 / G2 - 2) * t + (-2 * (1 - 2 * G2) * (1 - 2 * G2) + a);
if (c > 0) {
let x2 = x0 + (2 * G2 - 1);
let y2 = y0 + (2 * G2 - 1);
let cccc = c * c * (c * c);
let xo, yo;
if (outGradOnly) {
let hash = this._HashR2(seed, i + this._PrimeX, j + this._PrimeY) & (255 << 1);
xo = this._RandVecs2D[hash];
yo = this._RandVecs2D[hash | 1];
} else {
let hash = this._HashR2(seed, i + this._PrimeX, j + this._PrimeY);
let index1 = hash & (127 << 1);
let index2 = (hash >> 7) & (255 << 1);
let xg = this._Gradients2D[index1];
let yg = this._Gradients2D[index1 | 1];
let value = x2 * xg + y2 * yg;
let xgo = this._RandVecs2D[index2];
let ygo = this._RandVecs2D[index2 | 1];
xo = value * xgo;
yo = value * ygo;
}
vx += cccc * xo;
vy += cccc * yo;
}
if (y0 > x0) {
let x1 = x0 + G2;
let y1 = y0 + (G2 - 1);
let b = 0.5 - x1 * x1 - y1 * y1;
if (b > 0) {
let bbbb = b * b * (b * b);
let xo, yo;
if (outGradOnly) {
let hash = this._HashR2(seed, i, j + this._PrimeY) & (255 << 1);
xo = this._RandVecs2D[hash];
yo = this._RandVecs2D[hash | 1];
} else {
let hash = this._HashR2(seed, i, j + this._PrimeY);
let index1 = hash & (127 << 1);
let index2 = (hash >> 7) & (255 << 1);
let xg = this._Gradients2D[index1];
let yg = this._Gradients2D[index1 | 1];
let value = x1 * xg + y1 * yg;
let xgo = this._RandVecs2D[index2];
let ygo = this._RandVecs2D[index2 | 1];
xo = value * xgo;
yo = value * ygo;
}
vx += bbbb * xo;
vy += bbbb * yo;
}
} else {
let x1 = x0 + (G2 - 1);
let y1 = y0 + G2;
let b = 0.5 - x1 * x1 - y1 * y1;
if (b > 0) {
let bbbb = b * b * (b * b);
let xo, yo;
if (outGradOnly) {
let hash = this._HashR2(seed, i + this._PrimeX, j) & (255 << 1);
xo = this._RandVecs2D[hash];
yo = this._RandVecs2D[hash | 1];
} else {
let hash = this._HashR2(seed, i + this._PrimeX, j);
let index1 = hash & (127 << 1);
let index2 = (hash >> 7) & (255 << 1);
let xg = this._Gradients2D[index1];
let yg = this._Gradients2D[index1 | 1];
let value = x1 * xg + y1 * yg;
let xgo = this._RandVecs2D[index2];
let ygo = this._RandVecs2D[index2 | 1];
xo = value * xgo;
yo = value * ygo;
}
vx += bbbb * xo;
vy += bbbb * yo;
}
}
coord.x += vx * warpAmp;
coord.y += vy * warpAmp;
};
/**
*
* @param {number} seed
* @param {number} warpAmp
* @param {number} frequency
* @param {Vector3} coord
* @param {boolean} outGradOnly
* @param {number} x
* @param {number} y
* @param {number} z
*/
let R3 = (seed, warpAmp, frequency, coord, outGradOnly, x, y, z) => {
x *= frequency;
y *= frequency;
z *= frequency;
let i = Math.round(x);
let j = Math.round(y);
let k = Math.round(z);
let x0 = x - i;
let y0 = y - j;
let z0 = z - k;
let xNSign = (-x0 - 1.0) | 1;
let yNSign = (-y0 - 1.0) | 1;
let zNSign = (-z0 - 1.0) | 1;
let ax0 = xNSign * -x0;
let ay0 = yNSign * -y0;
let az0 = zNSign * -z0;
i = Math.imul(i, this._PrimeX);
j = Math.imul(j, this._PrimeY);
k = Math.imul(k, this._PrimeZ);
let vx, vy, vz;
vx = vy = vz = 0;
let a = 0.6 - x0 * x0 - (y0 * y0 + z0 * z0);
for (let l = 0; ; l++) {
if (a > 0) {
let aaaa = a * a * (a * a);
let xo, yo, zo;
if (outGradOnly) {
let hash = this._HashR3(seed, i, j, k) & (255 << 2);
xo = this._RandVecs3D[hash];
yo = this._RandVecs3D[hash | 1];
zo = this._RandVecs3D[hash | 2];
} else {
let hash = this._HashR3(seed, i, j, k);
let index1 = hash & (63 << 2);
let index2 = (hash >> 6) & (255 << 2);
let xg = this._Gradients3D[index1];
let yg = this._Gradients3D[index1 | 1];
let zg = this._Gradients3D[index1 | 2];
let value = x0 * xg + y0 * yg + z0 * zg;
let xgo = this._RandVecs3D[index2];
let ygo = this._RandVecs3D[index2 | 1];
let zgo = this._RandVecs3D[index2 | 2];
xo = value * xgo;
yo = value * ygo;
zo = value * zgo;
}
vx += aaaa * xo;
vy += aaaa * yo;
vz += aaaa * zo;
}
let b = a;
let i1 = i;
let j1 = j;
let k1 = k;
let x1 = x0;
let y1 = y0;
let z1 = z0;
if (ax0 >= ay0 && ax0 >= az0) {
x1 += xNSign;
b = b + ax0 + ax0;
i1 -= xNSign * this._PrimeX;
} else if (ay0 > ax0 && ay0 >= az0) {
y1 += yNSign;
b = b + ay0 + ay0;
j1 -= yNSign * this._PrimeY;
} else {
z1 += zNSign;
b = b + az0 + az0;
k1 -= zNSign * this._PrimeZ;
}
if (b > 1) {
b -= 1;
let bbbb = b * b * (b * b);
let xo, yo, zo;
if (outGradOnly) {
let hash = this._HashR3(seed, i1, j1, k1) & (255 << 2);
xo = this._RandVecs3D[hash];
yo = this._RandVecs3D[hash | 1];
zo = this._RandVecs3D[hash | 2];
} else {
let hash = this._HashR3(seed, i1, j1, k1);
let index1 = hash & (63 << 2);
let index2 = (hash >> 6) & (255 << 2);
let xg = this._Gradients3D[index1];
let yg = this._Gradients3D[index1 | 1];
let zg = this._Gradients3D[index1 | 2];
let value = x1 * xg + y1 * yg + z1 * zg;
let xgo = this._RandVecs3D[index2];
let ygo = this._RandVecs3D[index2 | 1];
let zgo = this._RandVecs3D[index2 | 2];
xo = value * xgo;
yo = value * ygo;
zo = value * zgo;
}
vx += bbbb * xo;
vy += bbbb * yo;
vz += bbbb * zo;
}
if (l === 1) break;
ax0 = 0.5 - ax0;
ay0 = 0.5 - ay0;
az0 = 0.5 - az0;
x0 = xNSign * ax0;
y0 = yNSign * ay0;
z0 = zNSign * az0;
a += 0.75 - ax0 - (ay0 + az0);
i += (xNSign >> 1) & this._PrimeX;
j += (yNSign >> 1) & this._PrimeY;
k += (zNSign >> 1) & this._PrimeZ;
xNSign = -xNSign;
yNSign = -yNSign;
zNSign = -zNSign;
seed += 1293373;
}
coord.x += vx * warpAmp;
coord.y += vy * warpAmp;
coord.z += vz * warpAmp;
};
if (arguments.length === 7) {
R2(
arguments[0],
arguments[1],
arguments[2],
arguments[3],
arguments[4],
arguments[5],
arguments[6]
);
}
if (arguments.length === 8) {
R3(
arguments[0],
arguments[1],
arguments[2],
arguments[3],
arguments[4],
arguments[5],
arguments[6],
arguments[7]
);
}
}
}
class Vector2 {
/**
* 2d Vector
* @param {number} x
* @param {number} y
*/
constructor(x, y) {
this.x = x;
this.y = y;
}
}
class Vector3 {
/**
* 3d Vector
* @param {number} x
* @param {number} y
* @param {number} z
*/
constructor(x, y, z) {
this.x = x;
this.y = y;
this.z = z;
}
}
``` | /content/code_sandbox/JavaScript/FastNoiseLite.js | javascript | 2016-03-28T02:35:12 | 2024-08-16T07:09:20 | FastNoiseLite | Auburn/FastNoiseLite | 2,688 | 43,128 |
```objective-c
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// .'',;:cldxkO00KKXXNNWWWNNXKOkxdollcc::::::;:::ccllloooolllllllllooollc:,'... ...........',;cldxkO000Okxdlc::;;;,,;;;::cclllllll
// ..',;:ldxO0KXXNNNNNNNNXXK0kxdolcc::::::;;;,,,,,,;;;;;;;;;;:::cclllllc:;'.... ...........',;:ldxO0KXXXK0Okxdolc::;;;;::cllodddddo
// ...',:loxO0KXNNNNNXXKK0Okxdolc::;::::::::;;;,,'''''.....''',;:clllllc:;,'............''''''''',;:loxO0KXNNNNNXK0Okxdollccccllodxxxxxxd
// ....';:ldkO0KXXXKK00Okxdolcc:;;;;;::cclllcc:;;,''..... ....',;clooddolcc:;;;;,,;;;;;::::;;;;;;:cloxk0KXNWWWWWWNXKK0Okxddoooddxxkkkkkxx
// .....';:ldxkOOOOOkxxdolcc:;;;,,,;;:cllooooolcc:;'... ..,:codxkkkxddooollloooooooollcc:::::clodkO0KXNWWWWWWNNXK00Okxxxxxxxxkkkkxxx
// . ....';:cloddddo___________,,,,;;:clooddddoolc:,... ..,:ldx__00OOOkkk___kkkkkkxxdollc::::cclodkO0KXXNNNNNNXXK0OOkxxxxxxxxxxxxddd
// .......',;:cccc:| |,,,;;:cclooddddoll:;'.. ..';cox| \KKK000| |KK00OOkxdocc___;::clldxxkO0KKKKK00Okkxdddddddddddddddoo
// .......'',,,,,''| ________|',,;;::cclloooooolc:;'......___:ldk| \KK000| |XKKK0Okxolc| |;;::cclodxxkkkkxxdoolllcclllooodddooooo
// ''......''''....| | ....'',,,,;;;::cclloooollc:;,''.'| |oxk| \OOO0| |KKK00Oxdoll|___|;;;;;::ccllllllcc::;;,,;;;:cclloooooooo
// ;;,''.......... | |_____',,;;;____:___cllo________.___| |___| \xkk| |KK_______ool___:::;________;;;_______...'',;;:ccclllloo
// c:;,''......... | |:::/ ' |lo/ | | \dx| |0/ \d| |cc/ |'/ \......',,;;:ccllo
// ol:;,'..........| _____|ll/ __ |o/ ______|____ ___| | \o| |/ ___ \| |o/ ______|/ ___ \ .......'',;:clo
// dlc;,...........| |::clooo| / | |x\___ \KXKKK0| |dol| |\ \| | | | | |d\___ \..| | / / ....',:cl
// xoc;'... .....'| |llodddd| \__| |_____\ \KKK0O| |lc:| |'\ | |___| | |_____\ \.| |_/___/... ...',;:c
// dlc;'... ....',;| |oddddddo\ | |Okkx| |::;| |..\ |\ /| | | \ |... ....',;:c
// ol:,'.......',:c|___|xxxddollc\_____,___|_________/ddoll|___|,,,|___|...\_____|:\ ______/l|___|_________/...\________|'........',;::cc
// c:;'.......';:codxxkkkkxxolc::;::clodxkOO0OOkkxdollc::;;,,''''',,,,''''''''''',,'''''',;:loxkkOOkxol:;,'''',,;:ccllcc:;,'''''',;::ccll
// ;,'.......',:codxkOO0OOkxdlc:;,,;;:cldxxkkxxdolc:;;,,''.....'',;;:::;;,,,'''''........,;cldkO0KK0Okdoc::;;::cloodddoolc:;;;;;::ccllooo
// .........',;:lodxOO0000Okdoc:,,',,;:clloddoolc:;,''.......'',;:clooollc:;;,,''.......',:ldkOKXNNXX0Oxdolllloddxxxxxxdolccccccllooodddd
// . .....';:cldxkO0000Okxol:;,''',,;::cccc:;,,'.......'',;:cldxxkkxxdolc:;;,'.......';coxOKXNWWWNXKOkxddddxxkkkkkkxdoollllooddxxxxkkk
// ....',;:codxkO000OOxdoc:;,''',,,;;;;,''.......',,;:clodkO00000Okxolc::;,,''..',;:ldxOKXNWWWNNK0OkkkkkkkkkkkxxddooooodxxkOOOOO000
// ....',;;clodxkkOOOkkdolc:;,,,,,,,,'..........,;:clodxkO0KKXKK0Okxdolcc::;;,,,;;:codkO0XXNNNNXKK0OOOOOkkkkxxdoollloodxkO0KKKXXXXX
//
// VERSION: 1.1.1
// path_to_url
// In *one* C or C++ file, use #define FNL_IMPL to generate implementation
#ifndef FASTNOISELITE_H
#define FASTNOISELITE_H
// Switch between using floats or doubles for input position
typedef float FNLfloat;
//typedef double FNLfloat;
#if defined(__cplusplus)
extern "C" {
#endif
#include <math.h>
#include <stdint.h>
#include <stdbool.h>
#include <float.h>
// Enums
typedef enum
{
FNL_NOISE_OPENSIMPLEX2,
FNL_NOISE_OPENSIMPLEX2S,
FNL_NOISE_CELLULAR,
FNL_NOISE_PERLIN,
FNL_NOISE_VALUE_CUBIC,
FNL_NOISE_VALUE
} fnl_noise_type;
typedef enum
{
FNL_ROTATION_NONE,
FNL_ROTATION_IMPROVE_XY_PLANES,
FNL_ROTATION_IMPROVE_XZ_PLANES
} fnl_rotation_type_3d;
typedef enum
{
FNL_FRACTAL_NONE,
FNL_FRACTAL_FBM,
FNL_FRACTAL_RIDGED,
FNL_FRACTAL_PINGPONG,
FNL_FRACTAL_DOMAIN_WARP_PROGRESSIVE,
FNL_FRACTAL_DOMAIN_WARP_INDEPENDENT
} fnl_fractal_type;
typedef enum
{
FNL_CELLULAR_DISTANCE_EUCLIDEAN,
FNL_CELLULAR_DISTANCE_EUCLIDEANSQ,
FNL_CELLULAR_DISTANCE_MANHATTAN,
FNL_CELLULAR_DISTANCE_HYBRID
} fnl_cellular_distance_func;
typedef enum
{
FNL_CELLULAR_RETURN_TYPE_CELLVALUE,
FNL_CELLULAR_RETURN_TYPE_DISTANCE,
FNL_CELLULAR_RETURN_TYPE_DISTANCE2,
FNL_CELLULAR_RETURN_TYPE_DISTANCE2ADD,
FNL_CELLULAR_RETURN_TYPE_DISTANCE2SUB,
FNL_CELLULAR_RETURN_TYPE_DISTANCE2MUL,
FNL_CELLULAR_RETURN_TYPE_DISTANCE2DIV,
} fnl_cellular_return_type;
typedef enum
{
FNL_DOMAIN_WARP_OPENSIMPLEX2,
FNL_DOMAIN_WARP_OPENSIMPLEX2_REDUCED,
FNL_DOMAIN_WARP_BASICGRID
} fnl_domain_warp_type;
/**
* Structure containing entire noise system state.
* @note Must only be created using fnlCreateState(optional: seed). To ensure defaults are set.
*/
typedef struct fnl_state
{
/**
* Seed used for all noise types.
* @remark Default: 1337
*/
int seed;
/**
* The frequency for all noise types.
* @remark Default: 0.01
*/
float frequency;
/**
* The noise algorithm to be used by GetNoise(...).
* @remark Default: FNL_NOISE_OPENSIMPLEX2
*/
fnl_noise_type noise_type;
/**
* Sets noise rotation type for 3D.
* @remark Default: FNL_ROTATION_NONE
*/
fnl_rotation_type_3d rotation_type_3d;
/**
* The method used for combining octaves for all fractal noise types.
* @remark Default: None
* @remark FNL_FRACTAL_DOMAIN_WARP_... only effects fnlDomainWarp...
*/
fnl_fractal_type fractal_type;
/**
* The octave count for all fractal noise types.
* @remark Default: 3
*/
int octaves;
/**
* The octave lacunarity for all fractal noise types.
* @remark Default: 2.0
*/
float lacunarity;
/**
* The octave gain for all fractal noise types.
* @remark Default: 0.5
*/
float gain;
/**
* The octave weighting for all none Domaain Warp fractal types.
* @remark Default: 0.0
* @remark
*/
float weighted_strength;
/**
* The strength of the fractal ping pong effect.
* @remark Default: 2.0
*/
float ping_pong_strength;
/**
* The distance function used in cellular noise calculations.
* @remark Default: FNL_CELLULAR_DISTANCE_EUCLIDEANSQ
*/
fnl_cellular_distance_func cellular_distance_func;
/**
* The cellular return type from cellular noise calculations.
* @remark Default: FNL_CELLULAR_RETURN_TYPE_DISTANCE
*/
fnl_cellular_return_type cellular_return_type;
/**
* The maximum distance a cellular point can move from it's grid position.
* @remark Default: 1.0
* @note Setting this higher than 1 will cause artifacts.
*/
float cellular_jitter_mod;
/**
* The warp algorithm when using fnlDomainWarp...
* @remark Default: OpenSimplex2
*/
fnl_domain_warp_type domain_warp_type;
/**
* The maximum warp distance from original position when using fnlDomainWarp...
* @remark Default: 1.0
*/
float domain_warp_amp;
} fnl_state;
/**
* Creates a noise state with default values.
* @param seed Optionally set the state seed.
*/
fnl_state fnlCreateState();
/**
* 2D noise at given position using the state settings
* @returns Noise output bounded between -1 and 1.
*/
float fnlGetNoise2D(fnl_state *state, FNLfloat x, FNLfloat y);
/**
* 3D noise at given position using the state settings
* @returns Noise output bounded between -1 and 1.
*/
float fnlGetNoise3D(fnl_state *state, FNLfloat x, FNLfloat y, FNLfloat z);
/**
* 2D warps the input position using current domain warp settings.
*
* Example usage with fnlGetNoise2D:
* ```
* fnlDomainWarp2D(&state, &x, &y);
* noise = fnlGetNoise2D(&state, x, y);
* ```
*/
void fnlDomainWarp2D(fnl_state *state, FNLfloat *x, FNLfloat *y);
/**
* 3D warps the input position using current domain warp settings.
*
* Example usage with fnlGetNoise3D:
* ```
* fnlDomainWarp3D(&state, &x, &y, &z);
* noise = fnlGetNoise3D(&state, x, y, z);
* ```
*/
void fnlDomainWarp3D(fnl_state *state, FNLfloat *x, FNLfloat *y, FNLfloat *z);
// ====================
// Below this line is the implementation
// ====================
#if defined(FNL_IMPL)
// Constants
static const float GRADIENTS_2D[] =
{
0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, 0.793353340291235f, 0.793353340291235f, 0.608761429008721f,
0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, -0.130526192220051f, 0.923879532511287f, -0.38268343236509f,
0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, -0.923879532511287f, 0.130526192220052f, -0.99144486137381f,
-0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, -0.793353340291235f, -0.793353340291235f, -0.608761429008721f,
-0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, 0.130526192220051f, -0.923879532511287f, 0.38268343236509f,
-0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, 0.923879532511287f, -0.130526192220052f, 0.99144486137381f,
0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, 0.793353340291235f, 0.793353340291235f, 0.608761429008721f,
0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, -0.130526192220051f, 0.923879532511287f, -0.38268343236509f,
0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, -0.923879532511287f, 0.130526192220052f, -0.99144486137381f,
-0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, -0.793353340291235f, -0.793353340291235f, -0.608761429008721f,
-0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, 0.130526192220051f, -0.923879532511287f, 0.38268343236509f,
-0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, 0.923879532511287f, -0.130526192220052f, 0.99144486137381f,
0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, 0.793353340291235f, 0.793353340291235f, 0.608761429008721f,
0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, -0.130526192220051f, 0.923879532511287f, -0.38268343236509f,
0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, -0.923879532511287f, 0.130526192220052f, -0.99144486137381f,
-0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, -0.793353340291235f, -0.793353340291235f, -0.608761429008721f,
-0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, 0.130526192220051f, -0.923879532511287f, 0.38268343236509f,
-0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, 0.923879532511287f, -0.130526192220052f, 0.99144486137381f,
0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, 0.793353340291235f, 0.793353340291235f, 0.608761429008721f,
0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, -0.130526192220051f, 0.923879532511287f, -0.38268343236509f,
0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, -0.923879532511287f, 0.130526192220052f, -0.99144486137381f,
-0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, -0.793353340291235f, -0.793353340291235f, -0.608761429008721f,
-0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, 0.130526192220051f, -0.923879532511287f, 0.38268343236509f,
-0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, 0.923879532511287f, -0.130526192220052f, 0.99144486137381f,
0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, 0.793353340291235f, 0.793353340291235f, 0.608761429008721f,
0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, -0.130526192220051f, 0.923879532511287f, -0.38268343236509f,
0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, -0.923879532511287f, 0.130526192220052f, -0.99144486137381f,
-0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, -0.793353340291235f, -0.793353340291235f, -0.608761429008721f,
-0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, 0.130526192220051f, -0.923879532511287f, 0.38268343236509f,
-0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, 0.923879532511287f, -0.130526192220052f, 0.99144486137381f,
0.38268343236509f, 0.923879532511287f, 0.923879532511287f, 0.38268343236509f, 0.923879532511287f, -0.38268343236509f, 0.38268343236509f, -0.923879532511287f,
-0.38268343236509f, -0.923879532511287f, -0.923879532511287f, -0.38268343236509f, -0.923879532511287f, 0.38268343236509f, -0.38268343236509f, 0.923879532511287f,
};
static const float RAND_VECS_2D[] =
{
-0.2700222198f, -0.9628540911f, 0.3863092627f, -0.9223693152f, 0.04444859006f, -0.999011673f, -0.5992523158f, -0.8005602176f, -0.7819280288f, 0.6233687174f, 0.9464672271f, 0.3227999196f, -0.6514146797f, -0.7587218957f, 0.9378472289f, 0.347048376f,
-0.8497875957f, -0.5271252623f, -0.879042592f, 0.4767432447f, -0.892300288f, -0.4514423508f, -0.379844434f, -0.9250503802f, -0.9951650832f, 0.0982163789f, 0.7724397808f, -0.6350880136f, 0.7573283322f, -0.6530343002f, -0.9928004525f, -0.119780055f,
-0.0532665713f, 0.9985803285f, 0.9754253726f, -0.2203300762f, -0.7665018163f, 0.6422421394f, 0.991636706f, 0.1290606184f, -0.994696838f, 0.1028503788f, -0.5379205513f, -0.84299554f, 0.5022815471f, -0.8647041387f, 0.4559821461f, -0.8899889226f,
-0.8659131224f, -0.5001944266f, 0.0879458407f, -0.9961252577f, -0.5051684983f, 0.8630207346f, 0.7753185226f, -0.6315704146f, -0.6921944612f, 0.7217110418f, -0.5191659449f, -0.8546734591f, 0.8978622882f, -0.4402764035f, -0.1706774107f, 0.9853269617f,
-0.9353430106f, -0.3537420705f, -0.9992404798f, 0.03896746794f, -0.2882064021f, -0.9575683108f, -0.9663811329f, 0.2571137995f, -0.8759714238f, -0.4823630009f, -0.8303123018f, -0.5572983775f, 0.05110133755f, -0.9986934731f, -0.8558373281f, -0.5172450752f,
0.09887025282f, 0.9951003332f, 0.9189016087f, 0.3944867976f, -0.2439375892f, -0.9697909324f, -0.8121409387f, -0.5834613061f, -0.9910431363f, 0.1335421355f, 0.8492423985f, -0.5280031709f, -0.9717838994f, -0.2358729591f, 0.9949457207f, 0.1004142068f,
0.6241065508f, -0.7813392434f, 0.662910307f, 0.7486988212f, -0.7197418176f, 0.6942418282f, -0.8143370775f, -0.5803922158f, 0.104521054f, -0.9945226741f, -0.1065926113f, -0.9943027784f, 0.445799684f, -0.8951327509f, 0.105547406f, 0.9944142724f,
-0.992790267f, 0.1198644477f, -0.8334366408f, 0.552615025f, 0.9115561563f, -0.4111755999f, 0.8285544909f, -0.5599084351f, 0.7217097654f, -0.6921957921f, 0.4940492677f, -0.8694339084f, -0.3652321272f, -0.9309164803f, -0.9696606758f, 0.2444548501f,
0.08925509731f, -0.996008799f, 0.5354071276f, -0.8445941083f, -0.1053576186f, 0.9944343981f, -0.9890284586f, 0.1477251101f, 0.004856104961f, 0.9999882091f, 0.9885598478f, 0.1508291331f, 0.9286129562f, -0.3710498316f, -0.5832393863f, -0.8123003252f,
0.3015207509f, 0.9534596146f, -0.9575110528f, 0.2883965738f, 0.9715802154f, -0.2367105511f, 0.229981792f, 0.9731949318f, 0.955763816f, -0.2941352207f, 0.740956116f, 0.6715534485f, -0.9971513787f, -0.07542630764f, 0.6905710663f, -0.7232645452f,
-0.290713703f, -0.9568100872f, 0.5912777791f, -0.8064679708f, -0.9454592212f, -0.325740481f, 0.6664455681f, 0.74555369f, 0.6236134912f, 0.7817328275f, 0.9126993851f, -0.4086316587f, -0.8191762011f, 0.5735419353f, -0.8812745759f, -0.4726046147f,
0.9953313627f, 0.09651672651f, 0.9855650846f, -0.1692969699f, -0.8495980887f, 0.5274306472f, 0.6174853946f, -0.7865823463f, 0.8508156371f, 0.52546432f, 0.9985032451f, -0.05469249926f, 0.1971371563f, -0.9803759185f, 0.6607855748f, -0.7505747292f,
-0.03097494063f, 0.9995201614f, -0.6731660801f, 0.739491331f, -0.7195018362f, -0.6944905383f, 0.9727511689f, 0.2318515979f, 0.9997059088f, -0.0242506907f, 0.4421787429f, -0.8969269532f, 0.9981350961f, -0.061043673f, -0.9173660799f, -0.3980445648f,
-0.8150056635f, -0.5794529907f, -0.8789331304f, 0.4769450202f, 0.0158605829f, 0.999874213f, -0.8095464474f, 0.5870558317f, -0.9165898907f, -0.3998286786f, -0.8023542565f, 0.5968480938f, -0.5176737917f, 0.8555780767f, -0.8154407307f, -0.5788405779f,
0.4022010347f, -0.9155513791f, -0.9052556868f, -0.4248672045f, 0.7317445619f, 0.6815789728f, -0.5647632201f, -0.8252529947f, -0.8403276335f, -0.5420788397f, -0.9314281527f, 0.363925262f, 0.5238198472f, 0.8518290719f, 0.7432803869f, -0.6689800195f,
-0.985371561f, -0.1704197369f, 0.4601468731f, 0.88784281f, 0.825855404f, 0.5638819483f, 0.6182366099f, 0.7859920446f, 0.8331502863f, -0.553046653f, 0.1500307506f, 0.9886813308f, -0.662330369f, -0.7492119075f, -0.668598664f, 0.743623444f,
0.7025606278f, 0.7116238924f, -0.5419389763f, -0.8404178401f, -0.3388616456f, 0.9408362159f, 0.8331530315f, 0.5530425174f, -0.2989720662f, -0.9542618632f, 0.2638522993f, 0.9645630949f, 0.124108739f, -0.9922686234f, -0.7282649308f, -0.6852956957f,
0.6962500149f, 0.7177993569f, -0.9183535368f, 0.3957610156f, -0.6326102274f, -0.7744703352f, -0.9331891859f, -0.359385508f, -0.1153779357f, -0.9933216659f, 0.9514974788f, -0.3076565421f, -0.08987977445f, -0.9959526224f, 0.6678496916f, 0.7442961705f,
0.7952400393f, -0.6062947138f, -0.6462007402f, -0.7631674805f, -0.2733598753f, 0.9619118351f, 0.9669590226f, -0.254931851f, -0.9792894595f, 0.2024651934f, -0.5369502995f, -0.8436138784f, -0.270036471f, -0.9628500944f, -0.6400277131f, 0.7683518247f,
-0.7854537493f, -0.6189203566f, 0.06005905383f, -0.9981948257f, -0.02455770378f, 0.9996984141f, -0.65983623f, 0.751409442f, -0.6253894466f, -0.7803127835f, -0.6210408851f, -0.7837781695f, 0.8348888491f, 0.5504185768f, -0.1592275245f, 0.9872419133f,
0.8367622488f, 0.5475663786f, -0.8675753916f, -0.4973056806f, -0.2022662628f, -0.9793305667f, 0.9399189937f, 0.3413975472f, 0.9877404807f, -0.1561049093f, -0.9034455656f, 0.4287028224f, 0.1269804218f, -0.9919052235f, -0.3819600854f, 0.924178821f,
0.9754625894f, 0.2201652486f, -0.3204015856f, -0.9472818081f, -0.9874760884f, 0.1577687387f, 0.02535348474f, -0.9996785487f, 0.4835130794f, -0.8753371362f, -0.2850799925f, -0.9585037287f, -0.06805516006f, -0.99768156f, -0.7885244045f, -0.6150034663f,
0.3185392127f, -0.9479096845f, 0.8880043089f, 0.4598351306f, 0.6476921488f, -0.7619021462f, 0.9820241299f, 0.1887554194f, 0.9357275128f, -0.3527237187f, -0.8894895414f, 0.4569555293f, 0.7922791302f, 0.6101588153f, 0.7483818261f, 0.6632681526f,
-0.7288929755f, -0.6846276581f, 0.8729032783f, -0.4878932944f, 0.8288345784f, 0.5594937369f, 0.08074567077f, 0.9967347374f, 0.9799148216f, -0.1994165048f, -0.580730673f, -0.8140957471f, -0.4700049791f, -0.8826637636f, 0.2409492979f, 0.9705377045f,
0.9437816757f, -0.3305694308f, -0.8927998638f, -0.4504535528f, -0.8069622304f, 0.5906030467f, 0.06258973166f, 0.9980393407f, -0.9312597469f, 0.3643559849f, 0.5777449785f, 0.8162173362f, -0.3360095855f, -0.941858566f, 0.697932075f, -0.7161639607f,
-0.002008157227f, -0.9999979837f, -0.1827294312f, -0.9831632392f, -0.6523911722f, 0.7578824173f, -0.4302626911f, -0.9027037258f, -0.9985126289f, -0.05452091251f, -0.01028102172f, -0.9999471489f, -0.4946071129f, 0.8691166802f, -0.2999350194f, 0.9539596344f,
0.8165471961f, 0.5772786819f, 0.2697460475f, 0.962931498f, -0.7306287391f, -0.6827749597f, -0.7590952064f, -0.6509796216f, -0.907053853f, 0.4210146171f, -0.5104861064f, -0.8598860013f, 0.8613350597f, 0.5080373165f, 0.5007881595f, -0.8655698812f,
-0.654158152f, 0.7563577938f, -0.8382755311f, -0.545246856f, 0.6940070834f, 0.7199681717f, 0.06950936031f, 0.9975812994f, 0.1702942185f, -0.9853932612f, 0.2695973274f, 0.9629731466f, 0.5519612192f, -0.8338697815f, 0.225657487f, -0.9742067022f,
0.4215262855f, -0.9068161835f, 0.4881873305f, -0.8727388672f, -0.3683854996f, -0.9296731273f, -0.9825390578f, 0.1860564427f, 0.81256471f, 0.5828709909f, 0.3196460933f, -0.9475370046f, 0.9570913859f, 0.2897862643f, -0.6876655497f, -0.7260276109f,
-0.9988770922f, -0.047376731f, -0.1250179027f, 0.992154486f, -0.8280133617f, 0.560708367f, 0.9324863769f, -0.3612051451f, 0.6394653183f, 0.7688199442f, -0.01623847064f, -0.9998681473f, -0.9955014666f, -0.09474613458f, -0.81453315f, 0.580117012f,
0.4037327978f, -0.9148769469f, 0.9944263371f, 0.1054336766f, -0.1624711654f, 0.9867132919f, -0.9949487814f, -0.100383875f, -0.6995302564f, 0.7146029809f, 0.5263414922f, -0.85027327f, -0.5395221479f, 0.841971408f, 0.6579370318f, 0.7530729462f,
0.01426758847f, -0.9998982128f, -0.6734383991f, 0.7392433447f, 0.639412098f, -0.7688642071f, 0.9211571421f, 0.3891908523f, -0.146637214f, -0.9891903394f, -0.782318098f, 0.6228791163f, -0.5039610839f, -0.8637263605f, -0.7743120191f, -0.6328039957f,
};
static const float GRADIENTS_3D[] =
{
0, 1, 1, 0, 0,-1, 1, 0, 0, 1,-1, 0, 0,-1,-1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0,-1, 0, -1, 0,-1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1,-1, 0, 0, -1,-1, 0, 0,
0, 1, 1, 0, 0,-1, 1, 0, 0, 1,-1, 0, 0,-1,-1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0,-1, 0, -1, 0,-1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1,-1, 0, 0, -1,-1, 0, 0,
0, 1, 1, 0, 0,-1, 1, 0, 0, 1,-1, 0, 0,-1,-1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0,-1, 0, -1, 0,-1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1,-1, 0, 0, -1,-1, 0, 0,
0, 1, 1, 0, 0,-1, 1, 0, 0, 1,-1, 0, 0,-1,-1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0,-1, 0, -1, 0,-1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1,-1, 0, 0, -1,-1, 0, 0,
0, 1, 1, 0, 0,-1, 1, 0, 0, 1,-1, 0, 0,-1,-1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0,-1, 0, -1, 0,-1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1,-1, 0, 0, -1,-1, 0, 0,
1, 1, 0, 0, 0,-1, 1, 0, -1, 1, 0, 0, 0,-1,-1, 0
};
static const float RAND_VECS_3D[] =
{
-0.7292736885f, -0.6618439697f, 0.1735581948f, 0, 0.790292081f, -0.5480887466f, -0.2739291014f, 0, 0.7217578935f, 0.6226212466f, -0.3023380997f, 0, 0.565683137f, -0.8208298145f, -0.0790000257f, 0, 0.760049034f, -0.5555979497f, -0.3370999617f, 0, 0.3713945616f, 0.5011264475f, 0.7816254623f, 0, -0.1277062463f, -0.4254438999f, -0.8959289049f, 0, -0.2881560924f, -0.5815838982f, 0.7607405838f, 0,
0.5849561111f, -0.662820239f, -0.4674352136f, 0, 0.3307171178f, 0.0391653737f, 0.94291689f, 0, 0.8712121778f, -0.4113374369f, -0.2679381538f, 0, 0.580981015f, 0.7021915846f, 0.4115677815f, 0, 0.503756873f, 0.6330056931f, -0.5878203852f, 0, 0.4493712205f, 0.601390195f, 0.6606022552f, 0, -0.6878403724f, 0.09018890807f, -0.7202371714f, 0, -0.5958956522f, -0.6469350577f, 0.475797649f, 0,
-0.5127052122f, 0.1946921978f, -0.8361987284f, 0, -0.9911507142f, -0.05410276466f, -0.1212153153f, 0, -0.2149721042f, 0.9720882117f, -0.09397607749f, 0, -0.7518650936f, -0.5428057603f, 0.3742469607f, 0, 0.5237068895f, 0.8516377189f, -0.02107817834f, 0, 0.6333504779f, 0.1926167129f, -0.7495104896f, 0, -0.06788241606f, 0.3998305789f, 0.9140719259f, 0, -0.5538628599f, -0.4729896695f, -0.6852128902f, 0,
-0.7261455366f, -0.5911990757f, 0.3509933228f, 0, -0.9229274737f, -0.1782808786f, 0.3412049336f, 0, -0.6968815002f, 0.6511274338f, 0.3006480328f, 0, 0.9608044783f, -0.2098363234f, -0.1811724921f, 0, 0.06817146062f, -0.9743405129f, 0.2145069156f, 0, -0.3577285196f, -0.6697087264f, -0.6507845481f, 0, -0.1868621131f, 0.7648617052f, -0.6164974636f, 0, -0.6541697588f, 0.3967914832f, 0.6439087246f, 0,
0.6993340405f, -0.6164538506f, 0.3618239211f, 0, -0.1546665739f, 0.6291283928f, 0.7617583057f, 0, -0.6841612949f, -0.2580482182f, -0.6821542638f, 0, 0.5383980957f, 0.4258654885f, 0.7271630328f, 0, -0.5026987823f, -0.7939832935f, -0.3418836993f, 0, 0.3202971715f, 0.2834415347f, 0.9039195862f, 0, 0.8683227101f, -0.0003762656404f, -0.4959995258f, 0, 0.791120031f, -0.08511045745f, 0.6057105799f, 0,
-0.04011016052f, -0.4397248749f, 0.8972364289f, 0, 0.9145119872f, 0.3579346169f, -0.1885487608f, 0, -0.9612039066f, -0.2756484276f, 0.01024666929f, 0, 0.6510361721f, -0.2877799159f, -0.7023778346f, 0, -0.2041786351f, 0.7365237271f, 0.644859585f, 0, -0.7718263711f, 0.3790626912f, 0.5104855816f, 0, -0.3060082741f, -0.7692987727f, 0.5608371729f, 0, 0.454007341f, -0.5024843065f, 0.7357899537f, 0,
0.4816795475f, 0.6021208291f, -0.6367380315f, 0, 0.6961980369f, -0.3222197429f, 0.641469197f, 0, -0.6532160499f, -0.6781148932f, 0.3368515753f, 0, 0.5089301236f, -0.6154662304f, -0.6018234363f, 0, -0.1635919754f, -0.9133604627f, -0.372840892f, 0, 0.52408019f, -0.8437664109f, 0.1157505864f, 0, 0.5902587356f, 0.4983817807f, -0.6349883666f, 0, 0.5863227872f, 0.494764745f, 0.6414307729f, 0,
0.6779335087f, 0.2341345225f, 0.6968408593f, 0, 0.7177054546f, -0.6858979348f, 0.120178631f, 0, -0.5328819713f, -0.5205125012f, 0.6671608058f, 0, -0.8654874251f, -0.0700727088f, -0.4960053754f, 0, -0.2861810166f, 0.7952089234f, 0.5345495242f, 0, -0.04849529634f, 0.9810836427f, -0.1874115585f, 0, -0.6358521667f, 0.6058348682f, 0.4781800233f, 0, 0.6254794696f, -0.2861619734f, 0.7258696564f, 0,
-0.2585259868f, 0.5061949264f, -0.8227581726f, 0, 0.02136306781f, 0.5064016808f, -0.8620330371f, 0, 0.200111773f, 0.8599263484f, 0.4695550591f, 0, 0.4743561372f, 0.6014985084f, -0.6427953014f, 0, 0.6622993731f, -0.5202474575f, -0.5391679918f, 0, 0.08084972818f, -0.6532720452f, 0.7527940996f, 0, -0.6893687501f, 0.0592860349f, 0.7219805347f, 0, -0.1121887082f, -0.9673185067f, 0.2273952515f, 0,
0.7344116094f, 0.5979668656f, -0.3210532909f, 0, 0.5789393465f, -0.2488849713f, 0.7764570201f, 0, 0.6988182827f, 0.3557169806f, -0.6205791146f, 0, -0.8636845529f, -0.2748771249f, -0.4224826141f, 0, -0.4247027957f, -0.4640880967f, 0.777335046f, 0, 0.5257722489f, -0.8427017621f, 0.1158329937f, 0, 0.9343830603f, 0.316302472f, -0.1639543925f, 0, -0.1016836419f, -0.8057303073f, -0.5834887393f, 0,
-0.6529238969f, 0.50602126f, -0.5635892736f, 0, -0.2465286165f, -0.9668205684f, -0.06694497494f, 0, -0.9776897119f, -0.2099250524f, -0.007368825344f, 0, 0.7736893337f, 0.5734244712f, 0.2694238123f, 0, -0.6095087895f, 0.4995678998f, 0.6155736747f, 0, 0.5794535482f, 0.7434546771f, 0.3339292269f, 0, -0.8226211154f, 0.08142581855f, 0.5627293636f, 0, -0.510385483f, 0.4703667658f, 0.7199039967f, 0,
-0.5764971849f, -0.07231656274f, -0.8138926898f, 0, 0.7250628871f, 0.3949971505f, -0.5641463116f, 0, -0.1525424005f, 0.4860840828f, -0.8604958341f, 0, -0.5550976208f, -0.4957820792f, 0.667882296f, 0, -0.1883614327f, 0.9145869398f, 0.357841725f, 0, 0.7625556724f, -0.5414408243f, -0.3540489801f, 0, -0.5870231946f, -0.3226498013f, -0.7424963803f, 0, 0.3051124198f, 0.2262544068f, -0.9250488391f, 0,
0.6379576059f, 0.577242424f, -0.5097070502f, 0, -0.5966775796f, 0.1454852398f, -0.7891830656f, 0, -0.658330573f, 0.6555487542f, -0.3699414651f, 0, 0.7434892426f, 0.2351084581f, 0.6260573129f, 0, 0.5562114096f, 0.8264360377f, -0.0873632843f, 0, -0.3028940016f, -0.8251527185f, 0.4768419182f, 0, 0.1129343818f, -0.985888439f, -0.1235710781f, 0, 0.5937652891f, -0.5896813806f, 0.5474656618f, 0,
0.6757964092f, -0.5835758614f, -0.4502648413f, 0, 0.7242302609f, -0.1152719764f, 0.6798550586f, 0, -0.9511914166f, 0.0753623979f, -0.2992580792f, 0, 0.2539470961f, -0.1886339355f, 0.9486454084f, 0, 0.571433621f, -0.1679450851f, -0.8032795685f, 0, -0.06778234979f, 0.3978269256f, 0.9149531629f, 0, 0.6074972649f, 0.733060024f, -0.3058922593f, 0, -0.5435478392f, 0.1675822484f, 0.8224791405f, 0,
-0.5876678086f, -0.3380045064f, -0.7351186982f, 0, -0.7967562402f, 0.04097822706f, -0.6029098428f, 0, -0.1996350917f, 0.8706294745f, 0.4496111079f, 0, -0.02787660336f, -0.9106232682f, -0.4122962022f, 0, -0.7797625996f, -0.6257634692f, 0.01975775581f, 0, -0.5211232846f, 0.7401644346f, -0.4249554471f, 0, 0.8575424857f, 0.4053272873f, -0.3167501783f, 0, 0.1045223322f, 0.8390195772f, -0.5339674439f, 0,
0.3501822831f, 0.9242524096f, -0.1520850155f, 0, 0.1987849858f, 0.07647613266f, 0.9770547224f, 0, 0.7845996363f, 0.6066256811f, -0.1280964233f, 0, 0.09006737436f, -0.9750989929f, -0.2026569073f, 0, -0.8274343547f, -0.542299559f, 0.1458203587f, 0, -0.3485797732f, -0.415802277f, 0.840000362f, 0, -0.2471778936f, -0.7304819962f, -0.6366310879f, 0, -0.3700154943f, 0.8577948156f, 0.3567584454f, 0,
0.5913394901f, -0.548311967f, -0.5913303597f, 0, 0.1204873514f, -0.7626472379f, -0.6354935001f, 0, 0.616959265f, 0.03079647928f, 0.7863922953f, 0, 0.1258156836f, -0.6640829889f, -0.7369967419f, 0, -0.6477565124f, -0.1740147258f, -0.7417077429f, 0, 0.6217889313f, -0.7804430448f, -0.06547655076f, 0, 0.6589943422f, -0.6096987708f, 0.4404473475f, 0, -0.2689837504f, -0.6732403169f, -0.6887635427f, 0,
-0.3849775103f, 0.5676542638f, 0.7277093879f, 0, 0.5754444408f, 0.8110471154f, -0.1051963504f, 0, 0.9141593684f, 0.3832947817f, 0.131900567f, 0, -0.107925319f, 0.9245493968f, 0.3654593525f, 0, 0.377977089f, 0.3043148782f, 0.8743716458f, 0, -0.2142885215f, -0.8259286236f, 0.5214617324f, 0, 0.5802544474f, 0.4148098596f, -0.7008834116f, 0, -0.1982660881f, 0.8567161266f, -0.4761596756f, 0,
-0.03381553704f, 0.3773180787f, -0.9254661404f, 0, -0.6867922841f, -0.6656597827f, 0.2919133642f, 0, 0.7731742607f, -0.2875793547f, -0.5652430251f, 0, -0.09655941928f, 0.9193708367f, -0.3813575004f, 0, 0.2715702457f, -0.9577909544f, -0.09426605581f, 0, 0.2451015704f, -0.6917998565f, -0.6792188003f, 0, 0.977700782f, -0.1753855374f, 0.1155036542f, 0, -0.5224739938f, 0.8521606816f, 0.02903615945f, 0,
-0.7734880599f, -0.5261292347f, 0.3534179531f, 0, -0.7134492443f, -0.269547243f, 0.6467878011f, 0, 0.1644037271f, 0.5105846203f, -0.8439637196f, 0, 0.6494635788f, 0.05585611296f, 0.7583384168f, 0, -0.4711970882f, 0.5017280509f, -0.7254255765f, 0, -0.6335764307f, -0.2381686273f, -0.7361091029f, 0, -0.9021533097f, -0.270947803f, -0.3357181763f, 0, -0.3793711033f, 0.872258117f, 0.3086152025f, 0,
-0.6855598966f, -0.3250143309f, 0.6514394162f, 0, 0.2900942212f, -0.7799057743f, -0.5546100667f, 0, -0.2098319339f, 0.85037073f, 0.4825351604f, 0, -0.4592603758f, 0.6598504336f, -0.5947077538f, 0, 0.8715945488f, 0.09616365406f, -0.4807031248f, 0, -0.6776666319f, 0.7118504878f, -0.1844907016f, 0, 0.7044377633f, 0.312427597f, 0.637304036f, 0, -0.7052318886f, -0.2401093292f, -0.6670798253f, 0,
0.081921007f, -0.7207336136f, -0.6883545647f, 0, -0.6993680906f, -0.5875763221f, -0.4069869034f, 0, -0.1281454481f, 0.6419895885f, 0.7559286424f, 0, -0.6337388239f, -0.6785471501f, -0.3714146849f, 0, 0.5565051903f, -0.2168887573f, -0.8020356851f, 0, -0.5791554484f, 0.7244372011f, -0.3738578718f, 0, 0.1175779076f, -0.7096451073f, 0.6946792478f, 0, -0.6134619607f, 0.1323631078f, 0.7785527795f, 0,
0.6984635305f, -0.02980516237f, -0.715024719f, 0, 0.8318082963f, -0.3930171956f, 0.3919597455f, 0, 0.1469576422f, 0.05541651717f, -0.9875892167f, 0, 0.708868575f, -0.2690503865f, 0.6520101478f, 0, 0.2726053183f, 0.67369766f, -0.68688995f, 0, -0.6591295371f, 0.3035458599f, -0.6880466294f, 0, 0.4815131379f, -0.7528270071f, 0.4487723203f, 0, 0.9430009463f, 0.1675647412f, -0.2875261255f, 0,
0.434802957f, 0.7695304522f, -0.4677277752f, 0, 0.3931996188f, 0.594473625f, 0.7014236729f, 0, 0.7254336655f, -0.603925654f, 0.3301814672f, 0, 0.7590235227f, -0.6506083235f, 0.02433313207f, 0, -0.8552768592f, -0.3430042733f, 0.3883935666f, 0, -0.6139746835f, 0.6981725247f, 0.3682257648f, 0, -0.7465905486f, -0.5752009504f, 0.3342849376f, 0, 0.5730065677f, 0.810555537f, -0.1210916791f, 0,
-0.9225877367f, -0.3475211012f, -0.167514036f, 0, -0.7105816789f, -0.4719692027f, -0.5218416899f, 0, -0.08564609717f, 0.3583001386f, 0.929669703f, 0, -0.8279697606f, -0.2043157126f, 0.5222271202f, 0, 0.427944023f, 0.278165994f, 0.8599346446f, 0, 0.5399079671f, -0.7857120652f, -0.3019204161f, 0, 0.5678404253f, -0.5495413974f, -0.6128307303f, 0, -0.9896071041f, 0.1365639107f, -0.04503418428f, 0,
-0.6154342638f, -0.6440875597f, 0.4543037336f, 0, 0.1074204368f, -0.7946340692f, 0.5975094525f, 0, -0.3595449969f, -0.8885529948f, 0.28495784f, 0, -0.2180405296f, 0.1529888965f, 0.9638738118f, 0, -0.7277432317f, -0.6164050508f, -0.3007234646f, 0, 0.7249729114f, -0.00669719484f, 0.6887448187f, 0, -0.5553659455f, -0.5336586252f, 0.6377908264f, 0, 0.5137558015f, 0.7976208196f, -0.3160000073f, 0,
-0.3794024848f, 0.9245608561f, -0.03522751494f, 0, 0.8229248658f, 0.2745365933f, -0.4974176556f, 0, -0.5404114394f, 0.6091141441f, 0.5804613989f, 0, 0.8036581901f, -0.2703029469f, 0.5301601931f, 0, 0.6044318879f, 0.6832968393f, 0.4095943388f, 0, 0.06389988817f, 0.9658208605f, -0.2512108074f, 0, 0.1087113286f, 0.7402471173f, -0.6634877936f, 0, -0.713427712f, -0.6926784018f, 0.1059128479f, 0,
0.6458897819f, -0.5724548511f, -0.5050958653f, 0, -0.6553931414f, 0.7381471625f, 0.159995615f, 0, 0.3910961323f, 0.9188871375f, -0.05186755998f, 0, -0.4879022471f, -0.5904376907f, 0.6429111375f, 0, 0.6014790094f, 0.7707441366f, -0.2101820095f, 0, -0.5677173047f, 0.7511360995f, 0.3368851762f, 0, 0.7858573506f, 0.226674665f, 0.5753666838f, 0, -0.4520345543f, -0.604222686f, -0.6561857263f, 0,
0.002272116345f, 0.4132844051f, -0.9105991643f, 0, -0.5815751419f, -0.5162925989f, 0.6286591339f, 0, -0.03703704785f, 0.8273785755f, 0.5604221175f, 0, -0.5119692504f, 0.7953543429f, -0.3244980058f, 0, -0.2682417366f, -0.9572290247f, -0.1084387619f, 0, -0.2322482736f, -0.9679131102f, -0.09594243324f, 0, 0.3554328906f, -0.8881505545f, 0.2913006227f, 0, 0.7346520519f, -0.4371373164f, 0.5188422971f, 0,
0.9985120116f, 0.04659011161f, -0.02833944577f, 0, -0.3727687496f, -0.9082481361f, 0.1900757285f, 0, 0.91737377f, -0.3483642108f, 0.1925298489f, 0, 0.2714911074f, 0.4147529736f, -0.8684886582f, 0, 0.5131763485f, -0.7116334161f, 0.4798207128f, 0, -0.8737353606f, 0.18886992f, -0.4482350644f, 0, 0.8460043821f, -0.3725217914f, 0.3814499973f, 0, 0.8978727456f, -0.1780209141f, -0.4026575304f, 0,
0.2178065647f, -0.9698322841f, -0.1094789531f, 0, -0.1518031304f, -0.7788918132f, -0.6085091231f, 0, -0.2600384876f, -0.4755398075f, -0.8403819825f, 0, 0.572313509f, -0.7474340931f, -0.3373418503f, 0, -0.7174141009f, 0.1699017182f, -0.6756111411f, 0, -0.684180784f, 0.02145707593f, -0.7289967412f, 0, -0.2007447902f, 0.06555605789f, -0.9774476623f, 0, -0.1148803697f, -0.8044887315f, 0.5827524187f, 0,
-0.7870349638f, 0.03447489231f, 0.6159443543f, 0, -0.2015596421f, 0.6859872284f, 0.6991389226f, 0, -0.08581082512f, -0.10920836f, -0.9903080513f, 0, 0.5532693395f, 0.7325250401f, -0.396610771f, 0, -0.1842489331f, -0.9777375055f, -0.1004076743f, 0, 0.0775473789f, -0.9111505856f, 0.4047110257f, 0, 0.1399838409f, 0.7601631212f, -0.6344734459f, 0, 0.4484419361f, -0.845289248f, 0.2904925424f, 0
};
// Utilities
static inline float _fnlFastMin(float x, float y) { return x < y ? x : y; }
static inline float _fnlFastMax(float x, float y) { return x > y ? x : y; }
static inline float _fnlFastAbs(float f) { return f < 0 ? -f : f; }
static inline float _fnlCasti32Tof32(int i)
{
union
{
float f;
int32_t i;
} u;
u.i = i;
return u.f;
}
static inline int _fnlCastf32Toi32(float f)
{
union
{
float f;
int32_t i;
} u;
u.f = f;
return u.i;
}
static inline float _fnlInvSqrt(float a)
{
float xhalf = 0.5f * a;
a = _fnlCasti32Tof32(0x5f3759df - (_fnlCastf32Toi32(a) >> 1));
a = a * (1.5f - xhalf * a * a);
return a;
}
// NOTE: If your language does not support this method (seen above), then simply use the native sqrt function.
static inline float _fnlFastSqrt(float a) { return a * _fnlInvSqrt(a); }
static inline int _fnlFastFloor(FNLfloat f) { return (f >= 0 ? (int)f : (int)f - 1); }
static inline int _fnlFastRound(FNLfloat f) { return (f >= 0) ? (int)(f + 0.5f) : (int)(f - 0.5f); }
static inline float _fnlLerp(float a, float b, float t) { return a + t * (b - a); }
static inline float _fnlInterpHermite(float t) { return t * t * (3 - 2 * t); }
static inline float _fnlInterpQuintic(float t) { return t * t * t * (t * (t * 6 - 15) + 10); }
static inline float _fnlCubicLerp(float a, float b, float c, float d, float t)
{
float p = (d - c) - (a - b);
return t * t * t * p + t * t * ((a - b) - p) + t * (c - a) + b;
}
static inline float _fnlPingPong(float t)
{
t -= (int)(t * 0.5f) * 2;
return t < 1 ? t : 2 - t;
}
static float _fnlCalculateFractalBounding(fnl_state *state)
{
float gain = _fnlFastAbs(state->gain);
float amp = gain;
float ampFractal = 1.0f;
for (int i = 1; i < state->octaves; i++)
{
ampFractal += amp;
amp *= gain;
}
return 1.0f / ampFractal;
}
// Hashing
static const int PRIME_X = 501125321;
static const int PRIME_Y = 1136930381;
static const int PRIME_Z = 1720413743;
static inline int _fnlHash2D(int seed, int xPrimed, int yPrimed)
{
int hash = seed ^ xPrimed ^ yPrimed;
hash *= 0x27d4eb2d;
return hash;
}
static inline int _fnlHash3D(int seed, int xPrimed, int yPrimed, int zPrimed)
{
int hash = seed ^ xPrimed ^ yPrimed ^ zPrimed;
hash *= 0x27d4eb2d;
return hash;
}
static inline float _fnlValCoord2D(int seed, int xPrimed, int yPrimed)
{
int hash = _fnlHash2D(seed, xPrimed, yPrimed);
hash *= hash;
hash ^= hash << 19;
return hash * (1 / 2147483648.0f);
}
static inline float _fnlValCoord3D(int seed, int xPrimed, int yPrimed, int zPrimed)
{
int hash = _fnlHash3D(seed, xPrimed, yPrimed, zPrimed);
hash *= hash;
hash ^= hash << 19;
return hash * (1 / 2147483648.0f);
}
static inline float _fnlGradCoord2D(int seed, int xPrimed, int yPrimed, float xd, float yd)
{
int hash = _fnlHash2D(seed, xPrimed, yPrimed);
hash ^= hash >> 15;
hash &= 127 << 1;
return xd * GRADIENTS_2D[hash] + yd * GRADIENTS_2D[hash | 1];
}
static inline float _fnlGradCoord3D(int seed, int xPrimed, int yPrimed, int zPrimed, float xd, float yd, float zd)
{
int hash = _fnlHash3D(seed, xPrimed, yPrimed, zPrimed);
hash ^= hash >> 15;
hash &= 63 << 2;
return xd * GRADIENTS_3D[hash] + yd * GRADIENTS_3D[hash | 1] + zd * GRADIENTS_3D[hash | 2];
}
static inline void _fnlGradCoordOut2D(int seed, int xPrimed, int yPrimed, float *xo, float *yo)
{
int hash = _fnlHash2D(seed, xPrimed, yPrimed) & (255 << 1);
*xo = RAND_VECS_2D[hash];
*yo = RAND_VECS_2D[hash | 1];
}
static inline void _fnlGradCoordOut3D(int seed, int xPrimed, int yPrimed, int zPrimed, float *xo, float *yo, float *zo)
{
int hash = _fnlHash3D(seed, xPrimed, yPrimed, zPrimed) & (255 << 2);
*xo = RAND_VECS_3D[hash];
*yo = RAND_VECS_3D[hash | 1];
*zo = RAND_VECS_3D[hash | 2];
}
static inline void _fnlGradCoordDual2D(int seed, int xPrimed, int yPrimed, float xd, float yd, float *xo, float *yo)
{
int hash = _fnlHash2D(seed, xPrimed, yPrimed);
int index1 = hash & (127 << 1);
int index2 = (hash >> 7) & (255 << 1);
float xg = GRADIENTS_2D[index1];
float yg = GRADIENTS_2D[index1 | 1];
float value = xd * xg + yd * yg;
float xgo = RAND_VECS_2D[index2];
float ygo = RAND_VECS_2D[index2 | 1];
*xo = value * xgo;
*yo = value * ygo;
}
static inline void _fnlGradCoordDual3D(int seed, int xPrimed, int yPrimed, int zPrimed, float xd, float yd, float zd, float *xo, float *yo, float *zo)
{
int hash = _fnlHash3D(seed, xPrimed, yPrimed, zPrimed);
int index1 = hash & (63 << 2);
int index2 = (hash >> 6) & (255 << 2);
float xg = GRADIENTS_3D[index1];
float yg = GRADIENTS_3D[index1 | 1];
float zg = GRADIENTS_3D[index1 | 2];
float value = xd * xg + yd * yg + zd * zg;
float xgo = RAND_VECS_3D[index2];
float ygo = RAND_VECS_3D[index2 | 1];
float zgo = RAND_VECS_3D[index2 | 2];
*xo = value * xgo;
*yo = value * ygo;
*zo = value * zgo;
}
// Generic Noise Gen
static float _fnlSingleSimplex2D(int seed, FNLfloat x, FNLfloat y);
static float _fnlSingleOpenSimplex23D(int seed, FNLfloat x, FNLfloat y, FNLfloat z);
static float _fnlSingleOpenSimplex2S2D(int seed, FNLfloat x, FNLfloat y);
static float _fnlSingleOpenSimplex2S3D(int seed, FNLfloat x, FNLfloat y, FNLfloat z);
static float _fnlSingleCellular2D(fnl_state *state, int seed, FNLfloat x, FNLfloat y);
static float _fnlSingleCellular3D(fnl_state *state, int seed, FNLfloat x, FNLfloat y, FNLfloat z);
static float _fnlSinglePerlin2D(int seed, FNLfloat x, FNLfloat y);
static float _fnlSinglePerlin3D(int seed, FNLfloat x, FNLfloat y, FNLfloat z);
static float _fnlSingleValueCubic2D(int seed, FNLfloat x, FNLfloat y);
static float _fnlSingleValueCubic3D(int seed, FNLfloat x, FNLfloat y, FNLfloat z);
static float _fnlSingleValue2D(int seed, FNLfloat x, FNLfloat y);
static float _fnlSingleValue3D(int seed, FNLfloat x, FNLfloat y, FNLfloat z);
static float _fnlGenNoiseSingle2D(fnl_state *state, int seed, FNLfloat x, FNLfloat y)
{
switch (state->noise_type)
{
case FNL_NOISE_OPENSIMPLEX2:
return _fnlSingleSimplex2D(seed, x, y);
case FNL_NOISE_OPENSIMPLEX2S:
return _fnlSingleOpenSimplex2S2D(seed, x, y);
case FNL_NOISE_CELLULAR:
return _fnlSingleCellular2D(state, seed, x, y);
case FNL_NOISE_PERLIN:
return _fnlSinglePerlin2D(seed, x, y);
case FNL_NOISE_VALUE_CUBIC:
return _fnlSingleValueCubic2D(seed, x, y);
case FNL_NOISE_VALUE:
return _fnlSingleValue2D(seed, x, y);
default:
return 0;
}
}
static float _fnlGenNoiseSingle3D(fnl_state *state, int seed, FNLfloat x, FNLfloat y, FNLfloat z)
{
switch (state->noise_type)
{
case FNL_NOISE_OPENSIMPLEX2:
return _fnlSingleOpenSimplex23D(seed, x, y, z);
case FNL_NOISE_OPENSIMPLEX2S:
return _fnlSingleOpenSimplex2S3D(seed, x, y, z);
case FNL_NOISE_CELLULAR:
return _fnlSingleCellular3D(state, seed, x, y, z);
case FNL_NOISE_PERLIN:
return _fnlSinglePerlin3D(seed, x, y, z);
case FNL_NOISE_VALUE_CUBIC:
return _fnlSingleValueCubic3D(seed, x, y, z);
case FNL_NOISE_VALUE:
return _fnlSingleValue3D(seed, x, y, z);
default:
return 0;
}
}
// Noise Coordinate Transforms (frequency, and possible skew or rotation)
static void _fnlTransformNoiseCoordinate2D(fnl_state *state, FNLfloat *x, FNLfloat *y)
{
*x *= state->frequency;
*y *= state->frequency;
switch (state->noise_type)
{
case FNL_NOISE_OPENSIMPLEX2:
case FNL_NOISE_OPENSIMPLEX2S:
{
const FNLfloat SQRT3 = (FNLfloat)1.7320508075688772935274463415059;
const FNLfloat F2 = 0.5f * (SQRT3 - 1);
FNLfloat t = (*x + *y) * F2;
*x += t;
*y += t;
}
break;
default:
break;
}
}
static void _fnlTransformNoiseCoordinate3D(fnl_state *state, FNLfloat *x, FNLfloat *y, FNLfloat *z)
{
*x *= state->frequency;
*y *= state->frequency;
*z *= state->frequency;
switch (state->rotation_type_3d)
{
case FNL_ROTATION_IMPROVE_XY_PLANES:
{
FNLfloat xy = *x + *y;
FNLfloat s2 = xy * -(FNLfloat)0.211324865405187;
*z *= (FNLfloat)0.577350269189626;
*x += s2 - *z;
*y = *y + s2 - *z;
*z += xy * (FNLfloat)0.577350269189626;
}
break;
case FNL_ROTATION_IMPROVE_XZ_PLANES:
{
FNLfloat xz = *x + *z;
FNLfloat s2 = xz * -(FNLfloat)0.211324865405187;
*y *= (FNLfloat)0.577350269189626;
*x += s2 - *y;
*z += s2 - *y;
*y += xz * (FNLfloat)0.577350269189626;
}
break;
default:
switch (state->noise_type)
{
case FNL_NOISE_OPENSIMPLEX2:
case FNL_NOISE_OPENSIMPLEX2S:
{
const FNLfloat R3 = (FNLfloat)(2.0 / 3.0);
FNLfloat r = (*x + *y + *z) * R3; // Rotation, not skew
*x = r - *x;
*y = r - *y;
*z = r - *z;
}
break;
default:
break;
}
}
}
// Domain Warp Coordinate Transforms
static void _fnlTransformDomainWarpCoordinate2D(fnl_state *state, FNLfloat *x, FNLfloat *y)
{
switch (state->domain_warp_type)
{
case FNL_DOMAIN_WARP_OPENSIMPLEX2:
case FNL_DOMAIN_WARP_OPENSIMPLEX2_REDUCED:
{
const FNLfloat SQRT3 = (FNLfloat)1.7320508075688772935274463415059;
const FNLfloat F2 = 0.5f * (SQRT3 - 1);
FNLfloat t = (*x + *y) * F2;
*x += t;
*y += t;
}
break;
default:
break;
}
}
static void _fnlTransformDomainWarpCoordinate3D(fnl_state *state, FNLfloat *x, FNLfloat *y, FNLfloat *z)
{
switch (state->rotation_type_3d)
{
case FNL_ROTATION_IMPROVE_XY_PLANES:
{
FNLfloat xy = *x + *y;
FNLfloat s2 = xy * -(FNLfloat)0.211324865405187;
*z *= (FNLfloat)0.577350269189626;
*x += s2 - *z;
*y = *y + s2 - *z;
*z += xy * (FNLfloat)0.577350269189626;
}
break;
case FNL_ROTATION_IMPROVE_XZ_PLANES:
{
FNLfloat xz = *x + *z;
FNLfloat s2 = xz * -(FNLfloat)0.211324865405187;
*y *= (FNLfloat)0.577350269189626;
*x += s2 - *y;
*z += s2 - *y;
*y += xz * (FNLfloat)0.577350269189626;
}
break;
default:
switch (state->domain_warp_type)
{
case FNL_DOMAIN_WARP_OPENSIMPLEX2:
case FNL_DOMAIN_WARP_OPENSIMPLEX2_REDUCED:
{
const FNLfloat R3 = (FNLfloat)(2.0 / 3.0);
FNLfloat r = (*x + *y + *z) * R3; // Rotation, not skew
*x = r - *x;
*y = r - *y;
*z = r - *z;
}
break;
default:
break;
}
}
}
// Fractal FBm
static float _fnlGenFractalFBM2D(fnl_state *state, FNLfloat x, FNLfloat y)
{
int seed = state->seed;
float sum = 0;
float amp = _fnlCalculateFractalBounding(state);
for (int i = 0; i < state->octaves; i++)
{
float noise = _fnlGenNoiseSingle2D(state, seed++, x, y);
sum += noise * amp;
amp *= _fnlLerp(1.0f, _fnlFastMin(noise + 1, 2) * 0.5f, state->weighted_strength);
x *= state->lacunarity;
y *= state->lacunarity;
amp *= state->gain;
}
return sum;
}
static float _fnlGenFractalFBM3D(fnl_state *state, FNLfloat x, FNLfloat y, FNLfloat z)
{
int seed = state->seed;
float sum = 0;
float amp = _fnlCalculateFractalBounding(state);
for (int i = 0; i < state->octaves; i++)
{
float noise = _fnlGenNoiseSingle3D(state, seed++, x, y, z);
sum += noise * amp;
amp *= _fnlLerp(1.0f, (noise + 1) * 0.5f, state->weighted_strength);
x *= state->lacunarity;
y *= state->lacunarity;
z *= state->lacunarity;
amp *= state->gain;
}
return sum;
}
// Fractal Ridged
static float _fnlGenFractalRidged2D(fnl_state *state, FNLfloat x, FNLfloat y)
{
int seed = state->seed;
float sum = 0;
float amp = _fnlCalculateFractalBounding(state);
for (int i = 0; i < state->octaves; i++)
{
float noise = _fnlFastAbs(_fnlGenNoiseSingle2D(state, seed++, x, y));
sum += (noise * -2 + 1) * amp;
amp *= _fnlLerp(1.0f, 1 - noise, state->weighted_strength);
x *= state->lacunarity;
y *= state->lacunarity;
amp *= state->gain;
}
return sum;
}
static float _fnlGenFractalRidged3D(fnl_state *state, FNLfloat x, FNLfloat y, FNLfloat z)
{
int seed = state->seed;
float sum = 0;
float amp = _fnlCalculateFractalBounding(state);
for (int i = 0; i < state->octaves; i++)
{
float noise = _fnlFastAbs(_fnlGenNoiseSingle3D(state, seed++, x, y, z));
sum += (noise * -2 + 1) * amp;
amp *= _fnlLerp(1.0f, 1 - noise, state->weighted_strength);
x *= state->lacunarity;
y *= state->lacunarity;
z *= state->lacunarity;
amp *= state->gain;
}
return sum;
}
// Fractal PingPong
static float _fnlGenFractalPingPong2D(fnl_state *state, FNLfloat x, FNLfloat y)
{
int seed = state->seed;
float sum = 0;
float amp = _fnlCalculateFractalBounding(state);
for (int i = 0; i < state->octaves; i++)
{
float noise = _fnlPingPong((_fnlGenNoiseSingle2D(state, seed++, x, y) + 1) * state->ping_pong_strength);
sum += (noise - 0.5f) * 2 * amp;
amp *= _fnlLerp(1.0f, noise, state->weighted_strength);
x *= state->lacunarity;
y *= state->lacunarity;
amp *= state->gain;
}
return sum;
}
static float _fnlGenFractalPingPong3D(fnl_state *state, FNLfloat x, FNLfloat y, FNLfloat z)
{
int seed = state->seed;
float sum = 0;
float amp = _fnlCalculateFractalBounding(state);
for (int i = 0; i < state->octaves; i++)
{
float noise = _fnlPingPong((_fnlGenNoiseSingle3D(state, seed++, x, y, z) + 1) * state->ping_pong_strength);
sum += (noise - 0.5f) * 2 * amp;
amp *= _fnlLerp(1.0f, noise, state->weighted_strength);
x *= state->lacunarity;
y *= state->lacunarity;
z *= state->lacunarity;
amp *= state->gain;
}
return sum;
}
// Simplex/OpenSimplex2 Noise
static float _fnlSingleSimplex2D(int seed, FNLfloat x, FNLfloat y)
{
// 2D OpenSimplex2 case uses the same algorithm as ordinary Simplex.
const float SQRT3 = 1.7320508075688772935274463415059f;
const float G2 = (3 - SQRT3) / 6;
/*
* --- Skew moved to TransformNoiseCoordinate method ---
* const FNLfloat F2 = 0.5f * (SQRT3 - 1);
* FNLfloat s = (x + y) * F2;
* x += s; y += s;
*/
int i = _fnlFastFloor(x);
int j = _fnlFastFloor(y);
float xi = (float)(x - i);
float yi = (float)(y - j);
float t = (xi + yi) * G2;
float x0 = (float)(xi - t);
float y0 = (float)(yi - t);
i *= PRIME_X;
j *= PRIME_Y;
float n0, n1, n2;
float a = 0.5f - x0 * x0 - y0 * y0;
if (a <= 0)
n0 = 0;
else
{
n0 = (a * a) * (a * a) * _fnlGradCoord2D(seed, i, j, x0, y0);
}
float c = (float)(2 * (1 - 2 * G2) * (1 / G2 - 2)) * t + ((float)(-2 * (1 - 2 * G2) * (1 - 2 * G2)) + a);
if (c <= 0)
n2 = 0;
else
{
float x2 = x0 + (2 * (float)G2 - 1);
float y2 = y0 + (2 * (float)G2 - 1);
n2 = (c * c) * (c * c) * _fnlGradCoord2D(seed, i + PRIME_X, j + PRIME_Y, x2, y2);
}
if (y0 > x0)
{
float x1 = x0 + (float)G2;
float y1 = y0 + ((float)G2 - 1);
float b = 0.5f - x1 * x1 - y1 * y1;
if (b <= 0)
n1 = 0;
else
{
n1 = (b * b) * (b * b) * _fnlGradCoord2D(seed, i, j + PRIME_Y, x1, y1);
}
}
else
{
float x1 = x0 + ((float)G2 - 1);
float y1 = y0 + (float)G2;
float b = 0.5f - x1 * x1 - y1 * y1;
if (b <= 0)
n1 = 0;
else
{
n1 = (b * b) * (b * b) * _fnlGradCoord2D(seed, i + PRIME_X, j, x1, y1);
}
}
return (n0 + n1 + n2) * 99.83685446303647f;
}
static float _fnlSingleOpenSimplex23D(int seed, FNLfloat x, FNLfloat y, FNLfloat z)
{
// 3D OpenSimplex2 case uses two offset rotated cube grids.
/*
* --- Rotation moved to TransformNoiseCoordinate method ---
* const FNLfloat R3 = (FNLfloat)(2.0 / 3.0);
* FNLfloat r = (x + y + z) * R3; // Rotation, not skew
* x = r - x; y = r - y; z = r - z;
*/
int i = _fnlFastRound(x);
int j = _fnlFastRound(y);
int k = _fnlFastRound(z);
float x0 = (float)(x - i);
float y0 = (float)(y - j);
float z0 = (float)(z - k);
int xNSign = (int)(-1.0f - x0) | 1;
int yNSign = (int)(-1.0f - y0) | 1;
int zNSign = (int)(-1.0f - z0) | 1;
float ax0 = xNSign * -x0;
float ay0 = yNSign * -y0;
float az0 = zNSign * -z0;
i *= PRIME_X;
j *= PRIME_Y;
k *= PRIME_Z;
float value = 0;
float a = (0.6f - x0 * x0) - (y0 * y0 + z0 * z0);
for (int l = 0; ; l++)
{
if (a > 0)
{
value += (a * a) * (a * a) * _fnlGradCoord3D(seed, i, j, k, x0, y0, z0);
}
float b = a + 1;
int i1 = i;
int j1 = j;
int k1 = k;
float x1 = x0;
float y1 = y0;
float z1 = z0;
if (ax0 >= ay0 && ax0 >= az0)
{
x1 += xNSign;
b -= xNSign * 2 * x1;
i1 -= xNSign * PRIME_X;
}
else if (ay0 > ax0 && ay0 >= az0)
{
y1 += yNSign;
b -= yNSign * 2 * y1;
j1 -= yNSign * PRIME_Y;
}
else
{
z1 += zNSign;
b -= zNSign * 2 * z1;
k1 -= zNSign * PRIME_Z;
}
if (b > 0)
{
value += (b * b) * (b * b) * _fnlGradCoord3D(seed, i1, j1, k1, x1, y1, z1);
}
if (l == 1)
break;
ax0 = 0.5f - ax0;
ay0 = 0.5f - ay0;
az0 = 0.5f - az0;
x0 = xNSign * ax0;
y0 = yNSign * ay0;
z0 = zNSign * az0;
a += (0.75f - ax0) - (ay0 + az0);
i += (xNSign >> 1) & PRIME_X;
j += (yNSign >> 1) & PRIME_Y;
k += (zNSign >> 1) & PRIME_Z;
xNSign = -xNSign;
yNSign = -yNSign;
zNSign = -zNSign;
seed = ~seed;
}
return value * 32.69428253173828125f;
}
// OpenSimplex2S Noise
static float _fnlSingleOpenSimplex2S2D(int seed, FNLfloat x, FNLfloat y)
{
// 2D OpenSimplex2S case is a modified 2D simplex noise.
const FNLfloat SQRT3 = (FNLfloat)1.7320508075688772935274463415059;
const FNLfloat G2 = (3 - SQRT3) / 6;
/*
* --- Skew moved to TransformNoiseCoordinate method ---
* const FNLfloat F2 = 0.5f * (SQRT3 - 1);
* FNLfloat s = (x + y) * F2;
* x += s; y += s;
*/
int i = _fnlFastFloor(x);
int j = _fnlFastFloor(y);
float xi = (float)(x - i);
float yi = (float)(y - j);
i *= PRIME_X;
j *= PRIME_Y;
int i1 = i + PRIME_X;
int j1 = j + PRIME_Y;
float t = (xi + yi) * (float)G2;
float x0 = xi - t;
float y0 = yi - t;
float a0 = (2.0f / 3.0f) - x0 * x0 - y0 * y0;
float value = (a0 * a0) * (a0 * a0) * _fnlGradCoord2D(seed, i, j, x0, y0);
float a1 = (float)(2 * (1 - 2 * G2) * (1 / G2 - 2)) * t + ((float)(-2 * (1 - 2 * G2) * (1 - 2 * G2)) + a0);
float x1 = x0 - (float)(1 - 2 * G2);
float y1 = y0 - (float)(1 - 2 * G2);
value += (a1 * a1) * (a1 * a1) * _fnlGradCoord2D(seed, i1, j1, x1, y1);
// Nested conditionals were faster than compact bit logic/arithmetic.
float xmyi = xi - yi;
if (t > G2)
{
if (xi + xmyi > 1)
{
float x2 = x0 + (float)(3 * G2 - 2);
float y2 = y0 + (float)(3 * G2 - 1);
float a2 = (2.0f / 3.0f) - x2 * x2 - y2 * y2;
if (a2 > 0)
{
value += (a2 * a2) * (a2 * a2) * _fnlGradCoord2D(seed, i + (PRIME_X << 1), j + PRIME_Y, x2, y2);
}
}
else
{
float x2 = x0 + (float)G2;
float y2 = y0 + (float)(G2 - 1);
float a2 = (2.0f / 3.0f) - x2 * x2 - y2 * y2;
if (a2 > 0)
{
value += (a2 * a2) * (a2 * a2) * _fnlGradCoord2D(seed, i, j + PRIME_Y, x2, y2);
}
}
if (yi - xmyi > 1)
{
float x3 = x0 + (float)(3 * G2 - 1);
float y3 = y0 + (float)(3 * G2 - 2);
float a3 = (2.0f / 3.0f) - x3 * x3 - y3 * y3;
if (a3 > 0)
{
value += (a3 * a3) * (a3 * a3) * _fnlGradCoord2D(seed, i + PRIME_X, j + (PRIME_Y << 1), x3, y3);
}
}
else
{
float x3 = x0 + (float)(G2 - 1);
float y3 = y0 + (float)G2;
float a3 = (2.0f / 3.0f) - x3 * x3 - y3 * y3;
if (a3 > 0)
{
value += (a3 * a3) * (a3 * a3) * _fnlGradCoord2D(seed, i + PRIME_X, j, x3, y3);
}
}
}
else
{
if (xi + xmyi < 0)
{
float x2 = x0 + (float)(1 - G2);
float y2 = y0 - (float)G2;
float a2 = (2.0f / 3.0f) - x2 * x2 - y2 * y2;
if (a2 > 0)
{
value += (a2 * a2) * (a2 * a2) * _fnlGradCoord2D(seed, i - PRIME_X, j, x2, y2);
}
}
else
{
float x2 = x0 + (float)(G2 - 1);
float y2 = y0 + (float)G2;
float a2 = (2.0f / 3.0f) - x2 * x2 - y2 * y2;
if (a2 > 0)
{
value += (a2 * a2) * (a2 * a2) * _fnlGradCoord2D(seed, i + PRIME_X, j, x2, y2);
}
}
if (yi < xmyi)
{
float x2 = x0 - (float)G2;
float y2 = y0 - (float)(G2 - 1);
float a2 = (2.0f / 3.0f) - x2 * x2 - y2 * y2;
if (a2 > 0)
{
value += (a2 * a2) * (a2 * a2) * _fnlGradCoord2D(seed, i, j - PRIME_Y, x2, y2);
}
}
else
{
float x2 = x0 + (float)G2;
float y2 = y0 + (float)(G2 - 1);
float a2 = (2.0f / 3.0f) - x2 * x2 - y2 * y2;
if (a2 > 0)
{
value += (a2 * a2) * (a2 * a2) * _fnlGradCoord2D(seed, i, j + PRIME_Y, x2, y2);
}
}
}
return value * 18.24196194486065f;
}
static float _fnlSingleOpenSimplex2S3D(int seed, FNLfloat x, FNLfloat y, FNLfloat z)
{
// 3D OpenSimplex2S case uses two offset rotated cube grids.
/*
* --- Rotation moved to TransformNoiseCoordinate method ---
* const FNLfloat R3 = (FNLfloat)(2.0 / 3.0);
* FNLfloat r = (x + y + z) * R3; // Rotation, not skew
* x = r - x; y = r - y; z = r - z;
*/
int i = _fnlFastFloor(x);
int j = _fnlFastFloor(y);
int k = _fnlFastFloor(z);
float xi = (float)(x - i);
float yi = (float)(y - j);
float zi = (float)(z - k);
i *= PRIME_X;
j *= PRIME_Y;
k *= PRIME_Z;
int seed2 = seed + 1293373;
int xNMask = (int)(-0.5f - xi);
int yNMask = (int)(-0.5f - yi);
int zNMask = (int)(-0.5f - zi);
float x0 = xi + xNMask;
float y0 = yi + yNMask;
float z0 = zi + zNMask;
float a0 = 0.75f - x0 * x0 - y0 * y0 - z0 * z0;
float value = (a0 * a0) * (a0 * a0) * _fnlGradCoord3D(seed,
i + (xNMask & PRIME_X), j + (yNMask & PRIME_Y), k + (zNMask & PRIME_Z), x0, y0, z0);
float x1 = xi - 0.5f;
float y1 = yi - 0.5f;
float z1 = zi - 0.5f;
float a1 = 0.75f - x1 * x1 - y1 * y1 - z1 * z1;
value += (a1 * a1) * (a1 * a1) * _fnlGradCoord3D(seed2,
i + PRIME_X, j + PRIME_Y, k + PRIME_Z, x1, y1, z1);
float xAFlipMask0 = ((xNMask | 1) << 1) * x1;
float yAFlipMask0 = ((yNMask | 1) << 1) * y1;
float zAFlipMask0 = ((zNMask | 1) << 1) * z1;
float xAFlipMask1 = (-2 - (xNMask << 2)) * x1 - 1.0f;
float yAFlipMask1 = (-2 - (yNMask << 2)) * y1 - 1.0f;
float zAFlipMask1 = (-2 - (zNMask << 2)) * z1 - 1.0f;
bool skip5 = false;
float a2 = xAFlipMask0 + a0;
if (a2 > 0)
{
float x2 = x0 - (xNMask | 1);
float y2 = y0;
float z2 = z0;
value += (a2 * a2) * (a2 * a2) * _fnlGradCoord3D(seed,
i + (~xNMask & PRIME_X), j + (yNMask & PRIME_Y), k + (zNMask & PRIME_Z), x2, y2, z2);
}
else
{
float a3 = yAFlipMask0 + zAFlipMask0 + a0;
if (a3 > 0)
{
float x3 = x0;
float y3 = y0 - (yNMask | 1);
float z3 = z0 - (zNMask | 1);
value += (a3 * a3) * (a3 * a3) * _fnlGradCoord3D(seed,
i + (xNMask & PRIME_X), j + (~yNMask & PRIME_Y), k + (~zNMask & PRIME_Z), x3, y3, z3);
}
float a4 = xAFlipMask1 + a1;
if (a4 > 0)
{
float x4 = (xNMask | 1) + x1;
float y4 = y1;
float z4 = z1;
value += (a4 * a4) * (a4 * a4) * _fnlGradCoord3D(seed2,
i + (xNMask & (PRIME_X * 2)), j + PRIME_Y, k + PRIME_Z, x4, y4, z4);
skip5 = true;
}
}
bool skip9 = false;
float a6 = yAFlipMask0 + a0;
if (a6 > 0)
{
float x6 = x0;
float y6 = y0 - (yNMask | 1);
float z6 = z0;
value += (a6 * a6) * (a6 * a6) * _fnlGradCoord3D(seed,
i + (xNMask & PRIME_X), j + (~yNMask & PRIME_Y), k + (zNMask & PRIME_Z), x6, y6, z6);
}
else
{
float a7 = xAFlipMask0 + zAFlipMask0 + a0;
if (a7 > 0)
{
float x7 = x0 - (xNMask | 1);
float y7 = y0;
float z7 = z0 - (zNMask | 1);
value += (a7 * a7) * (a7 * a7) * _fnlGradCoord3D(seed,
i + (~xNMask & PRIME_X), j + (yNMask & PRIME_Y), k + (~zNMask & PRIME_Z), x7, y7, z7);
}
float a8 = yAFlipMask1 + a1;
if (a8 > 0)
{
float x8 = x1;
float y8 = (yNMask | 1) + y1;
float z8 = z1;
value += (a8 * a8) * (a8 * a8) * _fnlGradCoord3D(seed2,
i + PRIME_X, j + (yNMask & (PRIME_Y << 1)), k + PRIME_Z, x8, y8, z8);
skip9 = true;
}
}
bool skipD = false;
float aA = zAFlipMask0 + a0;
if (aA > 0)
{
float xA = x0;
float yA = y0;
float zA = z0 - (zNMask | 1);
value += (aA * aA) * (aA * aA) * _fnlGradCoord3D(seed,
i + (xNMask & PRIME_X), j + (yNMask & PRIME_Y), k + (~zNMask & PRIME_Z), xA, yA, zA);
}
else
{
float aB = xAFlipMask0 + yAFlipMask0 + a0;
if (aB > 0)
{
float xB = x0 - (xNMask | 1);
float yB = y0 - (yNMask | 1);
float zB = z0;
value += (aB * aB) * (aB * aB) * _fnlGradCoord3D(seed,
i + (~xNMask & PRIME_X), j + (~yNMask & PRIME_Y), k + (zNMask & PRIME_Z), xB, yB, zB);
}
float aC = zAFlipMask1 + a1;
if (aC > 0)
{
float xC = x1;
float yC = y1;
float zC = (zNMask | 1) + z1;
value += (aC * aC) * (aC * aC) * _fnlGradCoord3D(seed2,
i + PRIME_X, j + PRIME_Y, k + (zNMask & (PRIME_Z << 1)), xC, yC, zC);
skipD = true;
}
}
if (!skip5)
{
float a5 = yAFlipMask1 + zAFlipMask1 + a1;
if (a5 > 0)
{
float x5 = x1;
float y5 = (yNMask | 1) + y1;
float z5 = (zNMask | 1) + z1;
value += (a5 * a5) * (a5 * a5) * _fnlGradCoord3D(seed2,
i + PRIME_X, j + (yNMask & (PRIME_Y << 1)), k + (zNMask & (PRIME_Z << 1)), x5, y5, z5);
}
}
if (!skip9)
{
float a9 = xAFlipMask1 + zAFlipMask1 + a1;
if (a9 > 0)
{
float x9 = (xNMask | 1) + x1;
float y9 = y1;
float z9 = (zNMask | 1) + z1;
value += (a9 * a9) * (a9 * a9) * _fnlGradCoord3D(seed2,
i + (xNMask & (PRIME_X * 2)), j + PRIME_Y, k + (zNMask & (PRIME_Z << 1)), x9, y9, z9);
}
}
if (!skipD)
{
float aD = xAFlipMask1 + yAFlipMask1 + a1;
if (aD > 0)
{
float xD = (xNMask | 1) + x1;
float yD = (yNMask | 1) + y1;
float zD = z1;
value += (aD * aD) * (aD * aD) * _fnlGradCoord3D(seed2,
i + (xNMask & (PRIME_X << 1)), j + (yNMask & (PRIME_Y << 1)), k + PRIME_Z, xD, yD, zD);
}
}
return value * 9.046026385208288f;
}
// Cellular Noise
static float _fnlSingleCellular2D(fnl_state *state, int seed, FNLfloat x, FNLfloat y)
{
int xr = _fnlFastRound(x);
int yr = _fnlFastRound(y);
float distance0 = FLT_MAX;
float distance1 = FLT_MAX;
int closestHash = 0;
float cellularJitter = 0.43701595f * state->cellular_jitter_mod;
int xPrimed = (xr - 1) * PRIME_X;
int yPrimedBase = (yr - 1) * PRIME_Y;
switch (state->cellular_distance_func)
{
default:
case FNL_CELLULAR_DISTANCE_EUCLIDEAN:
case FNL_CELLULAR_DISTANCE_EUCLIDEANSQ:
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int hash = _fnlHash2D(seed, xPrimed, yPrimed);
int idx = hash & (255 << 1);
float vecX = (float)(xi - x) + RAND_VECS_2D[idx] * cellularJitter;
float vecY = (float)(yi - y) + RAND_VECS_2D[idx | 1] * cellularJitter;
float newDistance = vecX * vecX + vecY * vecY;
distance1 = _fnlFastMax(_fnlFastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
yPrimed += PRIME_Y;
}
xPrimed += PRIME_X;
}
break;
case FNL_CELLULAR_DISTANCE_MANHATTAN:
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int hash = _fnlHash2D(seed, xPrimed, yPrimed);
int idx = hash & (255 << 1);
float vecX = (float)(xi - x) + RAND_VECS_2D[idx] * cellularJitter;
float vecY = (float)(yi - y) + RAND_VECS_2D[idx | 1] * cellularJitter;
float newDistance = _fnlFastAbs(vecX) + _fnlFastAbs(vecY);
distance1 = _fnlFastMax(_fnlFastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
yPrimed += PRIME_Y;
}
xPrimed += PRIME_X;
}
break;
case FNL_CELLULAR_DISTANCE_HYBRID:
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int hash = _fnlHash2D(seed, xPrimed, yPrimed);
int idx = hash & (255 << 1);
float vecX = (float)(xi - x) + RAND_VECS_2D[idx] * cellularJitter;
float vecY = (float)(yi - y) + RAND_VECS_2D[idx | 1] * cellularJitter;
float newDistance = (_fnlFastAbs(vecX) + _fnlFastAbs(vecY)) + (vecX * vecX + vecY * vecY);
distance1 = _fnlFastMax(_fnlFastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
yPrimed += PRIME_Y;
}
xPrimed += PRIME_X;
}
break;
}
if (state->cellular_distance_func == FNL_CELLULAR_DISTANCE_EUCLIDEAN && state->cellular_return_type >= FNL_CELLULAR_RETURN_TYPE_DISTANCE)
{
distance0 = _fnlFastSqrt(distance0);
if (state->cellular_return_type >= FNL_CELLULAR_RETURN_TYPE_DISTANCE2)
distance1 = _fnlFastSqrt(distance1);
}
switch (state->cellular_return_type)
{
case FNL_CELLULAR_RETURN_TYPE_CELLVALUE:
return closestHash * (1 / 2147483648.0f);
case FNL_CELLULAR_RETURN_TYPE_DISTANCE:
return distance0 - 1;
case FNL_CELLULAR_RETURN_TYPE_DISTANCE2:
return distance1 - 1;
case FNL_CELLULAR_RETURN_TYPE_DISTANCE2ADD:
return (distance1 + distance0) * 0.5f - 1;
case FNL_CELLULAR_RETURN_TYPE_DISTANCE2SUB:
return distance1 - distance0 - 1;
case FNL_CELLULAR_RETURN_TYPE_DISTANCE2MUL:
return distance1 * distance0 * 0.5f - 1;
case FNL_CELLULAR_RETURN_TYPE_DISTANCE2DIV:
return distance0 / distance1 - 1;
default:
return 0;
}
}
static float _fnlSingleCellular3D(fnl_state *state, int seed, FNLfloat x, FNLfloat y, FNLfloat z)
{
int xr = _fnlFastRound(x);
int yr = _fnlFastRound(y);
int zr = _fnlFastRound(z);
float distance0 = FLT_MAX;
float distance1 = FLT_MAX;
int closestHash = 0;
float cellularJitter = 0.39614353f * state->cellular_jitter_mod;
int xPrimed = (xr - 1) * PRIME_X;
int yPrimedBase = (yr - 1) * PRIME_Y;
int zPrimedBase = (zr - 1) * PRIME_Z;
switch (state->cellular_distance_func)
{
default:
case FNL_CELLULAR_DISTANCE_EUCLIDEAN:
case FNL_CELLULAR_DISTANCE_EUCLIDEANSQ:
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int zPrimed = zPrimedBase;
for (int zi = zr - 1; zi <= zr + 1; zi++)
{
int hash = _fnlHash3D(seed, xPrimed, yPrimed, zPrimed);
int idx = hash & (255 << 2);
float vecX = (float)(xi - x) + RAND_VECS_3D[idx] * cellularJitter;
float vecY = (float)(yi - y) + RAND_VECS_3D[idx | 1] * cellularJitter;
float vecZ = (float)(zi - z) + RAND_VECS_3D[idx | 2] * cellularJitter;
float newDistance = vecX * vecX + vecY * vecY + vecZ * vecZ;
distance1 = _fnlFastMax(_fnlFastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
zPrimed += PRIME_Z;
}
yPrimed += PRIME_Y;
}
xPrimed += PRIME_X;
}
break;
case FNL_CELLULAR_DISTANCE_MANHATTAN:
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int zPrimed = zPrimedBase;
for (int zi = zr - 1; zi <= zr + 1; zi++)
{
int hash = _fnlHash3D(seed, xPrimed, yPrimed, zPrimed);
int idx = hash & (255 << 2);
float vecX = (float)(xi - x) + RAND_VECS_3D[idx] * cellularJitter;
float vecY = (float)(yi - y) + RAND_VECS_3D[idx | 1] * cellularJitter;
float vecZ = (float)(zi - z) + RAND_VECS_3D[idx | 2] * cellularJitter;
float newDistance = _fnlFastAbs(vecX) + _fnlFastAbs(vecY) + _fnlFastAbs(vecZ);
distance1 = _fnlFastMax(_fnlFastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
zPrimed += PRIME_Z;
}
yPrimed += PRIME_Y;
}
xPrimed += PRIME_X;
}
break;
case FNL_CELLULAR_DISTANCE_HYBRID:
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int zPrimed = zPrimedBase;
for (int zi = zr - 1; zi <= zr + 1; zi++)
{
int hash = _fnlHash3D(seed, xPrimed, yPrimed, zPrimed);
int idx = hash & (255 << 2);
float vecX = (float)(xi - x) + RAND_VECS_3D[idx] * cellularJitter;
float vecY = (float)(yi - y) + RAND_VECS_3D[idx | 1] * cellularJitter;
float vecZ = (float)(zi - z) + RAND_VECS_3D[idx | 2] * cellularJitter;
float newDistance = (_fnlFastAbs(vecX) + _fnlFastAbs(vecY) + _fnlFastAbs(vecZ)) + (vecX * vecX + vecY * vecY + vecZ * vecZ);
distance1 = _fnlFastMax(_fnlFastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
zPrimed += PRIME_Z;
}
yPrimed += PRIME_Y;
}
xPrimed += PRIME_X;
}
break;
}
if (state->cellular_distance_func == FNL_CELLULAR_DISTANCE_EUCLIDEAN && state->cellular_return_type >= FNL_CELLULAR_RETURN_TYPE_DISTANCE)
{
distance0 = _fnlFastSqrt(distance0);
if (state->cellular_return_type >= FNL_CELLULAR_RETURN_TYPE_DISTANCE2)
distance1 = _fnlFastSqrt(distance1);
}
switch (state->cellular_return_type)
{
case FNL_CELLULAR_RETURN_TYPE_CELLVALUE:
return closestHash * (1 / 2147483648.0f);
case FNL_CELLULAR_RETURN_TYPE_DISTANCE:
return distance0 - 1;
case FNL_CELLULAR_RETURN_TYPE_DISTANCE2:
return distance1 - 1;
case FNL_CELLULAR_RETURN_TYPE_DISTANCE2ADD:
return (distance1 + distance0) * 0.5f - 1;
case FNL_CELLULAR_RETURN_TYPE_DISTANCE2SUB:
return distance1 - distance0 - 1;
case FNL_CELLULAR_RETURN_TYPE_DISTANCE2MUL:
return distance1 * distance0 * 0.5f - 1;
case FNL_CELLULAR_RETURN_TYPE_DISTANCE2DIV:
return distance0 / distance1 - 1;
default:
return 0;
}
}
// Perlin Noise
static float _fnlSinglePerlin2D(int seed, FNLfloat x, FNLfloat y)
{
int x0 = _fnlFastFloor(x);
int y0 = _fnlFastFloor(y);
float xd0 = (float)(x - x0);
float yd0 = (float)(y - y0);
float xd1 = xd0 - 1;
float yd1 = yd0 - 1;
float xs = _fnlInterpQuintic(xd0);
float ys = _fnlInterpQuintic(yd0);
x0 *= PRIME_X;
y0 *= PRIME_Y;
int x1 = x0 + PRIME_X;
int y1 = y0 + PRIME_Y;
float xf0 = _fnlLerp(_fnlGradCoord2D(seed, x0, y0, xd0, yd0), _fnlGradCoord2D(seed, x1, y0, xd1, yd0), xs);
float xf1 = _fnlLerp(_fnlGradCoord2D(seed, x0, y1, xd0, yd1), _fnlGradCoord2D(seed, x1, y1, xd1, yd1), xs);
return _fnlLerp(xf0, xf1, ys) * 1.4247691104677813f;
}
static float _fnlSinglePerlin3D(int seed, FNLfloat x, FNLfloat y, FNLfloat z)
{
int x0 = _fnlFastFloor(x);
int y0 = _fnlFastFloor(y);
int z0 = _fnlFastFloor(z);
float xd0 = (float)(x - x0);
float yd0 = (float)(y - y0);
float zd0 = (float)(z - z0);
float xd1 = xd0 - 1;
float yd1 = yd0 - 1;
float zd1 = zd0 - 1;
float xs = _fnlInterpQuintic(xd0);
float ys = _fnlInterpQuintic(yd0);
float zs = _fnlInterpQuintic(zd0);
x0 *= PRIME_X;
y0 *= PRIME_Y;
z0 *= PRIME_Z;
int x1 = x0 + PRIME_X;
int y1 = y0 + PRIME_Y;
int z1 = z0 + PRIME_Z;
float xf00 = _fnlLerp(_fnlGradCoord3D(seed, x0, y0, z0, xd0, yd0, zd0), _fnlGradCoord3D(seed, x1, y0, z0, xd1, yd0, zd0), xs);
float xf10 = _fnlLerp(_fnlGradCoord3D(seed, x0, y1, z0, xd0, yd1, zd0), _fnlGradCoord3D(seed, x1, y1, z0, xd1, yd1, zd0), xs);
float xf01 = _fnlLerp(_fnlGradCoord3D(seed, x0, y0, z1, xd0, yd0, zd1), _fnlGradCoord3D(seed, x1, y0, z1, xd1, yd0, zd1), xs);
float xf11 = _fnlLerp(_fnlGradCoord3D(seed, x0, y1, z1, xd0, yd1, zd1), _fnlGradCoord3D(seed, x1, y1, z1, xd1, yd1, zd1), xs);
float yf0 = _fnlLerp(xf00, xf10, ys);
float yf1 = _fnlLerp(xf01, xf11, ys);
return _fnlLerp(yf0, yf1, zs) * 0.964921414852142333984375f;
}
// Value Cubic
static float _fnlSingleValueCubic2D(int seed, FNLfloat x, FNLfloat y)
{
int x1 = _fnlFastFloor(x);
int y1 = _fnlFastFloor(y);
float xs = x - (float)x1;
float ys = y - (float)y1;
x1 *= PRIME_X;
y1 *= PRIME_Y;
int x0 = x1 - PRIME_X;
int y0 = y1 - PRIME_Y;
int x2 = x1 + PRIME_X;
int y2 = y1 + PRIME_Y;
int x3 = x1 + (int)((long)PRIME_X << 1);
int y3 = y1 + (int)((long)PRIME_Y << 1);
return _fnlCubicLerp(
_fnlCubicLerp(_fnlValCoord2D(seed, x0, y0), _fnlValCoord2D(seed, x1, y0), _fnlValCoord2D(seed, x2, y0), _fnlValCoord2D(seed, x3, y0),
xs),
_fnlCubicLerp(_fnlValCoord2D(seed, x0, y1), _fnlValCoord2D(seed, x1, y1), _fnlValCoord2D(seed, x2, y1), _fnlValCoord2D(seed, x3, y1),
xs),
_fnlCubicLerp(_fnlValCoord2D(seed, x0, y2), _fnlValCoord2D(seed, x1, y2), _fnlValCoord2D(seed, x2, y2), _fnlValCoord2D(seed, x3, y2),
xs),
_fnlCubicLerp(_fnlValCoord2D(seed, x0, y3), _fnlValCoord2D(seed, x1, y3), _fnlValCoord2D(seed, x2, y3), _fnlValCoord2D(seed, x3, y3),
xs),
ys) * (1 / (1.5f * 1.5f));
}
static float _fnlSingleValueCubic3D(int seed, FNLfloat x, FNLfloat y, FNLfloat z)
{
int x1 = _fnlFastFloor(x);
int y1 = _fnlFastFloor(y);
int z1 = _fnlFastFloor(z);
float xs = x - (float)x1;
float ys = y - (float)y1;
float zs = z - (float)z1;
x1 *= PRIME_X;
y1 *= PRIME_Y;
z1 *= PRIME_Z;
int x0 = x1 - PRIME_X;
int y0 = y1 - PRIME_Y;
int z0 = z1 - PRIME_Z;
int x2 = x1 + PRIME_X;
int y2 = y1 + PRIME_Y;
int z2 = z1 + PRIME_Z;
int x3 = x1 + (int)((long)PRIME_X << 1);
int y3 = y1 + (int)((long)PRIME_Y << 1);
int z3 = z1 + (int)((long)PRIME_Z << 1);
return _fnlCubicLerp(
_fnlCubicLerp(
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y0, z0), _fnlValCoord3D(seed, x1, y0, z0), _fnlValCoord3D(seed, x2, y0, z0), _fnlValCoord3D(seed, x3, y0, z0), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y1, z0), _fnlValCoord3D(seed, x1, y1, z0), _fnlValCoord3D(seed, x2, y1, z0), _fnlValCoord3D(seed, x3, y1, z0), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y2, z0), _fnlValCoord3D(seed, x1, y2, z0), _fnlValCoord3D(seed, x2, y2, z0), _fnlValCoord3D(seed, x3, y2, z0), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y3, z0), _fnlValCoord3D(seed, x1, y3, z0), _fnlValCoord3D(seed, x2, y3, z0), _fnlValCoord3D(seed, x3, y3, z0), xs),
ys),
_fnlCubicLerp(
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y0, z1), _fnlValCoord3D(seed, x1, y0, z1), _fnlValCoord3D(seed, x2, y0, z1), _fnlValCoord3D(seed, x3, y0, z1), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y1, z1), _fnlValCoord3D(seed, x1, y1, z1), _fnlValCoord3D(seed, x2, y1, z1), _fnlValCoord3D(seed, x3, y1, z1), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y2, z1), _fnlValCoord3D(seed, x1, y2, z1), _fnlValCoord3D(seed, x2, y2, z1), _fnlValCoord3D(seed, x3, y2, z1), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y3, z1), _fnlValCoord3D(seed, x1, y3, z1), _fnlValCoord3D(seed, x2, y3, z1), _fnlValCoord3D(seed, x3, y3, z1), xs),
ys),
_fnlCubicLerp(
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y0, z2), _fnlValCoord3D(seed, x1, y0, z2), _fnlValCoord3D(seed, x2, y0, z2), _fnlValCoord3D(seed, x3, y0, z2), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y1, z2), _fnlValCoord3D(seed, x1, y1, z2), _fnlValCoord3D(seed, x2, y1, z2), _fnlValCoord3D(seed, x3, y1, z2), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y2, z2), _fnlValCoord3D(seed, x1, y2, z2), _fnlValCoord3D(seed, x2, y2, z2), _fnlValCoord3D(seed, x3, y2, z2), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y3, z2), _fnlValCoord3D(seed, x1, y3, z2), _fnlValCoord3D(seed, x2, y3, z2), _fnlValCoord3D(seed, x3, y3, z2), xs),
ys),
_fnlCubicLerp(
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y0, z3), _fnlValCoord3D(seed, x1, y0, z3), _fnlValCoord3D(seed, x2, y0, z3), _fnlValCoord3D(seed, x3, y0, z3), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y1, z3), _fnlValCoord3D(seed, x1, y1, z3), _fnlValCoord3D(seed, x2, y1, z3), _fnlValCoord3D(seed, x3, y1, z3), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y2, z3), _fnlValCoord3D(seed, x1, y2, z3), _fnlValCoord3D(seed, x2, y2, z3), _fnlValCoord3D(seed, x3, y2, z3), xs),
_fnlCubicLerp(_fnlValCoord3D(seed, x0, y3, z3), _fnlValCoord3D(seed, x1, y3, z3), _fnlValCoord3D(seed, x2, y3, z3), _fnlValCoord3D(seed, x3, y3, z3), xs),
ys),
zs) * (1 / 1.5f * 1.5f * 1.5f);
}
// Value noise
static float _fnlSingleValue2D(int seed, FNLfloat x, FNLfloat y)
{
int x0 = _fnlFastFloor(x);
int y0 = _fnlFastFloor(y);
float xs = _fnlInterpHermite((float)(x - x0));
float ys = _fnlInterpHermite((float)(y - y0));
x0 *= PRIME_X;
y0 *= PRIME_Y;
int x1 = x0 + PRIME_X;
int y1 = y0 + PRIME_Y;
float xf0 = _fnlLerp(_fnlValCoord2D(seed, x0, y0), _fnlValCoord2D(seed, x1, y0), xs);
float xf1 = _fnlLerp(_fnlValCoord2D(seed, x0, y1), _fnlValCoord2D(seed, x1, y1), xs);
return _fnlLerp(xf0, xf1, ys);
}
static float _fnlSingleValue3D(int seed, FNLfloat x, FNLfloat y, FNLfloat z)
{
int x0 = _fnlFastFloor(x);
int y0 = _fnlFastFloor(y);
int z0 = _fnlFastFloor(z);
float xs = _fnlInterpHermite((float)(x - x0));
float ys = _fnlInterpHermite((float)(y - y0));
float zs = _fnlInterpHermite((float)(z - z0));
x0 *= PRIME_X;
y0 *= PRIME_Y;
z0 *= PRIME_Z;
int x1 = x0 + PRIME_X;
int y1 = y0 + PRIME_Y;
int z1 = z0 + PRIME_Z;
float xf00 = _fnlLerp(_fnlValCoord3D(seed, x0, y0, z0), _fnlValCoord3D(seed, x1, y0, z0), xs);
float xf10 = _fnlLerp(_fnlValCoord3D(seed, x0, y1, z0), _fnlValCoord3D(seed, x1, y1, z0), xs);
float xf01 = _fnlLerp(_fnlValCoord3D(seed, x0, y0, z1), _fnlValCoord3D(seed, x1, y0, z1), xs);
float xf11 = _fnlLerp(_fnlValCoord3D(seed, x0, y1, z1), _fnlValCoord3D(seed, x1, y1, z1), xs);
float yf0 = _fnlLerp(xf00, xf10, ys);
float yf1 = _fnlLerp(xf01, xf11, ys);
return _fnlLerp(yf0, yf1, zs);
}
// Domain Warp
// Forward declare
static void _fnlSingleDomainWarpBasicGrid2D(int seed, float warpAmp, float frequency, FNLfloat x, FNLfloat y, FNLfloat *xp, FNLfloat *yp);
static void _fnlSingleDomainWarpBasicGrid3D(int seed, float warpAmp, float frequency, FNLfloat x, FNLfloat y, FNLfloat z, FNLfloat *xp, FNLfloat *yp, FNLfloat *zp);
static void _fnlSingleDomainWarpSimplexGradient(int seed, float warpAmp, float frequency, FNLfloat x, FNLfloat y, FNLfloat *xr, FNLfloat *yr, bool outGradOnly);
static void _fnlSingleDomainWarpOpenSimplex2Gradient(int seed, float warpAmp, float frequency, FNLfloat x, FNLfloat y, FNLfloat z, FNLfloat *xr, FNLfloat *yr, FNLfloat *zr, bool outGradOnly);
static inline void _fnlDoSingleDomainWarp2D(fnl_state *state, int seed, float amp, float freq, FNLfloat x, FNLfloat y, FNLfloat *xp, FNLfloat *yp)
{
switch (state->domain_warp_type)
{
case FNL_DOMAIN_WARP_OPENSIMPLEX2:
_fnlSingleDomainWarpSimplexGradient(seed, amp * 38.283687591552734375f, freq, x, y, xp, yp, false);
break;
case FNL_DOMAIN_WARP_OPENSIMPLEX2_REDUCED:
_fnlSingleDomainWarpSimplexGradient(seed, amp * 16.0f, freq, x, y, xp, yp, true);
break;
case FNL_DOMAIN_WARP_BASICGRID:
_fnlSingleDomainWarpBasicGrid2D(seed, amp, freq, x, y, xp, yp);
break;
}
}
static inline void _fnlDoSingleDomainWarp3D(fnl_state *state, int seed, float amp, float freq, FNLfloat x, FNLfloat y, FNLfloat z, FNLfloat *xp, FNLfloat *yp, FNLfloat *zp)
{
switch (state->domain_warp_type)
{
case FNL_DOMAIN_WARP_OPENSIMPLEX2:
_fnlSingleDomainWarpOpenSimplex2Gradient(seed, amp * 32.69428253173828125f, freq, x, y, z, xp, yp, zp, false);
break;
case FNL_DOMAIN_WARP_OPENSIMPLEX2_REDUCED:
_fnlSingleDomainWarpOpenSimplex2Gradient(seed, amp * 7.71604938271605f, freq, x, y, z, xp, yp, zp, true);
break;
case FNL_DOMAIN_WARP_BASICGRID:
_fnlSingleDomainWarpBasicGrid3D(seed, amp, freq, x, y, z, xp, yp, zp);
break;
}
}
// Domain Warp Single Wrapper
static void _fnlDomainWarpSingle2D(fnl_state *state, FNLfloat *x, FNLfloat *y)
{
int seed = state->seed;
float amp = state->domain_warp_amp * _fnlCalculateFractalBounding(state);
float freq = state->frequency;
FNLfloat xs = *x;
FNLfloat ys = *y;
_fnlTransformDomainWarpCoordinate2D(state, &xs, &ys);
_fnlDoSingleDomainWarp2D(state, seed, amp, freq, xs, ys, x, y);
}
static void _fnlDomainWarpSingle3D(fnl_state *state, FNLfloat *x, FNLfloat *y, FNLfloat *z)
{
int seed = state->seed;
float amp = state->domain_warp_amp * _fnlCalculateFractalBounding(state);
float freq = state->frequency;
FNLfloat xs = *x;
FNLfloat ys = *y;
FNLfloat zs = *z;
_fnlTransformDomainWarpCoordinate3D(state, &xs, &ys, &zs);
_fnlDoSingleDomainWarp3D(state, seed, amp, freq, xs, ys, zs, x, y, z);
}
// Domain Warp Fractal Progressive
static void _fnlDomainWarpFractalProgressive2D(fnl_state *state, FNLfloat *x, FNLfloat *y)
{
int seed = state->seed;
float amp = state->domain_warp_amp * _fnlCalculateFractalBounding(state);
float freq = state->frequency;
for (int i = 0; i < state->octaves; i++)
{
FNLfloat xs = *x;
FNLfloat ys = *y;
_fnlTransformDomainWarpCoordinate2D(state, &xs, &ys);
_fnlDoSingleDomainWarp2D(state, seed, amp, freq, xs, ys, x, y);
seed++;
amp *= state->gain;
freq *= state->lacunarity;
}
}
static void _fnlDomainWarpFractalProgressive3D(fnl_state *state, FNLfloat *x, FNLfloat *y, FNLfloat *z)
{
int seed = state->seed;
float amp = state->domain_warp_amp * _fnlCalculateFractalBounding(state);
float freq = state->frequency;
for (int i = 0; i < state->octaves; i++)
{
FNLfloat xs = *x;
FNLfloat ys = *y;
FNLfloat zs = *z;
_fnlTransformDomainWarpCoordinate3D(state, &xs, &ys, &zs);
_fnlDoSingleDomainWarp3D(state, seed, amp, freq, xs, ys, zs, x, y, z);
seed++;
amp *= state->gain;
freq *= state->lacunarity;
}
}
// Domain Warp Fractal Independent
static void _fnlDomainWarpFractalIndependent2D(fnl_state *state, FNLfloat *x, FNLfloat *y)
{
FNLfloat xs = *x;
FNLfloat ys = *y;
_fnlTransformDomainWarpCoordinate2D(state, &xs, &ys);
int seed = state->seed;
float amp = state->domain_warp_amp * _fnlCalculateFractalBounding(state);
float freq = state->frequency;
for (int i = 0; i < state->octaves; i++)
{
_fnlDoSingleDomainWarp2D(state, seed, amp, freq, xs, ys, x, y);
seed++;
amp *= state->gain;
freq *= state->lacunarity;
}
}
static void _fnlDomainWarpFractalIndependent3D(fnl_state *state, FNLfloat *x, FNLfloat *y, FNLfloat *z)
{
FNLfloat xs = *x;
FNLfloat ys = *y;
FNLfloat zs = *z;
_fnlTransformDomainWarpCoordinate3D(state, &xs, &ys, &zs);
int seed = state->seed;
float amp = state->domain_warp_amp * _fnlCalculateFractalBounding(state);
float freq = state->frequency;
for (int i = 0; i < state->octaves; i++)
{
_fnlDoSingleDomainWarp3D(state, seed, amp, freq, xs, ys, zs, x, y, z);
seed++;
amp *= state->gain;
freq *= state->lacunarity;
}
}
// Domain Warp Basic Grid
static void _fnlSingleDomainWarpBasicGrid2D(int seed, float warpAmp, float frequency, FNLfloat x, FNLfloat y, FNLfloat *xp, FNLfloat *yp)
{
FNLfloat xf = x * frequency;
FNLfloat yf = y * frequency;
int x0 = _fnlFastFloor(xf);
int y0 = _fnlFastFloor(yf);
float xs = _fnlInterpHermite((float)(xf - x0));
float ys = _fnlInterpHermite((float)(yf - y0));
x0 *= PRIME_X;
y0 *= PRIME_Y;
int x1 = x0 + PRIME_X;
int y1 = y0 + PRIME_Y;
int idx0 = _fnlHash2D(seed, x0, y0) & (255 << 1);
int idx1 = _fnlHash2D(seed, x1, y0) & (255 << 1);
float lx0x = _fnlLerp(RAND_VECS_2D[idx0], RAND_VECS_2D[idx1], xs);
float ly0x = _fnlLerp(RAND_VECS_2D[idx0 | 1], RAND_VECS_2D[idx1 | 1], xs);
idx0 = _fnlHash2D(seed, x0, y1) & (255 << 1);
idx1 = _fnlHash2D(seed, x1, y1) & (255 << 1);
float lx1x = _fnlLerp(RAND_VECS_2D[idx0], RAND_VECS_2D[idx1], xs);
float ly1x = _fnlLerp(RAND_VECS_2D[idx0 | 1], RAND_VECS_2D[idx1 | 1], xs);
*xp += _fnlLerp(lx0x, lx1x, ys) * warpAmp;
*yp += _fnlLerp(ly0x, ly1x, ys) * warpAmp;
}
static void _fnlSingleDomainWarpBasicGrid3D(int seed, float warpAmp, float frequency, FNLfloat x, FNLfloat y, FNLfloat z, FNLfloat *xp, FNLfloat *yp, FNLfloat *zp)
{
FNLfloat xf = x * frequency;
FNLfloat yf = y * frequency;
FNLfloat zf = z * frequency;
int x0 = _fnlFastFloor(xf);
int y0 = _fnlFastFloor(yf);
int z0 = _fnlFastFloor(zf);
float xs = _fnlInterpHermite((float)(xf - x0));
float ys = _fnlInterpHermite((float)(yf - y0));
float zs = _fnlInterpHermite((float)(zf - z0));
x0 *= PRIME_X;
y0 *= PRIME_Y;
z0 *= PRIME_Z;
int x1 = x0 + PRIME_X;
int y1 = y0 + PRIME_Y;
int z1 = z0 + PRIME_Z;
int idx0 = _fnlHash3D(seed, x0, y0, z0) & (255 << 2);
int idx1 = _fnlHash3D(seed, x1, y0, z0) & (255 << 2);
float lx0x = _fnlLerp(RAND_VECS_3D[idx0], RAND_VECS_3D[idx1], xs);
float ly0x = _fnlLerp(RAND_VECS_3D[idx0 | 1], RAND_VECS_3D[idx1 | 1], xs);
float lz0x = _fnlLerp(RAND_VECS_3D[idx0 | 2], RAND_VECS_3D[idx1 | 2], xs);
idx0 = _fnlHash3D(seed, x0, y1, z0) & (255 << 2);
idx1 = _fnlHash3D(seed, x1, y1, z0) & (255 << 2);
float lx1x = _fnlLerp(RAND_VECS_3D[idx0], RAND_VECS_3D[idx1], xs);
float ly1x = _fnlLerp(RAND_VECS_3D[idx0 | 1], RAND_VECS_3D[idx1 | 1], xs);
float lz1x = _fnlLerp(RAND_VECS_3D[idx0 | 2], RAND_VECS_3D[idx1 | 2], xs);
float lx0y = _fnlLerp(lx0x, lx1x, ys);
float ly0y = _fnlLerp(ly0x, ly1x, ys);
float lz0y = _fnlLerp(lz0x, lz1x, ys);
idx0 = _fnlHash3D(seed, x0, y0, z1) & (255 << 2);
idx1 = _fnlHash3D(seed, x1, y0, z1) & (255 << 2);
lx0x = _fnlLerp(RAND_VECS_3D[idx0], RAND_VECS_3D[idx1], xs);
ly0x = _fnlLerp(RAND_VECS_3D[idx0 | 1], RAND_VECS_3D[idx1 | 1], xs);
lz0x = _fnlLerp(RAND_VECS_3D[idx0 | 2], RAND_VECS_3D[idx1 | 2], xs);
idx0 = _fnlHash3D(seed, x0, y1, z1) & (255 << 2);
idx1 = _fnlHash3D(seed, x1, y1, z1) & (255 << 2);
lx1x = _fnlLerp(RAND_VECS_3D[idx0], RAND_VECS_3D[idx1], xs);
ly1x = _fnlLerp(RAND_VECS_3D[idx0 | 1], RAND_VECS_3D[idx1 | 1], xs);
lz1x = _fnlLerp(RAND_VECS_3D[idx0 | 2], RAND_VECS_3D[idx1 | 2], xs);
*xp += _fnlLerp(lx0y, _fnlLerp(lx0x, lx1x, ys), zs) * warpAmp;
*yp += _fnlLerp(ly0y, _fnlLerp(ly0x, ly1x, ys), zs) * warpAmp;
*zp += _fnlLerp(lz0y, _fnlLerp(lz0x, lz1x, ys), zs) * warpAmp;
}
// Domain Warp Simplex/OpenSimplex2
static void _fnlSingleDomainWarpSimplexGradient(int seed, float warpAmp, float frequency, FNLfloat x, FNLfloat y, FNLfloat *xr, FNLfloat *yr, bool outGradOnly)
{
const float SQRT3 = 1.7320508075688772935274463415059f;
const float G2 = (3 - SQRT3) / 6;
x *= frequency;
y *= frequency;
/*
* --- Skew moved to TransformNoiseCoordinate method ---
* const FNLfloat F2 = 0.5f * (SQRT3 - 1);
* FNLfloat s = (x + y) * F2;
* x += s; y += s;
*/
int i = _fnlFastFloor(x);
int j = _fnlFastFloor(y);
float xi = (float)(x - i);
float yi = (float)(y - j);
float t = (xi + yi) * G2;
float x0 = (float)(xi - t);
float y0 = (float)(yi - t);
i *= PRIME_X;
j *= PRIME_Y;
float vx, vy;
vx = vy = 0;
float a = 0.5f - x0 * x0 - y0 * y0;
if (a > 0)
{
float aaaa = (a * a) * (a * a);
float xo, yo;
if (outGradOnly)
_fnlGradCoordOut2D(seed, i, j, &xo, &yo);
else
_fnlGradCoordDual2D(seed, i, j, x0, y0, &xo, &yo);
vx += aaaa * xo;
vy += aaaa * yo;
}
float c = (float)(2 * (1 - 2 * G2) * (1 / G2 - 2)) * t + ((float)(-2 * (1 - 2 * G2) * (1 - 2 * G2)) + a);
if (c > 0)
{
float x2 = x0 + (2 * (float)G2 - 1);
float y2 = y0 + (2 * (float)G2 - 1);
float cccc = (c * c) * (c * c);
float xo, yo;
if (outGradOnly)
_fnlGradCoordOut2D(seed, i + PRIME_X, j + PRIME_Y, &xo, &yo);
else
_fnlGradCoordDual2D(seed, i + PRIME_X, j + PRIME_Y, x2, y2, &xo, &yo);
vx += cccc * xo;
vy += cccc * yo;
}
if (y0 > x0)
{
float x1 = x0 + (float)G2;
float y1 = y0 + ((float)G2 - 1);
float b = 0.5f - x1 * x1 - y1 * y1;
if (b > 0)
{
float bbbb = (b * b) * (b * b);
float xo, yo;
if (outGradOnly)
_fnlGradCoordOut2D(seed, i, j + PRIME_Y, &xo, &yo);
else
_fnlGradCoordDual2D(seed, i, j + PRIME_Y, x1, y1, &xo, &yo);
vx += bbbb * xo;
vy += bbbb * yo;
}
}
else
{
float x1 = x0 + ((float)G2 - 1);
float y1 = y0 + (float)G2;
float b = 0.5f - x1 * x1 - y1 * y1;
if (b > 0)
{
float bbbb = (b * b) * (b * b);
float xo, yo;
if (outGradOnly)
_fnlGradCoordOut2D(seed, i + PRIME_X, j, &xo, &yo);
else
_fnlGradCoordDual2D(seed, i + PRIME_X, j, x1, y1, &xo, &yo);
vx += bbbb * xo;
vy += bbbb * yo;
}
}
*xr += vx * warpAmp;
*yr += vy * warpAmp;
}
static void _fnlSingleDomainWarpOpenSimplex2Gradient(int seed, float warpAmp, float frequency, FNLfloat x, FNLfloat y, FNLfloat z, FNLfloat *xr, FNLfloat *yr, FNLfloat *zr, bool outGradOnly)
{
x *= frequency;
y *= frequency;
z *= frequency;
/*
* --- Rotation moved to TransformDomainWarpCoordinate method ---
* const FNLfloat R3 = (FNLfloat)(2.0 / 3.0);
* FNLfloat r = (x + y + z) * R3; // Rotation, not skew
* x = r - x; y = r - y; z = r - z;
*/
int i = _fnlFastRound(x);
int j = _fnlFastRound(y);
int k = _fnlFastRound(z);
float x0 = (float)x - i;
float y0 = (float)y - j;
float z0 = (float)z - k;
int xNSign = (int)(-x0 - 1.0f) | 1;
int yNSign = (int)(-y0 - 1.0f) | 1;
int zNSign = (int)(-z0 - 1.0f) | 1;
float ax0 = xNSign * -x0;
float ay0 = yNSign * -y0;
float az0 = zNSign * -z0;
i *= PRIME_X;
j *= PRIME_Y;
k *= PRIME_Z;
float vx, vy, vz;
vx = vy = vz = 0;
float a = (0.6f - x0 * x0) - (y0 * y0 + z0 * z0);
for (int l = 0; l < 2; l++)
{
if (a > 0)
{
float aaaa = (a * a) * (a * a);
float xo, yo, zo;
if (outGradOnly)
_fnlGradCoordOut3D(seed, i, j, k, &xo, &yo, &zo);
else
_fnlGradCoordDual3D(seed, i, j, k, x0, y0, z0, &xo, &yo, &zo);
vx += aaaa * xo;
vy += aaaa * yo;
vz += aaaa * zo;
}
float b = a + 1;
int i1 = i;
int j1 = j;
int k1 = k;
float x1 = x0;
float y1 = y0;
float z1 = z0;
if (ax0 >= ay0 && ax0 >= az0)
{
x1 += xNSign;
b -= xNSign * 2 * x1;
i1 -= xNSign * PRIME_X;
}
else if (ay0 > ax0 && ay0 >= az0)
{
y1 += yNSign;
b -= yNSign * 2 * y1;
j1 -= yNSign * PRIME_Y;
}
else
{
z1 += zNSign;
b -= zNSign * 2 * z1;
k1 -= zNSign * PRIME_Z;
}
if (b > 0)
{
float bbbb = (b * b) * (b * b);
float xo, yo, zo;
if (outGradOnly)
_fnlGradCoordOut3D(seed, i1, j1, k1, &xo, &yo, &zo);
else
_fnlGradCoordDual3D(seed, i1, j1, k1, x1, y1, z1, &xo, &yo, &zo);
vx += bbbb * xo;
vy += bbbb * yo;
vz += bbbb * zo;
}
if (l == 1)
break;
ax0 = 0.5f - ax0;
ay0 = 0.5f - ay0;
az0 = 0.5f - az0;
x0 = xNSign * ax0;
y0 = yNSign * ay0;
z0 = zNSign * az0;
a += (0.75f - ax0) - (ay0 + az0);
i += (xNSign >> 1) & PRIME_X;
j += (yNSign >> 1) & PRIME_Y;
k += (zNSign >> 1) & PRIME_Z;
xNSign = -xNSign;
yNSign = -yNSign;
zNSign = -zNSign;
seed += 1293373;
}
*xr += vx * warpAmp;
*yr += vy * warpAmp;
*zr += vz * warpAmp;
}
// ====================
// Public API
// ====================
fnl_state fnlCreateState()
{
fnl_state newState;
newState.seed = 1337;
newState.frequency = 0.01f;
newState.noise_type = FNL_NOISE_OPENSIMPLEX2;
newState.rotation_type_3d = FNL_ROTATION_NONE;
newState.fractal_type = FNL_FRACTAL_NONE;
newState.octaves = 3;
newState.lacunarity = 2.0f;
newState.gain = 0.5f;
newState.weighted_strength = 0.0f;
newState.ping_pong_strength = 2.0f;
newState.cellular_distance_func = FNL_CELLULAR_DISTANCE_EUCLIDEANSQ;
newState.cellular_return_type = FNL_CELLULAR_RETURN_TYPE_DISTANCE;
newState.cellular_jitter_mod = 1.0f;
newState.domain_warp_amp = 30.0f;
newState.domain_warp_type = FNL_DOMAIN_WARP_OPENSIMPLEX2;
return newState;
}
float fnlGetNoise2D(fnl_state *state, FNLfloat x, FNLfloat y)
{
_fnlTransformNoiseCoordinate2D(state, &x, &y);
switch (state->fractal_type)
{
default:
return _fnlGenNoiseSingle2D(state, state->seed, x, y);
case FNL_FRACTAL_FBM:
return _fnlGenFractalFBM2D(state, x, y);
case FNL_FRACTAL_RIDGED:
return _fnlGenFractalRidged2D(state, x, y);
case FNL_FRACTAL_PINGPONG:
return _fnlGenFractalPingPong2D(state, x, y);
}
}
float fnlGetNoise3D(fnl_state *state, FNLfloat x, FNLfloat y, FNLfloat z)
{
_fnlTransformNoiseCoordinate3D(state, &x, &y, &z);
// Select a noise type
switch (state->fractal_type)
{
default:
return _fnlGenNoiseSingle3D(state, state->seed, x, y, z);
case FNL_FRACTAL_FBM:
return _fnlGenFractalFBM3D(state, x, y, z);
case FNL_FRACTAL_RIDGED:
return _fnlGenFractalRidged3D(state, x, y, z);
case FNL_FRACTAL_PINGPONG:
return _fnlGenFractalPingPong3D(state, x, y, z);
}
}
void fnlDomainWarp2D(fnl_state *state, FNLfloat *x, FNLfloat *y)
{
switch (state->fractal_type)
{
default:
_fnlDomainWarpSingle2D(state, x, y);
break;
case FNL_FRACTAL_DOMAIN_WARP_PROGRESSIVE:
_fnlDomainWarpFractalProgressive2D(state, x, y);
break;
case FNL_FRACTAL_DOMAIN_WARP_INDEPENDENT:
_fnlDomainWarpFractalIndependent2D(state, x, y);
break;
}
}
void fnlDomainWarp3D(fnl_state *state, FNLfloat *x, FNLfloat *y, FNLfloat *z)
{
switch (state->fractal_type)
{
default:
_fnlDomainWarpSingle3D(state, x, y, z);
break;
case FNL_FRACTAL_DOMAIN_WARP_PROGRESSIVE:
_fnlDomainWarpFractalProgressive3D(state, x, y, z);
break;
case FNL_FRACTAL_DOMAIN_WARP_INDEPENDENT:
_fnlDomainWarpFractalIndependent3D(state, x, y, z);
break;
}
}
#endif // FNL_IMPL
#if defined(__cplusplus)
}
#endif
#endif // FASTNOISELITE_H
``` | /content/code_sandbox/C/FastNoiseLite.h | objective-c | 2016-03-28T02:35:12 | 2024-08-16T07:09:20 | FastNoiseLite | Auburn/FastNoiseLite | 2,688 | 42,132 |
```objective-c
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// .'',;:cldxkO00KKXXNNWWWNNXKOkxdollcc::::::;:::ccllloooolllllllllooollc:,'... ...........',;cldxkO000Okxdlc::;;;,,;;;::cclllllll
// ..',;:ldxO0KXXNNNNNNNNXXK0kxdolcc::::::;;;,,,,,,;;;;;;;;;;:::cclllllc:;'.... ...........',;:ldxO0KXXXK0Okxdolc::;;;;::cllodddddo
// ...',:loxO0KXNNNNNXXKK0Okxdolc::;::::::::;;;,,'''''.....''',;:clllllc:;,'............''''''''',;:loxO0KXNNNNNXK0Okxdollccccllodxxxxxxd
// ....';:ldkO0KXXXKK00Okxdolcc:;;;;;::cclllcc:;;,''..... ....',;clooddolcc:;;;;,,;;;;;::::;;;;;;:cloxk0KXNWWWWWWNXKK0Okxddoooddxxkkkkkxx
// .....';:ldxkOOOOOkxxdolcc:;;;,,,;;:cllooooolcc:;'... ..,:codxkkkxddooollloooooooollcc:::::clodkO0KXNWWWWWWNNXK00Okxxxxxxxxkkkkxxx
// . ....';:cloddddo___________,,,,;;:clooddddoolc:,... ..,:ldx__00OOOkkk___kkkkkkxxdollc::::cclodkO0KXXNNNNNNXXK0OOkxxxxxxxxxxxxddd
// .......',;:cccc:| |,,,;;:cclooddddoll:;'.. ..';cox| \KKK000| |KK00OOkxdocc___;::clldxxkO0KKKKK00Okkxdddddddddddddddoo
// .......'',,,,,''| ________|',,;;::cclloooooolc:;'......___:ldk| \KK000| |XKKK0Okxolc| |;;::cclodxxkkkkxxdoolllcclllooodddooooo
// ''......''''....| | ....'',,,,;;;::cclloooollc:;,''.'| |oxk| \OOO0| |KKK00Oxdoll|___|;;;;;::ccllllllcc::;;,,;;;:cclloooooooo
// ;;,''.......... | |_____',,;;;____:___cllo________.___| |___| \xkk| |KK_______ool___:::;________;;;_______...'',;;:ccclllloo
// c:;,''......... | |:::/ ' |lo/ | | \dx| |0/ \d| |cc/ |'/ \......',,;;:ccllo
// ol:;,'..........| _____|ll/ __ |o/ ______|____ ___| | \o| |/ ___ \| |o/ ______|/ ___ \ .......'',;:clo
// dlc;,...........| |::clooo| / | |x\___ \KXKKK0| |dol| |\ \| | | | | |d\___ \..| | / / ....',:cl
// xoc;'... .....'| |llodddd| \__| |_____\ \KKK0O| |lc:| |'\ | |___| | |_____\ \.| |_/___/... ...',;:c
// dlc;'... ....',;| |oddddddo\ | |Okkx| |::;| |..\ |\ /| | | \ |... ....',;:c
// ol:,'.......',:c|___|xxxddollc\_____,___|_________/ddoll|___|,,,|___|...\_____|:\ ______/l|___|_________/...\________|'........',;::cc
// c:;'.......';:codxxkkkkxxolc::;::clodxkOO0OOkkxdollc::;;,,''''',,,,''''''''''',,'''''',;:loxkkOOkxol:;,'''',,;:ccllcc:;,'''''',;::ccll
// ;,'.......',:codxkOO0OOkxdlc:;,,;;:cldxxkkxxdolc:;;,,''.....'',;;:::;;,,,'''''........,;cldkO0KK0Okdoc::;;::cloodddoolc:;;;;;::ccllooo
// .........',;:lodxOO0000Okdoc:,,',,;:clloddoolc:;,''.......'',;:clooollc:;;,,''.......',:ldkOKXNNXX0Oxdolllloddxxxxxxdolccccccllooodddd
// . .....';:cldxkO0000Okxol:;,''',,;::cccc:;,,'.......'',;:cldxxkkxxdolc:;;,'.......';coxOKXNWWWNXKOkxddddxxkkkkkkxdoollllooddxxxxkkk
// ....',;:codxkO000OOxdoc:;,''',,,;;;;,''.......',,;:clodkO00000Okxolc::;,,''..',;:ldxOKXNWWWNNK0OkkkkkkkkkkkxxddooooodxxkOOOOO000
// ....',;;clodxkkOOOkkdolc:;,,,,,,,,'..........,;:clodxkO0KKXKK0Okxdolcc::;;,,,;;:codkO0XXNNNNXKK0OOOOOkkkkxxdoollloodxkO0KKKXXXXX
//
// VERSION: 1.1.1
// path_to_url
#ifndef FASTNOISELITE_H
#define FASTNOISELITE_H
#include <cmath>
class FastNoiseLite
{
public:
enum NoiseType
{
NoiseType_OpenSimplex2,
NoiseType_OpenSimplex2S,
NoiseType_Cellular,
NoiseType_Perlin,
NoiseType_ValueCubic,
NoiseType_Value
};
enum RotationType3D
{
RotationType3D_None,
RotationType3D_ImproveXYPlanes,
RotationType3D_ImproveXZPlanes
};
enum FractalType
{
FractalType_None,
FractalType_FBm,
FractalType_Ridged,
FractalType_PingPong,
FractalType_DomainWarpProgressive,
FractalType_DomainWarpIndependent
};
enum CellularDistanceFunction
{
CellularDistanceFunction_Euclidean,
CellularDistanceFunction_EuclideanSq,
CellularDistanceFunction_Manhattan,
CellularDistanceFunction_Hybrid
};
enum CellularReturnType
{
CellularReturnType_CellValue,
CellularReturnType_Distance,
CellularReturnType_Distance2,
CellularReturnType_Distance2Add,
CellularReturnType_Distance2Sub,
CellularReturnType_Distance2Mul,
CellularReturnType_Distance2Div
};
enum DomainWarpType
{
DomainWarpType_OpenSimplex2,
DomainWarpType_OpenSimplex2Reduced,
DomainWarpType_BasicGrid
};
/// <summary>
/// Create new FastNoise object with optional seed
/// </summary>
FastNoiseLite(int seed = 1337)
{
mSeed = seed;
mFrequency = 0.01f;
mNoiseType = NoiseType_OpenSimplex2;
mRotationType3D = RotationType3D_None;
mTransformType3D = TransformType3D_DefaultOpenSimplex2;
mFractalType = FractalType_None;
mOctaves = 3;
mLacunarity = 2.0f;
mGain = 0.5f;
mWeightedStrength = 0.0f;
mPingPongStrength = 2.0f;
mFractalBounding = 1 / 1.75f;
mCellularDistanceFunction = CellularDistanceFunction_EuclideanSq;
mCellularReturnType = CellularReturnType_Distance;
mCellularJitterModifier = 1.0f;
mDomainWarpType = DomainWarpType_OpenSimplex2;
mWarpTransformType3D = TransformType3D_DefaultOpenSimplex2;
mDomainWarpAmp = 1.0f;
}
/// <summary>
/// Sets seed used for all noise types
/// </summary>
/// <remarks>
/// Default: 1337
/// </remarks>
void SetSeed(int seed) { mSeed = seed; }
/// <summary>
/// Sets frequency for all noise types
/// </summary>
/// <remarks>
/// Default: 0.01
/// </remarks>
void SetFrequency(float frequency) { mFrequency = frequency; }
/// <summary>
/// Sets noise algorithm used for GetNoise(...)
/// </summary>
/// <remarks>
/// Default: OpenSimplex2
/// </remarks>
void SetNoiseType(NoiseType noiseType)
{
mNoiseType = noiseType;
UpdateTransformType3D();
}
/// <summary>
/// Sets domain rotation type for 3D Noise and 3D DomainWarp.
/// Can aid in reducing directional artifacts when sampling a 2D plane in 3D
/// </summary>
/// <remarks>
/// Default: None
/// </remarks>
void SetRotationType3D(RotationType3D rotationType3D)
{
mRotationType3D = rotationType3D;
UpdateTransformType3D();
UpdateWarpTransformType3D();
}
/// <summary>
/// Sets method for combining octaves in all fractal noise types
/// </summary>
/// <remarks>
/// Default: None
/// Note: FractalType_DomainWarp... only affects DomainWarp(...)
/// </remarks>
void SetFractalType(FractalType fractalType) { mFractalType = fractalType; }
/// <summary>
/// Sets octave count for all fractal noise types
/// </summary>
/// <remarks>
/// Default: 3
/// </remarks>
void SetFractalOctaves(int octaves)
{
mOctaves = octaves;
CalculateFractalBounding();
}
/// <summary>
/// Sets octave lacunarity for all fractal noise types
/// </summary>
/// <remarks>
/// Default: 2.0
/// </remarks>
void SetFractalLacunarity(float lacunarity) { mLacunarity = lacunarity; }
/// <summary>
/// Sets octave gain for all fractal noise types
/// </summary>
/// <remarks>
/// Default: 0.5
/// </remarks>
void SetFractalGain(float gain)
{
mGain = gain;
CalculateFractalBounding();
}
/// <summary>
/// Sets octave weighting for all none DomainWarp fratal types
/// </summary>
/// <remarks>
/// Default: 0.0
/// Note: Keep between 0...1 to maintain -1...1 output bounding
/// </remarks>
void SetFractalWeightedStrength(float weightedStrength) { mWeightedStrength = weightedStrength; }
/// <summary>
/// Sets strength of the fractal ping pong effect
/// </summary>
/// <remarks>
/// Default: 2.0
/// </remarks>
void SetFractalPingPongStrength(float pingPongStrength) { mPingPongStrength = pingPongStrength; }
/// <summary>
/// Sets distance function used in cellular noise calculations
/// </summary>
/// <remarks>
/// Default: Distance
/// </remarks>
void SetCellularDistanceFunction(CellularDistanceFunction cellularDistanceFunction) { mCellularDistanceFunction = cellularDistanceFunction; }
/// <summary>
/// Sets return type from cellular noise calculations
/// </summary>
/// <remarks>
/// Default: EuclideanSq
/// </remarks>
void SetCellularReturnType(CellularReturnType cellularReturnType) { mCellularReturnType = cellularReturnType; }
/// <summary>
/// Sets the maximum distance a cellular point can move from it's grid position
/// </summary>
/// <remarks>
/// Default: 1.0
/// Note: Setting this higher than 1 will cause artifacts
/// </remarks>
void SetCellularJitter(float cellularJitter) { mCellularJitterModifier = cellularJitter; }
/// <summary>
/// Sets the warp algorithm when using DomainWarp(...)
/// </summary>
/// <remarks>
/// Default: OpenSimplex2
/// </remarks>
void SetDomainWarpType(DomainWarpType domainWarpType)
{
mDomainWarpType = domainWarpType;
UpdateWarpTransformType3D();
}
/// <summary>
/// Sets the maximum warp distance from original position when using DomainWarp(...)
/// </summary>
/// <remarks>
/// Default: 1.0
/// </remarks>
void SetDomainWarpAmp(float domainWarpAmp) { mDomainWarpAmp = domainWarpAmp; }
/// <summary>
/// 2D noise at given position using current settings
/// </summary>
/// <returns>
/// Noise output bounded between -1...1
/// </returns>
template <typename FNfloat>
float GetNoise(FNfloat x, FNfloat y) const
{
Arguments_must_be_floating_point_values<FNfloat>();
TransformNoiseCoordinate(x, y);
switch (mFractalType)
{
default:
return GenNoiseSingle(mSeed, x, y);
case FractalType_FBm:
return GenFractalFBm(x, y);
case FractalType_Ridged:
return GenFractalRidged(x, y);
case FractalType_PingPong:
return GenFractalPingPong(x, y);
}
}
/// <summary>
/// 3D noise at given position using current settings
/// </summary>
/// <returns>
/// Noise output bounded between -1...1
/// </returns>
template <typename FNfloat>
float GetNoise(FNfloat x, FNfloat y, FNfloat z) const
{
Arguments_must_be_floating_point_values<FNfloat>();
TransformNoiseCoordinate(x, y, z);
switch (mFractalType)
{
default:
return GenNoiseSingle(mSeed, x, y, z);
case FractalType_FBm:
return GenFractalFBm(x, y, z);
case FractalType_Ridged:
return GenFractalRidged(x, y, z);
case FractalType_PingPong:
return GenFractalPingPong(x, y, z);
}
}
/// <summary>
/// 2D warps the input position using current domain warp settings
/// </summary>
/// <example>
/// Example usage with GetNoise
/// <code>DomainWarp(x, y)
/// noise = GetNoise(x, y)</code>
/// </example>
template <typename FNfloat>
void DomainWarp(FNfloat& x, FNfloat& y) const
{
Arguments_must_be_floating_point_values<FNfloat>();
switch (mFractalType)
{
default:
DomainWarpSingle(x, y);
break;
case FractalType_DomainWarpProgressive:
DomainWarpFractalProgressive(x, y);
break;
case FractalType_DomainWarpIndependent:
DomainWarpFractalIndependent(x, y);
break;
}
}
/// <summary>
/// 3D warps the input position using current domain warp settings
/// </summary>
/// <example>
/// Example usage with GetNoise
/// <code>DomainWarp(x, y, z)
/// noise = GetNoise(x, y, z)</code>
/// </example>
template <typename FNfloat>
void DomainWarp(FNfloat& x, FNfloat& y, FNfloat& z) const
{
Arguments_must_be_floating_point_values<FNfloat>();
switch (mFractalType)
{
default:
DomainWarpSingle(x, y, z);
break;
case FractalType_DomainWarpProgressive:
DomainWarpFractalProgressive(x, y, z);
break;
case FractalType_DomainWarpIndependent:
DomainWarpFractalIndependent(x, y, z);
break;
}
}
private:
template <typename T>
struct Arguments_must_be_floating_point_values;
enum TransformType3D
{
TransformType3D_None,
TransformType3D_ImproveXYPlanes,
TransformType3D_ImproveXZPlanes,
TransformType3D_DefaultOpenSimplex2
};
int mSeed;
float mFrequency;
NoiseType mNoiseType;
RotationType3D mRotationType3D;
TransformType3D mTransformType3D;
FractalType mFractalType;
int mOctaves;
float mLacunarity;
float mGain;
float mWeightedStrength;
float mPingPongStrength;
float mFractalBounding;
CellularDistanceFunction mCellularDistanceFunction;
CellularReturnType mCellularReturnType;
float mCellularJitterModifier;
DomainWarpType mDomainWarpType;
TransformType3D mWarpTransformType3D;
float mDomainWarpAmp;
template <typename T>
struct Lookup
{
static const T Gradients2D[];
static const T Gradients3D[];
static const T RandVecs2D[];
static const T RandVecs3D[];
};
static float FastMin(float a, float b) { return a < b ? a : b; }
static float FastMax(float a, float b) { return a > b ? a : b; }
static float FastAbs(float f) { return f < 0 ? -f : f; }
static float FastSqrt(float f) { return sqrtf(f); }
template <typename FNfloat>
static int FastFloor(FNfloat f) { return f >= 0 ? (int)f : (int)f - 1; }
template <typename FNfloat>
static int FastRound(FNfloat f) { return f >= 0 ? (int)(f + 0.5f) : (int)(f - 0.5f); }
static float Lerp(float a, float b, float t) { return a + t * (b - a); }
static float InterpHermite(float t) { return t * t * (3 - 2 * t); }
static float InterpQuintic(float t) { return t * t * t * (t * (t * 6 - 15) + 10); }
static float CubicLerp(float a, float b, float c, float d, float t)
{
float p = (d - c) - (a - b);
return t * t * t * p + t * t * ((a - b) - p) + t * (c - a) + b;
}
static float PingPong(float t)
{
t -= (int)(t * 0.5f) * 2;
return t < 1 ? t : 2 - t;
}
void CalculateFractalBounding()
{
float gain = FastAbs(mGain);
float amp = gain;
float ampFractal = 1.0f;
for (int i = 1; i < mOctaves; i++)
{
ampFractal += amp;
amp *= gain;
}
mFractalBounding = 1 / ampFractal;
}
// Hashing
static const int PrimeX = 501125321;
static const int PrimeY = 1136930381;
static const int PrimeZ = 1720413743;
static int Hash(int seed, int xPrimed, int yPrimed)
{
int hash = seed ^ xPrimed ^ yPrimed;
hash *= 0x27d4eb2d;
return hash;
}
static int Hash(int seed, int xPrimed, int yPrimed, int zPrimed)
{
int hash = seed ^ xPrimed ^ yPrimed ^ zPrimed;
hash *= 0x27d4eb2d;
return hash;
}
static float ValCoord(int seed, int xPrimed, int yPrimed)
{
int hash = Hash(seed, xPrimed, yPrimed);
hash *= hash;
hash ^= hash << 19;
return hash * (1 / 2147483648.0f);
}
static float ValCoord(int seed, int xPrimed, int yPrimed, int zPrimed)
{
int hash = Hash(seed, xPrimed, yPrimed, zPrimed);
hash *= hash;
hash ^= hash << 19;
return hash * (1 / 2147483648.0f);
}
float GradCoord(int seed, int xPrimed, int yPrimed, float xd, float yd) const
{
int hash = Hash(seed, xPrimed, yPrimed);
hash ^= hash >> 15;
hash &= 127 << 1;
float xg = Lookup<float>::Gradients2D[hash];
float yg = Lookup<float>::Gradients2D[hash | 1];
return xd * xg + yd * yg;
}
float GradCoord(int seed, int xPrimed, int yPrimed, int zPrimed, float xd, float yd, float zd) const
{
int hash = Hash(seed, xPrimed, yPrimed, zPrimed);
hash ^= hash >> 15;
hash &= 63 << 2;
float xg = Lookup<float>::Gradients3D[hash];
float yg = Lookup<float>::Gradients3D[hash | 1];
float zg = Lookup<float>::Gradients3D[hash | 2];
return xd * xg + yd * yg + zd * zg;
}
void GradCoordOut(int seed, int xPrimed, int yPrimed, float& xo, float& yo) const
{
int hash = Hash(seed, xPrimed, yPrimed) & (255 << 1);
xo = Lookup<float>::RandVecs2D[hash];
yo = Lookup<float>::RandVecs2D[hash | 1];
}
void GradCoordOut(int seed, int xPrimed, int yPrimed, int zPrimed, float& xo, float& yo, float& zo) const
{
int hash = Hash(seed, xPrimed, yPrimed, zPrimed) & (255 << 2);
xo = Lookup<float>::RandVecs3D[hash];
yo = Lookup<float>::RandVecs3D[hash | 1];
zo = Lookup<float>::RandVecs3D[hash | 2];
}
void GradCoordDual(int seed, int xPrimed, int yPrimed, float xd, float yd, float& xo, float& yo) const
{
int hash = Hash(seed, xPrimed, yPrimed);
int index1 = hash & (127 << 1);
int index2 = (hash >> 7) & (255 << 1);
float xg = Lookup<float>::Gradients2D[index1];
float yg = Lookup<float>::Gradients2D[index1 | 1];
float value = xd * xg + yd * yg;
float xgo = Lookup<float>::RandVecs2D[index2];
float ygo = Lookup<float>::RandVecs2D[index2 | 1];
xo = value * xgo;
yo = value * ygo;
}
void GradCoordDual(int seed, int xPrimed, int yPrimed, int zPrimed, float xd, float yd, float zd, float& xo, float& yo, float& zo) const
{
int hash = Hash(seed, xPrimed, yPrimed, zPrimed);
int index1 = hash & (63 << 2);
int index2 = (hash >> 6) & (255 << 2);
float xg = Lookup<float>::Gradients3D[index1];
float yg = Lookup<float>::Gradients3D[index1 | 1];
float zg = Lookup<float>::Gradients3D[index1 | 2];
float value = xd * xg + yd * yg + zd * zg;
float xgo = Lookup<float>::RandVecs3D[index2];
float ygo = Lookup<float>::RandVecs3D[index2 | 1];
float zgo = Lookup<float>::RandVecs3D[index2 | 2];
xo = value * xgo;
yo = value * ygo;
zo = value * zgo;
}
// Generic noise gen
template <typename FNfloat>
float GenNoiseSingle(int seed, FNfloat x, FNfloat y) const
{
switch (mNoiseType)
{
case NoiseType_OpenSimplex2:
return SingleSimplex(seed, x, y);
case NoiseType_OpenSimplex2S:
return SingleOpenSimplex2S(seed, x, y);
case NoiseType_Cellular:
return SingleCellular(seed, x, y);
case NoiseType_Perlin:
return SinglePerlin(seed, x, y);
case NoiseType_ValueCubic:
return SingleValueCubic(seed, x, y);
case NoiseType_Value:
return SingleValue(seed, x, y);
default:
return 0;
}
}
template <typename FNfloat>
float GenNoiseSingle(int seed, FNfloat x, FNfloat y, FNfloat z) const
{
switch (mNoiseType)
{
case NoiseType_OpenSimplex2:
return SingleOpenSimplex2(seed, x, y, z);
case NoiseType_OpenSimplex2S:
return SingleOpenSimplex2S(seed, x, y, z);
case NoiseType_Cellular:
return SingleCellular(seed, x, y, z);
case NoiseType_Perlin:
return SinglePerlin(seed, x, y, z);
case NoiseType_ValueCubic:
return SingleValueCubic(seed, x, y, z);
case NoiseType_Value:
return SingleValue(seed, x, y, z);
default:
return 0;
}
}
// Noise Coordinate Transforms (frequency, and possible skew or rotation)
template <typename FNfloat>
void TransformNoiseCoordinate(FNfloat& x, FNfloat& y) const
{
x *= mFrequency;
y *= mFrequency;
switch (mNoiseType)
{
case NoiseType_OpenSimplex2:
case NoiseType_OpenSimplex2S:
{
const FNfloat SQRT3 = (FNfloat)1.7320508075688772935274463415059;
const FNfloat F2 = 0.5f * (SQRT3 - 1);
FNfloat t = (x + y) * F2;
x += t;
y += t;
}
break;
default:
break;
}
}
template <typename FNfloat>
void TransformNoiseCoordinate(FNfloat& x, FNfloat& y, FNfloat& z) const
{
x *= mFrequency;
y *= mFrequency;
z *= mFrequency;
switch (mTransformType3D)
{
case TransformType3D_ImproveXYPlanes:
{
FNfloat xy = x + y;
FNfloat s2 = xy * -(FNfloat)0.211324865405187;
z *= (FNfloat)0.577350269189626;
x += s2 - z;
y = y + s2 - z;
z += xy * (FNfloat)0.577350269189626;
}
break;
case TransformType3D_ImproveXZPlanes:
{
FNfloat xz = x + z;
FNfloat s2 = xz * -(FNfloat)0.211324865405187;
y *= (FNfloat)0.577350269189626;
x += s2 - y;
z += s2 - y;
y += xz * (FNfloat)0.577350269189626;
}
break;
case TransformType3D_DefaultOpenSimplex2:
{
const FNfloat R3 = (FNfloat)(2.0 / 3.0);
FNfloat r = (x + y + z) * R3; // Rotation, not skew
x = r - x;
y = r - y;
z = r - z;
}
break;
default:
break;
}
}
void UpdateTransformType3D()
{
switch (mRotationType3D)
{
case RotationType3D_ImproveXYPlanes:
mTransformType3D = TransformType3D_ImproveXYPlanes;
break;
case RotationType3D_ImproveXZPlanes:
mTransformType3D = TransformType3D_ImproveXZPlanes;
break;
default:
switch (mNoiseType)
{
case NoiseType_OpenSimplex2:
case NoiseType_OpenSimplex2S:
mTransformType3D = TransformType3D_DefaultOpenSimplex2;
break;
default:
mTransformType3D = TransformType3D_None;
break;
}
break;
}
}
// Domain Warp Coordinate Transforms
template <typename FNfloat>
void TransformDomainWarpCoordinate(FNfloat& x, FNfloat& y) const
{
switch (mDomainWarpType)
{
case DomainWarpType_OpenSimplex2:
case DomainWarpType_OpenSimplex2Reduced:
{
const FNfloat SQRT3 = (FNfloat)1.7320508075688772935274463415059;
const FNfloat F2 = 0.5f * (SQRT3 - 1);
FNfloat t = (x + y) * F2;
x += t;
y += t;
}
break;
default:
break;
}
}
template <typename FNfloat>
void TransformDomainWarpCoordinate(FNfloat& x, FNfloat& y, FNfloat& z) const
{
switch (mWarpTransformType3D)
{
case TransformType3D_ImproveXYPlanes:
{
FNfloat xy = x + y;
FNfloat s2 = xy * -(FNfloat)0.211324865405187;
z *= (FNfloat)0.577350269189626;
x += s2 - z;
y = y + s2 - z;
z += xy * (FNfloat)0.577350269189626;
}
break;
case TransformType3D_ImproveXZPlanes:
{
FNfloat xz = x + z;
FNfloat s2 = xz * -(FNfloat)0.211324865405187;
y *= (FNfloat)0.577350269189626;
x += s2 - y;
z += s2 - y;
y += xz * (FNfloat)0.577350269189626;
}
break;
case TransformType3D_DefaultOpenSimplex2:
{
const FNfloat R3 = (FNfloat)(2.0 / 3.0);
FNfloat r = (x + y + z) * R3; // Rotation, not skew
x = r - x;
y = r - y;
z = r - z;
}
break;
default:
break;
}
}
void UpdateWarpTransformType3D()
{
switch (mRotationType3D)
{
case RotationType3D_ImproveXYPlanes:
mWarpTransformType3D = TransformType3D_ImproveXYPlanes;
break;
case RotationType3D_ImproveXZPlanes:
mWarpTransformType3D = TransformType3D_ImproveXZPlanes;
break;
default:
switch (mDomainWarpType)
{
case DomainWarpType_OpenSimplex2:
case DomainWarpType_OpenSimplex2Reduced:
mWarpTransformType3D = TransformType3D_DefaultOpenSimplex2;
break;
default:
mWarpTransformType3D = TransformType3D_None;
break;
}
break;
}
}
// Fractal FBm
template <typename FNfloat>
float GenFractalFBm(FNfloat x, FNfloat y) const
{
int seed = mSeed;
float sum = 0;
float amp = mFractalBounding;
for (int i = 0; i < mOctaves; i++)
{
float noise = GenNoiseSingle(seed++, x, y);
sum += noise * amp;
amp *= Lerp(1.0f, FastMin(noise + 1, 2) * 0.5f, mWeightedStrength);
x *= mLacunarity;
y *= mLacunarity;
amp *= mGain;
}
return sum;
}
template <typename FNfloat>
float GenFractalFBm(FNfloat x, FNfloat y, FNfloat z) const
{
int seed = mSeed;
float sum = 0;
float amp = mFractalBounding;
for (int i = 0; i < mOctaves; i++)
{
float noise = GenNoiseSingle(seed++, x, y, z);
sum += noise * amp;
amp *= Lerp(1.0f, (noise + 1) * 0.5f, mWeightedStrength);
x *= mLacunarity;
y *= mLacunarity;
z *= mLacunarity;
amp *= mGain;
}
return sum;
}
// Fractal Ridged
template <typename FNfloat>
float GenFractalRidged(FNfloat x, FNfloat y) const
{
int seed = mSeed;
float sum = 0;
float amp = mFractalBounding;
for (int i = 0; i < mOctaves; i++)
{
float noise = FastAbs(GenNoiseSingle(seed++, x, y));
sum += (noise * -2 + 1) * amp;
amp *= Lerp(1.0f, 1 - noise, mWeightedStrength);
x *= mLacunarity;
y *= mLacunarity;
amp *= mGain;
}
return sum;
}
template <typename FNfloat>
float GenFractalRidged(FNfloat x, FNfloat y, FNfloat z) const
{
int seed = mSeed;
float sum = 0;
float amp = mFractalBounding;
for (int i = 0; i < mOctaves; i++)
{
float noise = FastAbs(GenNoiseSingle(seed++, x, y, z));
sum += (noise * -2 + 1) * amp;
amp *= Lerp(1.0f, 1 - noise, mWeightedStrength);
x *= mLacunarity;
y *= mLacunarity;
z *= mLacunarity;
amp *= mGain;
}
return sum;
}
// Fractal PingPong
template <typename FNfloat>
float GenFractalPingPong(FNfloat x, FNfloat y) const
{
int seed = mSeed;
float sum = 0;
float amp = mFractalBounding;
for (int i = 0; i < mOctaves; i++)
{
float noise = PingPong((GenNoiseSingle(seed++, x, y) + 1) * mPingPongStrength);
sum += (noise - 0.5f) * 2 * amp;
amp *= Lerp(1.0f, noise, mWeightedStrength);
x *= mLacunarity;
y *= mLacunarity;
amp *= mGain;
}
return sum;
}
template <typename FNfloat>
float GenFractalPingPong(FNfloat x, FNfloat y, FNfloat z) const
{
int seed = mSeed;
float sum = 0;
float amp = mFractalBounding;
for (int i = 0; i < mOctaves; i++)
{
float noise = PingPong((GenNoiseSingle(seed++, x, y, z) + 1) * mPingPongStrength);
sum += (noise - 0.5f) * 2 * amp;
amp *= Lerp(1.0f, noise, mWeightedStrength);
x *= mLacunarity;
y *= mLacunarity;
z *= mLacunarity;
amp *= mGain;
}
return sum;
}
// Simplex/OpenSimplex2 Noise
template <typename FNfloat>
float SingleSimplex(int seed, FNfloat x, FNfloat y) const
{
// 2D OpenSimplex2 case uses the same algorithm as ordinary Simplex.
const float SQRT3 = 1.7320508075688772935274463415059f;
const float G2 = (3 - SQRT3) / 6;
/*
* --- Skew moved to TransformNoiseCoordinate method ---
* const FNfloat F2 = 0.5f * (SQRT3 - 1);
* FNfloat s = (x + y) * F2;
* x += s; y += s;
*/
int i = FastFloor(x);
int j = FastFloor(y);
float xi = (float)(x - i);
float yi = (float)(y - j);
float t = (xi + yi) * G2;
float x0 = (float)(xi - t);
float y0 = (float)(yi - t);
i *= PrimeX;
j *= PrimeY;
float n0, n1, n2;
float a = 0.5f - x0 * x0 - y0 * y0;
if (a <= 0) n0 = 0;
else
{
n0 = (a * a) * (a * a) * GradCoord(seed, i, j, x0, y0);
}
float c = (float)(2 * (1 - 2 * G2) * (1 / G2 - 2)) * t + ((float)(-2 * (1 - 2 * G2) * (1 - 2 * G2)) + a);
if (c <= 0) n2 = 0;
else
{
float x2 = x0 + (2 * (float)G2 - 1);
float y2 = y0 + (2 * (float)G2 - 1);
n2 = (c * c) * (c * c) * GradCoord(seed, i + PrimeX, j + PrimeY, x2, y2);
}
if (y0 > x0)
{
float x1 = x0 + (float)G2;
float y1 = y0 + ((float)G2 - 1);
float b = 0.5f - x1 * x1 - y1 * y1;
if (b <= 0) n1 = 0;
else
{
n1 = (b * b) * (b * b) * GradCoord(seed, i, j + PrimeY, x1, y1);
}
}
else
{
float x1 = x0 + ((float)G2 - 1);
float y1 = y0 + (float)G2;
float b = 0.5f - x1 * x1 - y1 * y1;
if (b <= 0) n1 = 0;
else
{
n1 = (b * b) * (b * b) * GradCoord(seed, i + PrimeX, j, x1, y1);
}
}
return (n0 + n1 + n2) * 99.83685446303647f;
}
template <typename FNfloat>
float SingleOpenSimplex2(int seed, FNfloat x, FNfloat y, FNfloat z) const
{
// 3D OpenSimplex2 case uses two offset rotated cube grids.
/*
* --- Rotation moved to TransformNoiseCoordinate method ---
* const FNfloat R3 = (FNfloat)(2.0 / 3.0);
* FNfloat r = (x + y + z) * R3; // Rotation, not skew
* x = r - x; y = r - y; z = r - z;
*/
int i = FastRound(x);
int j = FastRound(y);
int k = FastRound(z);
float x0 = (float)(x - i);
float y0 = (float)(y - j);
float z0 = (float)(z - k);
int xNSign = (int)(-1.0f - x0) | 1;
int yNSign = (int)(-1.0f - y0) | 1;
int zNSign = (int)(-1.0f - z0) | 1;
float ax0 = xNSign * -x0;
float ay0 = yNSign * -y0;
float az0 = zNSign * -z0;
i *= PrimeX;
j *= PrimeY;
k *= PrimeZ;
float value = 0;
float a = (0.6f - x0 * x0) - (y0 * y0 + z0 * z0);
for (int l = 0; ; l++)
{
if (a > 0)
{
value += (a * a) * (a * a) * GradCoord(seed, i, j, k, x0, y0, z0);
}
float b = a + 1;
int i1 = i;
int j1 = j;
int k1 = k;
float x1 = x0;
float y1 = y0;
float z1 = z0;
if (ax0 >= ay0 && ax0 >= az0)
{
x1 += xNSign;
b -= xNSign * 2 * x1;
i1 -= xNSign * PrimeX;
}
else if (ay0 > ax0 && ay0 >= az0)
{
y1 += yNSign;
b -= yNSign * 2 * y1;
j1 -= yNSign * PrimeY;
}
else
{
z1 += zNSign;
b -= zNSign * 2 * z1;
k1 -= zNSign * PrimeZ;
}
if (b > 0)
{
value += (b * b) * (b * b) * GradCoord(seed, i1, j1, k1, x1, y1, z1);
}
if (l == 1) break;
ax0 = 0.5f - ax0;
ay0 = 0.5f - ay0;
az0 = 0.5f - az0;
x0 = xNSign * ax0;
y0 = yNSign * ay0;
z0 = zNSign * az0;
a += (0.75f - ax0) - (ay0 + az0);
i += (xNSign >> 1) & PrimeX;
j += (yNSign >> 1) & PrimeY;
k += (zNSign >> 1) & PrimeZ;
xNSign = -xNSign;
yNSign = -yNSign;
zNSign = -zNSign;
seed = ~seed;
}
return value * 32.69428253173828125f;
}
// OpenSimplex2S Noise
template <typename FNfloat>
float SingleOpenSimplex2S(int seed, FNfloat x, FNfloat y) const
{
// 2D OpenSimplex2S case is a modified 2D simplex noise.
const FNfloat SQRT3 = (FNfloat)1.7320508075688772935274463415059;
const FNfloat G2 = (3 - SQRT3) / 6;
/*
* --- Skew moved to TransformNoiseCoordinate method ---
* const FNfloat F2 = 0.5f * (SQRT3 - 1);
* FNfloat s = (x + y) * F2;
* x += s; y += s;
*/
int i = FastFloor(x);
int j = FastFloor(y);
float xi = (float)(x - i);
float yi = (float)(y - j);
i *= PrimeX;
j *= PrimeY;
int i1 = i + PrimeX;
int j1 = j + PrimeY;
float t = (xi + yi) * (float)G2;
float x0 = xi - t;
float y0 = yi - t;
float a0 = (2.0f / 3.0f) - x0 * x0 - y0 * y0;
float value = (a0 * a0) * (a0 * a0) * GradCoord(seed, i, j, x0, y0);
float a1 = (float)(2 * (1 - 2 * G2) * (1 / G2 - 2)) * t + ((float)(-2 * (1 - 2 * G2) * (1 - 2 * G2)) + a0);
float x1 = x0 - (float)(1 - 2 * G2);
float y1 = y0 - (float)(1 - 2 * G2);
value += (a1 * a1) * (a1 * a1) * GradCoord(seed, i1, j1, x1, y1);
// Nested conditionals were faster than compact bit logic/arithmetic.
float xmyi = xi - yi;
if (t > G2)
{
if (xi + xmyi > 1)
{
float x2 = x0 + (float)(3 * G2 - 2);
float y2 = y0 + (float)(3 * G2 - 1);
float a2 = (2.0f / 3.0f) - x2 * x2 - y2 * y2;
if (a2 > 0)
{
value += (a2 * a2) * (a2 * a2) * GradCoord(seed, i + (PrimeX << 1), j + PrimeY, x2, y2);
}
}
else
{
float x2 = x0 + (float)G2;
float y2 = y0 + (float)(G2 - 1);
float a2 = (2.0f / 3.0f) - x2 * x2 - y2 * y2;
if (a2 > 0)
{
value += (a2 * a2) * (a2 * a2) * GradCoord(seed, i, j + PrimeY, x2, y2);
}
}
if (yi - xmyi > 1)
{
float x3 = x0 + (float)(3 * G2 - 1);
float y3 = y0 + (float)(3 * G2 - 2);
float a3 = (2.0f / 3.0f) - x3 * x3 - y3 * y3;
if (a3 > 0)
{
value += (a3 * a3) * (a3 * a3) * GradCoord(seed, i + PrimeX, j + (PrimeY << 1), x3, y3);
}
}
else
{
float x3 = x0 + (float)(G2 - 1);
float y3 = y0 + (float)G2;
float a3 = (2.0f / 3.0f) - x3 * x3 - y3 * y3;
if (a3 > 0)
{
value += (a3 * a3) * (a3 * a3) * GradCoord(seed, i + PrimeX, j, x3, y3);
}
}
}
else
{
if (xi + xmyi < 0)
{
float x2 = x0 + (float)(1 - G2);
float y2 = y0 - (float)G2;
float a2 = (2.0f / 3.0f) - x2 * x2 - y2 * y2;
if (a2 > 0)
{
value += (a2 * a2) * (a2 * a2) * GradCoord(seed, i - PrimeX, j, x2, y2);
}
}
else
{
float x2 = x0 + (float)(G2 - 1);
float y2 = y0 + (float)G2;
float a2 = (2.0f / 3.0f) - x2 * x2 - y2 * y2;
if (a2 > 0)
{
value += (a2 * a2) * (a2 * a2) * GradCoord(seed, i + PrimeX, j, x2, y2);
}
}
if (yi < xmyi)
{
float x2 = x0 - (float)G2;
float y2 = y0 - (float)(G2 - 1);
float a2 = (2.0f / 3.0f) - x2 * x2 - y2 * y2;
if (a2 > 0)
{
value += (a2 * a2) * (a2 * a2) * GradCoord(seed, i, j - PrimeY, x2, y2);
}
}
else
{
float x2 = x0 + (float)G2;
float y2 = y0 + (float)(G2 - 1);
float a2 = (2.0f / 3.0f) - x2 * x2 - y2 * y2;
if (a2 > 0)
{
value += (a2 * a2) * (a2 * a2) * GradCoord(seed, i, j + PrimeY, x2, y2);
}
}
}
return value * 18.24196194486065f;
}
template <typename FNfloat>
float SingleOpenSimplex2S(int seed, FNfloat x, FNfloat y, FNfloat z) const
{
// 3D OpenSimplex2S case uses two offset rotated cube grids.
/*
* --- Rotation moved to TransformNoiseCoordinate method ---
* const FNfloat R3 = (FNfloat)(2.0 / 3.0);
* FNfloat r = (x + y + z) * R3; // Rotation, not skew
* x = r - x; y = r - y; z = r - z;
*/
int i = FastFloor(x);
int j = FastFloor(y);
int k = FastFloor(z);
float xi = (float)(x - i);
float yi = (float)(y - j);
float zi = (float)(z - k);
i *= PrimeX;
j *= PrimeY;
k *= PrimeZ;
int seed2 = seed + 1293373;
int xNMask = (int)(-0.5f - xi);
int yNMask = (int)(-0.5f - yi);
int zNMask = (int)(-0.5f - zi);
float x0 = xi + xNMask;
float y0 = yi + yNMask;
float z0 = zi + zNMask;
float a0 = 0.75f - x0 * x0 - y0 * y0 - z0 * z0;
float value = (a0 * a0) * (a0 * a0) * GradCoord(seed,
i + (xNMask & PrimeX), j + (yNMask & PrimeY), k + (zNMask & PrimeZ), x0, y0, z0);
float x1 = xi - 0.5f;
float y1 = yi - 0.5f;
float z1 = zi - 0.5f;
float a1 = 0.75f - x1 * x1 - y1 * y1 - z1 * z1;
value += (a1 * a1) * (a1 * a1) * GradCoord(seed2,
i + PrimeX, j + PrimeY, k + PrimeZ, x1, y1, z1);
float xAFlipMask0 = ((xNMask | 1) << 1) * x1;
float yAFlipMask0 = ((yNMask | 1) << 1) * y1;
float zAFlipMask0 = ((zNMask | 1) << 1) * z1;
float xAFlipMask1 = (-2 - (xNMask << 2)) * x1 - 1.0f;
float yAFlipMask1 = (-2 - (yNMask << 2)) * y1 - 1.0f;
float zAFlipMask1 = (-2 - (zNMask << 2)) * z1 - 1.0f;
bool skip5 = false;
float a2 = xAFlipMask0 + a0;
if (a2 > 0)
{
float x2 = x0 - (xNMask | 1);
float y2 = y0;
float z2 = z0;
value += (a2 * a2) * (a2 * a2) * GradCoord(seed,
i + (~xNMask & PrimeX), j + (yNMask & PrimeY), k + (zNMask & PrimeZ), x2, y2, z2);
}
else
{
float a3 = yAFlipMask0 + zAFlipMask0 + a0;
if (a3 > 0)
{
float x3 = x0;
float y3 = y0 - (yNMask | 1);
float z3 = z0 - (zNMask | 1);
value += (a3 * a3) * (a3 * a3) * GradCoord(seed,
i + (xNMask & PrimeX), j + (~yNMask & PrimeY), k + (~zNMask & PrimeZ), x3, y3, z3);
}
float a4 = xAFlipMask1 + a1;
if (a4 > 0)
{
float x4 = (xNMask | 1) + x1;
float y4 = y1;
float z4 = z1;
value += (a4 * a4) * (a4 * a4) * GradCoord(seed2,
i + (xNMask & (PrimeX * 2)), j + PrimeY, k + PrimeZ, x4, y4, z4);
skip5 = true;
}
}
bool skip9 = false;
float a6 = yAFlipMask0 + a0;
if (a6 > 0)
{
float x6 = x0;
float y6 = y0 - (yNMask | 1);
float z6 = z0;
value += (a6 * a6) * (a6 * a6) * GradCoord(seed,
i + (xNMask & PrimeX), j + (~yNMask & PrimeY), k + (zNMask & PrimeZ), x6, y6, z6);
}
else
{
float a7 = xAFlipMask0 + zAFlipMask0 + a0;
if (a7 > 0)
{
float x7 = x0 - (xNMask | 1);
float y7 = y0;
float z7 = z0 - (zNMask | 1);
value += (a7 * a7) * (a7 * a7) * GradCoord(seed,
i + (~xNMask & PrimeX), j + (yNMask & PrimeY), k + (~zNMask & PrimeZ), x7, y7, z7);
}
float a8 = yAFlipMask1 + a1;
if (a8 > 0)
{
float x8 = x1;
float y8 = (yNMask | 1) + y1;
float z8 = z1;
value += (a8 * a8) * (a8 * a8) * GradCoord(seed2,
i + PrimeX, j + (yNMask & (PrimeY << 1)), k + PrimeZ, x8, y8, z8);
skip9 = true;
}
}
bool skipD = false;
float aA = zAFlipMask0 + a0;
if (aA > 0)
{
float xA = x0;
float yA = y0;
float zA = z0 - (zNMask | 1);
value += (aA * aA) * (aA * aA) * GradCoord(seed,
i + (xNMask & PrimeX), j + (yNMask & PrimeY), k + (~zNMask & PrimeZ), xA, yA, zA);
}
else
{
float aB = xAFlipMask0 + yAFlipMask0 + a0;
if (aB > 0)
{
float xB = x0 - (xNMask | 1);
float yB = y0 - (yNMask | 1);
float zB = z0;
value += (aB * aB) * (aB * aB) * GradCoord(seed,
i + (~xNMask & PrimeX), j + (~yNMask & PrimeY), k + (zNMask & PrimeZ), xB, yB, zB);
}
float aC = zAFlipMask1 + a1;
if (aC > 0)
{
float xC = x1;
float yC = y1;
float zC = (zNMask | 1) + z1;
value += (aC * aC) * (aC * aC) * GradCoord(seed2,
i + PrimeX, j + PrimeY, k + (zNMask & (PrimeZ << 1)), xC, yC, zC);
skipD = true;
}
}
if (!skip5)
{
float a5 = yAFlipMask1 + zAFlipMask1 + a1;
if (a5 > 0)
{
float x5 = x1;
float y5 = (yNMask | 1) + y1;
float z5 = (zNMask | 1) + z1;
value += (a5 * a5) * (a5 * a5) * GradCoord(seed2,
i + PrimeX, j + (yNMask & (PrimeY << 1)), k + (zNMask & (PrimeZ << 1)), x5, y5, z5);
}
}
if (!skip9)
{
float a9 = xAFlipMask1 + zAFlipMask1 + a1;
if (a9 > 0)
{
float x9 = (xNMask | 1) + x1;
float y9 = y1;
float z9 = (zNMask | 1) + z1;
value += (a9 * a9) * (a9 * a9) * GradCoord(seed2,
i + (xNMask & (PrimeX * 2)), j + PrimeY, k + (zNMask & (PrimeZ << 1)), x9, y9, z9);
}
}
if (!skipD)
{
float aD = xAFlipMask1 + yAFlipMask1 + a1;
if (aD > 0)
{
float xD = (xNMask | 1) + x1;
float yD = (yNMask | 1) + y1;
float zD = z1;
value += (aD * aD) * (aD * aD) * GradCoord(seed2,
i + (xNMask & (PrimeX << 1)), j + (yNMask & (PrimeY << 1)), k + PrimeZ, xD, yD, zD);
}
}
return value * 9.046026385208288f;
}
// Cellular Noise
template <typename FNfloat>
float SingleCellular(int seed, FNfloat x, FNfloat y) const
{
int xr = FastRound(x);
int yr = FastRound(y);
float distance0 = 1e10f;
float distance1 = 1e10f;
int closestHash = 0;
float cellularJitter = 0.43701595f * mCellularJitterModifier;
int xPrimed = (xr - 1) * PrimeX;
int yPrimedBase = (yr - 1) * PrimeY;
switch (mCellularDistanceFunction)
{
default:
case CellularDistanceFunction_Euclidean:
case CellularDistanceFunction_EuclideanSq:
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int hash = Hash(seed, xPrimed, yPrimed);
int idx = hash & (255 << 1);
float vecX = (float)(xi - x) + Lookup<float>::RandVecs2D[idx] * cellularJitter;
float vecY = (float)(yi - y) + Lookup<float>::RandVecs2D[idx | 1] * cellularJitter;
float newDistance = vecX * vecX + vecY * vecY;
distance1 = FastMax(FastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
yPrimed += PrimeY;
}
xPrimed += PrimeX;
}
break;
case CellularDistanceFunction_Manhattan:
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int hash = Hash(seed, xPrimed, yPrimed);
int idx = hash & (255 << 1);
float vecX = (float)(xi - x) + Lookup<float>::RandVecs2D[idx] * cellularJitter;
float vecY = (float)(yi - y) + Lookup<float>::RandVecs2D[idx | 1] * cellularJitter;
float newDistance = FastAbs(vecX) + FastAbs(vecY);
distance1 = FastMax(FastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
yPrimed += PrimeY;
}
xPrimed += PrimeX;
}
break;
case CellularDistanceFunction_Hybrid:
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int hash = Hash(seed, xPrimed, yPrimed);
int idx = hash & (255 << 1);
float vecX = (float)(xi - x) + Lookup<float>::RandVecs2D[idx] * cellularJitter;
float vecY = (float)(yi - y) + Lookup<float>::RandVecs2D[idx | 1] * cellularJitter;
float newDistance = (FastAbs(vecX) + FastAbs(vecY)) + (vecX * vecX + vecY * vecY);
distance1 = FastMax(FastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
yPrimed += PrimeY;
}
xPrimed += PrimeX;
}
break;
}
if (mCellularDistanceFunction == CellularDistanceFunction_Euclidean && mCellularReturnType >= CellularReturnType_Distance)
{
distance0 = FastSqrt(distance0);
if (mCellularReturnType >= CellularReturnType_Distance2)
{
distance1 = FastSqrt(distance1);
}
}
switch (mCellularReturnType)
{
case CellularReturnType_CellValue:
return closestHash * (1 / 2147483648.0f);
case CellularReturnType_Distance:
return distance0 - 1;
case CellularReturnType_Distance2:
return distance1 - 1;
case CellularReturnType_Distance2Add:
return (distance1 + distance0) * 0.5f - 1;
case CellularReturnType_Distance2Sub:
return distance1 - distance0 - 1;
case CellularReturnType_Distance2Mul:
return distance1 * distance0 * 0.5f - 1;
case CellularReturnType_Distance2Div:
return distance0 / distance1 - 1;
default:
return 0;
}
}
template <typename FNfloat>
float SingleCellular(int seed, FNfloat x, FNfloat y, FNfloat z) const
{
int xr = FastRound(x);
int yr = FastRound(y);
int zr = FastRound(z);
float distance0 = 1e10f;
float distance1 = 1e10f;
int closestHash = 0;
float cellularJitter = 0.39614353f * mCellularJitterModifier;
int xPrimed = (xr - 1) * PrimeX;
int yPrimedBase = (yr - 1) * PrimeY;
int zPrimedBase = (zr - 1) * PrimeZ;
switch (mCellularDistanceFunction)
{
case CellularDistanceFunction_Euclidean:
case CellularDistanceFunction_EuclideanSq:
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int zPrimed = zPrimedBase;
for (int zi = zr - 1; zi <= zr + 1; zi++)
{
int hash = Hash(seed, xPrimed, yPrimed, zPrimed);
int idx = hash & (255 << 2);
float vecX = (float)(xi - x) + Lookup<float>::RandVecs3D[idx] * cellularJitter;
float vecY = (float)(yi - y) + Lookup<float>::RandVecs3D[idx | 1] * cellularJitter;
float vecZ = (float)(zi - z) + Lookup<float>::RandVecs3D[idx | 2] * cellularJitter;
float newDistance = vecX * vecX + vecY * vecY + vecZ * vecZ;
distance1 = FastMax(FastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
zPrimed += PrimeZ;
}
yPrimed += PrimeY;
}
xPrimed += PrimeX;
}
break;
case CellularDistanceFunction_Manhattan:
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int zPrimed = zPrimedBase;
for (int zi = zr - 1; zi <= zr + 1; zi++)
{
int hash = Hash(seed, xPrimed, yPrimed, zPrimed);
int idx = hash & (255 << 2);
float vecX = (float)(xi - x) + Lookup<float>::RandVecs3D[idx] * cellularJitter;
float vecY = (float)(yi - y) + Lookup<float>::RandVecs3D[idx | 1] * cellularJitter;
float vecZ = (float)(zi - z) + Lookup<float>::RandVecs3D[idx | 2] * cellularJitter;
float newDistance = FastAbs(vecX) + FastAbs(vecY) + FastAbs(vecZ);
distance1 = FastMax(FastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
zPrimed += PrimeZ;
}
yPrimed += PrimeY;
}
xPrimed += PrimeX;
}
break;
case CellularDistanceFunction_Hybrid:
for (int xi = xr - 1; xi <= xr + 1; xi++)
{
int yPrimed = yPrimedBase;
for (int yi = yr - 1; yi <= yr + 1; yi++)
{
int zPrimed = zPrimedBase;
for (int zi = zr - 1; zi <= zr + 1; zi++)
{
int hash = Hash(seed, xPrimed, yPrimed, zPrimed);
int idx = hash & (255 << 2);
float vecX = (float)(xi - x) + Lookup<float>::RandVecs3D[idx] * cellularJitter;
float vecY = (float)(yi - y) + Lookup<float>::RandVecs3D[idx | 1] * cellularJitter;
float vecZ = (float)(zi - z) + Lookup<float>::RandVecs3D[idx | 2] * cellularJitter;
float newDistance = (FastAbs(vecX) + FastAbs(vecY) + FastAbs(vecZ)) + (vecX * vecX + vecY * vecY + vecZ * vecZ);
distance1 = FastMax(FastMin(distance1, newDistance), distance0);
if (newDistance < distance0)
{
distance0 = newDistance;
closestHash = hash;
}
zPrimed += PrimeZ;
}
yPrimed += PrimeY;
}
xPrimed += PrimeX;
}
break;
default:
break;
}
if (mCellularDistanceFunction == CellularDistanceFunction_Euclidean && mCellularReturnType >= CellularReturnType_Distance)
{
distance0 = FastSqrt(distance0);
if (mCellularReturnType >= CellularReturnType_Distance2)
{
distance1 = FastSqrt(distance1);
}
}
switch (mCellularReturnType)
{
case CellularReturnType_CellValue:
return closestHash * (1 / 2147483648.0f);
case CellularReturnType_Distance:
return distance0 - 1;
case CellularReturnType_Distance2:
return distance1 - 1;
case CellularReturnType_Distance2Add:
return (distance1 + distance0) * 0.5f - 1;
case CellularReturnType_Distance2Sub:
return distance1 - distance0 - 1;
case CellularReturnType_Distance2Mul:
return distance1 * distance0 * 0.5f - 1;
case CellularReturnType_Distance2Div:
return distance0 / distance1 - 1;
default:
return 0;
}
}
// Perlin Noise
template <typename FNfloat>
float SinglePerlin(int seed, FNfloat x, FNfloat y) const
{
int x0 = FastFloor(x);
int y0 = FastFloor(y);
float xd0 = (float)(x - x0);
float yd0 = (float)(y - y0);
float xd1 = xd0 - 1;
float yd1 = yd0 - 1;
float xs = InterpQuintic(xd0);
float ys = InterpQuintic(yd0);
x0 *= PrimeX;
y0 *= PrimeY;
int x1 = x0 + PrimeX;
int y1 = y0 + PrimeY;
float xf0 = Lerp(GradCoord(seed, x0, y0, xd0, yd0), GradCoord(seed, x1, y0, xd1, yd0), xs);
float xf1 = Lerp(GradCoord(seed, x0, y1, xd0, yd1), GradCoord(seed, x1, y1, xd1, yd1), xs);
return Lerp(xf0, xf1, ys) * 1.4247691104677813f;
}
template <typename FNfloat>
float SinglePerlin(int seed, FNfloat x, FNfloat y, FNfloat z) const
{
int x0 = FastFloor(x);
int y0 = FastFloor(y);
int z0 = FastFloor(z);
float xd0 = (float)(x - x0);
float yd0 = (float)(y - y0);
float zd0 = (float)(z - z0);
float xd1 = xd0 - 1;
float yd1 = yd0 - 1;
float zd1 = zd0 - 1;
float xs = InterpQuintic(xd0);
float ys = InterpQuintic(yd0);
float zs = InterpQuintic(zd0);
x0 *= PrimeX;
y0 *= PrimeY;
z0 *= PrimeZ;
int x1 = x0 + PrimeX;
int y1 = y0 + PrimeY;
int z1 = z0 + PrimeZ;
float xf00 = Lerp(GradCoord(seed, x0, y0, z0, xd0, yd0, zd0), GradCoord(seed, x1, y0, z0, xd1, yd0, zd0), xs);
float xf10 = Lerp(GradCoord(seed, x0, y1, z0, xd0, yd1, zd0), GradCoord(seed, x1, y1, z0, xd1, yd1, zd0), xs);
float xf01 = Lerp(GradCoord(seed, x0, y0, z1, xd0, yd0, zd1), GradCoord(seed, x1, y0, z1, xd1, yd0, zd1), xs);
float xf11 = Lerp(GradCoord(seed, x0, y1, z1, xd0, yd1, zd1), GradCoord(seed, x1, y1, z1, xd1, yd1, zd1), xs);
float yf0 = Lerp(xf00, xf10, ys);
float yf1 = Lerp(xf01, xf11, ys);
return Lerp(yf0, yf1, zs) * 0.964921414852142333984375f;
}
// Value Cubic Noise
template <typename FNfloat>
float SingleValueCubic(int seed, FNfloat x, FNfloat y) const
{
int x1 = FastFloor(x);
int y1 = FastFloor(y);
float xs = (float)(x - x1);
float ys = (float)(y - y1);
x1 *= PrimeX;
y1 *= PrimeY;
int x0 = x1 - PrimeX;
int y0 = y1 - PrimeY;
int x2 = x1 + PrimeX;
int y2 = y1 + PrimeY;
int x3 = x1 + (int)((long)PrimeX << 1);
int y3 = y1 + (int)((long)PrimeY << 1);
return CubicLerp(
CubicLerp(ValCoord(seed, x0, y0), ValCoord(seed, x1, y0), ValCoord(seed, x2, y0), ValCoord(seed, x3, y0),
xs),
CubicLerp(ValCoord(seed, x0, y1), ValCoord(seed, x1, y1), ValCoord(seed, x2, y1), ValCoord(seed, x3, y1),
xs),
CubicLerp(ValCoord(seed, x0, y2), ValCoord(seed, x1, y2), ValCoord(seed, x2, y2), ValCoord(seed, x3, y2),
xs),
CubicLerp(ValCoord(seed, x0, y3), ValCoord(seed, x1, y3), ValCoord(seed, x2, y3), ValCoord(seed, x3, y3),
xs),
ys) * (1 / (1.5f * 1.5f));
}
template <typename FNfloat>
float SingleValueCubic(int seed, FNfloat x, FNfloat y, FNfloat z) const
{
int x1 = FastFloor(x);
int y1 = FastFloor(y);
int z1 = FastFloor(z);
float xs = (float)(x - x1);
float ys = (float)(y - y1);
float zs = (float)(z - z1);
x1 *= PrimeX;
y1 *= PrimeY;
z1 *= PrimeZ;
int x0 = x1 - PrimeX;
int y0 = y1 - PrimeY;
int z0 = z1 - PrimeZ;
int x2 = x1 + PrimeX;
int y2 = y1 + PrimeY;
int z2 = z1 + PrimeZ;
int x3 = x1 + (int)((long)PrimeX << 1);
int y3 = y1 + (int)((long)PrimeY << 1);
int z3 = z1 + (int)((long)PrimeZ << 1);
return CubicLerp(
CubicLerp(
CubicLerp(ValCoord(seed, x0, y0, z0), ValCoord(seed, x1, y0, z0), ValCoord(seed, x2, y0, z0), ValCoord(seed, x3, y0, z0), xs),
CubicLerp(ValCoord(seed, x0, y1, z0), ValCoord(seed, x1, y1, z0), ValCoord(seed, x2, y1, z0), ValCoord(seed, x3, y1, z0), xs),
CubicLerp(ValCoord(seed, x0, y2, z0), ValCoord(seed, x1, y2, z0), ValCoord(seed, x2, y2, z0), ValCoord(seed, x3, y2, z0), xs),
CubicLerp(ValCoord(seed, x0, y3, z0), ValCoord(seed, x1, y3, z0), ValCoord(seed, x2, y3, z0), ValCoord(seed, x3, y3, z0), xs),
ys),
CubicLerp(
CubicLerp(ValCoord(seed, x0, y0, z1), ValCoord(seed, x1, y0, z1), ValCoord(seed, x2, y0, z1), ValCoord(seed, x3, y0, z1), xs),
CubicLerp(ValCoord(seed, x0, y1, z1), ValCoord(seed, x1, y1, z1), ValCoord(seed, x2, y1, z1), ValCoord(seed, x3, y1, z1), xs),
CubicLerp(ValCoord(seed, x0, y2, z1), ValCoord(seed, x1, y2, z1), ValCoord(seed, x2, y2, z1), ValCoord(seed, x3, y2, z1), xs),
CubicLerp(ValCoord(seed, x0, y3, z1), ValCoord(seed, x1, y3, z1), ValCoord(seed, x2, y3, z1), ValCoord(seed, x3, y3, z1), xs),
ys),
CubicLerp(
CubicLerp(ValCoord(seed, x0, y0, z2), ValCoord(seed, x1, y0, z2), ValCoord(seed, x2, y0, z2), ValCoord(seed, x3, y0, z2), xs),
CubicLerp(ValCoord(seed, x0, y1, z2), ValCoord(seed, x1, y1, z2), ValCoord(seed, x2, y1, z2), ValCoord(seed, x3, y1, z2), xs),
CubicLerp(ValCoord(seed, x0, y2, z2), ValCoord(seed, x1, y2, z2), ValCoord(seed, x2, y2, z2), ValCoord(seed, x3, y2, z2), xs),
CubicLerp(ValCoord(seed, x0, y3, z2), ValCoord(seed, x1, y3, z2), ValCoord(seed, x2, y3, z2), ValCoord(seed, x3, y3, z2), xs),
ys),
CubicLerp(
CubicLerp(ValCoord(seed, x0, y0, z3), ValCoord(seed, x1, y0, z3), ValCoord(seed, x2, y0, z3), ValCoord(seed, x3, y0, z3), xs),
CubicLerp(ValCoord(seed, x0, y1, z3), ValCoord(seed, x1, y1, z3), ValCoord(seed, x2, y1, z3), ValCoord(seed, x3, y1, z3), xs),
CubicLerp(ValCoord(seed, x0, y2, z3), ValCoord(seed, x1, y2, z3), ValCoord(seed, x2, y2, z3), ValCoord(seed, x3, y2, z3), xs),
CubicLerp(ValCoord(seed, x0, y3, z3), ValCoord(seed, x1, y3, z3), ValCoord(seed, x2, y3, z3), ValCoord(seed, x3, y3, z3), xs),
ys),
zs) * (1 / (1.5f * 1.5f * 1.5f));
}
// Value Noise
template <typename FNfloat>
float SingleValue(int seed, FNfloat x, FNfloat y) const
{
int x0 = FastFloor(x);
int y0 = FastFloor(y);
float xs = InterpHermite((float)(x - x0));
float ys = InterpHermite((float)(y - y0));
x0 *= PrimeX;
y0 *= PrimeY;
int x1 = x0 + PrimeX;
int y1 = y0 + PrimeY;
float xf0 = Lerp(ValCoord(seed, x0, y0), ValCoord(seed, x1, y0), xs);
float xf1 = Lerp(ValCoord(seed, x0, y1), ValCoord(seed, x1, y1), xs);
return Lerp(xf0, xf1, ys);
}
template <typename FNfloat>
float SingleValue(int seed, FNfloat x, FNfloat y, FNfloat z) const
{
int x0 = FastFloor(x);
int y0 = FastFloor(y);
int z0 = FastFloor(z);
float xs = InterpHermite((float)(x - x0));
float ys = InterpHermite((float)(y - y0));
float zs = InterpHermite((float)(z - z0));
x0 *= PrimeX;
y0 *= PrimeY;
z0 *= PrimeZ;
int x1 = x0 + PrimeX;
int y1 = y0 + PrimeY;
int z1 = z0 + PrimeZ;
float xf00 = Lerp(ValCoord(seed, x0, y0, z0), ValCoord(seed, x1, y0, z0), xs);
float xf10 = Lerp(ValCoord(seed, x0, y1, z0), ValCoord(seed, x1, y1, z0), xs);
float xf01 = Lerp(ValCoord(seed, x0, y0, z1), ValCoord(seed, x1, y0, z1), xs);
float xf11 = Lerp(ValCoord(seed, x0, y1, z1), ValCoord(seed, x1, y1, z1), xs);
float yf0 = Lerp(xf00, xf10, ys);
float yf1 = Lerp(xf01, xf11, ys);
return Lerp(yf0, yf1, zs);
}
// Domain Warp
template <typename FNfloat>
void DoSingleDomainWarp(int seed, float amp, float freq, FNfloat x, FNfloat y, FNfloat& xr, FNfloat& yr) const
{
switch (mDomainWarpType)
{
case DomainWarpType_OpenSimplex2:
SingleDomainWarpSimplexGradient(seed, amp * 38.283687591552734375f, freq, x, y, xr, yr, false);
break;
case DomainWarpType_OpenSimplex2Reduced:
SingleDomainWarpSimplexGradient(seed, amp * 16.0f, freq, x, y, xr, yr, true);
break;
case DomainWarpType_BasicGrid:
SingleDomainWarpBasicGrid(seed, amp, freq, x, y, xr, yr);
break;
}
}
template <typename FNfloat>
void DoSingleDomainWarp(int seed, float amp, float freq, FNfloat x, FNfloat y, FNfloat z, FNfloat& xr, FNfloat& yr, FNfloat& zr) const
{
switch (mDomainWarpType)
{
case DomainWarpType_OpenSimplex2:
SingleDomainWarpOpenSimplex2Gradient(seed, amp * 32.69428253173828125f, freq, x, y, z, xr, yr, zr, false);
break;
case DomainWarpType_OpenSimplex2Reduced:
SingleDomainWarpOpenSimplex2Gradient(seed, amp * 7.71604938271605f, freq, x, y, z, xr, yr, zr, true);
break;
case DomainWarpType_BasicGrid:
SingleDomainWarpBasicGrid(seed, amp, freq, x, y, z, xr, yr, zr);
break;
}
}
// Domain Warp Single Wrapper
template <typename FNfloat>
void DomainWarpSingle(FNfloat& x, FNfloat& y) const
{
int seed = mSeed;
float amp = mDomainWarpAmp * mFractalBounding;
float freq = mFrequency;
FNfloat xs = x;
FNfloat ys = y;
TransformDomainWarpCoordinate(xs, ys);
DoSingleDomainWarp(seed, amp, freq, xs, ys, x, y);
}
template <typename FNfloat>
void DomainWarpSingle(FNfloat& x, FNfloat& y, FNfloat& z) const
{
int seed = mSeed;
float amp = mDomainWarpAmp * mFractalBounding;
float freq = mFrequency;
FNfloat xs = x;
FNfloat ys = y;
FNfloat zs = z;
TransformDomainWarpCoordinate(xs, ys, zs);
DoSingleDomainWarp(seed, amp, freq, xs, ys, zs, x, y, z);
}
// Domain Warp Fractal Progressive
template <typename FNfloat>
void DomainWarpFractalProgressive(FNfloat& x, FNfloat& y) const
{
int seed = mSeed;
float amp = mDomainWarpAmp * mFractalBounding;
float freq = mFrequency;
for (int i = 0; i < mOctaves; i++)
{
FNfloat xs = x;
FNfloat ys = y;
TransformDomainWarpCoordinate(xs, ys);
DoSingleDomainWarp(seed, amp, freq, xs, ys, x, y);
seed++;
amp *= mGain;
freq *= mLacunarity;
}
}
template <typename FNfloat>
void DomainWarpFractalProgressive(FNfloat& x, FNfloat& y, FNfloat& z) const
{
int seed = mSeed;
float amp = mDomainWarpAmp * mFractalBounding;
float freq = mFrequency;
for (int i = 0; i < mOctaves; i++)
{
FNfloat xs = x;
FNfloat ys = y;
FNfloat zs = z;
TransformDomainWarpCoordinate(xs, ys, zs);
DoSingleDomainWarp(seed, amp, freq, xs, ys, zs, x, y, z);
seed++;
amp *= mGain;
freq *= mLacunarity;
}
}
// Domain Warp Fractal Independant
template <typename FNfloat>
void DomainWarpFractalIndependent(FNfloat& x, FNfloat& y) const
{
FNfloat xs = x;
FNfloat ys = y;
TransformDomainWarpCoordinate(xs, ys);
int seed = mSeed;
float amp = mDomainWarpAmp * mFractalBounding;
float freq = mFrequency;
for (int i = 0; i < mOctaves; i++)
{
DoSingleDomainWarp(seed, amp, freq, xs, ys, x, y);
seed++;
amp *= mGain;
freq *= mLacunarity;
}
}
template <typename FNfloat>
void DomainWarpFractalIndependent(FNfloat& x, FNfloat& y, FNfloat& z) const
{
FNfloat xs = x;
FNfloat ys = y;
FNfloat zs = z;
TransformDomainWarpCoordinate(xs, ys, zs);
int seed = mSeed;
float amp = mDomainWarpAmp * mFractalBounding;
float freq = mFrequency;
for (int i = 0; i < mOctaves; i++)
{
DoSingleDomainWarp(seed, amp, freq, xs, ys, zs, x, y, z);
seed++;
amp *= mGain;
freq *= mLacunarity;
}
}
// Domain Warp Basic Grid
template <typename FNfloat>
void SingleDomainWarpBasicGrid(int seed, float warpAmp, float frequency, FNfloat x, FNfloat y, FNfloat& xr, FNfloat& yr) const
{
FNfloat xf = x * frequency;
FNfloat yf = y * frequency;
int x0 = FastFloor(xf);
int y0 = FastFloor(yf);
float xs = InterpHermite((float)(xf - x0));
float ys = InterpHermite((float)(yf - y0));
x0 *= PrimeX;
y0 *= PrimeY;
int x1 = x0 + PrimeX;
int y1 = y0 + PrimeY;
int hash0 = Hash(seed, x0, y0) & (255 << 1);
int hash1 = Hash(seed, x1, y0) & (255 << 1);
float lx0x = Lerp(Lookup<float>::RandVecs2D[hash0], Lookup<float>::RandVecs2D[hash1], xs);
float ly0x = Lerp(Lookup<float>::RandVecs2D[hash0 | 1], Lookup<float>::RandVecs2D[hash1 | 1], xs);
hash0 = Hash(seed, x0, y1) & (255 << 1);
hash1 = Hash(seed, x1, y1) & (255 << 1);
float lx1x = Lerp(Lookup<float>::RandVecs2D[hash0], Lookup<float>::RandVecs2D[hash1], xs);
float ly1x = Lerp(Lookup<float>::RandVecs2D[hash0 | 1], Lookup<float>::RandVecs2D[hash1 | 1], xs);
xr += Lerp(lx0x, lx1x, ys) * warpAmp;
yr += Lerp(ly0x, ly1x, ys) * warpAmp;
}
template <typename FNfloat>
void SingleDomainWarpBasicGrid(int seed, float warpAmp, float frequency, FNfloat x, FNfloat y, FNfloat z, FNfloat& xr, FNfloat& yr, FNfloat& zr) const
{
FNfloat xf = x * frequency;
FNfloat yf = y * frequency;
FNfloat zf = z * frequency;
int x0 = FastFloor(xf);
int y0 = FastFloor(yf);
int z0 = FastFloor(zf);
float xs = InterpHermite((float)(xf - x0));
float ys = InterpHermite((float)(yf - y0));
float zs = InterpHermite((float)(zf - z0));
x0 *= PrimeX;
y0 *= PrimeY;
z0 *= PrimeZ;
int x1 = x0 + PrimeX;
int y1 = y0 + PrimeY;
int z1 = z0 + PrimeZ;
int hash0 = Hash(seed, x0, y0, z0) & (255 << 2);
int hash1 = Hash(seed, x1, y0, z0) & (255 << 2);
float lx0x = Lerp(Lookup<float>::RandVecs3D[hash0], Lookup<float>::RandVecs3D[hash1], xs);
float ly0x = Lerp(Lookup<float>::RandVecs3D[hash0 | 1], Lookup<float>::RandVecs3D[hash1 | 1], xs);
float lz0x = Lerp(Lookup<float>::RandVecs3D[hash0 | 2], Lookup<float>::RandVecs3D[hash1 | 2], xs);
hash0 = Hash(seed, x0, y1, z0) & (255 << 2);
hash1 = Hash(seed, x1, y1, z0) & (255 << 2);
float lx1x = Lerp(Lookup<float>::RandVecs3D[hash0], Lookup<float>::RandVecs3D[hash1], xs);
float ly1x = Lerp(Lookup<float>::RandVecs3D[hash0 | 1], Lookup<float>::RandVecs3D[hash1 | 1], xs);
float lz1x = Lerp(Lookup<float>::RandVecs3D[hash0 | 2], Lookup<float>::RandVecs3D[hash1 | 2], xs);
float lx0y = Lerp(lx0x, lx1x, ys);
float ly0y = Lerp(ly0x, ly1x, ys);
float lz0y = Lerp(lz0x, lz1x, ys);
hash0 = Hash(seed, x0, y0, z1) & (255 << 2);
hash1 = Hash(seed, x1, y0, z1) & (255 << 2);
lx0x = Lerp(Lookup<float>::RandVecs3D[hash0], Lookup<float>::RandVecs3D[hash1], xs);
ly0x = Lerp(Lookup<float>::RandVecs3D[hash0 | 1], Lookup<float>::RandVecs3D[hash1 | 1], xs);
lz0x = Lerp(Lookup<float>::RandVecs3D[hash0 | 2], Lookup<float>::RandVecs3D[hash1 | 2], xs);
hash0 = Hash(seed, x0, y1, z1) & (255 << 2);
hash1 = Hash(seed, x1, y1, z1) & (255 << 2);
lx1x = Lerp(Lookup<float>::RandVecs3D[hash0], Lookup<float>::RandVecs3D[hash1], xs);
ly1x = Lerp(Lookup<float>::RandVecs3D[hash0 | 1], Lookup<float>::RandVecs3D[hash1 | 1], xs);
lz1x = Lerp(Lookup<float>::RandVecs3D[hash0 | 2], Lookup<float>::RandVecs3D[hash1 | 2], xs);
xr += Lerp(lx0y, Lerp(lx0x, lx1x, ys), zs) * warpAmp;
yr += Lerp(ly0y, Lerp(ly0x, ly1x, ys), zs) * warpAmp;
zr += Lerp(lz0y, Lerp(lz0x, lz1x, ys), zs) * warpAmp;
}
// Domain Warp Simplex/OpenSimplex2
template <typename FNfloat>
void SingleDomainWarpSimplexGradient(int seed, float warpAmp, float frequency, FNfloat x, FNfloat y, FNfloat& xr, FNfloat& yr, bool outGradOnly) const
{
const float SQRT3 = 1.7320508075688772935274463415059f;
const float G2 = (3 - SQRT3) / 6;
x *= frequency;
y *= frequency;
/*
* --- Skew moved to TransformNoiseCoordinate method ---
* const FNfloat F2 = 0.5f * (SQRT3 - 1);
* FNfloat s = (x + y) * F2;
* x += s; y += s;
*/
int i = FastFloor(x);
int j = FastFloor(y);
float xi = (float)(x - i);
float yi = (float)(y - j);
float t = (xi + yi) * G2;
float x0 = (float)(xi - t);
float y0 = (float)(yi - t);
i *= PrimeX;
j *= PrimeY;
float vx, vy;
vx = vy = 0;
float a = 0.5f - x0 * x0 - y0 * y0;
if (a > 0)
{
float aaaa = (a * a) * (a * a);
float xo, yo;
if (outGradOnly)
GradCoordOut(seed, i, j, xo, yo);
else
GradCoordDual(seed, i, j, x0, y0, xo, yo);
vx += aaaa * xo;
vy += aaaa * yo;
}
float c = (float)(2 * (1 - 2 * G2) * (1 / G2 - 2)) * t + ((float)(-2 * (1 - 2 * G2) * (1 - 2 * G2)) + a);
if (c > 0)
{
float x2 = x0 + (2 * (float)G2 - 1);
float y2 = y0 + (2 * (float)G2 - 1);
float cccc = (c * c) * (c * c);
float xo, yo;
if (outGradOnly)
GradCoordOut(seed, i + PrimeX, j + PrimeY, xo, yo);
else
GradCoordDual(seed, i + PrimeX, j + PrimeY, x2, y2, xo, yo);
vx += cccc * xo;
vy += cccc * yo;
}
if (y0 > x0)
{
float x1 = x0 + (float)G2;
float y1 = y0 + ((float)G2 - 1);
float b = 0.5f - x1 * x1 - y1 * y1;
if (b > 0)
{
float bbbb = (b * b) * (b * b);
float xo, yo;
if (outGradOnly)
GradCoordOut(seed, i, j + PrimeY, xo, yo);
else
GradCoordDual(seed, i, j + PrimeY, x1, y1, xo, yo);
vx += bbbb * xo;
vy += bbbb * yo;
}
}
else
{
float x1 = x0 + ((float)G2 - 1);
float y1 = y0 + (float)G2;
float b = 0.5f - x1 * x1 - y1 * y1;
if (b > 0)
{
float bbbb = (b * b) * (b * b);
float xo, yo;
if (outGradOnly)
GradCoordOut(seed, i + PrimeX, j, xo, yo);
else
GradCoordDual(seed, i + PrimeX, j, x1, y1, xo, yo);
vx += bbbb * xo;
vy += bbbb * yo;
}
}
xr += vx * warpAmp;
yr += vy * warpAmp;
}
template <typename FNfloat>
void SingleDomainWarpOpenSimplex2Gradient(int seed, float warpAmp, float frequency, FNfloat x, FNfloat y, FNfloat z, FNfloat& xr, FNfloat& yr, FNfloat& zr, bool outGradOnly) const
{
x *= frequency;
y *= frequency;
z *= frequency;
/*
* --- Rotation moved to TransformDomainWarpCoordinate method ---
* const FNfloat R3 = (FNfloat)(2.0 / 3.0);
* FNfloat r = (x + y + z) * R3; // Rotation, not skew
* x = r - x; y = r - y; z = r - z;
*/
int i = FastRound(x);
int j = FastRound(y);
int k = FastRound(z);
float x0 = (float)x - i;
float y0 = (float)y - j;
float z0 = (float)z - k;
int xNSign = (int)(-x0 - 1.0f) | 1;
int yNSign = (int)(-y0 - 1.0f) | 1;
int zNSign = (int)(-z0 - 1.0f) | 1;
float ax0 = xNSign * -x0;
float ay0 = yNSign * -y0;
float az0 = zNSign * -z0;
i *= PrimeX;
j *= PrimeY;
k *= PrimeZ;
float vx, vy, vz;
vx = vy = vz = 0;
float a = (0.6f - x0 * x0) - (y0 * y0 + z0 * z0);
for (int l = 0; l < 2; l++)
{
if (a > 0)
{
float aaaa = (a * a) * (a * a);
float xo, yo, zo;
if (outGradOnly)
GradCoordOut(seed, i, j, k, xo, yo, zo);
else
GradCoordDual(seed, i, j, k, x0, y0, z0, xo, yo, zo);
vx += aaaa * xo;
vy += aaaa * yo;
vz += aaaa * zo;
}
float b = a + 1;
int i1 = i;
int j1 = j;
int k1 = k;
float x1 = x0;
float y1 = y0;
float z1 = z0;
if (ax0 >= ay0 && ax0 >= az0)
{
x1 += xNSign;
b -= xNSign * 2 * x1;
i1 -= xNSign * PrimeX;
}
else if (ay0 > ax0 && ay0 >= az0)
{
y1 += yNSign;
b -= yNSign * 2 * y1;
j1 -= yNSign * PrimeY;
}
else
{
z1 += zNSign;
b -= zNSign * 2 * z1;
k1 -= zNSign * PrimeZ;
}
if (b > 0)
{
float bbbb = (b * b) * (b * b);
float xo, yo, zo;
if (outGradOnly)
GradCoordOut(seed, i1, j1, k1, xo, yo, zo);
else
GradCoordDual(seed, i1, j1, k1, x1, y1, z1, xo, yo, zo);
vx += bbbb * xo;
vy += bbbb * yo;
vz += bbbb * zo;
}
if (l == 1) break;
ax0 = 0.5f - ax0;
ay0 = 0.5f - ay0;
az0 = 0.5f - az0;
x0 = xNSign * ax0;
y0 = yNSign * ay0;
z0 = zNSign * az0;
a += (0.75f - ax0) - (ay0 + az0);
i += (xNSign >> 1) & PrimeX;
j += (yNSign >> 1) & PrimeY;
k += (zNSign >> 1) & PrimeZ;
xNSign = -xNSign;
yNSign = -yNSign;
zNSign = -zNSign;
seed += 1293373;
}
xr += vx * warpAmp;
yr += vy * warpAmp;
zr += vz * warpAmp;
}
};
template <>
struct FastNoiseLite::Arguments_must_be_floating_point_values<float> {};
template <>
struct FastNoiseLite::Arguments_must_be_floating_point_values<double> {};
template <>
struct FastNoiseLite::Arguments_must_be_floating_point_values<long double> {};
template <typename T>
const T FastNoiseLite::Lookup<T>::Gradients2D[] =
{
0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, 0.793353340291235f, 0.793353340291235f, 0.608761429008721f,
0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, -0.130526192220051f, 0.923879532511287f, -0.38268343236509f,
0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, -0.923879532511287f, 0.130526192220052f, -0.99144486137381f,
-0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, -0.793353340291235f, -0.793353340291235f, -0.608761429008721f,
-0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, 0.130526192220051f, -0.923879532511287f, 0.38268343236509f,
-0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, 0.923879532511287f, -0.130526192220052f, 0.99144486137381f,
0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, 0.793353340291235f, 0.793353340291235f, 0.608761429008721f,
0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, -0.130526192220051f, 0.923879532511287f, -0.38268343236509f,
0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, -0.923879532511287f, 0.130526192220052f, -0.99144486137381f,
-0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, -0.793353340291235f, -0.793353340291235f, -0.608761429008721f,
-0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, 0.130526192220051f, -0.923879532511287f, 0.38268343236509f,
-0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, 0.923879532511287f, -0.130526192220052f, 0.99144486137381f,
0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, 0.793353340291235f, 0.793353340291235f, 0.608761429008721f,
0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, -0.130526192220051f, 0.923879532511287f, -0.38268343236509f,
0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, -0.923879532511287f, 0.130526192220052f, -0.99144486137381f,
-0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, -0.793353340291235f, -0.793353340291235f, -0.608761429008721f,
-0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, 0.130526192220051f, -0.923879532511287f, 0.38268343236509f,
-0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, 0.923879532511287f, -0.130526192220052f, 0.99144486137381f,
0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, 0.793353340291235f, 0.793353340291235f, 0.608761429008721f,
0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, -0.130526192220051f, 0.923879532511287f, -0.38268343236509f,
0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, -0.923879532511287f, 0.130526192220052f, -0.99144486137381f,
-0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, -0.793353340291235f, -0.793353340291235f, -0.608761429008721f,
-0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, 0.130526192220051f, -0.923879532511287f, 0.38268343236509f,
-0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, 0.923879532511287f, -0.130526192220052f, 0.99144486137381f,
0.130526192220052f, 0.99144486137381f, 0.38268343236509f, 0.923879532511287f, 0.608761429008721f, 0.793353340291235f, 0.793353340291235f, 0.608761429008721f,
0.923879532511287f, 0.38268343236509f, 0.99144486137381f, 0.130526192220051f, 0.99144486137381f, -0.130526192220051f, 0.923879532511287f, -0.38268343236509f,
0.793353340291235f, -0.60876142900872f, 0.608761429008721f, -0.793353340291235f, 0.38268343236509f, -0.923879532511287f, 0.130526192220052f, -0.99144486137381f,
-0.130526192220052f, -0.99144486137381f, -0.38268343236509f, -0.923879532511287f, -0.608761429008721f, -0.793353340291235f, -0.793353340291235f, -0.608761429008721f,
-0.923879532511287f, -0.38268343236509f, -0.99144486137381f, -0.130526192220052f, -0.99144486137381f, 0.130526192220051f, -0.923879532511287f, 0.38268343236509f,
-0.793353340291235f, 0.608761429008721f, -0.608761429008721f, 0.793353340291235f, -0.38268343236509f, 0.923879532511287f, -0.130526192220052f, 0.99144486137381f,
0.38268343236509f, 0.923879532511287f, 0.923879532511287f, 0.38268343236509f, 0.923879532511287f, -0.38268343236509f, 0.38268343236509f, -0.923879532511287f,
-0.38268343236509f, -0.923879532511287f, -0.923879532511287f, -0.38268343236509f, -0.923879532511287f, 0.38268343236509f, -0.38268343236509f, 0.923879532511287f,
};
template <typename T>
const T FastNoiseLite::Lookup<T>::RandVecs2D[] =
{
-0.2700222198f, -0.9628540911f, 0.3863092627f, -0.9223693152f, 0.04444859006f, -0.999011673f, -0.5992523158f, -0.8005602176f, -0.7819280288f, 0.6233687174f, 0.9464672271f, 0.3227999196f, -0.6514146797f, -0.7587218957f, 0.9378472289f, 0.347048376f,
-0.8497875957f, -0.5271252623f, -0.879042592f, 0.4767432447f, -0.892300288f, -0.4514423508f, -0.379844434f, -0.9250503802f, -0.9951650832f, 0.0982163789f, 0.7724397808f, -0.6350880136f, 0.7573283322f, -0.6530343002f, -0.9928004525f, -0.119780055f,
-0.0532665713f, 0.9985803285f, 0.9754253726f, -0.2203300762f, -0.7665018163f, 0.6422421394f, 0.991636706f, 0.1290606184f, -0.994696838f, 0.1028503788f, -0.5379205513f, -0.84299554f, 0.5022815471f, -0.8647041387f, 0.4559821461f, -0.8899889226f,
-0.8659131224f, -0.5001944266f, 0.0879458407f, -0.9961252577f, -0.5051684983f, 0.8630207346f, 0.7753185226f, -0.6315704146f, -0.6921944612f, 0.7217110418f, -0.5191659449f, -0.8546734591f, 0.8978622882f, -0.4402764035f, -0.1706774107f, 0.9853269617f,
-0.9353430106f, -0.3537420705f, -0.9992404798f, 0.03896746794f, -0.2882064021f, -0.9575683108f, -0.9663811329f, 0.2571137995f, -0.8759714238f, -0.4823630009f, -0.8303123018f, -0.5572983775f, 0.05110133755f, -0.9986934731f, -0.8558373281f, -0.5172450752f,
0.09887025282f, 0.9951003332f, 0.9189016087f, 0.3944867976f, -0.2439375892f, -0.9697909324f, -0.8121409387f, -0.5834613061f, -0.9910431363f, 0.1335421355f, 0.8492423985f, -0.5280031709f, -0.9717838994f, -0.2358729591f, 0.9949457207f, 0.1004142068f,
0.6241065508f, -0.7813392434f, 0.662910307f, 0.7486988212f, -0.7197418176f, 0.6942418282f, -0.8143370775f, -0.5803922158f, 0.104521054f, -0.9945226741f, -0.1065926113f, -0.9943027784f, 0.445799684f, -0.8951327509f, 0.105547406f, 0.9944142724f,
-0.992790267f, 0.1198644477f, -0.8334366408f, 0.552615025f, 0.9115561563f, -0.4111755999f, 0.8285544909f, -0.5599084351f, 0.7217097654f, -0.6921957921f, 0.4940492677f, -0.8694339084f, -0.3652321272f, -0.9309164803f, -0.9696606758f, 0.2444548501f,
0.08925509731f, -0.996008799f, 0.5354071276f, -0.8445941083f, -0.1053576186f, 0.9944343981f, -0.9890284586f, 0.1477251101f, 0.004856104961f, 0.9999882091f, 0.9885598478f, 0.1508291331f, 0.9286129562f, -0.3710498316f, -0.5832393863f, -0.8123003252f,
0.3015207509f, 0.9534596146f, -0.9575110528f, 0.2883965738f, 0.9715802154f, -0.2367105511f, 0.229981792f, 0.9731949318f, 0.955763816f, -0.2941352207f, 0.740956116f, 0.6715534485f, -0.9971513787f, -0.07542630764f, 0.6905710663f, -0.7232645452f,
-0.290713703f, -0.9568100872f, 0.5912777791f, -0.8064679708f, -0.9454592212f, -0.325740481f, 0.6664455681f, 0.74555369f, 0.6236134912f, 0.7817328275f, 0.9126993851f, -0.4086316587f, -0.8191762011f, 0.5735419353f, -0.8812745759f, -0.4726046147f,
0.9953313627f, 0.09651672651f, 0.9855650846f, -0.1692969699f, -0.8495980887f, 0.5274306472f, 0.6174853946f, -0.7865823463f, 0.8508156371f, 0.52546432f, 0.9985032451f, -0.05469249926f, 0.1971371563f, -0.9803759185f, 0.6607855748f, -0.7505747292f,
-0.03097494063f, 0.9995201614f, -0.6731660801f, 0.739491331f, -0.7195018362f, -0.6944905383f, 0.9727511689f, 0.2318515979f, 0.9997059088f, -0.0242506907f, 0.4421787429f, -0.8969269532f, 0.9981350961f, -0.061043673f, -0.9173660799f, -0.3980445648f,
-0.8150056635f, -0.5794529907f, -0.8789331304f, 0.4769450202f, 0.0158605829f, 0.999874213f, -0.8095464474f, 0.5870558317f, -0.9165898907f, -0.3998286786f, -0.8023542565f, 0.5968480938f, -0.5176737917f, 0.8555780767f, -0.8154407307f, -0.5788405779f,
0.4022010347f, -0.9155513791f, -0.9052556868f, -0.4248672045f, 0.7317445619f, 0.6815789728f, -0.5647632201f, -0.8252529947f, -0.8403276335f, -0.5420788397f, -0.9314281527f, 0.363925262f, 0.5238198472f, 0.8518290719f, 0.7432803869f, -0.6689800195f,
-0.985371561f, -0.1704197369f, 0.4601468731f, 0.88784281f, 0.825855404f, 0.5638819483f, 0.6182366099f, 0.7859920446f, 0.8331502863f, -0.553046653f, 0.1500307506f, 0.9886813308f, -0.662330369f, -0.7492119075f, -0.668598664f, 0.743623444f,
0.7025606278f, 0.7116238924f, -0.5419389763f, -0.8404178401f, -0.3388616456f, 0.9408362159f, 0.8331530315f, 0.5530425174f, -0.2989720662f, -0.9542618632f, 0.2638522993f, 0.9645630949f, 0.124108739f, -0.9922686234f, -0.7282649308f, -0.6852956957f,
0.6962500149f, 0.7177993569f, -0.9183535368f, 0.3957610156f, -0.6326102274f, -0.7744703352f, -0.9331891859f, -0.359385508f, -0.1153779357f, -0.9933216659f, 0.9514974788f, -0.3076565421f, -0.08987977445f, -0.9959526224f, 0.6678496916f, 0.7442961705f,
0.7952400393f, -0.6062947138f, -0.6462007402f, -0.7631674805f, -0.2733598753f, 0.9619118351f, 0.9669590226f, -0.254931851f, -0.9792894595f, 0.2024651934f, -0.5369502995f, -0.8436138784f, -0.270036471f, -0.9628500944f, -0.6400277131f, 0.7683518247f,
-0.7854537493f, -0.6189203566f, 0.06005905383f, -0.9981948257f, -0.02455770378f, 0.9996984141f, -0.65983623f, 0.751409442f, -0.6253894466f, -0.7803127835f, -0.6210408851f, -0.7837781695f, 0.8348888491f, 0.5504185768f, -0.1592275245f, 0.9872419133f,
0.8367622488f, 0.5475663786f, -0.8675753916f, -0.4973056806f, -0.2022662628f, -0.9793305667f, 0.9399189937f, 0.3413975472f, 0.9877404807f, -0.1561049093f, -0.9034455656f, 0.4287028224f, 0.1269804218f, -0.9919052235f, -0.3819600854f, 0.924178821f,
0.9754625894f, 0.2201652486f, -0.3204015856f, -0.9472818081f, -0.9874760884f, 0.1577687387f, 0.02535348474f, -0.9996785487f, 0.4835130794f, -0.8753371362f, -0.2850799925f, -0.9585037287f, -0.06805516006f, -0.99768156f, -0.7885244045f, -0.6150034663f,
0.3185392127f, -0.9479096845f, 0.8880043089f, 0.4598351306f, 0.6476921488f, -0.7619021462f, 0.9820241299f, 0.1887554194f, 0.9357275128f, -0.3527237187f, -0.8894895414f, 0.4569555293f, 0.7922791302f, 0.6101588153f, 0.7483818261f, 0.6632681526f,
-0.7288929755f, -0.6846276581f, 0.8729032783f, -0.4878932944f, 0.8288345784f, 0.5594937369f, 0.08074567077f, 0.9967347374f, 0.9799148216f, -0.1994165048f, -0.580730673f, -0.8140957471f, -0.4700049791f, -0.8826637636f, 0.2409492979f, 0.9705377045f,
0.9437816757f, -0.3305694308f, -0.8927998638f, -0.4504535528f, -0.8069622304f, 0.5906030467f, 0.06258973166f, 0.9980393407f, -0.9312597469f, 0.3643559849f, 0.5777449785f, 0.8162173362f, -0.3360095855f, -0.941858566f, 0.697932075f, -0.7161639607f,
-0.002008157227f, -0.9999979837f, -0.1827294312f, -0.9831632392f, -0.6523911722f, 0.7578824173f, -0.4302626911f, -0.9027037258f, -0.9985126289f, -0.05452091251f, -0.01028102172f, -0.9999471489f, -0.4946071129f, 0.8691166802f, -0.2999350194f, 0.9539596344f,
0.8165471961f, 0.5772786819f, 0.2697460475f, 0.962931498f, -0.7306287391f, -0.6827749597f, -0.7590952064f, -0.6509796216f, -0.907053853f, 0.4210146171f, -0.5104861064f, -0.8598860013f, 0.8613350597f, 0.5080373165f, 0.5007881595f, -0.8655698812f,
-0.654158152f, 0.7563577938f, -0.8382755311f, -0.545246856f, 0.6940070834f, 0.7199681717f, 0.06950936031f, 0.9975812994f, 0.1702942185f, -0.9853932612f, 0.2695973274f, 0.9629731466f, 0.5519612192f, -0.8338697815f, 0.225657487f, -0.9742067022f,
0.4215262855f, -0.9068161835f, 0.4881873305f, -0.8727388672f, -0.3683854996f, -0.9296731273f, -0.9825390578f, 0.1860564427f, 0.81256471f, 0.5828709909f, 0.3196460933f, -0.9475370046f, 0.9570913859f, 0.2897862643f, -0.6876655497f, -0.7260276109f,
-0.9988770922f, -0.047376731f, -0.1250179027f, 0.992154486f, -0.8280133617f, 0.560708367f, 0.9324863769f, -0.3612051451f, 0.6394653183f, 0.7688199442f, -0.01623847064f, -0.9998681473f, -0.9955014666f, -0.09474613458f, -0.81453315f, 0.580117012f,
0.4037327978f, -0.9148769469f, 0.9944263371f, 0.1054336766f, -0.1624711654f, 0.9867132919f, -0.9949487814f, -0.100383875f, -0.6995302564f, 0.7146029809f, 0.5263414922f, -0.85027327f, -0.5395221479f, 0.841971408f, 0.6579370318f, 0.7530729462f,
0.01426758847f, -0.9998982128f, -0.6734383991f, 0.7392433447f, 0.639412098f, -0.7688642071f, 0.9211571421f, 0.3891908523f, -0.146637214f, -0.9891903394f, -0.782318098f, 0.6228791163f, -0.5039610839f, -0.8637263605f, -0.7743120191f, -0.6328039957f,
};
template <typename T>
const T FastNoiseLite::Lookup<T>::Gradients3D[] =
{
0, 1, 1, 0, 0,-1, 1, 0, 0, 1,-1, 0, 0,-1,-1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0,-1, 0, -1, 0,-1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1,-1, 0, 0, -1,-1, 0, 0,
0, 1, 1, 0, 0,-1, 1, 0, 0, 1,-1, 0, 0,-1,-1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0,-1, 0, -1, 0,-1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1,-1, 0, 0, -1,-1, 0, 0,
0, 1, 1, 0, 0,-1, 1, 0, 0, 1,-1, 0, 0,-1,-1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0,-1, 0, -1, 0,-1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1,-1, 0, 0, -1,-1, 0, 0,
0, 1, 1, 0, 0,-1, 1, 0, 0, 1,-1, 0, 0,-1,-1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0,-1, 0, -1, 0,-1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1,-1, 0, 0, -1,-1, 0, 0,
0, 1, 1, 0, 0,-1, 1, 0, 0, 1,-1, 0, 0,-1,-1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0,-1, 0, -1, 0,-1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1,-1, 0, 0, -1,-1, 0, 0,
1, 1, 0, 0, 0,-1, 1, 0, -1, 1, 0, 0, 0,-1,-1, 0
};
template <typename T>
const T FastNoiseLite::Lookup<T>::RandVecs3D[] =
{
-0.7292736885f, -0.6618439697f, 0.1735581948f, 0, 0.790292081f, -0.5480887466f, -0.2739291014f, 0, 0.7217578935f, 0.6226212466f, -0.3023380997f, 0, 0.565683137f, -0.8208298145f, -0.0790000257f, 0, 0.760049034f, -0.5555979497f, -0.3370999617f, 0, 0.3713945616f, 0.5011264475f, 0.7816254623f, 0, -0.1277062463f, -0.4254438999f, -0.8959289049f, 0, -0.2881560924f, -0.5815838982f, 0.7607405838f, 0,
0.5849561111f, -0.662820239f, -0.4674352136f, 0, 0.3307171178f, 0.0391653737f, 0.94291689f, 0, 0.8712121778f, -0.4113374369f, -0.2679381538f, 0, 0.580981015f, 0.7021915846f, 0.4115677815f, 0, 0.503756873f, 0.6330056931f, -0.5878203852f, 0, 0.4493712205f, 0.601390195f, 0.6606022552f, 0, -0.6878403724f, 0.09018890807f, -0.7202371714f, 0, -0.5958956522f, -0.6469350577f, 0.475797649f, 0,
-0.5127052122f, 0.1946921978f, -0.8361987284f, 0, -0.9911507142f, -0.05410276466f, -0.1212153153f, 0, -0.2149721042f, 0.9720882117f, -0.09397607749f, 0, -0.7518650936f, -0.5428057603f, 0.3742469607f, 0, 0.5237068895f, 0.8516377189f, -0.02107817834f, 0, 0.6333504779f, 0.1926167129f, -0.7495104896f, 0, -0.06788241606f, 0.3998305789f, 0.9140719259f, 0, -0.5538628599f, -0.4729896695f, -0.6852128902f, 0,
-0.7261455366f, -0.5911990757f, 0.3509933228f, 0, -0.9229274737f, -0.1782808786f, 0.3412049336f, 0, -0.6968815002f, 0.6511274338f, 0.3006480328f, 0, 0.9608044783f, -0.2098363234f, -0.1811724921f, 0, 0.06817146062f, -0.9743405129f, 0.2145069156f, 0, -0.3577285196f, -0.6697087264f, -0.6507845481f, 0, -0.1868621131f, 0.7648617052f, -0.6164974636f, 0, -0.6541697588f, 0.3967914832f, 0.6439087246f, 0,
0.6993340405f, -0.6164538506f, 0.3618239211f, 0, -0.1546665739f, 0.6291283928f, 0.7617583057f, 0, -0.6841612949f, -0.2580482182f, -0.6821542638f, 0, 0.5383980957f, 0.4258654885f, 0.7271630328f, 0, -0.5026987823f, -0.7939832935f, -0.3418836993f, 0, 0.3202971715f, 0.2834415347f, 0.9039195862f, 0, 0.8683227101f, -0.0003762656404f, -0.4959995258f, 0, 0.791120031f, -0.08511045745f, 0.6057105799f, 0,
-0.04011016052f, -0.4397248749f, 0.8972364289f, 0, 0.9145119872f, 0.3579346169f, -0.1885487608f, 0, -0.9612039066f, -0.2756484276f, 0.01024666929f, 0, 0.6510361721f, -0.2877799159f, -0.7023778346f, 0, -0.2041786351f, 0.7365237271f, 0.644859585f, 0, -0.7718263711f, 0.3790626912f, 0.5104855816f, 0, -0.3060082741f, -0.7692987727f, 0.5608371729f, 0, 0.454007341f, -0.5024843065f, 0.7357899537f, 0,
0.4816795475f, 0.6021208291f, -0.6367380315f, 0, 0.6961980369f, -0.3222197429f, 0.641469197f, 0, -0.6532160499f, -0.6781148932f, 0.3368515753f, 0, 0.5089301236f, -0.6154662304f, -0.6018234363f, 0, -0.1635919754f, -0.9133604627f, -0.372840892f, 0, 0.52408019f, -0.8437664109f, 0.1157505864f, 0, 0.5902587356f, 0.4983817807f, -0.6349883666f, 0, 0.5863227872f, 0.494764745f, 0.6414307729f, 0,
0.6779335087f, 0.2341345225f, 0.6968408593f, 0, 0.7177054546f, -0.6858979348f, 0.120178631f, 0, -0.5328819713f, -0.5205125012f, 0.6671608058f, 0, -0.8654874251f, -0.0700727088f, -0.4960053754f, 0, -0.2861810166f, 0.7952089234f, 0.5345495242f, 0, -0.04849529634f, 0.9810836427f, -0.1874115585f, 0, -0.6358521667f, 0.6058348682f, 0.4781800233f, 0, 0.6254794696f, -0.2861619734f, 0.7258696564f, 0,
-0.2585259868f, 0.5061949264f, -0.8227581726f, 0, 0.02136306781f, 0.5064016808f, -0.8620330371f, 0, 0.200111773f, 0.8599263484f, 0.4695550591f, 0, 0.4743561372f, 0.6014985084f, -0.6427953014f, 0, 0.6622993731f, -0.5202474575f, -0.5391679918f, 0, 0.08084972818f, -0.6532720452f, 0.7527940996f, 0, -0.6893687501f, 0.0592860349f, 0.7219805347f, 0, -0.1121887082f, -0.9673185067f, 0.2273952515f, 0,
0.7344116094f, 0.5979668656f, -0.3210532909f, 0, 0.5789393465f, -0.2488849713f, 0.7764570201f, 0, 0.6988182827f, 0.3557169806f, -0.6205791146f, 0, -0.8636845529f, -0.2748771249f, -0.4224826141f, 0, -0.4247027957f, -0.4640880967f, 0.777335046f, 0, 0.5257722489f, -0.8427017621f, 0.1158329937f, 0, 0.9343830603f, 0.316302472f, -0.1639543925f, 0, -0.1016836419f, -0.8057303073f, -0.5834887393f, 0,
-0.6529238969f, 0.50602126f, -0.5635892736f, 0, -0.2465286165f, -0.9668205684f, -0.06694497494f, 0, -0.9776897119f, -0.2099250524f, -0.007368825344f, 0, 0.7736893337f, 0.5734244712f, 0.2694238123f, 0, -0.6095087895f, 0.4995678998f, 0.6155736747f, 0, 0.5794535482f, 0.7434546771f, 0.3339292269f, 0, -0.8226211154f, 0.08142581855f, 0.5627293636f, 0, -0.510385483f, 0.4703667658f, 0.7199039967f, 0,
-0.5764971849f, -0.07231656274f, -0.8138926898f, 0, 0.7250628871f, 0.3949971505f, -0.5641463116f, 0, -0.1525424005f, 0.4860840828f, -0.8604958341f, 0, -0.5550976208f, -0.4957820792f, 0.667882296f, 0, -0.1883614327f, 0.9145869398f, 0.357841725f, 0, 0.7625556724f, -0.5414408243f, -0.3540489801f, 0, -0.5870231946f, -0.3226498013f, -0.7424963803f, 0, 0.3051124198f, 0.2262544068f, -0.9250488391f, 0,
0.6379576059f, 0.577242424f, -0.5097070502f, 0, -0.5966775796f, 0.1454852398f, -0.7891830656f, 0, -0.658330573f, 0.6555487542f, -0.3699414651f, 0, 0.7434892426f, 0.2351084581f, 0.6260573129f, 0, 0.5562114096f, 0.8264360377f, -0.0873632843f, 0, -0.3028940016f, -0.8251527185f, 0.4768419182f, 0, 0.1129343818f, -0.985888439f, -0.1235710781f, 0, 0.5937652891f, -0.5896813806f, 0.5474656618f, 0,
0.6757964092f, -0.5835758614f, -0.4502648413f, 0, 0.7242302609f, -0.1152719764f, 0.6798550586f, 0, -0.9511914166f, 0.0753623979f, -0.2992580792f, 0, 0.2539470961f, -0.1886339355f, 0.9486454084f, 0, 0.571433621f, -0.1679450851f, -0.8032795685f, 0, -0.06778234979f, 0.3978269256f, 0.9149531629f, 0, 0.6074972649f, 0.733060024f, -0.3058922593f, 0, -0.5435478392f, 0.1675822484f, 0.8224791405f, 0,
-0.5876678086f, -0.3380045064f, -0.7351186982f, 0, -0.7967562402f, 0.04097822706f, -0.6029098428f, 0, -0.1996350917f, 0.8706294745f, 0.4496111079f, 0, -0.02787660336f, -0.9106232682f, -0.4122962022f, 0, -0.7797625996f, -0.6257634692f, 0.01975775581f, 0, -0.5211232846f, 0.7401644346f, -0.4249554471f, 0, 0.8575424857f, 0.4053272873f, -0.3167501783f, 0, 0.1045223322f, 0.8390195772f, -0.5339674439f, 0,
0.3501822831f, 0.9242524096f, -0.1520850155f, 0, 0.1987849858f, 0.07647613266f, 0.9770547224f, 0, 0.7845996363f, 0.6066256811f, -0.1280964233f, 0, 0.09006737436f, -0.9750989929f, -0.2026569073f, 0, -0.8274343547f, -0.542299559f, 0.1458203587f, 0, -0.3485797732f, -0.415802277f, 0.840000362f, 0, -0.2471778936f, -0.7304819962f, -0.6366310879f, 0, -0.3700154943f, 0.8577948156f, 0.3567584454f, 0,
0.5913394901f, -0.548311967f, -0.5913303597f, 0, 0.1204873514f, -0.7626472379f, -0.6354935001f, 0, 0.616959265f, 0.03079647928f, 0.7863922953f, 0, 0.1258156836f, -0.6640829889f, -0.7369967419f, 0, -0.6477565124f, -0.1740147258f, -0.7417077429f, 0, 0.6217889313f, -0.7804430448f, -0.06547655076f, 0, 0.6589943422f, -0.6096987708f, 0.4404473475f, 0, -0.2689837504f, -0.6732403169f, -0.6887635427f, 0,
-0.3849775103f, 0.5676542638f, 0.7277093879f, 0, 0.5754444408f, 0.8110471154f, -0.1051963504f, 0, 0.9141593684f, 0.3832947817f, 0.131900567f, 0, -0.107925319f, 0.9245493968f, 0.3654593525f, 0, 0.377977089f, 0.3043148782f, 0.8743716458f, 0, -0.2142885215f, -0.8259286236f, 0.5214617324f, 0, 0.5802544474f, 0.4148098596f, -0.7008834116f, 0, -0.1982660881f, 0.8567161266f, -0.4761596756f, 0,
-0.03381553704f, 0.3773180787f, -0.9254661404f, 0, -0.6867922841f, -0.6656597827f, 0.2919133642f, 0, 0.7731742607f, -0.2875793547f, -0.5652430251f, 0, -0.09655941928f, 0.9193708367f, -0.3813575004f, 0, 0.2715702457f, -0.9577909544f, -0.09426605581f, 0, 0.2451015704f, -0.6917998565f, -0.6792188003f, 0, 0.977700782f, -0.1753855374f, 0.1155036542f, 0, -0.5224739938f, 0.8521606816f, 0.02903615945f, 0,
-0.7734880599f, -0.5261292347f, 0.3534179531f, 0, -0.7134492443f, -0.269547243f, 0.6467878011f, 0, 0.1644037271f, 0.5105846203f, -0.8439637196f, 0, 0.6494635788f, 0.05585611296f, 0.7583384168f, 0, -0.4711970882f, 0.5017280509f, -0.7254255765f, 0, -0.6335764307f, -0.2381686273f, -0.7361091029f, 0, -0.9021533097f, -0.270947803f, -0.3357181763f, 0, -0.3793711033f, 0.872258117f, 0.3086152025f, 0,
-0.6855598966f, -0.3250143309f, 0.6514394162f, 0, 0.2900942212f, -0.7799057743f, -0.5546100667f, 0, -0.2098319339f, 0.85037073f, 0.4825351604f, 0, -0.4592603758f, 0.6598504336f, -0.5947077538f, 0, 0.8715945488f, 0.09616365406f, -0.4807031248f, 0, -0.6776666319f, 0.7118504878f, -0.1844907016f, 0, 0.7044377633f, 0.312427597f, 0.637304036f, 0, -0.7052318886f, -0.2401093292f, -0.6670798253f, 0,
0.081921007f, -0.7207336136f, -0.6883545647f, 0, -0.6993680906f, -0.5875763221f, -0.4069869034f, 0, -0.1281454481f, 0.6419895885f, 0.7559286424f, 0, -0.6337388239f, -0.6785471501f, -0.3714146849f, 0, 0.5565051903f, -0.2168887573f, -0.8020356851f, 0, -0.5791554484f, 0.7244372011f, -0.3738578718f, 0, 0.1175779076f, -0.7096451073f, 0.6946792478f, 0, -0.6134619607f, 0.1323631078f, 0.7785527795f, 0,
0.6984635305f, -0.02980516237f, -0.715024719f, 0, 0.8318082963f, -0.3930171956f, 0.3919597455f, 0, 0.1469576422f, 0.05541651717f, -0.9875892167f, 0, 0.708868575f, -0.2690503865f, 0.6520101478f, 0, 0.2726053183f, 0.67369766f, -0.68688995f, 0, -0.6591295371f, 0.3035458599f, -0.6880466294f, 0, 0.4815131379f, -0.7528270071f, 0.4487723203f, 0, 0.9430009463f, 0.1675647412f, -0.2875261255f, 0,
0.434802957f, 0.7695304522f, -0.4677277752f, 0, 0.3931996188f, 0.594473625f, 0.7014236729f, 0, 0.7254336655f, -0.603925654f, 0.3301814672f, 0, 0.7590235227f, -0.6506083235f, 0.02433313207f, 0, -0.8552768592f, -0.3430042733f, 0.3883935666f, 0, -0.6139746835f, 0.6981725247f, 0.3682257648f, 0, -0.7465905486f, -0.5752009504f, 0.3342849376f, 0, 0.5730065677f, 0.810555537f, -0.1210916791f, 0,
-0.9225877367f, -0.3475211012f, -0.167514036f, 0, -0.7105816789f, -0.4719692027f, -0.5218416899f, 0, -0.08564609717f, 0.3583001386f, 0.929669703f, 0, -0.8279697606f, -0.2043157126f, 0.5222271202f, 0, 0.427944023f, 0.278165994f, 0.8599346446f, 0, 0.5399079671f, -0.7857120652f, -0.3019204161f, 0, 0.5678404253f, -0.5495413974f, -0.6128307303f, 0, -0.9896071041f, 0.1365639107f, -0.04503418428f, 0,
-0.6154342638f, -0.6440875597f, 0.4543037336f, 0, 0.1074204368f, -0.7946340692f, 0.5975094525f, 0, -0.3595449969f, -0.8885529948f, 0.28495784f, 0, -0.2180405296f, 0.1529888965f, 0.9638738118f, 0, -0.7277432317f, -0.6164050508f, -0.3007234646f, 0, 0.7249729114f, -0.00669719484f, 0.6887448187f, 0, -0.5553659455f, -0.5336586252f, 0.6377908264f, 0, 0.5137558015f, 0.7976208196f, -0.3160000073f, 0,
-0.3794024848f, 0.9245608561f, -0.03522751494f, 0, 0.8229248658f, 0.2745365933f, -0.4974176556f, 0, -0.5404114394f, 0.6091141441f, 0.5804613989f, 0, 0.8036581901f, -0.2703029469f, 0.5301601931f, 0, 0.6044318879f, 0.6832968393f, 0.4095943388f, 0, 0.06389988817f, 0.9658208605f, -0.2512108074f, 0, 0.1087113286f, 0.7402471173f, -0.6634877936f, 0, -0.713427712f, -0.6926784018f, 0.1059128479f, 0,
0.6458897819f, -0.5724548511f, -0.5050958653f, 0, -0.6553931414f, 0.7381471625f, 0.159995615f, 0, 0.3910961323f, 0.9188871375f, -0.05186755998f, 0, -0.4879022471f, -0.5904376907f, 0.6429111375f, 0, 0.6014790094f, 0.7707441366f, -0.2101820095f, 0, -0.5677173047f, 0.7511360995f, 0.3368851762f, 0, 0.7858573506f, 0.226674665f, 0.5753666838f, 0, -0.4520345543f, -0.604222686f, -0.6561857263f, 0,
0.002272116345f, 0.4132844051f, -0.9105991643f, 0, -0.5815751419f, -0.5162925989f, 0.6286591339f, 0, -0.03703704785f, 0.8273785755f, 0.5604221175f, 0, -0.5119692504f, 0.7953543429f, -0.3244980058f, 0, -0.2682417366f, -0.9572290247f, -0.1084387619f, 0, -0.2322482736f, -0.9679131102f, -0.09594243324f, 0, 0.3554328906f, -0.8881505545f, 0.2913006227f, 0, 0.7346520519f, -0.4371373164f, 0.5188422971f, 0,
0.9985120116f, 0.04659011161f, -0.02833944577f, 0, -0.3727687496f, -0.9082481361f, 0.1900757285f, 0, 0.91737377f, -0.3483642108f, 0.1925298489f, 0, 0.2714911074f, 0.4147529736f, -0.8684886582f, 0, 0.5131763485f, -0.7116334161f, 0.4798207128f, 0, -0.8737353606f, 0.18886992f, -0.4482350644f, 0, 0.8460043821f, -0.3725217914f, 0.3814499973f, 0, 0.8978727456f, -0.1780209141f, -0.4026575304f, 0,
0.2178065647f, -0.9698322841f, -0.1094789531f, 0, -0.1518031304f, -0.7788918132f, -0.6085091231f, 0, -0.2600384876f, -0.4755398075f, -0.8403819825f, 0, 0.572313509f, -0.7474340931f, -0.3373418503f, 0, -0.7174141009f, 0.1699017182f, -0.6756111411f, 0, -0.684180784f, 0.02145707593f, -0.7289967412f, 0, -0.2007447902f, 0.06555605789f, -0.9774476623f, 0, -0.1148803697f, -0.8044887315f, 0.5827524187f, 0,
-0.7870349638f, 0.03447489231f, 0.6159443543f, 0, -0.2015596421f, 0.6859872284f, 0.6991389226f, 0, -0.08581082512f, -0.10920836f, -0.9903080513f, 0, 0.5532693395f, 0.7325250401f, -0.396610771f, 0, -0.1842489331f, -0.9777375055f, -0.1004076743f, 0, 0.0775473789f, -0.9111505856f, 0.4047110257f, 0, 0.1399838409f, 0.7601631212f, -0.6344734459f, 0, 0.4484419361f, -0.845289248f, 0.2904925424f, 0
};
#endif
``` | /content/code_sandbox/Cpp/FastNoiseLite.h | objective-c | 2016-03-28T02:35:12 | 2024-08-16T07:09:20 | FastNoiseLite | Auburn/FastNoiseLite | 2,688 | 40,106 |
```go
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// .'',;:cldxkO00KKXXNNWWWNNXKOkxdollcc::::::;:::ccllloooolllllllllooollc:,'... ...........',;cldxkO000Okxdlc::;;;,,;;;::cclllllll
// ..',;:ldxO0KXXNNNNNNNNXXK0kxdolcc::::::;;;,,,,,,;;;;;;;;;;:::cclllllc:;'.... ...........',;:ldxO0KXXXK0Okxdolc::;;;;::cllodddddo
// ...',:loxO0KXNNNNNXXKK0Okxdolc::;::::::::;;;,,'''''.....''',;:clllllc:;,'............''''''''',;:loxO0KXNNNNNXK0Okxdollccccllodxxxxxxd
// ....';:ldkO0KXXXKK00Okxdolcc:;;;;;::cclllcc:;;,''..... ....',;clooddolcc:;;;;,,;;;;;::::;;;;;;:cloxk0KXNWWWWWWNXKK0Okxddoooddxxkkkkkxx
// .....';:ldxkOOOOOkxxdolcc:;;;,,,;;:cllooooolcc:;'... ..,:codxkkkxddooollloooooooollcc:::::clodkO0KXNWWWWWWNNXK00Okxxxxxxxxkkkkxxx
// . ....';:cloddddo___________,,,,;;:clooddddoolc:,... ..,:ldx__00OOOkkk___kkkkkkxxdollc::::cclodkO0KXXNNNNNNXXK0OOkxxxxxxxxxxxxddd
// .......',;:cccc:| |,,,;;:cclooddddoll:;'.. ..';cox| \KKK000| |KK00OOkxdocc___;::clldxxkO0KKKKK00Okkxdddddddddddddddoo
// .......'',,,,,''| ________|',,;;::cclloooooolc:;'......___:ldk| \KK000| |XKKK0Okxolc| |;;::cclodxxkkkkxxdoolllcclllooodddooooo
// ''......''''....| | ....'',,,,;;;::cclloooollc:;,''.'| |oxk| \OOO0| |KKK00Oxdoll|___|;;;;;::ccllllllcc::;;,,;;;:cclloooooooo
// ;;,''.......... | |_____',,;;;____:___cllo________.___| |___| \xkk| |KK_______ool___:::;________;;;_______...'',;;:ccclllloo
// c:;,''......... | |:::/ ' |lo/ | | \dx| |0/ \d| |cc/ |'/ \......',,;;:ccllo
// ol:;,'..........| _____|ll/ __ |o/ ______|____ ___| | \o| |/ ___ \| |o/ ______|/ ___ \ .......'',;:clo
// dlc;,...........| |::clooo| / | |x\___ \KXKKK0| |dol| |\ \| | | | | |d\___ \..| | / / ....',:cl
// xoc;'... .....'| |llodddd| \__| |_____\ \KKK0O| |lc:| |'\ | |___| | |_____\ \.| |_/___/... ...',;:c
// dlc;'... ....',;| |oddddddo\ | |Okkx| |::;| |..\ |\ /| | | \ |... ....',;:c
// ol:,'.......',:c|___|xxxddollc\_____,___|_________/ddoll|___|,,,|___|...\_____|:\ ______/l|___|_________/...\________|'........',;::cc
// c:;'.......';:codxxkkkkxxolc::;::clodxkOO0OOkkxdollc::;;,,''''',,,,''''''''''',,'''''',;:loxkkOOkxol:;,'''',,;:ccllcc:;,'''''',;::ccll
// ;,'.......',:codxkOO0OOkxdlc:;,,;;:cldxxkkxxdolc:;;,,''.....'',;;:::;;,,,'''''........,;cldkO0KK0Okdoc::;;::cloodddoolc:;;;;;::ccllooo
// .........',;:lodxOO0000Okdoc:,,',,;:clloddoolc:;,''.......'',;:clooollc:;;,,''.......',:ldkOKXNNXX0Oxdolllloddxxxxxxdolccccccllooodddd
// . .....';:cldxkO0000Okxol:;,''',,;::cccc:;,,'.......'',;:cldxxkkxxdolc:;;,'.......';coxOKXNWWWNXKOkxddddxxkkkkkkxdoollllooddxxxxkkk
// ....',;:codxkO000OOxdoc:;,''',,,;;;;,''.......',,;:clodkO00000Okxolc::;,,''..',;:ldxOKXNWWWNNK0OkkkkkkkkkkkxxddooooodxxkOOOOO000
// ....',;;clodxkkOOOkkdolc:;,,,,,,,,'..........,;:clodxkO0KKXKK0Okxdolcc::;;,,,;;:codkO0XXNNNNXKK0OOOOOkkkkxxdoollloodxkO0KKKXXXXX
//
// VERSION: 1.1.1
// path_to_url
package fastnoise
import (
"math"
)
// Float represents a floating-point number type.
type Float interface {
float32 | float64
}
// Enum types
type (
// NoiseType describes a noise algorithm.
NoiseType int
// RotationType3D describes a rotation method to apply to 3D noise.
RotationType3D int
// FractalType describes the fractal method for fractal noise types.
FractalType int
// CellularDistanceFunc describes the method for cellular distance functions.
CellularDistanceFunc int
// CellularReturnType describes the return type for cellular distance noise.
CellularReturnType int
// DomainWarpType describes the method used for domain warps.
DomainWarpType int
)
const (
OpenSimplex2 NoiseType = iota
OpenSimplex2S
Cellular
Perlin
ValueCubic
Value
TypeCount // The number of noise types
)
const (
RotationNone RotationType3D = iota
RotationImproveXYPlanes
RotationImproveXZPlanes
)
const (
FractalNone FractalType = iota
FractalFBm
FractalRidged
FractalPingPong
FractalDomainWarpProgressive
FractalDomainWarpIndependent
)
const (
CellularDistanceEuclidean CellularDistanceFunc = iota
CellularDistanceEuclideanSq
CellularDistanceManhattan
CellularDistanceHybrid
)
const (
CellularReturnCellValue CellularReturnType = iota
CellularReturnDistance
CellularReturnDistance2
CellularReturnDistance2Add
CellularReturnDistance2Sub
CellularReturnDistance2Mul
CellularReturnDistance2Div
)
const (
DomainWarpOpenSimplex2 DomainWarpType = iota
DomainWarpOpenSimplex2Reduced
DomainWarpBasicGrid
)
type (
// noise2DFunc is a prototype for a function that generates 2D noise.
noise2DFunc[T Float] func(state *State[T], seed int, x, y T) T
// noise3DFunc is a prototype for a function that generates 3D noise.
noise3DFunc[T Float] func(state *State[T], seed int, x, y, z T) T
)
// State contains the configuration for generating a noise. This should only be created
// with NewState, as it will initialize with sane defaults, including any private members.
//
// May be used to generate either float32 or float64 values.
type State[T Float] struct {
// Seed for all noise types.
//
// Default: 1337
Seed int
// Frequency for all noise types.
//
// Default: 0.01
Frequency T
// noiseType specifies the algorithm that will be used with GetNoise2D and GetNoise3D.
//
// Default: OpenSimplex2
noiseType NoiseType
// RotationType3D specified the type of rotation applied to 3D noise.
//
// Default: RotationNone
RotationType3D RotationType3D
// fractalType specifies the method used for combining octaves for all fractal noise types.
// Only effects DomainWarp2D and DomainWarp3D functions.
//
// Default: FractalNone
fractalType FractalType
// Octaves is the number of octaves used for all fractal noise types.
//
// Default: 3
Octaves int
// Lacunarity is the octave Lacunarity for all fractal noise types.
//
// Default: 2.0
Lacunarity T
// Gain is the octave gain for all fractal noise types.
//
// Default: 0.5
Gain T
// WeightedStrength is the octave weighting for all non-domain warp fractal types.
//
// Default: 0.0
WeightedStrength T
// PingPongStrength is the strength of the fractal ping pong effect.
//
// Default: 2.0
PingPongStrength T
// CellularDistanceFunc specifies the distance function used in cellular noise calculations.
//
// Default: CellularDistanceEuclideanSq,
CellularDistanceFunc CellularDistanceFunc
// CellularReturnType specifies the cellular return type from cellular noise calculations.
//
// Default: CellularReturnDistance,
CellularReturnType CellularReturnType
// CellularJitterMod is the maximum distance a cellular point can move from it's grid position.
// Setting this higher than 1 will cause artifacts.
//
// Default: 1.0
CellularJitterMod T
// DomainWarpType specifies the algorithm when using DomainWarp2D or DomainWarp3D.
//
// Default: DomainWarpOpenSimplex2
DomainWarpType DomainWarpType
// DomainWarpAmp is the maximum warp distance from original position when using DomainWarp2D
// or DomainWarp3D.
//
// Default: 1.0
DomainWarpAmp T
// noise2D contains the function used to generate 2D noise based on the state settings.
noise2D noise2DFunc[T]
// noise3D contains the function used to generate 3D noise based on the state settings.
noise3D noise3DFunc[T]
}
// Constants
var gradients2D = []float32{
0.130526192220052, 0.99144486137381, 0.38268343236509, 0.923879532511287, 0.608761429008721, 0.793353340291235, 0.793353340291235, 0.608761429008721,
0.923879532511287, 0.38268343236509, 0.99144486137381, 0.130526192220051, 0.99144486137381, -0.130526192220051, 0.923879532511287, -0.38268343236509,
0.793353340291235, -0.60876142900872, 0.608761429008721, -0.793353340291235, 0.38268343236509, -0.923879532511287, 0.130526192220052, -0.99144486137381,
-0.130526192220052, -0.99144486137381, -0.38268343236509, -0.923879532511287, -0.608761429008721, -0.793353340291235, -0.793353340291235, -0.608761429008721,
-0.923879532511287, -0.38268343236509, -0.99144486137381, -0.130526192220052, -0.99144486137381, 0.130526192220051, -0.923879532511287, 0.38268343236509,
-0.793353340291235, 0.608761429008721, -0.608761429008721, 0.793353340291235, -0.38268343236509, 0.923879532511287, -0.130526192220052, 0.99144486137381,
0.130526192220052, 0.99144486137381, 0.38268343236509, 0.923879532511287, 0.608761429008721, 0.793353340291235, 0.793353340291235, 0.608761429008721,
0.923879532511287, 0.38268343236509, 0.99144486137381, 0.130526192220051, 0.99144486137381, -0.130526192220051, 0.923879532511287, -0.38268343236509,
0.793353340291235, -0.60876142900872, 0.608761429008721, -0.793353340291235, 0.38268343236509, -0.923879532511287, 0.130526192220052, -0.99144486137381,
-0.130526192220052, -0.99144486137381, -0.38268343236509, -0.923879532511287, -0.608761429008721, -0.793353340291235, -0.793353340291235, -0.608761429008721,
-0.923879532511287, -0.38268343236509, -0.99144486137381, -0.130526192220052, -0.99144486137381, 0.130526192220051, -0.923879532511287, 0.38268343236509,
-0.793353340291235, 0.608761429008721, -0.608761429008721, 0.793353340291235, -0.38268343236509, 0.923879532511287, -0.130526192220052, 0.99144486137381,
0.130526192220052, 0.99144486137381, 0.38268343236509, 0.923879532511287, 0.608761429008721, 0.793353340291235, 0.793353340291235, 0.608761429008721,
0.923879532511287, 0.38268343236509, 0.99144486137381, 0.130526192220051, 0.99144486137381, -0.130526192220051, 0.923879532511287, -0.38268343236509,
0.793353340291235, -0.60876142900872, 0.608761429008721, -0.793353340291235, 0.38268343236509, -0.923879532511287, 0.130526192220052, -0.99144486137381,
-0.130526192220052, -0.99144486137381, -0.38268343236509, -0.923879532511287, -0.608761429008721, -0.793353340291235, -0.793353340291235, -0.608761429008721,
-0.923879532511287, -0.38268343236509, -0.99144486137381, -0.130526192220052, -0.99144486137381, 0.130526192220051, -0.923879532511287, 0.38268343236509,
-0.793353340291235, 0.608761429008721, -0.608761429008721, 0.793353340291235, -0.38268343236509, 0.923879532511287, -0.130526192220052, 0.99144486137381,
0.130526192220052, 0.99144486137381, 0.38268343236509, 0.923879532511287, 0.608761429008721, 0.793353340291235, 0.793353340291235, 0.608761429008721,
0.923879532511287, 0.38268343236509, 0.99144486137381, 0.130526192220051, 0.99144486137381, -0.130526192220051, 0.923879532511287, -0.38268343236509,
0.793353340291235, -0.60876142900872, 0.608761429008721, -0.793353340291235, 0.38268343236509, -0.923879532511287, 0.130526192220052, -0.99144486137381,
-0.130526192220052, -0.99144486137381, -0.38268343236509, -0.923879532511287, -0.608761429008721, -0.793353340291235, -0.793353340291235, -0.608761429008721,
-0.923879532511287, -0.38268343236509, -0.99144486137381, -0.130526192220052, -0.99144486137381, 0.130526192220051, -0.923879532511287, 0.38268343236509,
-0.793353340291235, 0.608761429008721, -0.608761429008721, 0.793353340291235, -0.38268343236509, 0.923879532511287, -0.130526192220052, 0.99144486137381,
0.130526192220052, 0.99144486137381, 0.38268343236509, 0.923879532511287, 0.608761429008721, 0.793353340291235, 0.793353340291235, 0.608761429008721,
0.923879532511287, 0.38268343236509, 0.99144486137381, 0.130526192220051, 0.99144486137381, -0.130526192220051, 0.923879532511287, -0.38268343236509,
0.793353340291235, -0.60876142900872, 0.608761429008721, -0.793353340291235, 0.38268343236509, -0.923879532511287, 0.130526192220052, -0.99144486137381,
-0.130526192220052, -0.99144486137381, -0.38268343236509, -0.923879532511287, -0.608761429008721, -0.793353340291235, -0.793353340291235, -0.608761429008721,
-0.923879532511287, -0.38268343236509, -0.99144486137381, -0.130526192220052, -0.99144486137381, 0.130526192220051, -0.923879532511287, 0.38268343236509,
-0.793353340291235, 0.608761429008721, -0.608761429008721, 0.793353340291235, -0.38268343236509, 0.923879532511287, -0.130526192220052, 0.99144486137381,
0.38268343236509, 0.923879532511287, 0.923879532511287, 0.38268343236509, 0.923879532511287, -0.38268343236509, 0.38268343236509, -0.923879532511287,
-0.38268343236509, -0.923879532511287, -0.923879532511287, -0.38268343236509, -0.923879532511287, 0.38268343236509, -0.38268343236509, 0.923879532511287,
}
var randVecs2D = []float32{
-0.2700222198, -0.9628540911, 0.3863092627, -0.9223693152,
0.04444859006, -0.999011673, -0.5992523158, -0.8005602176,
-0.7819280288, 0.6233687174, 0.9464672271, 0.3227999196,
-0.6514146797, -0.7587218957, 0.9378472289, 0.347048376,
-0.8497875957, -0.5271252623, -0.879042592, 0.4767432447,
-0.892300288, -0.4514423508, -0.379844434, -0.9250503802,
-0.9951650832, 0.0982163789, 0.7724397808, -0.6350880136,
0.7573283322, -0.6530343002, -0.9928004525, -0.119780055,
-0.0532665713, 0.9985803285, 0.9754253726, -0.2203300762,
-0.7665018163, 0.6422421394, 0.991636706, 0.1290606184,
-0.994696838, 0.1028503788, -0.5379205513, -0.84299554,
0.5022815471, -0.8647041387, 0.4559821461, -0.8899889226,
-0.8659131224, -0.5001944266, 0.0879458407, -0.9961252577,
-0.5051684983, 0.8630207346, 0.7753185226, -0.6315704146,
-0.6921944612, 0.7217110418, -0.5191659449, -0.8546734591,
0.8978622882, -0.4402764035, -0.1706774107, 0.9853269617,
-0.9353430106, -0.3537420705, -0.9992404798, 0.03896746794,
-0.2882064021, -0.9575683108, -0.9663811329, 0.2571137995,
-0.8759714238, -0.4823630009, -0.8303123018, -0.5572983775,
0.05110133755, -0.9986934731, -0.8558373281, -0.5172450752,
0.09887025282, 0.9951003332, 0.9189016087, 0.3944867976,
-0.2439375892, -0.9697909324, -0.8121409387, -0.5834613061,
-0.9910431363, 0.1335421355, 0.8492423985, -0.5280031709,
-0.9717838994, -0.2358729591, 0.9949457207, 0.1004142068,
0.6241065508, -0.7813392434, 0.662910307, 0.7486988212,
-0.7197418176, 0.6942418282, -0.8143370775, -0.5803922158,
0.104521054, -0.9945226741, -0.1065926113, -0.9943027784,
0.445799684, -0.8951327509, 0.105547406, 0.9944142724,
-0.992790267, 0.1198644477, -0.8334366408, 0.552615025,
0.9115561563, -0.4111755999, 0.8285544909, -0.5599084351,
0.7217097654, -0.6921957921, 0.4940492677, -0.8694339084,
-0.3652321272, -0.9309164803, -0.9696606758, 0.2444548501,
0.08925509731, -0.996008799, 0.5354071276, -0.8445941083,
-0.1053576186, 0.9944343981, -0.9890284586, 0.1477251101,
0.004856104961, 0.9999882091, 0.9885598478, 0.1508291331,
0.9286129562, -0.3710498316, -0.5832393863, -0.8123003252,
0.3015207509, 0.9534596146, -0.9575110528, 0.2883965738,
0.9715802154, -0.2367105511, 0.229981792, 0.9731949318,
0.955763816, -0.2941352207, 0.740956116, 0.6715534485,
-0.9971513787, -0.07542630764, 0.6905710663, -0.7232645452,
-0.290713703, -0.9568100872, 0.5912777791, -0.8064679708,
-0.9454592212, -0.325740481, 0.6664455681, 0.74555369,
0.6236134912, 0.7817328275, 0.9126993851, -0.4086316587,
-0.8191762011, 0.5735419353, -0.8812745759, -0.4726046147,
0.9953313627, 0.09651672651, 0.9855650846, -0.1692969699,
-0.8495980887, 0.5274306472, 0.6174853946, -0.7865823463,
0.8508156371, 0.52546432, 0.9985032451, -0.05469249926,
0.1971371563, -0.9803759185, 0.6607855748, -0.7505747292,
-0.03097494063, 0.9995201614, -0.6731660801, 0.739491331,
-0.7195018362, -0.6944905383, 0.9727511689, 0.2318515979,
0.9997059088, -0.0242506907, 0.4421787429, -0.8969269532,
0.9981350961, -0.061043673, -0.9173660799, -0.3980445648,
-0.8150056635, -0.5794529907, -0.8789331304, 0.4769450202,
0.0158605829, 0.999874213, -0.8095464474, 0.5870558317,
-0.9165898907, -0.3998286786, -0.8023542565, 0.5968480938,
-0.5176737917, 0.8555780767, -0.8154407307, -0.5788405779,
0.4022010347, -0.9155513791, -0.9052556868, -0.4248672045,
0.7317445619, 0.6815789728, -0.5647632201, -0.8252529947,
-0.8403276335, -0.5420788397, -0.9314281527, 0.363925262,
0.5238198472, 0.8518290719, 0.7432803869, -0.6689800195,
-0.985371561, -0.1704197369, 0.4601468731, 0.88784281,
0.825855404, 0.5638819483, 0.6182366099, 0.7859920446,
0.8331502863, -0.553046653, 0.1500307506, 0.9886813308,
-0.662330369, -0.7492119075, -0.668598664, 0.743623444,
0.7025606278, 0.7116238924, -0.5419389763, -0.8404178401,
-0.3388616456, 0.9408362159, 0.8331530315, 0.5530425174,
-0.2989720662, -0.9542618632, 0.2638522993, 0.9645630949,
0.124108739, -0.9922686234, -0.7282649308, -0.6852956957,
0.6962500149, 0.7177993569, -0.9183535368, 0.3957610156,
-0.6326102274, -0.7744703352, -0.9331891859, -0.359385508,
-0.1153779357, -0.9933216659, 0.9514974788, -0.3076565421,
-0.08987977445, -0.9959526224, 0.6678496916, 0.7442961705,
0.7952400393, -0.6062947138, -0.6462007402, -0.7631674805,
-0.2733598753, 0.9619118351, 0.9669590226, -0.254931851,
-0.9792894595, 0.2024651934, -0.5369502995, -0.8436138784,
-0.270036471, -0.9628500944, -0.6400277131, 0.7683518247,
-0.7854537493, -0.6189203566, 0.06005905383, -0.9981948257,
-0.02455770378, 0.9996984141, -0.65983623, 0.751409442,
-0.6253894466, -0.7803127835, -0.6210408851, -0.7837781695,
0.8348888491, 0.5504185768, -0.1592275245, 0.9872419133,
0.8367622488, 0.5475663786, -0.8675753916, -0.4973056806,
-0.2022662628, -0.9793305667, 0.9399189937, 0.3413975472,
0.9877404807, -0.1561049093, -0.9034455656, 0.4287028224,
0.1269804218, -0.9919052235, -0.3819600854, 0.924178821,
0.9754625894, 0.2201652486, -0.3204015856, -0.9472818081,
-0.9874760884, 0.1577687387, 0.02535348474, -0.9996785487,
0.4835130794, -0.8753371362, -0.2850799925, -0.9585037287,
-0.06805516006, -0.99768156, -0.7885244045, -0.6150034663,
0.3185392127, -0.9479096845, 0.8880043089, 0.4598351306,
0.6476921488, -0.7619021462, 0.9820241299, 0.1887554194,
0.9357275128, -0.3527237187, -0.8894895414, 0.4569555293,
0.7922791302, 0.6101588153, 0.7483818261, 0.6632681526,
-0.7288929755, -0.6846276581, 0.8729032783, -0.4878932944,
0.8288345784, 0.5594937369, 0.08074567077, 0.9967347374,
0.9799148216, -0.1994165048, -0.580730673, -0.8140957471,
-0.4700049791, -0.8826637636, 0.2409492979, 0.9705377045,
0.9437816757, -0.3305694308, -0.8927998638, -0.4504535528,
-0.8069622304, 0.5906030467, 0.06258973166, 0.9980393407,
-0.9312597469, 0.3643559849, 0.5777449785, 0.8162173362,
-0.3360095855, -0.941858566, 0.697932075, -0.7161639607,
-0.002008157227, -0.9999979837, -0.1827294312, -0.9831632392,
-0.6523911722, 0.7578824173, -0.4302626911, -0.9027037258,
-0.9985126289, -0.05452091251, -0.01028102172, -0.9999471489,
-0.4946071129, 0.8691166802, -0.2999350194, 0.9539596344,
0.8165471961, 0.5772786819, 0.2697460475, 0.962931498,
-0.7306287391, -0.6827749597, -0.7590952064, -0.6509796216,
-0.907053853, 0.4210146171, -0.5104861064, -0.8598860013,
0.8613350597, 0.5080373165, 0.5007881595, -0.8655698812,
-0.654158152, 0.7563577938, -0.8382755311, -0.545246856,
0.6940070834, 0.7199681717, 0.06950936031, 0.9975812994,
0.1702942185, -0.9853932612, 0.2695973274, 0.9629731466,
0.5519612192, -0.8338697815, 0.225657487, -0.9742067022,
0.4215262855, -0.9068161835, 0.4881873305, -0.8727388672,
-0.3683854996, -0.9296731273, -0.9825390578, 0.1860564427,
0.81256471, 0.5828709909, 0.3196460933, -0.9475370046,
0.9570913859, 0.2897862643, -0.6876655497, -0.7260276109,
-0.9988770922, -0.047376731, -0.1250179027, 0.992154486,
-0.8280133617, 0.560708367, 0.9324863769, -0.3612051451,
0.6394653183, 0.7688199442, -0.01623847064, -0.9998681473,
-0.9955014666, -0.09474613458, -0.81453315, 0.580117012,
0.4037327978, -0.9148769469, 0.9944263371, 0.1054336766,
-0.1624711654, 0.9867132919, -0.9949487814, -0.100383875,
-0.6995302564, 0.7146029809, 0.5263414922, -0.85027327,
-0.5395221479, 0.841971408, 0.6579370318, 0.7530729462,
0.01426758847, -0.9998982128, -0.6734383991, 0.7392433447,
0.639412098, -0.7688642071, 0.9211571421, 0.3891908523,
-0.146637214, -0.9891903394, -0.782318098, 0.6228791163,
-0.5039610839, -0.8637263605, -0.7743120191, -0.6328039957,
}
var gradients3D = []float32{
0, 1, 1, 0, 0, -1, 1, 0, 0, 1, -1, 0, 0, -1, -1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0, -1, 0, -1, 0, -1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1, -1, 0, 0, -1, -1, 0, 0,
0, 1, 1, 0, 0, -1, 1, 0, 0, 1, -1, 0, 0, -1, -1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0, -1, 0, -1, 0, -1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1, -1, 0, 0, -1, -1, 0, 0,
0, 1, 1, 0, 0, -1, 1, 0, 0, 1, -1, 0, 0, -1, -1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0, -1, 0, -1, 0, -1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1, -1, 0, 0, -1, -1, 0, 0,
0, 1, 1, 0, 0, -1, 1, 0, 0, 1, -1, 0, 0, -1, -1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0, -1, 0, -1, 0, -1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1, -1, 0, 0, -1, -1, 0, 0,
0, 1, 1, 0, 0, -1, 1, 0, 0, 1, -1, 0, 0, -1, -1, 0,
1, 0, 1, 0, -1, 0, 1, 0, 1, 0, -1, 0, -1, 0, -1, 0,
1, 1, 0, 0, -1, 1, 0, 0, 1, -1, 0, 0, -1, -1, 0, 0,
1, 1, 0, 0, 0, -1, 1, 0, -1, 1, 0, 0, 0, -1, -1, 0,
}
var randVecs3D = []float32{
-0.7292736885, -0.6618439697, 0.1735581948, 0,
0.790292081, -0.5480887466, -0.2739291014, 0,
0.7217578935, 0.6226212466, -0.3023380997, 0,
0.565683137, -0.8208298145, -0.0790000257, 0,
0.760049034, -0.5555979497, -0.3370999617, 0,
0.3713945616, 0.5011264475, 0.7816254623, 0,
-0.1277062463, -0.4254438999, -0.8959289049, 0,
-0.2881560924, -0.5815838982, 0.7607405838, 0,
0.5849561111, -0.662820239, -0.4674352136, 0,
0.3307171178, 0.0391653737, 0.94291689, 0,
0.8712121778, -0.4113374369, -0.2679381538, 0,
0.580981015, 0.7021915846, 0.4115677815, 0,
0.503756873, 0.6330056931, -0.5878203852, 0,
0.4493712205, 0.601390195, 0.6606022552, 0,
-0.6878403724, 0.09018890807, -0.7202371714, 0,
-0.5958956522, -0.6469350577, 0.475797649, 0,
-0.5127052122, 0.1946921978, -0.8361987284, 0,
-0.9911507142, -0.05410276466, -0.1212153153, 0,
-0.2149721042, 0.9720882117, -0.09397607749, 0,
-0.7518650936, -0.5428057603, 0.3742469607, 0,
0.5237068895, 0.8516377189, -0.02107817834, 0,
0.6333504779, 0.1926167129, -0.7495104896, 0,
-0.06788241606, 0.3998305789, 0.9140719259, 0,
-0.5538628599, -0.4729896695, -0.6852128902, 0,
-0.7261455366, -0.5911990757, 0.3509933228, 0,
-0.9229274737, -0.1782808786, 0.3412049336, 0,
-0.6968815002, 0.6511274338, 0.3006480328, 0,
0.9608044783, -0.2098363234, -0.1811724921, 0,
0.06817146062, -0.9743405129, 0.2145069156, 0,
-0.3577285196, -0.6697087264, -0.6507845481, 0,
-0.1868621131, 0.7648617052, -0.6164974636, 0,
-0.6541697588, 0.3967914832, 0.6439087246, 0,
0.6993340405, -0.6164538506, 0.3618239211, 0,
-0.1546665739, 0.6291283928, 0.7617583057, 0,
-0.6841612949, -0.2580482182, -0.6821542638, 0,
0.5383980957, 0.4258654885, 0.7271630328, 0,
-0.5026987823, -0.7939832935, -0.3418836993, 0,
0.3202971715, 0.2834415347, 0.9039195862, 0,
0.8683227101, -0.0003762656404, -0.4959995258, 0,
0.791120031, -0.08511045745, 0.6057105799, 0,
-0.04011016052, -0.4397248749, 0.8972364289, 0,
0.9145119872, 0.3579346169, -0.1885487608, 0,
-0.9612039066, -0.2756484276, 0.01024666929, 0,
0.6510361721, -0.2877799159, -0.7023778346, 0,
-0.2041786351, 0.7365237271, 0.644859585, 0,
-0.7718263711, 0.3790626912, 0.5104855816, 0,
-0.3060082741, -0.7692987727, 0.5608371729, 0,
0.454007341, -0.5024843065, 0.7357899537, 0,
0.4816795475, 0.6021208291, -0.6367380315, 0,
0.6961980369, -0.3222197429, 0.641469197, 0,
-0.6532160499, -0.6781148932, 0.3368515753, 0,
0.5089301236, -0.6154662304, -0.6018234363, 0,
-0.1635919754, -0.9133604627, -0.372840892, 0,
0.52408019, -0.8437664109, 0.1157505864, 0,
0.5902587356, 0.4983817807, -0.6349883666, 0,
0.5863227872, 0.494764745, 0.6414307729, 0,
0.6779335087, 0.2341345225, 0.6968408593, 0,
0.7177054546, -0.6858979348, 0.120178631, 0,
-0.5328819713, -0.5205125012, 0.6671608058, 0,
-0.8654874251, -0.0700727088, -0.4960053754, 0,
-0.2861810166, 0.7952089234, 0.5345495242, 0,
-0.04849529634, 0.9810836427, -0.1874115585, 0,
-0.6358521667, 0.6058348682, 0.4781800233, 0,
0.6254794696, -0.2861619734, 0.7258696564, 0,
-0.2585259868, 0.5061949264, -0.8227581726, 0,
0.02136306781, 0.5064016808, -0.8620330371, 0,
0.200111773, 0.8599263484, 0.4695550591, 0,
0.4743561372, 0.6014985084, -0.6427953014, 0,
0.6622993731, -0.5202474575, -0.5391679918, 0,
0.08084972818, -0.6532720452, 0.7527940996, 0,
-0.6893687501, 0.0592860349, 0.7219805347, 0,
-0.1121887082, -0.9673185067, 0.2273952515, 0,
0.7344116094, 0.5979668656, -0.3210532909, 0,
0.5789393465, -0.2488849713, 0.7764570201, 0,
0.6988182827, 0.3557169806, -0.6205791146, 0,
-0.8636845529, -0.2748771249, -0.4224826141, 0,
-0.4247027957, -0.4640880967, 0.777335046, 0,
0.5257722489, -0.8427017621, 0.1158329937, 0,
0.9343830603, 0.316302472, -0.1639543925, 0,
-0.1016836419, -0.8057303073, -0.5834887393, 0,
-0.6529238969, 0.50602126, -0.5635892736, 0,
-0.2465286165, -0.9668205684, -0.06694497494, 0,
-0.9776897119, -0.2099250524, -0.007368825344, 0,
0.7736893337, 0.5734244712, 0.2694238123, 0,
-0.6095087895, 0.4995678998, 0.6155736747, 0,
0.5794535482, 0.7434546771, 0.3339292269, 0,
-0.8226211154, 0.08142581855, 0.5627293636, 0,
-0.510385483, 0.4703667658, 0.7199039967, 0,
-0.5764971849, -0.07231656274, -0.8138926898, 0,
0.7250628871, 0.3949971505, -0.5641463116, 0,
-0.1525424005, 0.4860840828, -0.8604958341, 0,
-0.5550976208, -0.4957820792, 0.667882296, 0,
-0.1883614327, 0.9145869398, 0.357841725, 0,
0.7625556724, -0.5414408243, -0.3540489801, 0,
-0.5870231946, -0.3226498013, -0.7424963803, 0,
0.3051124198, 0.2262544068, -0.9250488391, 0,
0.6379576059, 0.577242424, -0.5097070502, 0,
-0.5966775796, 0.1454852398, -0.7891830656, 0,
-0.658330573, 0.6555487542, -0.3699414651, 0,
0.7434892426, 0.2351084581, 0.6260573129, 0,
0.5562114096, 0.8264360377, -0.0873632843, 0,
-0.3028940016, -0.8251527185, 0.4768419182, 0,
0.1129343818, -0.985888439, -0.1235710781, 0,
0.5937652891, -0.5896813806, 0.5474656618, 0,
0.6757964092, -0.5835758614, -0.4502648413, 0,
0.7242302609, -0.1152719764, 0.6798550586, 0,
-0.9511914166, 0.0753623979, -0.2992580792, 0,
0.2539470961, -0.1886339355, 0.9486454084, 0,
0.571433621, -0.1679450851, -0.8032795685, 0,
-0.06778234979, 0.3978269256, 0.9149531629, 0,
0.6074972649, 0.733060024, -0.3058922593, 0,
-0.5435478392, 0.1675822484, 0.8224791405, 0,
-0.5876678086, -0.3380045064, -0.7351186982, 0,
-0.7967562402, 0.04097822706, -0.6029098428, 0,
-0.1996350917, 0.8706294745, 0.4496111079, 0,
-0.02787660336, -0.9106232682, -0.4122962022, 0,
-0.7797625996, -0.6257634692, 0.01975775581, 0,
-0.5211232846, 0.7401644346, -0.4249554471, 0,
0.8575424857, 0.4053272873, -0.3167501783, 0,
0.1045223322, 0.8390195772, -0.5339674439, 0,
0.3501822831, 0.9242524096, -0.1520850155, 0,
0.1987849858, 0.07647613266, 0.9770547224, 0,
0.7845996363, 0.6066256811, -0.1280964233, 0,
0.09006737436, -0.9750989929, -0.2026569073, 0,
-0.8274343547, -0.542299559, 0.1458203587, 0,
-0.3485797732, -0.415802277, 0.840000362, 0,
-0.2471778936, -0.7304819962, -0.6366310879, 0,
-0.3700154943, 0.8577948156, 0.3567584454, 0,
0.5913394901, -0.548311967, -0.5913303597, 0,
0.1204873514, -0.7626472379, -0.6354935001, 0,
0.616959265, 0.03079647928, 0.7863922953, 0,
0.1258156836, -0.6640829889, -0.7369967419, 0,
-0.6477565124, -0.1740147258, -0.7417077429, 0,
0.6217889313, -0.7804430448, -0.06547655076, 0,
0.6589943422, -0.6096987708, 0.4404473475, 0,
-0.2689837504, -0.6732403169, -0.6887635427, 0,
-0.3849775103, 0.5676542638, 0.7277093879, 0,
0.5754444408, 0.8110471154, -0.1051963504, 0,
0.9141593684, 0.3832947817, 0.131900567, 0,
-0.107925319, 0.9245493968, 0.3654593525, 0,
0.377977089, 0.3043148782, 0.8743716458, 0,
-0.2142885215, -0.8259286236, 0.5214617324, 0,
0.5802544474, 0.4148098596, -0.7008834116, 0,
-0.1982660881, 0.8567161266, -0.4761596756, 0,
-0.03381553704, 0.3773180787, -0.9254661404, 0,
-0.6867922841, -0.6656597827, 0.2919133642, 0,
0.7731742607, -0.2875793547, -0.5652430251, 0,
-0.09655941928, 0.9193708367, -0.3813575004, 0,
0.2715702457, -0.9577909544, -0.09426605581, 0,
0.2451015704, -0.6917998565, -0.6792188003, 0,
0.977700782, -0.1753855374, 0.1155036542, 0,
-0.5224739938, 0.8521606816, 0.02903615945, 0,
-0.7734880599, -0.5261292347, 0.3534179531, 0,
-0.7134492443, -0.269547243, 0.6467878011, 0,
0.1644037271, 0.5105846203, -0.8439637196, 0,
0.6494635788, 0.05585611296, 0.7583384168, 0,
-0.4711970882, 0.5017280509, -0.7254255765, 0,
-0.6335764307, -0.2381686273, -0.7361091029, 0,
-0.9021533097, -0.270947803, -0.3357181763, 0,
-0.3793711033, 0.872258117, 0.3086152025, 0,
-0.6855598966, -0.3250143309, 0.6514394162, 0,
0.2900942212, -0.7799057743, -0.5546100667, 0,
-0.2098319339, 0.85037073, 0.4825351604, 0,
-0.4592603758, 0.6598504336, -0.5947077538, 0,
0.8715945488, 0.09616365406, -0.4807031248, 0,
-0.6776666319, 0.7118504878, -0.1844907016, 0,
0.7044377633, 0.312427597, 0.637304036, 0,
-0.7052318886, -0.2401093292, -0.6670798253, 0,
0.081921007, -0.7207336136, -0.6883545647, 0,
-0.6993680906, -0.5875763221, -0.4069869034, 0,
-0.1281454481, 0.6419895885, 0.7559286424, 0,
-0.6337388239, -0.6785471501, -0.3714146849, 0,
0.5565051903, -0.2168887573, -0.8020356851, 0,
-0.5791554484, 0.7244372011, -0.3738578718, 0,
0.1175779076, -0.7096451073, 0.6946792478, 0,
-0.6134619607, 0.1323631078, 0.7785527795, 0,
0.6984635305, -0.02980516237, -0.715024719, 0,
0.8318082963, -0.3930171956, 0.3919597455, 0,
0.1469576422, 0.05541651717, -0.9875892167, 0,
0.708868575, -0.2690503865, 0.6520101478, 0,
0.2726053183, 0.67369766, -0.68688995, 0,
-0.6591295371, 0.3035458599, -0.6880466294, 0,
0.4815131379, -0.7528270071, 0.4487723203, 0,
0.9430009463, 0.1675647412, -0.2875261255, 0,
0.434802957, 0.7695304522, -0.4677277752, 0,
0.3931996188, 0.594473625, 0.7014236729, 0,
0.7254336655, -0.603925654, 0.3301814672, 0,
0.7590235227, -0.6506083235, 0.02433313207, 0,
-0.8552768592, -0.3430042733, 0.3883935666, 0,
-0.6139746835, 0.6981725247, 0.3682257648, 0,
-0.7465905486, -0.5752009504, 0.3342849376, 0,
0.5730065677, 0.810555537, -0.1210916791, 0,
-0.9225877367, -0.3475211012, -0.167514036, 0,
-0.7105816789, -0.4719692027, -0.5218416899, 0,
-0.08564609717, 0.3583001386, 0.929669703, 0,
-0.8279697606, -0.2043157126, 0.5222271202, 0,
0.427944023, 0.278165994, 0.8599346446, 0,
0.5399079671, -0.7857120652, -0.3019204161, 0,
0.5678404253, -0.5495413974, -0.6128307303, 0,
-0.9896071041, 0.1365639107, -0.04503418428, 0,
-0.6154342638, -0.6440875597, 0.4543037336, 0,
0.1074204368, -0.7946340692, 0.5975094525, 0,
-0.3595449969, -0.8885529948, 0.28495784, 0,
-0.2180405296, 0.1529888965, 0.9638738118, 0,
-0.7277432317, -0.6164050508, -0.3007234646, 0,
0.7249729114, -0.00669719484, 0.6887448187, 0,
-0.5553659455, -0.5336586252, 0.6377908264, 0,
0.5137558015, 0.7976208196, -0.3160000073, 0,
-0.3794024848, 0.9245608561, -0.03522751494, 0,
0.8229248658, 0.2745365933, -0.4974176556, 0,
-0.5404114394, 0.6091141441, 0.5804613989, 0,
0.8036581901, -0.2703029469, 0.5301601931, 0,
0.6044318879, 0.6832968393, 0.4095943388, 0,
0.06389988817, 0.9658208605, -0.2512108074, 0,
0.1087113286, 0.7402471173, -0.6634877936, 0,
-0.713427712, -0.6926784018, 0.1059128479, 0,
0.6458897819, -0.5724548511, -0.5050958653, 0,
-0.6553931414, 0.7381471625, 0.159995615, 0,
0.3910961323, 0.9188871375, -0.05186755998, 0,
-0.4879022471, -0.5904376907, 0.6429111375, 0,
0.6014790094, 0.7707441366, -0.2101820095, 0,
-0.5677173047, 0.7511360995, 0.3368851762, 0,
0.7858573506, 0.226674665, 0.5753666838, 0,
-0.4520345543, -0.604222686, -0.6561857263, 0,
0.002272116345, 0.4132844051, -0.9105991643, 0,
-0.5815751419, -0.5162925989, 0.6286591339, 0,
-0.03703704785, 0.8273785755, 0.5604221175, 0,
-0.5119692504, 0.7953543429, -0.3244980058, 0,
-0.2682417366, -0.9572290247, -0.1084387619, 0,
-0.2322482736, -0.9679131102, -0.09594243324, 0,
0.3554328906, -0.8881505545, 0.2913006227, 0,
0.7346520519, -0.4371373164, 0.5188422971, 0,
0.9985120116, 0.04659011161, -0.02833944577, 0,
-0.3727687496, -0.9082481361, 0.1900757285, 0,
0.91737377, -0.3483642108, 0.1925298489, 0,
0.2714911074, 0.4147529736, -0.8684886582, 0,
0.5131763485, -0.7116334161, 0.4798207128, 0,
-0.8737353606, 0.18886992, -0.4482350644, 0,
0.8460043821, -0.3725217914, 0.3814499973, 0,
0.8978727456, -0.1780209141, -0.4026575304, 0,
0.2178065647, -0.9698322841, -0.1094789531, 0,
-0.1518031304, -0.7788918132, -0.6085091231, 0,
-0.2600384876, -0.4755398075, -0.8403819825, 0,
0.572313509, -0.7474340931, -0.3373418503, 0,
-0.7174141009, 0.1699017182, -0.6756111411, 0,
-0.684180784, 0.02145707593, -0.7289967412, 0,
-0.2007447902, 0.06555605789, -0.9774476623, 0,
-0.1148803697, -0.8044887315, 0.5827524187, 0,
-0.7870349638, 0.03447489231, 0.6159443543, 0,
-0.2015596421, 0.6859872284, 0.6991389226, 0,
-0.08581082512, -0.10920836, -0.9903080513, 0,
0.5532693395, 0.7325250401, -0.396610771, 0,
-0.1842489331, -0.9777375055, -0.1004076743, 0,
0.0775473789, -0.9111505856, 0.4047110257, 0,
0.1399838409, 0.7601631212, -0.6344734459, 0,
0.4484419361, -0.845289248, 0.2904925424, 0,
}
// ====================
// Public API
// ====================
// New initializes a new noise generator state with default values. This function must be used
// to create new states.
func New[T Float]() *State[T] {
state := &State[T]{
Seed: 1337,
Frequency: 0.01,
noiseType: OpenSimplex2,
RotationType3D: RotationNone,
fractalType: FractalNone,
Octaves: 3,
Lacunarity: 2.0,
Gain: 0.5,
WeightedStrength: 0.0,
PingPongStrength: 2.0,
CellularDistanceFunc: CellularDistanceEuclideanSq,
CellularReturnType: CellularReturnDistance,
CellularJitterMod: 1.0,
DomainWarpAmp: 30.0,
DomainWarpType: DomainWarpOpenSimplex2,
}
state.apply()
return state
}
// apply determines the function to use for generating noise, and caches it to reduce overhead
// each time it GetNoise2D or GetNoise3D is invoked.
func (state *State[T]) apply() {
switch state.fractalType {
case FractalFBm:
state.noise2D = genFractalFBM2D[T]
state.noise3D = genFractalFBM3D[T]
case FractalRidged:
state.noise2D = genFractalRidged2D[T]
state.noise3D = genFractalRidged3D[T]
case FractalPingPong:
state.noise2D = genFractalPingPong2D[T]
state.noise3D = genFractalPingPong3D[T]
default:
switch state.noiseType {
case OpenSimplex2:
state.noise2D = singleSimplex2D[T]
state.noise3D = singleOpenSimplex23D[T]
case OpenSimplex2S:
state.noise2D = singleOpenSimplex2S2D[T]
state.noise3D = singleOpenSimplex2S3D[T]
case Cellular:
state.noise2D = singleCellular2D[T]
state.noise3D = singleCellular3D[T]
case Perlin:
state.noise2D = singlePerlin2D[T]
state.noise3D = singlePerlin3D[T]
case ValueCubic:
state.noise2D = singleValueCubic2D[T]
state.noise3D = singleValueCubic3D[T]
case Value:
state.noise2D = singleValue2D[T]
state.noise3D = singleValue3D[T]
default:
state.noise2D = func(_ *State[T], _ int, _, _ T) T { return 0 }
state.noise3D = func(_ *State[T], _ int, _, _, _ T) T { return 0 }
}
}
}
// NoiseType specifies the algorithm that will be used with GetNoise2D and GetNoise3D.
//
// Default: OpenSimplex2
func (state *State[T]) NoiseType(nt NoiseType) {
state.noiseType = nt
state.apply()
}
// FractalType specifies the method used for combining octaves for all fractal noise types.
// Only effects DomainWarp2D and DomainWarp3D functions.
//
// Default: FractalNone
func (state *State[T]) FractalType(ft FractalType) {
state.fractalType = ft
state.apply()
}
// GetNoise2D calculates the noise value at the specified 2D position using the current state
// settings.
//
// This is a convenience function for GetNoise2D that accepts integral coordinates.
// Return values are always normalized and in the range of -1.0 and 1.0.
func (state *State[T]) Noise2D(x, y int) T {
fx, fy := state.transformNoiseCoordinate2D(T(x), T(y))
return state.noise2D(state, state.Seed, fx, fy)
}
// GetNoise3D calculates the noise value at the specified 3D position using the current state
// settings.
//
// This is a convenience function for GetNoise3D that accepts integral coordinates.
// Return values are always normalized and in the range of -1.0 and 1.0.
func (state *State[T]) Noise3D(x, y, z int) T {
fx, fy, fz := state.transformNoiseCoordinate3D(T(x), T(y), T(z))
return state.noise3D(state, state.Seed, fx, fy, fz)
}
// GetNoise2D calculates the noise value at the specified 2D position using the current state
// settings.
//
// Return values are always normalized and in the range of -1.0 and 1.0.
func (state *State[T]) GetNoise2D(x, y T) T {
x, y = state.transformNoiseCoordinate2D(x, y)
return state.noise2D(state, state.Seed, x, y)
}
// GetNoise3D calculates the noise value at the specified 3D position using the current state
// settings.
//
// Return values are always normalized and in the range of -1.0 and 1.0.
func (state *State[T]) GetNoise3D(x, y, z T) T {
x, y, z = state.transformNoiseCoordinate3D(x, y, z)
return state.noise3D(state, state.Seed, x, y, z)
}
// DomainWarp2D warps the input position using current domain warp settings.
func (state *State[T]) DomainWarp2D(x, y T) (T, T) {
xx := x
yy := y
switch state.fractalType {
default:
domainWarpSingle2D(state, &xx, &yy)
case FractalDomainWarpProgressive:
domainWarpFractalProgressive2D(state, &xx, &yy)
case FractalDomainWarpIndependent:
domainWarpFractalIndependent2D(state, &xx, &yy)
}
return xx, yy
}
// DomainWarp2D warps the input position using current domain warp settings.
func (state *State[T]) DomainWarp3D(x, y, z T) (T, T, T) {
xx := x
yy := y
zz := z
switch state.fractalType {
default:
domainWarpSingle3D(state, &xx, &yy, &zz)
case FractalDomainWarpProgressive:
domainWarpFractalProgressive3D(state, &xx, &yy, &zz)
case FractalDomainWarpIndependent:
domainWarpFractalIndependent3D(state, &xx, &yy, &zz)
}
return xx, yy, zz
}
// ====================
// Private/implemenation
// ====================
// Utilities
func fastMin[T Float](x, y T) T {
if x < y {
return x
}
return y
}
func fastMax[T Float](x, y T) T {
if x > y {
return x
}
return y
}
func fastAbs[T Float](f T) T {
if f < 0 {
return -f
}
return f
}
func fastSqrt[T Float](a T) T {
// Benchmarks using Quake's famous "inverse square root" were actually slightly slower than
// using the built-in math library.
return T(math.Sqrt(float64(a)))
}
func fastFloor[T Float](f T) int {
if f >= 0 {
return int(f)
}
return int(f) - 1
}
func fastRound[T Float](f T) int {
if f >= 0 {
return int(f + 0.5)
}
return int(f - 0.5)
}
func lerp[T Float](a, b, t T) T {
return a + t*(b-a)
}
func interpHermite[T Float](t T) T {
return t * t * (3 - 2*t)
}
func interpQuintic[T Float](t T) T {
return t * t * t * (t*(t*6-15) + 10)
}
func cubicLerp[T Float](a, b, c, d, t T) T {
var p T = (d - c) - (a - b)
return t*t*t*p + t*t*((a-b)-p) + t*(c-a) + b
}
func pingPong[T Float](t T) T {
t -= T(int(t*0.5)) * 2
if t < 1 {
return t
}
return 2 - t
}
func calculateFractalBounding[T Float](state *State[T]) T {
gain := fastAbs(state.Gain)
amp := gain
var ampFractal T = 1.0
for i := 1; i < state.Octaves; i++ {
ampFractal += amp
amp *= gain
}
return 1.0 / ampFractal
}
// Hashing
const (
primeX int = 501125321
primeY int = 1136930381
primeZ int = 1720413743
primeX2 = primeX << 1
primeY2 = -2021106534
primeZ2 = -854139810
)
func hash2D(seed, xPrimed, yPrimed int) uint32 {
hash := seed ^ xPrimed ^ yPrimed
return uint32(hash) * 0x27d4eb2d
}
func hash3D(seed, xPrimed, yPrimed, zPrimed int) uint32 {
hash := seed ^ xPrimed ^ yPrimed ^ zPrimed
return uint32(hash) * 0x27d4eb2d
}
func valCoord2D[T Float](seed, xPrimed, yPrimed int) T {
hash := hash2D(seed, xPrimed, yPrimed)
hash *= hash
hash ^= hash << 19
return T(int32(hash)) * (1 / 2147483648.0)
}
func valCoord3D[T Float](seed, xPrimed, yPrimed, zPrimed int) T {
hash := hash3D(seed, xPrimed, yPrimed, zPrimed)
hash *= hash
hash ^= hash << 19
return T(int32(hash)) * (1 / 2147483648.0)
}
func gradCoord2D[T Float](seed, xPrimed, yPrimed int, xd, yd T) T {
hash := hash2D(seed, xPrimed, yPrimed)
hash ^= hash >> 15
hash &= 127 << 1
return xd*T(gradients2D[hash]) + yd*T(gradients2D[hash|1])
}
func gradCoord3D[T Float](seed, xPrimed, yPrimed, zPrimed int, xd, yd, zd T) T {
hash := hash3D(seed, xPrimed, yPrimed, zPrimed)
hash ^= hash >> 15
hash &= 63 << 2
return xd*T(gradients3D[hash]) + yd*T(gradients3D[hash|1]) + zd*T(gradients3D[hash|2])
}
func gradCoordOut2D[T Float](seed, xPrimed, yPrimed int, xo, yo *T) {
hash := hash2D(seed, xPrimed, yPrimed) & (255 << 1)
*xo = T(randVecs2D[hash])
*yo = T(randVecs2D[hash|1])
}
func gradCoordOut3D[T Float](seed, xPrimed, yPrimed, zPrimed int, xo, yo, zo *T) {
hash := hash3D(seed, xPrimed, yPrimed, zPrimed) & (255 << 2)
*xo = T(randVecs3D[hash])
*yo = T(randVecs3D[hash|1])
*zo = T(randVecs3D[hash|2])
}
func gradCoordDual2D[T Float](seed, xPrimed, yPrimed int, xd, yd T, xo, yo *T) {
hash := hash2D(seed, xPrimed, yPrimed)
index1 := hash & (127 << 1)
index2 := (hash >> 7) & (255 << 1)
xg := T(gradients2D[index1])
yg := T(gradients2D[index1|1])
value := xd*xg + yd*yg
xgo := T(randVecs2D[index2])
ygo := T(randVecs2D[index2|1])
*xo = value * xgo
*yo = value * ygo
}
func gradCoordDual3D[T Float](seed, xPrimed, yPrimed, zPrimed int, xd, yd, zd T, xo, yo, zo *T) {
hash := hash3D(seed, xPrimed, yPrimed, zPrimed)
index1 := hash & (63 << 2)
index2 := (hash >> 6) & (255 << 2)
xg := T(gradients3D[index1])
yg := T(gradients3D[index1|1])
zg := T(gradients3D[index1|2])
value := xd*xg + yd*yg + zd*zg
xgo := T(randVecs3D[index2])
ygo := T(randVecs3D[index2|1])
zgo := T(randVecs3D[index2|2])
*xo = value * xgo
*yo = value * ygo
*zo = value * zgo
}
func genNoiseSingle2D[T Float](state *State[T], seed int, x, y T) T {
switch state.noiseType {
case OpenSimplex2:
return singleSimplex2D(state, seed, x, y)
case OpenSimplex2S:
return singleOpenSimplex2S2D(state, seed, x, y)
case Cellular:
return singleCellular2D(state, seed, x, y)
case Perlin:
return singlePerlin2D(state, seed, x, y)
case ValueCubic:
return singleValueCubic2D(state, seed, x, y)
case Value:
return singleValue2D(state, seed, x, y)
default:
return 0
}
}
func genNoiseSingle3D[T Float](state *State[T], seed int, x, y, z T) T {
switch state.noiseType {
case OpenSimplex2:
return singleOpenSimplex23D(state, seed, x, y, z)
case OpenSimplex2S:
return singleOpenSimplex2S3D(state, seed, x, y, z)
case Cellular:
return singleCellular3D(state, seed, x, y, z)
case Perlin:
return singlePerlin3D(state, seed, x, y, z)
case ValueCubic:
return singleValueCubic3D(state, seed, x, y, z)
case Value:
return singleValue3D(state, seed, x, y, z)
default:
return 0
}
}
// Noise Coordinate Transforms (frequency, and possible skew or rotation)
func (state *State[T]) transformNoiseCoordinate2D(x, y T) (T, T) {
tx := x * state.Frequency
ty := y * state.Frequency
switch state.noiseType {
case OpenSimplex2, OpenSimplex2S:
const SQRT3 float64 = 1.7320508075688772935274463415059
const F2 float64 = 0.5 * (SQRT3 - 1)
t := (tx + ty) * T(F2)
tx += t
ty += t
}
return tx, ty
}
func (state *State[T]) transformNoiseCoordinate3D(x, y, z T) (T, T, T) {
tx := x * state.Frequency
ty := y * state.Frequency
tz := z * state.Frequency
switch state.RotationType3D {
case RotationImproveXYPlanes:
xy := tx + ty
s2 := xy * -0.211324865405187
tz *= 0.577350269189626
tx += s2 - tz
ty = ty + s2 - tz
tz += xy * 0.577350269189626
case RotationImproveXZPlanes:
xz := tx + tz
s2 := xz * -0.211324865405187
ty *= 0.577350269189626
tx += s2 - ty
tz += s2 - ty
ty += xz * 0.577350269189626
default:
switch state.noiseType {
case OpenSimplex2, OpenSimplex2S:
const R3 float64 = 2.0 / 3.0
r := (tx + ty + tz) * T(R3) // Rotation, not skew
tx = r - tx
ty = r - ty
tz = r - tz
}
}
return tx, ty, tz
}
// Domain Warp Coordinate Transforms
func transformDomainWarpCoordinate2D[T Float](state *State[T], x, y *T) {
switch state.DomainWarpType {
case DomainWarpOpenSimplex2, DomainWarpOpenSimplex2Reduced:
const SQRT3 float64 = 1.7320508075688772935274463415059
const F2 float64 = 0.5 * (SQRT3 - 1)
t := (*x + *y) * T(F2)
*x += t
*y += t
}
}
func transformDomainWarpCoordinate3D[T Float](state *State[T], x, y, z *T) {
switch state.RotationType3D {
case RotationImproveXYPlanes:
xy := *x + *y
s2 := xy * -0.211324865405187
*z *= 0.577350269189626
*x += s2 - *z
*y = *y + s2 - *z
*z += xy * 0.577350269189626
case RotationImproveXZPlanes:
xz := *x + *z
s2 := xz * -0.211324865405187
*y *= 0.577350269189626
*x += s2 - *y
*z += s2 - *y
*y += xz * 0.577350269189626
default:
switch state.DomainWarpType {
case DomainWarpOpenSimplex2, DomainWarpOpenSimplex2Reduced:
const R3 float64 = 2.0 / 3.0
r := (*x + *y + *z) * T(R3) // Rotation, not skew
*x = r - *x
*y = r - *y
*z = r - *z
}
}
}
// Fractal FBm
func genFractalFBM2D[T Float](state *State[T], seed int, x, y T) (sum T) {
amp := calculateFractalBounding(state)
for i := 0; i < state.Octaves; i++ {
noise := genNoiseSingle2D(state, seed, x, y)
seed++
sum += noise * amp
amp *= lerp(1.0, fastMin(noise+1, 2)*0.5, state.WeightedStrength)
x *= state.Lacunarity
y *= state.Lacunarity
amp *= state.Gain
}
return
}
func genFractalFBM3D[T Float](state *State[T], seed int, x, y, z T) (sum T) {
amp := calculateFractalBounding(state)
for i := 0; i < state.Octaves; i++ {
noise := genNoiseSingle3D(state, seed, x, y, z)
seed++
sum += noise * amp
amp *= lerp(1.0, (noise+1)*0.5, state.WeightedStrength)
x *= state.Lacunarity
y *= state.Lacunarity
z *= state.Lacunarity
amp *= state.Gain
}
return
}
// Fractal Ridged
func genFractalRidged2D[T Float](state *State[T], seed int, x, y T) (sum T) {
amp := calculateFractalBounding(state)
for i := 0; i < state.Octaves; i++ {
noise := fastAbs(genNoiseSingle2D(state, seed, x, y))
seed++
sum += (noise*-2 + 1) * amp
amp *= lerp(1.0, 1-noise, state.WeightedStrength)
x *= state.Lacunarity
y *= state.Lacunarity
amp *= state.Gain
}
return
}
func genFractalRidged3D[T Float](state *State[T], seed int, x, y, z T) (sum T) {
amp := calculateFractalBounding(state)
for i := 0; i < state.Octaves; i++ {
noise := fastAbs(genNoiseSingle3D(state, seed, x, y, z))
seed++
sum += (noise*-2 + 1) * amp
amp *= lerp(1.0, 1-noise, state.WeightedStrength)
x *= state.Lacunarity
y *= state.Lacunarity
z *= state.Lacunarity
amp *= state.Gain
}
return
}
// Fractal PingPong
func genFractalPingPong2D[T Float](state *State[T], seed int, x, y T) (sum T) {
amp := calculateFractalBounding(state)
for i := 0; i < state.Octaves; i++ {
noise := pingPong((genNoiseSingle2D(state, seed, x, y) + 1) * state.PingPongStrength)
seed++
sum += (noise - 0.5) * 2 * amp
amp *= lerp(1.0, noise, state.WeightedStrength)
x *= state.Lacunarity
y *= state.Lacunarity
amp *= state.Gain
}
return
}
func genFractalPingPong3D[T Float](state *State[T], seed int, x, y, z T) (sum T) {
amp := calculateFractalBounding(state)
for i := 0; i < state.Octaves; i++ {
noise := pingPong((genNoiseSingle3D(state, seed, x, y, z) + 1) * state.PingPongStrength)
seed++
sum += (noise - 0.5) * 2 * amp
amp *= lerp(1.0, noise, state.WeightedStrength)
x *= state.Lacunarity
y *= state.Lacunarity
z *= state.Lacunarity
amp *= state.Gain
}
return
}
// Simplex/OpenSimplex2 Noise
func singleSimplex2D[T Float](state *State[T], seed int, x, y T) T {
// 2D OpenSimplex2 case uses the same algorithm as ordinary Simplex.
const SQRT3 float64 = 1.7320508075688772935274463415059
const G2 float64 = (3 - SQRT3) / 6
i := fastFloor(x)
j := fastFloor(y)
xi := x - T(i)
yi := y - T(j)
t := (xi + yi) * T(G2)
x0 := xi - t
y0 := yi - t
i *= primeX
j *= primeY
var n0, n1, n2 T
a := 0.5 - x0*x0 - y0*y0
if a <= 0 {
n0 = 0
} else {
n0 = (a * a) * (a * a) * gradCoord2D(seed, i, j, x0, y0)
}
c := T(2*(1-2*G2)*(1/G2-2))*t + (T(-2*(1-2*G2)*(1-2*G2)) + a)
if c <= 0 {
n2 = 0
} else {
x2 := x0 + (2*T(G2) - 1)
y2 := y0 + (2*T(G2) - 1)
n2 = (c * c) * (c * c) * gradCoord2D(seed, i+primeX, j+primeY, x2, y2)
}
if y0 > x0 {
x1 := x0 + T(G2)
y1 := y0 + (T(G2) - 1)
b := 0.5 - x1*x1 - y1*y1
if b <= 0 {
n1 = 0
} else {
n1 = (b * b) * (b * b) * gradCoord2D(seed, i, j+primeY, x1, y1)
}
} else {
x1 := x0 + (T(G2) - 1)
y1 := y0 + T(G2)
b := 0.5 - x1*x1 - y1*y1
if b <= 0 {
n1 = 0
} else {
n1 = (b * b) * (b * b) * gradCoord2D(seed, i+primeX, j, x1, y1)
}
}
return (n0 + n1 + n2) * 99.83685446303647
}
func singleOpenSimplex23D[T Float](state *State[T], seed int, x, y, z T) T {
// 3D OpenSimplex2 case uses two offset rotated cube grids.
i := fastRound(x)
j := fastRound(y)
k := fastRound(z)
x0 := x - T(i)
y0 := y - T(j)
z0 := z - T(k)
xNSign := int(-x0-1.0) | 1
yNSign := int(-y0-1.0) | 1
zNSign := int(-z0-1.0) | 1
ax0 := T(xNSign) * -x0
ay0 := T(yNSign) * -y0
az0 := T(zNSign) * -z0
i *= primeX
j *= primeY
k *= primeZ
var value T
a := (0.6 - x0*x0) - (y0*y0 + z0*z0)
for l := 0; true; l++ {
if a > 0 {
value += (a * a) * (a * a) * gradCoord3D(seed, i, j, k, x0, y0, z0)
}
b := a + 1
i1 := i
j1 := j
k1 := k
x1 := x0
y1 := y0
z1 := z0
if ax0 >= ay0 && ax0 >= az0 {
x1 += T(xNSign)
b -= T(xNSign) * 2 * x1
i1 -= xNSign * primeX
} else if ay0 > ax0 && ay0 >= az0 {
y1 += T(yNSign)
b -= T(yNSign) * 2 * y1
j1 -= yNSign * primeY
} else {
z1 += T(zNSign)
b -= T(zNSign) * 2 * z1
k1 -= zNSign * primeZ
}
if b > 0 {
value += (b * b) * (b * b) * gradCoord3D(seed, i1, j1, k1, x1, y1, z1)
}
if l == 1 {
break
}
ax0 := 0.5 - ax0
ay0 := 0.5 - ay0
az0 := 0.5 - az0
x0 = T(xNSign) * ax0
y0 = T(yNSign) * ay0
z0 = T(zNSign) * az0
a += (0.75 - ax0) - (ay0 + az0)
i += (xNSign >> 1) & primeX
j += (yNSign >> 1) & primeY
k += (zNSign >> 1) & primeZ
xNSign = -xNSign
yNSign = -yNSign
zNSign = -zNSign
seed = ^seed
}
return value * 32.69428253173828125
}
// OpenSimplex2S Noise
func singleOpenSimplex2S2D[T Float](state *State[T], seed int, x, y T) T {
// 2D OpenSimplex2S case is a modified 2D simplex noise.
const SQRT3 float64 = 1.7320508075688772935274463415059
const G2 float64 = (3 - SQRT3) / 6
i := fastFloor(x)
j := fastFloor(y)
xi := x - T(i)
yi := y - T(j)
i *= primeX
j *= primeY
i1 := i + primeX
j1 := j + primeY
t := (xi + yi) * T(G2)
x0 := xi - t
y0 := yi - t
a0 := (2.0 / 3.0) - x0*x0 - y0*y0
value := (a0 * a0) * (a0 * a0) * gradCoord2D(seed, i, j, x0, y0)
a1 := T(2*(1-2*G2)*(1/G2-2))*t + (T(-2*(1-2*G2)*(1-2*G2)) + a0)
x1 := x0 - T(1-2*G2)
y1 := y0 - T(1-2*G2)
value += (a1 * a1) * (a1 * a1) * gradCoord2D(seed, i1, j1, x1, y1)
// Nested conditionals were faster than compact bit logic/arithmetic.
xmyi := xi - yi
if t > T(G2) {
if xi+xmyi > 1 {
x2 := x0 + T(3*G2-2)
y2 := y0 + T(3*G2-1)
a2 := (2.0 / 3.0) - x2*x2 - y2*y2
if a2 > 0 {
value += (a2 * a2) * (a2 * a2) * gradCoord2D(seed, i+(primeX2), j+primeY, x2, y2)
}
} else {
x2 := x0 + T(G2)
y2 := y0 + T(G2-1)
a2 := (2.0 / 3.0) - x2*x2 - y2*y2
if a2 > 0 {
value += (a2 * a2) * (a2 * a2) * gradCoord2D(seed, i, j+primeY, x2, y2)
}
}
if yi-xmyi > 1 {
x3 := x0 + T(3*G2-1)
y3 := y0 + T(3*G2-2)
a3 := (2.0 / 3.0) - x3*x3 - y3*y3
if a3 > 0 {
value += (a3 * a3) * (a3 * a3) * gradCoord2D(seed, i+primeX, j+(primeY2), x3, y3)
}
} else {
x3 := x0 + T(G2-1)
y3 := y0 + T(G2)
a3 := (2.0 / 3.0) - x3*x3 - y3*y3
if a3 > 0 {
value += (a3 * a3) * (a3 * a3) * gradCoord2D(seed, i+primeX, j, x3, y3)
}
}
} else {
if xi+xmyi < 0 {
x2 := x0 + T(1-G2)
y2 := y0 - T(G2)
a2 := (2.0 / 3.0) - x2*x2 - y2*y2
if a2 > 0 {
value += (a2 * a2) * (a2 * a2) * gradCoord2D(seed, i-primeX, j, x2, y2)
}
} else {
x2 := x0 + T(G2-1)
y2 := y0 + T(G2)
a2 := (2.0 / 3.0) - x2*x2 - y2*y2
if a2 > 0 {
value += (a2 * a2) * (a2 * a2) * gradCoord2D(seed, i+primeX, j, x2, y2)
}
}
if yi < xmyi {
x2 := x0 - T(G2)
y2 := y0 - T(G2-1)
a2 := (2.0 / 3.0) - x2*x2 - y2*y2
if a2 > 0 {
value += (a2 * a2) * (a2 * a2) * gradCoord2D(seed, i, j-primeY, x2, y2)
}
} else {
x2 := x0 + T(G2)
y2 := y0 + T(G2-1)
a2 := (2.0 / 3.0) - x2*x2 - y2*y2
if a2 > 0 {
value += (a2 * a2) * (a2 * a2) * gradCoord2D(seed, i, j+primeY, x2, y2)
}
}
}
return value * 18.24196194486065
}
func singleOpenSimplex2S3D[T Float](state *State[T], seed int, x, y, z T) T {
// 3D OpenSimplex2S case uses two offset rotated cube grids.
i := fastFloor(x)
j := fastFloor(y)
k := fastFloor(z)
xi := x - T(i)
yi := y - T(j)
zi := z - T(k)
i *= primeX
j *= primeY
k *= primeZ
seed2 := seed + 1293373
xNMask := int(-0.5 - xi)
yNMask := int(-0.5 - yi)
zNMask := int(-0.5 - zi)
x0 := xi + T(xNMask)
y0 := yi + T(yNMask)
z0 := zi + T(zNMask)
a0 := 0.75 - x0*x0 - y0*y0 - z0*z0
value := (a0 * a0) * (a0 * a0) * gradCoord3D(seed, i+(xNMask&primeX), j+(yNMask&primeY), k+(zNMask&primeZ), x0, y0, z0)
x1 := xi - 0.5
y1 := yi - 0.5
z1 := zi - 0.5
a1 := 0.75 - x1*x1 - y1*y1 - z1*z1
value += (a1 * a1) * (a1 * a1) * gradCoord3D(seed2, i+primeX, j+primeY, k+primeZ, x1, y1, z1)
xAFlipMask0 := T((xNMask|1)<<1) * x1
yAFlipMask0 := T((yNMask|1)<<1) * y1
zAFlipMask0 := T((zNMask|1)<<1) * z1
xAFlipMask1 := T(-2-(xNMask<<2))*x1 - 1.0
yAFlipMask1 := T(-2-(yNMask<<2))*y1 - 1.0
zAFlipMask1 := T(-2-(zNMask<<2))*z1 - 1.0
skip5 := false
a2 := T(xAFlipMask0) + a0
if a2 > 0 {
x2 := x0 - T(xNMask|1)
y2 := y0
z2 := z0
value += (a2 * a2) * (a2 * a2) * gradCoord3D(seed, i+(^xNMask&primeX), j+(yNMask&primeY), k+(zNMask&primeZ), x2, y2, z2)
} else {
a3 := yAFlipMask0 + zAFlipMask0 + a0
if a3 > 0 {
x3 := x0
y3 := y0 - T(yNMask|1)
z3 := z0 - T(zNMask|1)
value += (a3 * a3) * (a3 * a3) * gradCoord3D(seed, i+(xNMask&primeX), j+(^yNMask&primeY), k+(^zNMask&primeZ), x3, y3, z3)
}
a4 := T(xAFlipMask1) + a1
if a4 > 0 {
x4 := T(xNMask|1) + x1
y4 := y1
z4 := z1
value += (a4 * a4) * (a4 * a4) * gradCoord3D(seed2, i+(xNMask&(primeX2)), j+primeY, k+primeZ, x4, y4, z4)
skip5 = true
}
}
skip9 := false
a6 := T(yAFlipMask0) + a0
if a6 > 0 {
x6 := x0
y6 := y0 - T(yNMask|1)
z6 := z0
value += (a6 * a6) * (a6 * a6) * gradCoord3D(seed, i+(xNMask&primeX), j+(^yNMask&primeY), k+(zNMask&primeZ), x6, y6, z6)
} else {
a7 := T(xAFlipMask0+zAFlipMask0) + a0
if a7 > 0 {
x7 := x0 - T(xNMask|1)
y7 := y0
z7 := z0 - T(zNMask|1)
value += (a7 * a7) * (a7 * a7) * gradCoord3D(seed, i+(^xNMask&primeX), j+(yNMask&primeY), k+(^zNMask&primeZ), x7, y7, z7)
}
a8 := T(yAFlipMask1) + a1
if a8 > 0 {
x8 := x1
y8 := T(yNMask|1) + y1
z8 := z1
value += (a8 * a8) * (a8 * a8) * gradCoord3D(seed2, i+primeX, j+(yNMask&(primeY2)), k+primeZ, x8, y8, z8)
skip9 = true
}
}
skipD := false
aA := T(zAFlipMask0) + a0
if aA > 0 {
xA := x0
yA := y0
zA := z0 - T(zNMask|1)
value += (aA * aA) * (aA * aA) * gradCoord3D(seed, i+(xNMask&primeX), j+(yNMask&primeY), k+(^zNMask&primeZ), xA, yA, zA)
} else {
aB := T(xAFlipMask0+yAFlipMask0) + a0
if aB > 0 {
xB := x0 - T(xNMask|1)
yB := y0 - T(yNMask|1)
zB := z0
value += (aB * aB) * (aB * aB) * gradCoord3D(seed, i+(^xNMask&primeX), j+(^yNMask&primeY), k+(zNMask&primeZ), xB, yB, zB)
}
aC := T(zAFlipMask1) + a1
if aC > 0 {
xC := x1
yC := y1
zC := T(zNMask|1) + z1
value += (aC * aC) * (aC * aC) * gradCoord3D(seed2, i+primeX, j+primeY, k+(zNMask&(primeZ2)), xC, yC, zC)
skipD = true
}
}
if !skip5 {
a5 := T(yAFlipMask1+zAFlipMask1) + a1
if a5 > 0 {
x5 := x1
y5 := T(yNMask|1) + y1
z5 := T(zNMask|1) + z1
value += (a5 * a5) * (a5 * a5) * gradCoord3D(seed2, i+primeX, j+(yNMask&(primeY2)), k+(zNMask&(primeZ2)), x5, y5, z5)
}
}
if !skip9 {
a9 := T(xAFlipMask1+zAFlipMask1) + a1
if a9 > 0 {
x9 := T(xNMask|1) + x1
y9 := y1
z9 := T(zNMask|1) + z1
value += (a9 * a9) * (a9 * a9) * gradCoord3D(seed2, i+(xNMask&(primeX2)), j+primeY, k+(zNMask&(primeZ2)), x9, y9, z9)
}
}
if !skipD {
aD := T(xAFlipMask1+yAFlipMask1) + a1
if aD > 0 {
xD := T(xNMask|1) + x1
yD := T(yNMask|1) + y1
zD := z1
value += (aD * aD) * (aD * aD) * gradCoord3D(seed2, i+(xNMask&(primeX2)), j+(yNMask&(primeY2)), k+primeZ, xD, yD, zD)
}
}
return value * 9.046026385208288
}
// Cellular Noise
func singleCellular2D[T Float](state *State[T], seed int, x, y T) T {
xr := fastRound(x)
yr := fastRound(y)
// One of the more painful aspects of Go generics..
var dist0, dist1 T
switch dptr := any(&dist0).(type) {
case *float32:
*dptr = math.MaxFloat32
case *float64:
*dptr = math.MaxFloat64
}
dist1 = dist0
var closestHash uint32
// jitter := 0.5 * state.CellularJitterMod
jitter := 0.43701595 * state.CellularJitterMod
xPrimed := (xr - 1) * primeX
yPrimedBase := (yr - 1) * primeY
switch state.CellularDistanceFunc {
default:
for xi := xr - 1; xi <= xr+1; xi++ {
yPrimed := yPrimedBase
for yi := yr - 1; yi <= yr+1; yi++ {
hash := hash2D(seed, xPrimed, yPrimed)
idx := hash & (255 << 1)
vecX := (T(xi) - x) + T(randVecs2D[idx])*jitter
vecY := (T(yi) - y) + T(randVecs2D[idx|1])*jitter
newDistance := vecX*vecX + vecY*vecY
dist1 = fastMax(fastMin(dist1, newDistance), dist0)
if newDistance < dist0 {
dist0 = newDistance
closestHash = hash
}
yPrimed += primeY
}
xPrimed += primeX
}
case CellularDistanceManhattan:
for xi := xr - 1; xi <= xr+1; xi++ {
yPrimed := yPrimedBase
for yi := yr - 1; yi <= yr+1; yi++ {
hash := hash2D(seed, xPrimed, yPrimed)
idx := hash & (255 << 1)
vecX := (T(xi) - x) + T(randVecs2D[idx])*jitter
vecY := (T(yi) - y) + T(randVecs2D[idx|1])*jitter
newDistance := fastAbs(vecX) + fastAbs(vecY)
dist1 = fastMax(fastMin(dist1, newDistance), dist0)
if newDistance < dist0 {
dist0 = newDistance
closestHash = hash
}
yPrimed += primeY
}
xPrimed += primeX
}
case CellularDistanceHybrid:
for xi := xr - 1; xi <= xr+1; xi++ {
yPrimed := yPrimedBase
for yi := yr - 1; yi <= yr+1; yi++ {
hash := hash2D(seed, xPrimed, yPrimed)
idx := hash & (255 << 1)
vecX := (T(xi) - x) + T(randVecs2D[idx])*jitter
vecY := (T(yi) - y) + T(randVecs2D[idx|1])*jitter
newDistance := (fastAbs(vecX) + fastAbs(vecY)) + (vecX*vecX + vecY*vecY)
dist1 = fastMax(fastMin(dist1, newDistance), dist0)
if newDistance < dist0 {
dist0 = newDistance
closestHash = hash
}
yPrimed += primeY
}
xPrimed += primeX
}
}
if state.CellularDistanceFunc == CellularDistanceEuclidean && state.CellularReturnType >= CellularReturnDistance {
dist0 = fastSqrt(dist0)
if state.CellularReturnType >= CellularReturnDistance2 {
dist1 = fastSqrt(dist1)
}
}
switch state.CellularReturnType {
case CellularReturnCellValue:
return T(closestHash) * (1 / 2147483648.0)
case CellularReturnDistance:
return dist0 - 1
case CellularReturnDistance2:
return dist1 - 1
case CellularReturnDistance2Add:
return (dist1+dist0)*0.5 - 1
case CellularReturnDistance2Sub:
return dist1 - dist0 - 1
case CellularReturnDistance2Mul:
return dist1*dist0*0.5 - 1
case CellularReturnDistance2Div:
return dist0/dist1 - 1
default:
return 0
}
}
func singleCellular3D[T Float](state *State[T], seed int, x, y, z T) T {
xr := fastRound(x)
yr := fastRound(y)
zr := fastRound(z)
var dist0, dist1 T
switch dptr := any(&dist0).(type) {
case *float32:
*dptr = math.MaxFloat32
case *float64:
*dptr = math.MaxFloat64
}
dist1 = dist0
var closestHash uint32
jitter := 0.39614353 * state.CellularJitterMod
xPrimed := (xr - 1) * primeX
yPrimedBase := (yr - 1) * primeY
zPrimedBase := (zr - 1) * primeZ
switch state.CellularDistanceFunc {
default:
for xi := xr - 1; xi <= xr+1; xi++ {
yPrimed := yPrimedBase
for yi := yr - 1; yi <= yr+1; yi++ {
zPrimed := zPrimedBase
for zi := zr - 1; zi <= zr+1; zi++ {
hash := hash3D(seed, xPrimed, yPrimed, zPrimed)
idx := hash & (255 << 2)
vecX := (T(xi) - x) + T(randVecs3D[idx])*jitter
vecY := (T(yi) - y) + T(randVecs3D[idx|1])*jitter
vecZ := (T(zi) - z) + T(randVecs3D[idx|2])*jitter
newDistance := vecX*vecX + vecY*vecY + vecZ*vecZ
dist1 = fastMax(fastMin(dist1, newDistance), dist0)
if newDistance < dist0 {
dist0 = newDistance
closestHash = hash
}
zPrimed += primeZ
}
yPrimed += primeY
}
xPrimed += primeX
}
case CellularDistanceManhattan:
for xi := xr - 1; xi <= xr+1; xi++ {
yPrimed := yPrimedBase
for yi := yr - 1; yi <= yr+1; yi++ {
zPrimed := zPrimedBase
for zi := zr - 1; zi <= zr+1; zi++ {
hash := hash3D(seed, xPrimed, yPrimed, zPrimed)
idx := hash & (255 << 2)
vecX := (T(xi) - x) + T(randVecs3D[idx])*jitter
vecY := (T(yi) - y) + T(randVecs3D[idx|1])*jitter
vecZ := (T(zi) - z) + T(randVecs3D[idx|2])*jitter
newDistance := fastAbs(vecX) + fastAbs(vecY) + fastAbs(vecZ)
dist1 = fastMax(fastMin(dist1, newDistance), dist0)
if newDistance < dist0 {
dist0 = newDistance
closestHash = hash
}
zPrimed += primeZ
}
yPrimed += primeY
}
xPrimed += primeX
}
case CellularDistanceHybrid:
for xi := xr - 1; xi <= xr+1; xi++ {
yPrimed := yPrimedBase
for yi := yr - 1; yi <= yr+1; yi++ {
zPrimed := zPrimedBase
for zi := zr - 1; zi <= zr+1; zi++ {
hash := hash3D(seed, xPrimed, yPrimed, zPrimed)
idx := hash & (255 << 2)
vecX := (T(xi) - x) + T(randVecs3D[idx])*jitter
vecY := (T(yi) - y) + T(randVecs3D[idx|1])*jitter
vecZ := (T(zi) - z) + T(randVecs3D[idx|2])*jitter
newDistance := (fastAbs(vecX) + fastAbs(vecY) + fastAbs(vecZ)) + (vecX*vecX + vecY*vecY + vecZ*vecZ)
dist1 = fastMax(fastMin(dist1, newDistance), dist0)
if newDistance < dist0 {
dist0 = newDistance
closestHash = hash
}
zPrimed += primeZ
}
yPrimed += primeY
}
xPrimed += primeX
}
}
if state.CellularDistanceFunc == CellularDistanceEuclidean && state.CellularReturnType >= CellularReturnDistance {
dist0 = fastSqrt(dist0)
if state.CellularReturnType >= CellularReturnDistance2 {
dist1 = fastSqrt(dist1)
}
}
switch state.CellularReturnType {
case CellularReturnCellValue:
return T(closestHash) * (1 / 2147483648.0)
case CellularReturnDistance:
return dist0 - 1
case CellularReturnDistance2:
return dist1 - 1
case CellularReturnDistance2Add:
return (dist1+dist0)*0.5 - 1
case CellularReturnDistance2Sub:
return dist1 - dist0 - 1
case CellularReturnDistance2Mul:
return dist1*dist0*0.5 - 1
case CellularReturnDistance2Div:
return dist0/dist1 - 1
default:
return 0
}
}
// Perlin Noise
func singlePerlin2D[T Float](state *State[T], seed int, x, y T) T {
x0 := fastFloor(x)
y0 := fastFloor(y)
xd0 := x - T(x0)
yd0 := y - T(y0)
xd1 := xd0 - 1
yd1 := yd0 - 1
xs := interpQuintic(xd0)
ys := interpQuintic(yd0)
x0 *= primeX
y0 *= primeY
x1 := x0 + primeX
y1 := y0 + primeY
xf0 := lerp(gradCoord2D(seed, x0, y0, xd0, yd0), gradCoord2D(seed, x1, y0, xd1, yd0), xs)
xf1 := lerp(gradCoord2D(seed, x0, y1, xd0, yd1), gradCoord2D(seed, x1, y1, xd1, yd1), xs)
return lerp(xf0, xf1, ys) * 1.4247691104677813
}
func singlePerlin3D[T Float](state *State[T], seed int, x, y, z T) T {
x0 := fastFloor(x)
y0 := fastFloor(y)
z0 := fastFloor(z)
xd0 := x - T(x0)
yd0 := y - T(y0)
zd0 := z - T(z0)
xd1 := xd0 - 1
yd1 := yd0 - 1
zd1 := zd0 - 1
xs := interpQuintic(xd0)
ys := interpQuintic(yd0)
zs := interpQuintic(zd0)
x0 *= primeX
y0 *= primeY
z0 *= primeZ
x1 := x0 + primeX
y1 := y0 + primeY
z1 := z0 + primeZ
xf00 := lerp(gradCoord3D(seed, x0, y0, z0, xd0, yd0, zd0), gradCoord3D(seed, x1, y0, z0, xd1, yd0, zd0), xs)
xf10 := lerp(gradCoord3D(seed, x0, y1, z0, xd0, yd1, zd0), gradCoord3D(seed, x1, y1, z0, xd1, yd1, zd0), xs)
xf01 := lerp(gradCoord3D(seed, x0, y0, z1, xd0, yd0, zd1), gradCoord3D(seed, x1, y0, z1, xd1, yd0, zd1), xs)
xf11 := lerp(gradCoord3D(seed, x0, y1, z1, xd0, yd1, zd1), gradCoord3D(seed, x1, y1, z1, xd1, yd1, zd1), xs)
yf0 := lerp(xf00, xf10, ys)
yf1 := lerp(xf01, xf11, ys)
return lerp(yf0, yf1, zs) * 0.964921414852142333984375
}
// Value Cubic
func singleValueCubic2D[T Float](state *State[T], seed int, x, y T) T {
x1 := fastFloor(x)
y1 := fastFloor(y)
xs := x - T(x1)
ys := y - T(y1)
x1 *= primeX
y1 *= primeY
x0 := x1 - primeX
y0 := y1 - primeY
x2 := x1 + primeX
y2 := y1 + primeY
x3 := x1 + primeX2
y3 := y1 + primeY2
return cubicLerp(
cubicLerp(valCoord2D[T](seed, x0, y0), valCoord2D[T](seed, x1, y0), valCoord2D[T](seed, x2, y0), valCoord2D[T](seed, x3, y0), xs),
cubicLerp(valCoord2D[T](seed, x0, y1), valCoord2D[T](seed, x1, y1), valCoord2D[T](seed, x2, y1), valCoord2D[T](seed, x3, y1), xs),
cubicLerp(valCoord2D[T](seed, x0, y2), valCoord2D[T](seed, x1, y2), valCoord2D[T](seed, x2, y2), valCoord2D[T](seed, x3, y2), xs),
cubicLerp(valCoord2D[T](seed, x0, y3), valCoord2D[T](seed, x1, y3), valCoord2D[T](seed, x2, y3), valCoord2D[T](seed, x3, y3), xs), ys) * (1 / (1.5 * 1.5))
}
func singleValueCubic3D[T Float](state *State[T], seed int, x, y, z T) T {
x1 := fastFloor(x)
y1 := fastFloor(y)
z1 := fastFloor(z)
xs := x - T(x1)
ys := y - T(y1)
zs := z - T(z1)
x1 *= primeX
y1 *= primeY
z1 *= primeZ
x0 := x1 - primeX
y0 := y1 - primeY
z0 := z1 - primeZ
x2 := x1 + primeX
y2 := y1 + primeY
z2 := z1 + primeZ
x3 := x1 + primeX2
y3 := y1 + primeY2
z3 := z1 + primeZ2
return cubicLerp(
cubicLerp(
cubicLerp(valCoord3D[T](seed, x0, y0, z0), valCoord3D[T](seed, x1, y0, z0), valCoord3D[T](seed, x2, y0, z0), valCoord3D[T](seed, x3, y0, z0), xs),
cubicLerp(valCoord3D[T](seed, x0, y1, z0), valCoord3D[T](seed, x1, y1, z0), valCoord3D[T](seed, x2, y1, z0), valCoord3D[T](seed, x3, y1, z0), xs),
cubicLerp(valCoord3D[T](seed, x0, y2, z0), valCoord3D[T](seed, x1, y2, z0), valCoord3D[T](seed, x2, y2, z0), valCoord3D[T](seed, x3, y2, z0), xs),
cubicLerp(valCoord3D[T](seed, x0, y3, z0), valCoord3D[T](seed, x1, y3, z0), valCoord3D[T](seed, x2, y3, z0), valCoord3D[T](seed, x3, y3, z0), xs),
ys),
cubicLerp(
cubicLerp(valCoord3D[T](seed, x0, y0, z1), valCoord3D[T](seed, x1, y0, z1), valCoord3D[T](seed, x2, y0, z1), valCoord3D[T](seed, x3, y0, z1), xs),
cubicLerp(valCoord3D[T](seed, x0, y1, z1), valCoord3D[T](seed, x1, y1, z1), valCoord3D[T](seed, x2, y1, z1), valCoord3D[T](seed, x3, y1, z1), xs),
cubicLerp(valCoord3D[T](seed, x0, y2, z1), valCoord3D[T](seed, x1, y2, z1), valCoord3D[T](seed, x2, y2, z1), valCoord3D[T](seed, x3, y2, z1), xs),
cubicLerp(valCoord3D[T](seed, x0, y3, z1), valCoord3D[T](seed, x1, y3, z1), valCoord3D[T](seed, x2, y3, z1), valCoord3D[T](seed, x3, y3, z1), xs),
ys),
cubicLerp(
cubicLerp(valCoord3D[T](seed, x0, y0, z2), valCoord3D[T](seed, x1, y0, z2), valCoord3D[T](seed, x2, y0, z2), valCoord3D[T](seed, x3, y0, z2), xs),
cubicLerp(valCoord3D[T](seed, x0, y1, z2), valCoord3D[T](seed, x1, y1, z2), valCoord3D[T](seed, x2, y1, z2), valCoord3D[T](seed, x3, y1, z2), xs),
cubicLerp(valCoord3D[T](seed, x0, y2, z2), valCoord3D[T](seed, x1, y2, z2), valCoord3D[T](seed, x2, y2, z2), valCoord3D[T](seed, x3, y2, z2), xs),
cubicLerp(valCoord3D[T](seed, x0, y3, z2), valCoord3D[T](seed, x1, y3, z2), valCoord3D[T](seed, x2, y3, z2), valCoord3D[T](seed, x3, y3, z2), xs),
ys),
cubicLerp(
cubicLerp(valCoord3D[T](seed, x0, y0, z3), valCoord3D[T](seed, x1, y0, z3), valCoord3D[T](seed, x2, y0, z3), valCoord3D[T](seed, x3, y0, z3), xs),
cubicLerp(valCoord3D[T](seed, x0, y1, z3), valCoord3D[T](seed, x1, y1, z3), valCoord3D[T](seed, x2, y1, z3), valCoord3D[T](seed, x3, y1, z3), xs),
cubicLerp(valCoord3D[T](seed, x0, y2, z3), valCoord3D[T](seed, x1, y2, z3), valCoord3D[T](seed, x2, y2, z3), valCoord3D[T](seed, x3, y2, z3), xs),
cubicLerp(valCoord3D[T](seed, x0, y3, z3), valCoord3D[T](seed, x1, y3, z3), valCoord3D[T](seed, x2, y3, z3), valCoord3D[T](seed, x3, y3, z3), xs),
ys),
zs) * (1 / (1.5 * 1.5 * 1.5))
}
// Value noise
func singleValue2D[T Float](state *State[T], seed int, x, y T) T {
x0 := fastFloor(x)
y0 := fastFloor(y)
xs := interpHermite(x - T(x0))
ys := interpHermite(y - T(y0))
x0 *= primeX
y0 *= primeY
x1 := x0 + primeX
y1 := y0 + primeY
xf0 := lerp(valCoord2D[T](seed, x0, y0), valCoord2D[T](seed, x1, y0), xs)
xf1 := lerp(valCoord2D[T](seed, x0, y1), valCoord2D[T](seed, x1, y1), xs)
return lerp(xf0, xf1, ys)
}
func singleValue3D[T Float](state *State[T], seed int, x, y, z T) T {
x0 := fastFloor(x)
y0 := fastFloor(y)
z0 := fastFloor(z)
xs := interpHermite(x - T(x0))
ys := interpHermite(y - T(y0))
zs := interpHermite(z - T(z0))
x0 *= primeX
y0 *= primeY
z0 *= primeZ
x1 := x0 + primeX
y1 := y0 + primeY
z1 := z0 + primeZ
xf00 := lerp(valCoord3D[T](seed, x0, y0, z0), valCoord3D[T](seed, x1, y0, z0), xs)
xf10 := lerp(valCoord3D[T](seed, x0, y1, z0), valCoord3D[T](seed, x1, y1, z0), xs)
xf01 := lerp(valCoord3D[T](seed, x0, y0, z1), valCoord3D[T](seed, x1, y0, z1), xs)
xf11 := lerp(valCoord3D[T](seed, x0, y1, z1), valCoord3D[T](seed, x1, y1, z1), xs)
yf0 := lerp(xf00, xf10, ys)
yf1 := lerp(xf01, xf11, ys)
return lerp(yf0, yf1, zs)
}
// Domain Warp
func doSingleDomainWarp2D[T Float](state *State[T], seed int, amp, freq, x, y T, xp, yp *T) {
switch state.DomainWarpType {
case DomainWarpOpenSimplex2:
singleDomainWarpSimplexGradient(seed, amp*38.283687591552734375, freq, x, y, xp, yp, false)
case DomainWarpOpenSimplex2Reduced:
singleDomainWarpSimplexGradient(seed, amp*16.0, freq, x, y, xp, yp, true)
case DomainWarpBasicGrid:
singleDomainWarpBasicGrid2D(seed, amp, freq, x, y, xp, yp)
}
}
func doSingleDomainWarp3D[T Float](state *State[T], seed int, amp, freq, x, y, z T, xp, yp, zp *T) {
switch state.DomainWarpType {
case DomainWarpOpenSimplex2:
singleDomainWarpOpenSimplex2Gradient(seed, amp*32.69428253173828125, freq, x, y, z, xp, yp, zp, false)
case DomainWarpOpenSimplex2Reduced:
singleDomainWarpOpenSimplex2Gradient(seed, amp*7.71604938271605, freq, x, y, z, xp, yp, zp, true)
case DomainWarpBasicGrid:
singleDomainWarpBasicGrid3D(seed, amp, freq, x, y, z, xp, yp, zp)
}
}
// Domain Warp Single Wrapper
func domainWarpSingle2D[T Float](state *State[T], x, y *T) {
seed := state.Seed
amp := state.DomainWarpAmp * calculateFractalBounding(state)
freq := state.Frequency
xs := *x
ys := *y
transformDomainWarpCoordinate2D(state, &xs, &ys)
doSingleDomainWarp2D(state, seed, amp, freq, xs, ys, x, y)
}
func domainWarpSingle3D[T Float](state *State[T], x, y, z *T) {
seed := state.Seed
amp := state.DomainWarpAmp * calculateFractalBounding(state)
freq := state.Frequency
xs := *x
ys := *y
zs := *z
transformDomainWarpCoordinate3D(state, &xs, &ys, &zs)
doSingleDomainWarp3D(state, seed, amp, freq, xs, ys, zs, x, y, z)
}
// Domain Warp Fractal Progressive
func domainWarpFractalProgressive2D[T Float](state *State[T], x, y *T) {
seed := state.Seed
amp := state.DomainWarpAmp * calculateFractalBounding(state)
freq := state.Frequency
for i := 0; i < state.Octaves; i++ {
xs := *x
ys := *y
transformDomainWarpCoordinate2D(state, &xs, &ys)
doSingleDomainWarp2D(state, seed, amp, freq, xs, ys, x, y)
seed++
amp *= state.Gain
freq *= state.Lacunarity
}
}
func domainWarpFractalProgressive3D[T Float](state *State[T], x, y, z *T) {
seed := state.Seed
amp := state.DomainWarpAmp * calculateFractalBounding(state)
freq := state.Frequency
for i := 0; i < state.Octaves; i++ {
xs := *x
ys := *y
zs := *z
transformDomainWarpCoordinate3D(state, &xs, &ys, &zs)
doSingleDomainWarp3D(state, seed, amp, freq, xs, ys, zs, x, y, z)
seed++
amp *= state.Gain
freq *= state.Lacunarity
}
}
// Domain Warp Fractal Independent
func domainWarpFractalIndependent2D[T Float](state *State[T], x, y *T) {
xs := *x
ys := *y
transformDomainWarpCoordinate2D(state, &xs, &ys)
seed := state.Seed
amp := state.DomainWarpAmp * calculateFractalBounding(state)
freq := state.Frequency
for i := 0; i < state.Octaves; i++ {
doSingleDomainWarp2D(state, seed, amp, freq, xs, ys, x, y)
seed++
amp *= state.Gain
freq *= state.Lacunarity
}
}
func domainWarpFractalIndependent3D[T Float](state *State[T], x, y, z *T) {
xs := *x
ys := *y
zs := *z
transformDomainWarpCoordinate3D(state, &xs, &ys, &zs)
seed := state.Seed
amp := state.DomainWarpAmp * calculateFractalBounding(state)
freq := state.Frequency
for i := 0; i < state.Octaves; i++ {
doSingleDomainWarp3D(state, seed, amp, freq, xs, ys, zs, x, y, z)
seed++
amp *= state.Gain
freq *= state.Lacunarity
}
}
// Domain Warp Basic Grid
func singleDomainWarpBasicGrid2D[T Float](seed int, warpAmp, frequency, x, y T, xp, yp *T) {
xf := x * frequency
yf := y * frequency
x0 := fastFloor(xf)
y0 := fastFloor(yf)
xs := interpHermite(xf - T(x0))
ys := interpHermite(yf - T(y0))
x0 *= primeX
y0 *= primeY
x1 := x0 + primeX
y1 := y0 + primeY
idx0 := hash2D(seed, x0, y0) & (255 << 1)
idx1 := hash2D(seed, x1, y0) & (255 << 1)
lx0x := lerp(T(randVecs2D[idx0]), T(randVecs2D[idx1]), xs)
ly0x := lerp(T(randVecs2D[idx0|1]), T(randVecs2D[idx1|1]), xs)
idx0 = hash2D(seed, x0, y1) & (255 << 1)
idx1 = hash2D(seed, x1, y1) & (255 << 1)
lx1x := lerp(T(randVecs2D[idx0]), T(randVecs2D[idx1]), xs)
ly1x := lerp(T(randVecs2D[idx0|1]), T(randVecs2D[idx1|1]), xs)
*xp += lerp(lx0x, lx1x, ys) * warpAmp
*yp += lerp(ly0x, ly1x, ys) * warpAmp
}
func singleDomainWarpBasicGrid3D[T Float](seed int, warpAmp, frequency, x, y, z T, xp, yp, zp *T) {
xf := x * frequency
yf := y * frequency
zf := z * frequency
x0 := fastFloor(xf)
y0 := fastFloor(yf)
z0 := fastFloor(zf)
xs := interpHermite(xf - T(x0))
ys := interpHermite(yf - T(y0))
zs := interpHermite(zf - T(z0))
x0 *= primeX
y0 *= primeY
z0 *= primeZ
x1 := x0 + primeX
y1 := y0 + primeY
z1 := z0 + primeZ
idx0 := hash3D(seed, x0, y0, z0) & (255 << 2)
idx1 := hash3D(seed, x1, y0, z0) & (255 << 2)
lx0x := lerp(T(randVecs3D[idx0]), T(randVecs3D[idx1]), xs)
ly0x := lerp(T(randVecs3D[idx0|1]), T(randVecs3D[idx1|1]), xs)
lz0x := lerp(T(randVecs3D[idx0|2]), T(randVecs3D[idx1|2]), xs)
idx0 = hash3D(seed, x0, y1, z0) & (255 << 2)
idx1 = hash3D(seed, x1, y1, z0) & (255 << 2)
lx1x := lerp(T(randVecs3D[idx0]), T(randVecs3D[idx1]), xs)
ly1x := lerp(T(randVecs3D[idx0|1]), T(randVecs3D[idx1|1]), xs)
lz1x := lerp(T(randVecs3D[idx0|2]), T(randVecs3D[idx1|2]), xs)
lx0y := lerp(lx0x, lx1x, ys)
ly0y := lerp(ly0x, ly1x, ys)
lz0y := lerp(lz0x, lz1x, ys)
idx0 = hash3D(seed, x0, y0, z1) & (255 << 2)
idx1 = hash3D(seed, x1, y0, z1) & (255 << 2)
lx0x = lerp(T(randVecs3D[idx0]), T(randVecs3D[idx1]), xs)
ly0x = lerp(T(randVecs3D[idx0|1]), T(randVecs3D[idx1|1]), xs)
lz0x = lerp(T(randVecs3D[idx0|2]), T(randVecs3D[idx1|2]), xs)
idx0 = hash3D(seed, x0, y1, z1) & (255 << 2)
idx1 = hash3D(seed, x1, y1, z1) & (255 << 2)
lx1x = lerp(T(randVecs3D[idx0]), T(randVecs3D[idx1]), xs)
ly1x = lerp(T(randVecs3D[idx0|1]), T(randVecs3D[idx1|1]), xs)
lz1x = lerp(T(randVecs3D[idx0|2]), T(randVecs3D[idx1|2]), xs)
*xp += lerp(lx0y, lerp(lx0x, lx1x, ys), zs) * warpAmp
*yp += lerp(ly0y, lerp(ly0x, ly1x, ys), zs) * warpAmp
*zp += lerp(lz0y, lerp(lz0x, lz1x, ys), zs) * warpAmp
}
// Domain Warp Simplex/OpenSimplex2
func singleDomainWarpSimplexGradient[T Float](seed int, warpAmp, frequency, x, y T, xr, yr *T, outGradOnly bool) {
const SQRT3 float64 = 1.7320508075688772935274463415059
const G2 float64 = (3 - SQRT3) / 6
x *= frequency
y *= frequency
i := fastFloor(x)
j := fastFloor(y)
xi := x - T(i)
yi := y - T(j)
t := T(xi+yi) * T(G2)
x0 := xi - t
y0 := yi - t
i *= primeX
j *= primeY
var vx, vy T
a := 0.5 - x0*x0 - y0*y0
if a > 0 {
aaaa := (a * a) * (a * a)
var xo, yo T
if outGradOnly {
gradCoordOut2D(seed, i, j, &xo, &yo)
} else {
gradCoordDual2D(seed, i, j, x0, y0, &xo, &yo)
}
vx += aaaa * xo
vy += aaaa * yo
}
c := T(2*(1-2*G2)*(1/G2-2))*t + (T(-2*(1-2*G2)*(1-2*G2)) + a)
if c > 0 {
x2 := x0 + (2*T(G2) - 1)
y2 := y0 + (2*T(G2) - 1)
cccc := (c * c) * (c * c)
var xo, yo T
if outGradOnly {
gradCoordOut2D(seed, i+primeX, j+primeY, &xo, &yo)
} else {
gradCoordDual2D(seed, i+primeX, j+primeY, x2, y2, &xo, &yo)
}
vx += cccc * xo
vy += cccc * yo
}
if y0 > x0 {
x1 := x0 + T(G2)
y1 := y0 + T(G2-1)
b := 0.5 - x1*x1 - y1*y1
if b > 0 {
bbbb := (b * b) * (b * b)
var xo, yo T
if outGradOnly {
gradCoordOut2D(seed, i, j+primeY, &xo, &yo)
} else {
gradCoordDual2D(seed, i, j+primeY, x1, y1, &xo, &yo)
}
vx += bbbb * xo
vy += bbbb * yo
}
} else {
x1 := x0 + T(G2-1)
y1 := y0 + T(G2)
b := 0.5 - x1*x1 - y1*y1
if b > 0 {
bbbb := (b * b) * (b * b)
var xo, yo T
if outGradOnly {
gradCoordOut2D(seed, i+primeX, j, &xo, &yo)
} else {
gradCoordDual2D(seed, i+primeX, j, x1, y1, &xo, &yo)
}
vx += bbbb * xo
vy += bbbb * yo
}
}
*xr += vx * warpAmp
*yr += vy * warpAmp
}
func singleDomainWarpOpenSimplex2Gradient[T Float](seed int, warpAmp, frequency, x, y, z T, xr, yr, zr *T, outGradOnly bool) {
x *= frequency
y *= frequency
z *= frequency
i := fastRound(x)
j := fastRound(y)
k := fastRound(z)
x0 := x - T(i)
y0 := y - T(j)
z0 := z - T(k)
xNSign := int(-x0-1.0) | 1
yNSign := int(-y0-1.0) | 1
zNSign := int(-z0-1.0) | 1
ax0 := T(xNSign) * -x0
ay0 := T(yNSign) * -y0
az0 := T(zNSign) * -z0
i *= primeX
j *= primeY
k *= primeZ
var vx, vy, vz T
a := (0.6 - x0*x0) - (y0*y0 + z0*z0)
for l := 0; l < 2; l++ {
if a > 0 {
aaaa := (a * a) * (a * a)
var xo, yo, zo T
if outGradOnly {
gradCoordOut3D(seed, i, j, k, &xo, &yo, &zo)
} else {
gradCoordDual3D(seed, i, j, k, x0, y0, z0, &xo, &yo, &zo)
}
vx += aaaa * xo
vy += aaaa * yo
vz += aaaa * zo
}
b := a + 1
i1 := i
j1 := j
k1 := k
x1 := x0
y1 := y0
z1 := z0
if ax0 >= ay0 && ax0 >= az0 {
x1 += T(xNSign)
b -= T(xNSign) * 2 * x1
i1 -= xNSign * primeX
} else if ay0 > ax0 && ay0 >= az0 {
y1 += T(yNSign)
b -= T(yNSign) * 2 * y1
j1 -= yNSign * primeY
} else {
z1 += T(zNSign)
b -= T(zNSign) * 2 * z1
k1 -= zNSign * primeZ
}
if b > 0 {
bbbb := (b * b) * (b * b)
var xo, yo, zo T
if outGradOnly {
gradCoordOut3D(seed, i1, j1, k1, &xo, &yo, &zo)
} else {
gradCoordDual3D(seed, i1, j1, k1, x1, y1, z1, &xo, &yo, &zo)
}
vx += bbbb * xo
vy += bbbb * yo
vz += bbbb * zo
}
if l == 1 {
break
}
ax0 = 0.5 - ax0
ay0 = 0.5 - ay0
az0 = 0.5 - az0
x0 = T(xNSign) * ax0
y0 = T(yNSign) * ay0
z0 = T(zNSign) * az0
a += (0.75 - ax0) - (ay0 + az0)
i += (xNSign >> 1) & primeX
j += (yNSign >> 1) & primeY
k += (zNSign >> 1) & primeZ
xNSign = -xNSign
yNSign = -yNSign
zNSign = -zNSign
seed += 1293373
}
*xr += vx * warpAmp
*yr += vy * warpAmp
*zr += vz * warpAmp
}
// vim: ts=4
``` | /content/code_sandbox/Go/fastnoise.go | go | 2016-03-28T02:35:12 | 2024-08-16T07:09:20 | FastNoiseLite | Auburn/FastNoiseLite | 2,688 | 36,456 |
```swift
//EasyLayout
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
import PackageDescription
let package = Package(name: "Stellar")
``` | /content/code_sandbox/Package.swift | swift | 2016-05-25T09:02:36 | 2024-08-14T16:00:58 | Stellar | AugustRush/Stellar | 2,933 | 243 |
```ruby
Pod::Spec.new do |s|
s.name = "Stellar"
s.version = "0.67"
s.summary = "An Awesome Physical animation library base on UIDynamic. "
s.description = "A fantastic Physical animation library for swift(Not Just Spring !!!), it is base on UIDynamic and extension to it, friendly APIs make you use it or custom your own animation very easily!"
s.homepage = "path_to_url"
s.license = "LICENSE"
s.author = { "AugustRush" => "819373341@qq.com" }
s.source = { :git => "path_to_url", :tag => "0.67" }
s.source_files = "Sources", "Sources/*.swift"
s.platform = :ios, "8.0"
s.frameworks = "UIKit", "Foundation"
end
``` | /content/code_sandbox/Stellar.podspec | ruby | 2016-05-25T09:02:36 | 2024-08-14T16:00:58 | Stellar | AugustRush/Stellar | 2,933 | 191 |
```swift
//
// LiquidView.swift
// StellarDemo
//
// Created by AugustRush on 6/3/16.
//
import UIKit
class LiquidView: UIView {
override class func layerClass() -> AnyClass {
return CAShapeLayer.self
}
}
``` | /content/code_sandbox/StellarDemo/StellarDemo/LiquidView.swift | swift | 2016-05-25T09:02:36 | 2024-08-14T16:00:58 | Stellar | AugustRush/Stellar | 2,933 | 61 |
```swift
//
// Example3ViewController.swift
// StellarDemo
//
// Created by AugustRush on 5/30/16.
//
import UIKit
class Example3ViewController: UIViewController {
@IBOutlet var leftLines: [Ball]!
@IBOutlet var rightLines: [Ball]!
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
for (index,line) in leftLines.enumerated() {
let delay = Double(index) * 0.2
line.moveX(200).duration(2).delay(delay)
.then().moveX(-200).makeColor(UIColor.green).easing(.linear).repeatCount(100).reverses().duration(2).animate()
line.makeWidth(80).delay(delay).duration(1).reverses().easing(.linear).repeatCount(100).animate()
}
for (index,line) in rightLines.enumerated() {
let delay = Double(index) * 0.2
line.moveX(-200).duration(2).delay(delay)
.then().moveX(200).makeColor(UIColor.purple).easing(.linear).repeatCount(100).reverses().duration(2).animate()
line.makeWidth(80).delay(delay).duration(1).reverses().easing(.linear).repeatCount(100).animate()
}
}
}
``` | /content/code_sandbox/StellarDemo/StellarDemo/Example3ViewController.swift | swift | 2016-05-25T09:02:36 | 2024-08-14T16:00:58 | Stellar | AugustRush/Stellar | 2,933 | 315 |
```swift
//
// GravityViewController.swift
// StellarDemo
//
// Created by AugustRush on 5/25/16.
//
import UIKit
class Example1ViewController: UIViewController {
@IBOutlet var balls: [UIView]!
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor(red: 0.97,green: 0.97,blue: 0.97,alpha: 1.0)
self.title = "Basic"
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
let point = touches.first?.location(in: self.view)
for (index,ball) in balls.enumerated() {
let center = ball.center
let interval = 0.1 * Double(index)
center.animate(to: point!,
duration: 0.8,
delay: interval,
type: .swiftOut,
render: { (p) in
ball.center = p
}, completion: { (f) in
ball.backgroundColor?.animate(to: UIColor.red,
duration: 1.4,
type: .swiftOut,
autoreverses: true,
render: { (c) in
ball.backgroundColor = c
})
ball.center.snap(to: center, damping: 0.1
, render: { (p) in
ball.center = p
})
})
}
}
}
``` | /content/code_sandbox/StellarDemo/StellarDemo/Example1ViewController.swift | swift | 2016-05-25T09:02:36 | 2024-08-14T16:00:58 | Stellar | AugustRush/Stellar | 2,933 | 334 |
```swift
//
// Example7ViewController.swift
// StellarDemo
//
// Created by AugustRush on 6/8/16.
//
import UIKit
class Example7ViewController: UIViewController {
@IBOutlet weak var button: UIButton!
@IBAction func loadFromJSON(_ sender: AnyObject) {
}
}
``` | /content/code_sandbox/StellarDemo/StellarDemo/Example7ViewController.swift | swift | 2016-05-25T09:02:36 | 2024-08-14T16:00:58 | Stellar | AugustRush/Stellar | 2,933 | 68 |
```swift
//
// Ball.swift
// StellarDemo
//
// Created by AugustRush on 5/26/16.
//
import UIKit
@IBDesignable
class Ball: UIView {
@IBInspectable var cornerRadius: CGFloat = 15 {
didSet {
self.layer.cornerRadius = cornerRadius
}
}
}
``` | /content/code_sandbox/StellarDemo/StellarDemo/Ball.swift | swift | 2016-05-25T09:02:36 | 2024-08-14T16:00:58 | Stellar | AugustRush/Stellar | 2,933 | 72 |
```swift
//
// Example6ViewController.swift
// StellarDemo
//
// Created by AugustRush on 6/1/16.
//
import UIKit
class Example6ViewController: UIViewController {
//should be have more easily APIs to do
@IBOutlet var views: [UIView]!
var centerItems: [DynamicItemBasic<CGPoint>] = Array()
var colorItems: [DynamicItemBasic<UIColor>] = Array()
override func viewDidLoad() {
super.viewDidLoad()
for view in views {
let basic = DynamicItemBasic(from: view.center,to: CGPoint(x: 160, y: 200), render: { (p) in
view.center = p
})
basic.duration = 1.0
basic.speed = 0.0
basic.timingFunction = TimingFunctionType.swiftOut.easing()
centerItems.append(basic)
let color = view.backgroundColor!
let basic1 = DynamicItemBasic(from: color, to: UIColor.red, render: { (c) in
view.backgroundColor = c
})
basic1.duration = 1.0
basic1.speed = 0.0
basic1.timingFunction = TimingFunctionType.swiftOut.easing()
colorItems.append(basic1)
}
}
@IBAction func sliderValueChanged(_ sender: UISlider) {
let offset = Double(sender.value)
for item in centerItems {
item.timeOffset = offset
}
for item in colorItems {
item.timeOffset = offset
}
}
}
``` | /content/code_sandbox/StellarDemo/StellarDemo/Example6ViewController.swift | swift | 2016-05-25T09:02:36 | 2024-08-14T16:00:58 | Stellar | AugustRush/Stellar | 2,933 | 333 |
```swift
//
// ViewController.swift
// StellarDemo
//
// Created by AugustRush on 5/7/16.
//
import UIKit
class Example2ViewController: UIViewController {
@IBOutlet var balls: [UIView]!
var attachment: UIAttachmentBehavior!
var animator = UIDynamicAnimator()
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor(red: 0.98,green: 0.98,blue: 0.98,alpha: 1.0)
self.title = "Chainable"
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
for (index, ball) in balls.enumerated() {
let move = CGFloat(-20 + index * 20)
let opacity = Float(1 - 0.2 * CGFloat(index))
let size = CGSize(width: 20 - CGFloat(index) * 5, height: 20 - CGFloat(index) * 5)
ball.shadowOpacity(opacity).shadowOffset(size).shadowRadius(5).moveX(-move).moveY(-move).shadowColor(UIColor.gray).duration(2).easing(.bounceOut)
.then().moveY(move).moveX(move).shadowOpacity(0).shadowOffset(CGSize.zero).shadowColor(UIColor.clear).duration(1).easing(.bounceOut)
.completion({
print("all completion")
}).animate()
}
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesMoved(touches, with: event)
}
}
``` | /content/code_sandbox/StellarDemo/StellarDemo/Example2ViewController.swift | swift | 2016-05-25T09:02:36 | 2024-08-14T16:00:58 | Stellar | AugustRush/Stellar | 2,933 | 377 |
```swift
//
// Example8ViewController.swift
// StellarDemo
//
// Created by AugustRush on 6/29/16.
//
import UIKit
class Example8ViewController: UIViewController {
@IBOutlet weak var animateView: Ball!
@IBAction func segment1ValueChanged(_ sender: UISegmentedControl) {
let index = sender.selectedSegmentIndex;
switch index {
case 0:
animateView.moveX(200).duration(1.0).easing(.default).reverses().animate()
case 1:
animateView.moveX(200).duration(1.0).easing(.easeIn).reverses().animate()
case 2:
animateView.moveX(200).duration(1.0).easing(.easeOut).reverses().animate()
case 3:
animateView.moveX(200).duration(1.0).easing(.easeInEaseOut).reverses().animate()
default:
print("")
}
}
@IBAction func segment2ValueChanged(_ sender: UISegmentedControl) {
animateView.frame = CGRect(x: 20,y: 120,width: 40,height: 40)
let index = sender.selectedSegmentIndex;
switch index {
case 0:
animateView.moveX(200).duration(1.0).easing(.linear).reverses().animate()
case 1:
animateView.moveX(200).duration(1.0).easing(.swiftOut).reverses().animate()
case 2:
animateView.moveX(200).duration(1.0).easing(.backEaseIn).reverses().animate()
case 3:
animateView.moveX(200).duration(1.0).easing(.backEaseOut).reverses().animate()
default:
print("")
}
}
@IBAction func segment3ValueChanged(_ sender: UISegmentedControl) {
animateView.frame = CGRect(x: 20,y: 120,width: 40,height: 40)
let index = sender.selectedSegmentIndex;
switch index {
case 0:
animateView.moveX(200).duration(1.0).easing(.backEaseInOut).reverses().animate()
case 1:
animateView.moveX(200).duration(1.0).easing(.bounceOut).reverses().animate()
case 2:
animateView.moveX(200).duration(1.0).easing(.sine).reverses().animate()
case 3:
animateView.moveX(200).duration(1.0).easing(.circ).reverses().animate()
default:
print("")
}
}
@IBAction func segment4ValueChanged(_ sender: UISegmentedControl) {
animateView.frame = CGRect(x: 20,y: 120,width: 40,height: 40)
let index = sender.selectedSegmentIndex;
switch index {
case 0:
animateView.moveX(200).duration(1.0).easing(.exponentialIn).reverses().animate()
case 1:
animateView.moveX(200).duration(1.0).easing(.exponentialOut).reverses().animate()
case 2:
animateView.moveX(200).duration(1.0).easing(.elasticIn).reverses().animate()
case 3:
animateView.moveX(200).duration(1.0).easing(.elasticOut).reverses().animate()
default:
print("")
}
}
@IBAction func segment5ValueChanged(_ sender: UISegmentedControl) {
animateView.frame = CGRect(x: 20,y: 120,width: 40,height: 40)
let index = sender.selectedSegmentIndex;
switch index {
case 0:
animateView.moveX(200).duration(1.0).easing(.bounceReverse).reverses().animate()
case 1:
100.0.animate(to: 200, duration: 1.0, delay: 0.0, type: .swiftOut, autoreverses: false, repeatCount: 0, render: { (d) in
print("current value is \(d)")
}, completion: nil)
case 2:
100.0.attachment(to: 200, render: { (d) in
print("current value is \(d)")
})
case 3:
fallthrough
default:
print("")
}
}
}
``` | /content/code_sandbox/StellarDemo/StellarDemo/Example8ViewController.swift | swift | 2016-05-25T09:02:36 | 2024-08-14T16:00:58 | Stellar | AugustRush/Stellar | 2,933 | 999 |
```swift
//
// Example4ViewController.swift
// StellarDemo
//
// Created by AugustRush on 6/1/16.
//
import UIKit
class Example4ViewController: UIViewController {
@IBOutlet weak var animateView: Ball!
override func viewDidLoad() {
super.viewDidLoad()
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
animateView.makeSize(CGSize(width: 50, height: 150)).snap(0.3).completion({
print("First step")
})
.then().moveX(-100).moveY(-50).anchorPoint(CGPoint(x: 1, y: 1)).duration(1).completion({
print("Second step!")
})
.then().rotate(.pi).attachment(0.3, frequency: 0.8).completion({
print("Third step!")
})
.then().moveY(500).gravity().completion({
print("last step, all completion")
})
.animate()
}
}
``` | /content/code_sandbox/StellarDemo/StellarDemo/Example4ViewController.swift | swift | 2016-05-25T09:02:36 | 2024-08-14T16:00:58 | Stellar | AugustRush/Stellar | 2,933 | 236 |
```swift
//
// AppDelegate.swift
// StellarDemo
//
// Created by AugustRush on 5/7/16.
//
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}
``` | /content/code_sandbox/StellarDemo/StellarDemo/AppDelegate.swift | swift | 2016-05-25T09:02:36 | 2024-08-14T16:00:58 | Stellar | AugustRush/Stellar | 2,933 | 393 |
```swift
//
// Example5ViewController.swift
// StellarDemo
//
// Created by AugustRush on 6/1/16.
//
import UIKit
class Example5ViewController: UIViewController {
@IBOutlet weak var cyanView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
let rotation: CGFloat = .pi * 20.0
cyanView.makeSize(CGSize(width: 100, height: 30)).snap()
.then().moveY(-100).snap(1)
.then().rotate(rotation)
.duration(2)
.easing(.swiftOut)
.makeHeight(100)
.cornerRadius(50)
.then().moveY(100).gravity()
.then().moveY(-80)
.then().moveY(80).gravity()
.then().moveY(-40)
.then().moveY(40).gravity()
.then().makeWidth(120)
.makeHeight(30)
.cornerRadius(15)
.easing(.swiftOut)
.makeColor(UIColor.brown)
.animate()
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
//will cancel all remaining animations
// cyanView.cancelAllRemaining()
}
}
``` | /content/code_sandbox/StellarDemo/StellarDemo/Example5ViewController.swift | swift | 2016-05-25T09:02:36 | 2024-08-14T16:00:58 | Stellar | AugustRush/Stellar | 2,933 | 328 |
```swift
import UIKit
import PlaygroundSupport
let container = UIView(frame: CGRect.init(x: 0, y: 0, width: 600, height: 600))
container.backgroundColor = UIColor(red: 0.97,green: 0.97,blue: 0.97,alpha: 1.0)
//var balls: [Ball] = Array()
//for i in 0...5 {
// let ball = Ball(frame: CGRectMake(10,10 + 60 * CGFloat(i),50,50))
// ball.backgroundColor = UIColor.redColor()
// container.addSubview(ball)
// balls.append(ball)
//
// ball.moveX(200).duration(2)
// .delay(Double(i) * 0.1).repeatCount(1)
// .autoreverses()
// .animate()
//
// ball.makeWidth(200).duration(2).autoreverses().animate()
//}
let ball = Ball(frame: CGRect.init(x: 100, y: 100, width: 25, height: 25))
ball.backgroundColor = UIColor.cyan
container.addSubview(ball)
//ball.moveX(100).moveY(100).duration(2.5)
// .then().makeColor(UIColor.purple)
// .animate()
ball.moveX(100).moveY(100).delay(0.5).duration(2)
.then().makeWidth(160).duration(2).anchorPoint(CGPoint.init(x: 0, y: 0.5))
.then().rotate(1.5).snap(0.2)
.then().moveY(500).gravity(100)
.animate()
//let rotation: CGFloat = CGFloat(M_PI) * 20.0
//ball.makeSize(CGSizeMake(100, 30)).gravity()
// .then().moveY(-100).snap(1)
// .then().rotate(rotation).duration(2).easing(.SwiftOut).makeHeight(100).cornerRadius(50)
// .then().moveY(100).gravity()
// .then().moveY(-80)
// .then().moveY(80).gravity()
// .then().moveY(-40)
// .then().moveY(40).gravity()
// .then().makeWidth(120).makeHeight(30).cornerRadius(15).easing(.SwiftOut).makeColor(UIColor.brownColor())
// .animate()
/**
* @brief Easing Curve
*
* @param 200 move foreard
*/
//ball.moveX(200).easing(.BounceOut).delay(0.5).duration(1).animate()
//ball.moveX(200).easing(.ElasticIn).delay(0.5).duration(1).animate()
//ball.moveX(200).easing(.ElasticOut).delay(0.5).duration(1).animate()
//ball.moveX(200).easing(.Sine).delay(0.5).duration(1).animate()
//ball.moveX(200).easing(.Circ).delay(0.5).duration(1).animate()
//ball.moveX(200).easing(.ExponentialOut).delay(0.5).duration(1).animate()
//ball.moveX(200).easing(.ExponentialIn).delay(0.5).duration(1).animate()
ball.moveX(200).easing(.bounceReverse).delay(0.5).duration(3).autoreverses().animate()
PlaygroundPage.current.liveView = container
//basic curve
100.0.animate(to: 300, duration: 1, delay: 0.0, type: .custom(0.0, 1.39, 1.0, -0.55), autoreverses: false, repeatCount: 0, render: { (d) in
let y = d
}, completion: nil)
100.0.pushed(to: 300, render: { (d) in
let y = d
}, completion: nil)
100.0.snap(to: 150, damping: 0.8, render: { (d) in
let t = d
}, completion: nil)
100.0.attachment(to: 200, damping: 0.3, frequency: 1, render: { (d) in
let y = d
}, completion: nil)
//100.0.fallTo(200, magnitude: 0.6, render: { (d) in
// let y = d
// }, completion: nil)
``` | /content/code_sandbox/StellarDemo/StellarDemo/MyPlayground.playground/Contents.swift | swift | 2016-05-25T09:02:36 | 2024-08-14T16:00:58 | Stellar | AugustRush/Stellar | 2,933 | 992 |
```swift
//
// Ball.swift
// StellarDemo
//
// Created by AugustRush on 5/26/16.
//
import UIKit
@IBDesignable
public class Ball: UIView {
@IBInspectable var cornerRadius: CGFloat = 15 {
didSet {
self.layer.cornerRadius = cornerRadius
}
}
}
``` | /content/code_sandbox/StellarDemo/StellarDemo/MyPlayground.playground/Sources/Ball.swift | swift | 2016-05-25T09:02:36 | 2024-08-14T16:00:58 | Stellar | AugustRush/Stellar | 2,933 | 73 |
```swift
//
//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import UIKit
public enum AnimationStyle {
case basic
case snap(CGFloat)
case attachment(CGFloat,CGFloat)
case gravity(Double)
}
extension UIView: BasicConfigurable, SnapConfigurable, AttachmentConfigurable, GravityConfigurable, StepControllable {
//MARK: animation methods
public func moveX(_ increment: CGFloat) -> UIView {
let type = AnimationType(type: .basic, subType: .moveX(increment))
context.addAnimationType(type)
return self
}
public func moveY(_ increment: CGFloat) -> UIView {
let type = AnimationType(type: .basic, subType: .moveY(increment))
context.addAnimationType(type)
return self
}
public func moveTo(_ point: CGPoint) -> UIView {
let type = AnimationType(type: .basic, subType: .moveTo(point))
context.addAnimationType(type)
return self
}
public func makeColor(_ color: UIColor) -> UIView {
let type = AnimationType(type: .basic, subType: .color(color))
context.addAnimationType(type)
return self
}
public func makeAlpha(_ alpha: CGFloat) -> UIView {
let type = AnimationType(type: .basic, subType: .alpha(alpha))
context.addAnimationType(type)
return self
}
public func rotate(_ z: CGFloat) -> UIView {
let type = AnimationType(type: .basic, subType: .rotate(z))
context.addAnimationType(type)
return self
}
public func rotateX(_ x: CGFloat) -> UIView {
let type = AnimationType(type: .basic, subType: .rotateX(x))
context.addAnimationType(type)
return self
}
public func rotateY(_ y: CGFloat) -> UIView {
let type = AnimationType(type: .basic, subType: .rotateY(y))
context.addAnimationType(type)
return self
}
public func rotateXY(_ xy: CGFloat) -> UIView {
let type = AnimationType(type: .basic, subType: .rotateXY(xy))
context.addAnimationType(type)
return self
}
public func makeWidth(_ width: CGFloat) -> UIView {
let type = AnimationType(type: .basic, subType: .width(width))
context.addAnimationType(type)
return self
}
public func makeHeight(_ height: CGFloat) -> UIView {
let type = AnimationType(type: .basic, subType: .height(height))
context.addAnimationType(type)
return self
}
public func makeSize(_ size: CGSize) -> UIView {
let type = AnimationType(type: .basic, subType: .size(size))
context.addAnimationType(type)
return self
}
public func makeFrame(_ frame: CGRect) -> UIView {
let type = AnimationType(type: .basic, subType: .frame(frame))
context.addAnimationType(type)
return self
}
public func makeBounds(_ bounds: CGRect) -> UIView {
let type = AnimationType(type: .basic, subType: .bounds(bounds))
context.addAnimationType(type)
return self
}
public func scaleX(_ x: CGFloat) -> UIView {
let type = AnimationType(type: .basic, subType: .scaleX(x))
context.addAnimationType(type)
return self
}
public func scaleY(_ y: CGFloat) -> UIView {
let type = AnimationType(type: .basic, subType: .scaleY(y))
context.addAnimationType(type)
return self
}
public func scaleXY(_ x: CGFloat, _ y: CGFloat) -> UIView {
let type = AnimationType(type: .basic, subType: .scaleXY(x,y))
context.addAnimationType(type)
return self
}
public func cornerRadius(_ radius: CGFloat) -> UIView {
let type = AnimationType(type: .basic, subType: .cornerRadius(radius))
context.addAnimationType(type)
return self
}
public func borderWidth(_ width: CGFloat) -> UIView {
let type = AnimationType(type: .basic, subType: .borderWidth(width))
context.addAnimationType(type)
return self
}
public func shadowRadius(_ radius: CGFloat) -> UIView {
let type = AnimationType(type: .basic, subType: .shadowRadius(radius))
context.addAnimationType(type)
return self
}
public func zPosition(_ position: CGFloat) -> UIView {
let type = AnimationType(type: .basic, subType: .zPosition(position))
context.addAnimationType(type)
return self
}
public func anchorPoint(_ point: CGPoint) -> UIView {
let type = AnimationType(type: .basic, subType: .anchorPoint(point))
context.addAnimationType(type)
return self
}
public func anchorPointZ(_ z: CGFloat) -> UIView {
let type = AnimationType(type: .basic, subType: .anchorPointZ(z))
context.addAnimationType(type)
return self
}
public func shadowOffset(_ offset: CGSize) -> UIView {
let type = AnimationType(type: .basic, subType: .shadowOffset(offset))
context.addAnimationType(type)
return self
}
public func shadowColor(_ color: UIColor) -> UIView {
let type = AnimationType(type: .basic, subType: .shadowColor(color))
context.addAnimationType(type)
return self
}
public func shadowOpacity(_ opacity: Float) -> UIView {
let type = AnimationType(type: .basic, subType: .shadowOpacity(opacity))
context.addAnimationType(type)
return self
}
public func makeTintColor(_ color: UIColor) -> UIView {
let type = AnimationType(type: .basic, subType: .tintColor(color))
context.addAnimationType(type)
return self
}
public func completion(_ c: @escaping () -> Void) -> UIView {
context.changeCompletion(c)
return self
}
//MARK: Physical Animation
//Snap
public func snap(_ damping: CGFloat = 0.5) -> SnapConfigurable {
context.changeMainType(.snap(damping))
return self
}
//Attachment
public func attachment(_ damping: CGFloat = 0.5, frequency: CGFloat = 0.5) -> AttachmentConfigurable {
context.changeMainType(.attachment(damping, frequency))
return self
}
//Gravity
public func gravity(_ magnitude: Double = 1.0) -> GravityConfigurable {
context.changeMainType(.gravity(magnitude))
return self
}
//MARK: Basic Animation configurations
public func duration(_ d: CFTimeInterval) -> BasicConfigurable {
context.changeDuration(d)
return self
}
public func easing(_ type: TimingFunctionType) -> BasicConfigurable {
context.changeEasing(type)
return self
}
public func delay(_ d: CFTimeInterval) -> BasicConfigurable {
context.changeDelay(d)
return self
}
public func autoreverses() -> BasicConfigurable {
context.changeAutoreverses(true)
return self
}
public func repeatCount(_ count: Int) -> BasicConfigurable {
context.changeRepeatCount(count)
return self
}
//MARK: Chainable methods
public func then() -> UIView {
context.makeNextStep()
return self
}
//commit to excute
public func animate() -> Void {
context.commit()
}
//MARK: StepControllable methods
public func cancelAllRemaining() {
context.removeAllRemaining()
}
//Private Context for view and layer
fileprivate var context: AnimationContext {
get {
let identifier = String(describing: Unmanaged.passUnretained(self.layer).toOpaque())
var context = self.layer.value(forKey: identifier) as? AnimationContext
if context == nil {
context = AnimationContext(object: self)
self.layer.setValue(context!, forKey: identifier)
}
return context!
}
}
}
private var AnimationContextIdentifer = "#"
``` | /content/code_sandbox/StellarDemo/StellarDemo/MyPlayground.playground/Sources/Sources/UIView+Stellar.swift | swift | 2016-05-25T09:02:36 | 2024-08-14T16:00:58 | Stellar | AugustRush/Stellar | 2,933 | 1,997 |
```swift
//
//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import UIKit
internal class AnimatorCoordinator: NSObject, UIDynamicAnimatorDelegate {
static let shared = AnimatorCoordinator()
fileprivate var activedAnimators: [UIDynamicAnimator] = Array()
fileprivate var basicAnimator = UIDynamicAnimator()
//MARK: public methods
func addBasicBehavior(_ b: UIDynamicBehavior) {
basicAnimator.addBehavior(b)
}
func addBehavior(_ b: UIDynamicBehavior) {
addBehaviors([b])
}
func addBehaviors(_ behaviors: [UIDynamicBehavior]) {
let animator = activedAnimators.last
for b in behaviors {
if let exsist = animator {
switch b {
case b as UIGravityBehavior:
fallthrough
case b as UICollisionBehavior:
createAnimator(b)
default:
exsist.addBehavior(b)
}
} else {
createAnimator(b)
}
}
}
fileprivate func createAnimator(_ behavior: UIDynamicBehavior) {
let animator = UIDynamicAnimator()
animator.delegate = self
animator.addBehavior(behavior)
activedAnimators.append(animator)
}
//MARK: UIDynamicAnimatorDelegate methods
func dynamicAnimatorDidPause(_ animator: UIDynamicAnimator) {
let index = activedAnimators.index(of: animator)
activedAnimators.remove(at: index!)
}
func dynamicAnimatorWillResume(_ animator: UIDynamicAnimator) {
//
}
}
``` | /content/code_sandbox/StellarDemo/StellarDemo/MyPlayground.playground/Sources/Sources/AnimatorCoordinator.swift | swift | 2016-05-25T09:02:36 | 2024-08-14T16:00:58 | Stellar | AugustRush/Stellar | 2,933 | 517 |
```swift
//
//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import Foundation
protocol TimingType {
var duration: CFTimeInterval { get set }
var delay: CFTimeInterval { get set }
var timingFunction: TimingSolvable { get set }
var autoreverses: Bool { get set }
var repeatCount: Int { get set }
var speed: Double { get set }
var timeOffset: CFTimeInterval { get set }
}
``` | /content/code_sandbox/StellarDemo/StellarDemo/MyPlayground.playground/Sources/Sources/TimingType.swift | swift | 2016-05-25T09:02:36 | 2024-08-14T16:00:58 | Stellar | AugustRush/Stellar | 2,933 | 281 |
```swift
//
//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import UIKit
protocol AnimationSequenceDelegate: class {
func animationSequenceDidComplete(_ sequence: AnimationSequence);
}
internal class AnimationSequence: NSObject, UIDynamicAnimatorDelegate {
var steps: [AnimationStep] = Array()
weak var view: DriveAnimateBehaviors!
weak var delegate: AnimationSequenceDelegate?
var isRuning = false
lazy var animator: UIDynamicAnimator = {
let animator = UIDynamicAnimator()
animator.delegate = self
return animator
}()
//MARK: init method
init(object: DriveAnimateBehaviors) {
self.view = object
}
//MARK: internal method
func addStep(_ step: AnimationStep) {
steps.append(step)
}
func last() -> AnimationStep? {
return steps.last
}
func start() {
if !isRuning {
isRuning = true
excuteFirstStepIfExist()
}
}
func removeAllSteps() {
steps.removeAll()
}
fileprivate func excuteFirstStepIfExist() {
if self.view == nil {
return
}
let step = steps.first
if let step = step {
//if step has no animation types it must be the last temple step
if step.types.count == 0 {
steps.removeFirst()
popFirstStepIfExsist()
return
}
for type in step.types {
let behavior = view.behavior(forType: type, step: step)
animator.addBehavior(behavior)
}
} else {
popFirstStepIfExsist()
}
}
fileprivate func popFirstStepIfExsist() {
if !steps.isEmpty {
let step = steps.first!
//excute completion
step.completion?()
steps.removeFirst()
} else {
// all steps has completion
self.delegate?.animationSequenceDidComplete(self)
}
}
//MARK: UIDynamicAnimatorDelegate methods
func dynamicAnimatorDidPause(_ animator: UIDynamicAnimator) {
animator.removeAllBehaviors()
popFirstStepIfExsist()
excuteFirstStepIfExist()
}
func dynamicAnimatorWillResume(_ animator: UIDynamicAnimator) {
}
}
``` | /content/code_sandbox/StellarDemo/StellarDemo/MyPlayground.playground/Sources/Sources/AnimationSequence.swift | swift | 2016-05-25T09:02:36 | 2024-08-14T16:00:58 | Stellar | AugustRush/Stellar | 2,933 | 688 |
```swift
//
//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import Foundation
public protocol StepControllable {
//remove all remaining from excute sequence
func cancelAllRemaining()
//will add more methods to control animation steps
}
``` | /content/code_sandbox/StellarDemo/StellarDemo/MyPlayground.playground/Sources/Sources/StepControllable.swift | swift | 2016-05-25T09:02:36 | 2024-08-14T16:00:58 | Stellar | AugustRush/Stellar | 2,933 | 236 |
```swift
//
//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import UIKit
internal extension UIDynamicBehavior {
func commit() {
AnimatorCoordinator.shared.addBehavior(self)
}
func cancel() {
self.dynamicAnimator?.removeBehavior(self)
}
func commitToBasic() {
AnimatorCoordinator.shared.addBasicBehavior(self)
}
}
``` | /content/code_sandbox/StellarDemo/StellarDemo/MyPlayground.playground/Sources/Sources/UIDynamicBehavior+Commit.swift | swift | 2016-05-25T09:02:36 | 2024-08-14T16:00:58 | Stellar | AugustRush/Stellar | 2,933 | 261 |
```swift
//
//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import UIKit
public protocol GravityConfigurable: BasicChainable {
func gravity(_ magnitude: Double) -> GravityConfigurable
}
public protocol GravityConfigurable1: BasicChainable1 {
func gravity(_ magnitude: Double) -> GravityConfigurable1
}
``` | /content/code_sandbox/StellarDemo/StellarDemo/MyPlayground.playground/Sources/Sources/GravityConfigurable.swift | swift | 2016-05-25T09:02:36 | 2024-08-14T16:00:58 | Stellar | AugustRush/Stellar | 2,933 | 253 |
```swift
//
//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import UIKit
public protocol Physical: Interpolatable {}
extension Physical {
public func fall(to: Self,magnitude: Double = 1.0, render: @escaping (Self) -> Void, completion: (() -> Void)? = nil) {
let item = DynamicItemGravity(from: self, to: to, render: render)
let push = item.pushBehavior(.down)
item.behavior = push
item.magnitude = magnitude
item.completion = completion
push.commitToBasic()
}
public func snap(to: Self, damping: CGFloat = 0.5,render: @escaping (Self) -> Void, completion: (() -> Void)? = nil) {
let item = DynamicItem(from: self, to: to, render: render)
let toP = CGPoint.init(x: 0, y: CGFloat(item.referenceChangeLength))
let snap = item.snapBehavior(toP, damping: damping)
item.behavior = snap
item.completion = completion
snap.commit()
}
public func attachment(to: Self,damping: CGFloat = 0.5, frequency: CGFloat = 0.5,render: @escaping (Self) -> Void, completion: (() -> Void)? = nil) {
let item = DynamicItem(from: self, to: to,render: render)
let toP = CGPoint.init(x: 0, y: CGFloat(item.referenceChangeLength))
let attachment = item.attachmentBehavior(toP, length: 0.0, damping: damping, frequency: frequency)
item.behavior = attachment
item.completion = completion
attachment.commit()
}
public func pushed(to: Self,render: @escaping (Self) -> Void, completion: (() -> Void)? = nil) {
let item = DynamicItem(from: self,to: to,render: render)
let direction = CGVector(dx: item.toR.one - item.fromR.one, dy: item.toR.two - item.fromR.two)
let push = item.pushBehavior(direction, mode: .instantaneous, magnitude: 1.0)
item.behavior = push
item.boundaryLimit = true
item.completion = completion
push.commit()
}
public func animate(to: Self, duration: CFTimeInterval = 0.25, delay: CFTimeInterval = 0.0, type: TimingFunctionType = .default, autoreverses: Bool = false, repeatCount: Int = 0, render: @escaping (Self) -> Void, completion: ((Bool) -> Void)? = nil) {
let basicItem = DynamicItemBasic(from: self, to: to, render: render)
let push = basicItem.pushBehavior(.down)
basicItem.behavior = push
basicItem.duration = duration
basicItem.timingFunction = type.easing()
basicItem.completion = completion
basicItem.delay = delay
basicItem.autoreverses = autoreverses
push.commitToBasic()
}
}
``` | /content/code_sandbox/StellarDemo/StellarDemo/MyPlayground.playground/Sources/Sources/Physical.swift | swift | 2016-05-25T09:02:36 | 2024-08-14T16:00:58 | Stellar | AugustRush/Stellar | 2,933 | 842 |
```swift
//
// UIView+FileConfigurable.swift
// StellarDemo
//
// Created by AugustRush on 6/7/16.
//
import UIKit
enum ConfigurationError: Error {
case invalidString
case transformedError(Error)
case undefined
}
extension UIView {
//configure animation with JSON string
public func configureWithJSON(_ str: String) throws -> Void {
let data = str.data(using: String.Encoding.utf8)
guard let _ = data else {
throw ConfigurationError.invalidString
}
do {
let json = try JSONSerialization.jsonObject(with: data!, options: .allowFragments)
switch json {
case let dict as Dictionary<String,String>:
configureWithDictionary(dict)
default:
throw ConfigurationError.undefined
}
} catch {
throw ConfigurationError.transformedError(error)
}
}
fileprivate func configureWithDictionary(_ dict: Dictionary<String, String>) -> Void {
}
}
``` | /content/code_sandbox/StellarDemo/StellarDemo/MyPlayground.playground/Sources/Sources/UIView+FileConfigurable.swift | swift | 2016-05-25T09:02:36 | 2024-08-14T16:00:58 | Stellar | AugustRush/Stellar | 2,933 | 207 |
```swift
//
// DriveAnimateBehaviors.swift
// StellarDemo
//
// Created by AugustRush on 6/21/16.
//
import UIKit
protocol DriveAnimateBehaviors: class {
func behavior(forType type: AnimationType, step: AnimationStep) -> UIDynamicBehavior
}
``` | /content/code_sandbox/StellarDemo/StellarDemo/MyPlayground.playground/Sources/Sources/DriveAnimateBehaviors.swift | swift | 2016-05-25T09:02:36 | 2024-08-14T16:00:58 | Stellar | AugustRush/Stellar | 2,933 | 64 |
```swift
//
// CALayer+DriveAnimationBehaviors.swift
// StellarDemo
//
// Created by AugustRush on 6/21/16.
//
import Foundation
``` | /content/code_sandbox/StellarDemo/StellarDemo/MyPlayground.playground/Sources/Sources/CALayer+DriveAnimationBehaviors.swift | swift | 2016-05-25T09:02:36 | 2024-08-14T16:00:58 | Stellar | AugustRush/Stellar | 2,933 | 38 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.