Skip to content

Commit

Permalink
Added an example
Browse files Browse the repository at this point in the history
  • Loading branch information
jwagner committed Aug 23, 2021
1 parent e2c770d commit 6108753
Show file tree
Hide file tree
Showing 10 changed files with 578 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const random = new Alea(seed),
value2d = simplex.noise2D(x, y);
```

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

## node.js

Expand Down Expand Up @@ -99,7 +99,7 @@ npm install && npm test

## Changelog

### main
### 3.0.0
- Changed module structure. When using bundlers that import the es module even using require() the import might need to be updated.
- Dependency update
- Setting sideEffects: false in package.json
Expand Down
2 changes: 2 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
You can view the built examples here:
* https://29a.ch/simplex-noise/examples/plasma.html
1 change: 1 addition & 0 deletions examples/dist/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/node_modules/simplex-noise

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions examples/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"simplex-noise": "../.."
}
}
31 changes: 31 additions & 0 deletions examples/plasma.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import SimplexNoise from 'simplex-noise';

const canvas = document.createElement('canvas');
canvas.width = 512;
canvas.height = 512;
document.body.appendChild(canvas);

const simplex = new SimplexNoise(),
ctx = canvas.getContext('2d'),
imgdata = ctx.getImageData(0, 0, canvas.width, canvas.height),
width = imgdata.width,
height = imgdata.height,
data = imgdata.data;

function render() {
const t = performance.now()/1000;
for (var x = 0; x < width; x++) {
for (var y = 0; y < height; y++) {
var r = simplex.noise3D(x / 16, y / 16, t) * 0.5 + 0.5;
var g = simplex.noise3D(x / 8, y / 8, t) * 0.5 + 0.5;
data[(x + y * width) * 4 + 0] = r * 255;
data[(x + y * width) * 4 + 1] = (r + g) * 200;
data[(x + y * width) * 4 + 2] = 0;
data[(x + y * width) * 4 + 3] = 255;
}
}
ctx.putImageData(imgdata, 0, 0);
requestAnimationFrame(render);
}

requestAnimationFrame(render);
17 changes: 17 additions & 0 deletions examples/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');

module.exports = {
entry: {
plasma: './plasma.js',
},
output: {
path: path.resolve(__dirname, '../public/examples/'),
filename: 'static/[name].cache-[contenthash:8].js',
},
plugins: [new HtmlWebpackPlugin({
filename: '[name].html',
title: 'Simplex-Noise.js examples'
})],
};

0 comments on commit 6108753

Please sign in to comment.