Skip to content

Commit 6108753

Browse files
committed
Added an example
1 parent e2c770d commit 6108753

File tree

10 files changed

+578
-3
lines changed

10 files changed

+578
-3
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const random = new Alea(seed),
6363
value2d = simplex.noise2D(x, y);
6464
```
6565

66-
The ALEA PRNG can be found on in the npm package [alea](https://npmjs.org/package/alea).
66+
The ALEA PRNG can be found in the npm package [alea](https://npmjs.org/package/alea).
6767

6868
## node.js
6969

@@ -99,7 +99,7 @@ npm install && npm test
9999

100100
## Changelog
101101

102-
### main
102+
### 3.0.0
103103
- Changed module structure. When using bundlers that import the es module even using require() the import might need to be updated.
104104
- Dependency update
105105
- Setting sideEffects: false in package.json

examples/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
You can view the built examples here:
2+
* https://29a.ch/simplex-noise/examples/plasma.html

examples/dist/main.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/node_modules/simplex-noise

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"simplex-noise": "../.."
4+
}
5+
}

examples/plasma.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import SimplexNoise from 'simplex-noise';
2+
3+
const canvas = document.createElement('canvas');
4+
canvas.width = 512;
5+
canvas.height = 512;
6+
document.body.appendChild(canvas);
7+
8+
const simplex = new SimplexNoise(),
9+
ctx = canvas.getContext('2d'),
10+
imgdata = ctx.getImageData(0, 0, canvas.width, canvas.height),
11+
width = imgdata.width,
12+
height = imgdata.height,
13+
data = imgdata.data;
14+
15+
function render() {
16+
const t = performance.now()/1000;
17+
for (var x = 0; x < width; x++) {
18+
for (var y = 0; y < height; y++) {
19+
var r = simplex.noise3D(x / 16, y / 16, t) * 0.5 + 0.5;
20+
var g = simplex.noise3D(x / 8, y / 8, t) * 0.5 + 0.5;
21+
data[(x + y * width) * 4 + 0] = r * 255;
22+
data[(x + y * width) * 4 + 1] = (r + g) * 200;
23+
data[(x + y * width) * 4 + 2] = 0;
24+
data[(x + y * width) * 4 + 3] = 255;
25+
}
26+
}
27+
ctx.putImageData(imgdata, 0, 0);
28+
requestAnimationFrame(render);
29+
}
30+
31+
requestAnimationFrame(render);

examples/webpack.config.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* eslint-disable @typescript-eslint/no-var-requires */
2+
const HtmlWebpackPlugin = require('html-webpack-plugin');
3+
const path = require('path');
4+
5+
module.exports = {
6+
entry: {
7+
plasma: './plasma.js',
8+
},
9+
output: {
10+
path: path.resolve(__dirname, '../public/examples/'),
11+
filename: 'static/[name].cache-[contenthash:8].js',
12+
},
13+
plugins: [new HtmlWebpackPlugin({
14+
filename: '[name].html',
15+
title: 'Simplex-Noise.js examples'
16+
})],
17+
};

0 commit comments

Comments
 (0)