Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fractal-noise

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fractal-noise - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

11

CHANGELOG.md
# Change Log
## [Unreleased]
## [v0.3] – 2017-02-14
### Added
- Create `generateCuboid` for 3D rectangle.
- Create `generateSphere`.
## [v0.2] – 2017-02-14
### Changed

@@ -17,3 +24,5 @@ - Constrain noise source more accurately for `generateCylinder`.

[Unreleased]: https://github.com/joshforisha/fractal-noise-js/compare/v0.1...HEAD
[Unreleased]: https://github.com/joshforisha/fractal-noise-js/compare/v0.3...HEAD
[v0.3]: https://github.com/joshforisha/fractal-noise-js/compare/v0.2...v0.3
[v0.2]: https://github.com/joshforisha/fractal-noise-js/compare/v0.1...v0.2
[v0.1]: https://github.com/joshforisha/fractal-noise-js/releases/tag/v0.1

@@ -54,2 +54,18 @@ "use strict";

}
function generateCuboid(width, height, depth, options) {
if (options === void 0) { options = {}; }
var _a = processOptions(options), amplitude = _a.amplitude, frequency = _a.frequency, octaves = _a.octaves, persistence = _a.persistence;
var white = generateArray(width, function () { return generateArray(height, function () {
return window.crypto.getRandomValues(new Uint8Array(depth));
}); });
var noise = generate3DNoiseFn(white);
return generateArray(width, function (x) { return generateArray(height, function (y) { return generateArray(depth, function (z) {
return generateArray(octaves, function (octave) {
var freq = frequency * Math.pow(2, octave);
return noise(x * freq, y * freq, z * freq) * (amplitude * Math.pow(persistence, octave));
}).reduce(function (total, num) { return total + num; }, 0)
/ (2 - (1 / Math.pow(2, octaves - 1)));
}); }); });
}
exports.generateCuboid = generateCuboid;
function generateCylinder(circumference, height, options) {

@@ -59,8 +75,7 @@ if (options === void 0) { options = {}; }

var diameter = Math.ceil(circumference / Math.PI);
var white = generateArray(diameter, function () {
return generateArray(height, function () {
return window.crypto.getRandomValues(new Uint8Array(diameter));
});
});
var white = generateArray(diameter, function () { return generateArray(height, function () {
return window.crypto.getRandomValues(new Uint8Array(diameter));
}); });
var noise = generate3DNoiseFn(white);
var radius = circumference / TWO_PI;
return generateArray(circumference, function (x) { return generateArray(height, function (y) {

@@ -70,6 +85,4 @@ return generateArray(octaves, function (octave) {

var nx = x / circumference;
var r = circumference / TWO_PI;
var rdx = nx * TWO_PI;
var a = r * Math.sin(rdx);
var b = r * Math.cos(rdx);
var _a = [radius * Math.sin(rdx), radius * Math.cos(rdx)], a = _a[0], b = _a[1];
return noise(a * freq, b * freq, y * freq) * (amplitude * Math.pow(persistence, octave));

@@ -109,2 +122,27 @@ }).reduce(function (total, num) { return total + num; }, 0)

exports.generateRectangle = generateRectangle;
function generateSphere(circumference, options) {
if (options === void 0) { options = {}; }
var _a = processOptions(options), amplitude = _a.amplitude, frequency = _a.frequency, octaves = _a.octaves, persistence = _a.persistence;
var diameter = Math.ceil(circumference / Math.PI);
var white = generateArray(diameter, function () { return generateArray(diameter, function () {
return window.crypto.getRandomValues(new Uint8Array(diameter));
}); });
var noise = generate3DNoiseFn(white);
var radius = circumference / TWO_PI;
return generateArray(circumference, function (x) { return generateArray(circumference, function (y) {
return generateArray(octaves, function (octave) {
var freq = frequency * Math.pow(2, octave);
var _a = [x / circumference, y / circumference], nx = _a[0], ny = _a[1];
var _b = [nx * TWO_PI, ny * TWO_PI], rdx = _b[0], rdy = _b[1];
var sinY = Math.sin(rdy + Math.PI);
var sinRds = 2 * Math.PI;
var a = sinRds * Math.sin(rdx) * sinY;
var b = sinRds * Math.cos(rdx) * sinY;
var d = sinRds * Math.cos(rdy);
return noise(a * freq, b * freq, d * freq) * (amplitude * Math.pow(persistence, octave));
}).reduce(function (total, num) { return total + num; }, 0)
/ (2 - (1 / Math.pow(2, octaves - 1)));
}); });
}
exports.generateSphere = generateSphere;
function processOptions(options) {

@@ -111,0 +149,0 @@ return {

2

package.json
{
"name": "fractal-noise",
"version": "0.2.0",
"version": "0.3.0",
"description": "Fractal noise library",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -30,3 +30,3 @@ # Fractal Noise

```javascript
generateLine(width, { frequency: 0.1 }) // (Replicated across x-axis)
generateLine(height, { frequency: 0.1 }) // (Replicated across x-axis)
```

@@ -54,2 +54,5 @@ ![High frequency line](https://github.com/joshforisha/fractal-noise-js/blob/master/images/line-high.png)

##### `generateCuboid (width: number, height: number, depth: number, options: Options = {}): Uint8Array[][]`
Generates a three-dimensional noise field for a rectangular cuboid.
##### `generateCylinder (circumference: number, height: number, options: Options = {}): Uint8Array[]`

@@ -63,1 +66,4 @@ Generates a two-dimensional noise field formed around a three-dimensional cylinder, such that it is continuous across the x-boundaries.

Generates a two-dimensional noise field isolated to `width` and `height` (non-continuous noise).
##### `generateSphere (circumference: number, options: Options = {}): Uint8Array[]`
Generates a two-dimensional noise field formed on the surface of a three-dimensional sphere.

@@ -103,11 +103,25 @@ const TWO_PI = 2 * Math.PI

export function generateCuboid (width: number, height: number, depth: number, options: Options = {}): Uint8Array[][] {
const { amplitude, frequency, octaves, persistence } = processOptions(options)
const white = generateArray(width, () => generateArray(height, () =>
window.crypto.getRandomValues(new Uint8Array(depth))
))
const noise = generate3DNoiseFn(white)
return generateArray(width, x => generateArray(height, y => generateArray(depth, z =>
generateArray(octaves, octave => {
const freq = frequency * Math.pow(2, octave)
return noise(x * freq, y * freq, z * freq) * (amplitude * Math.pow(persistence, octave))
}).reduce((total, num) => total + num, 0)
/ (2 - (1 / Math.pow(2, octaves - 1)))
)))
}
export function generateCylinder (circumference: number, height: number, options: Options = {}): Uint8Array[] {
const { amplitude, frequency, octaves, persistence } = processOptions(options)
const diameter = Math.ceil(circumference / Math.PI)
const white = generateArray(diameter, () =>
generateArray(height, () =>
window.crypto.getRandomValues(new Uint8Array(diameter))
)
)
const white = generateArray(diameter, () => generateArray(height, () =>
window.crypto.getRandomValues(new Uint8Array(diameter))
))
const noise = generate3DNoiseFn(white)
const radius = circumference / TWO_PI
return generateArray(circumference, x => generateArray(height, y =>

@@ -117,6 +131,4 @@ generateArray(octaves, octave => {

const nx = x / circumference
const r = circumference / TWO_PI
const rdx = nx * TWO_PI
const a = r * Math.sin(rdx)
const b = r * Math.cos(rdx)
const [a, b] = [radius * Math.sin(rdx), radius * Math.cos(rdx)]
return noise(a * freq, b * freq, y * freq) * (amplitude * Math.pow(persistence, octave))

@@ -154,2 +166,26 @@ }).reduce((total, num) => total + num, 0)

export function generateSphere (circumference: number, options: Options = {}): Uint8Array[] {
const { amplitude, frequency, octaves, persistence } = processOptions(options)
const diameter = Math.ceil(circumference / Math.PI)
const white = generateArray(diameter, () => generateArray(diameter, () =>
window.crypto.getRandomValues(new Uint8Array(diameter))
))
const noise = generate3DNoiseFn(white)
const radius = circumference / TWO_PI
return generateArray(circumference, x => generateArray(circumference, y =>
generateArray(octaves, octave => {
const freq = frequency * Math.pow(2, octave)
const [nx, ny] = [x / circumference, y / circumference]
const [rdx, rdy] = [nx * TWO_PI, ny * TWO_PI]
const sinY = Math.sin(rdy + Math.PI)
const sinRds = 2 * Math.PI
const a = sinRds * Math.sin(rdx) * sinY
const b = sinRds * Math.cos(rdx) * sinY
const d = sinRds * Math.cos(rdy)
return noise(a * freq, b * freq, d * freq) * (amplitude * Math.pow(persistence, octave))
}).reduce((total, num) => total + num, 0)
/ (2 - (1 / Math.pow(2, octaves - 1)))
))
}
function processOptions (options: Options): Options {

@@ -156,0 +192,0 @@ return {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc