
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
@excaliburjs/plugin-perlin
Advanced tools
This is a small module that implements the original perlin noise implementation in Excalibur given the original Siggraph paper
You may want to use noise if you need "smooth" randomness from point to point. It's super useful for generating "natural" looking structures randomly.
In your excalibur project run
npm install @excaliburjs/plugin-perlin
import { PerlinGenerator } from '@excaliburjs/plugin-perlin';
const generator = new PerlinGenerator({
seed: 515, // random seed
octaves: 2, // number of times noise is laid on itself
frequency: 24, // number of times the pattern oscillates, higher is like zooming out
amplitude: 0.91, // [0-1] amplitude determines the relative height of the peaks generated in the noise
persistance: 0.95 // [0-1] he persistance determines how quickly the amplitude will drop off, a high degree of persistance results in smoother patterns, a low degree of persistance generates spiky patterns.
});
You can use the generator to sample perlin noise with the given configuration.
generator.noise(x)
- Sample 1D noise, outputs a value [0, 1]generator.noise(x, y)
- Sample 2D noise, outputs a value [0, 1]generator.noise(x, y, z)
- Sample 3D noise, , outputs a value [0, 1]generator.sequence(length, optionalStep)
- Generates a list of 1D noise starting at 0 and ending at 1 of continuous perlin noise, by default the step is 1/length;generator.grid(width, height, optionalStep)
- Generates a 2D grid as a packed array of perlin noise given a step value packed into a 1D array i = (x + y*width), by default the step will 1/(min(dimension))If you want to draw perlin noise directly there is a helper PerlinDrawer2D
which can be used to draw to a Canvas
or output an HTML Image.
// Create a perlin drawer and pass a generator
// Optionally pass a color function that takes a sample value [0, 1] and produces a Color
const drawer = new PerlinDrawer2D(generator, (value: number) => {
const rainbow = [
ex.Color.Red,
ex.Color.Orange,
ex.Color.Yellow,
ex.Color.Green,
ex.Color.Blue,
ex.Color.Violet
]
const colorIndex = Math.floor((value * rainbow.length));
return rainbow[colorIndex];
});
const canvas = new ex.Canvas({
width: 800,
height: 600,
cache: true,
draw: (ctx) => {
// Generating perlin noise expensive
drawer.draw(ctx, 0, 0, 800, 600);
}
});
const actor = new ex.Actor({x: 0, y: 0, width: 800, height: 600});
actor.graphics.use(canvas);
actor.graphics.anchor = ex.Vector.Zero;
game.add(actor);
Here is an example of HTML image output, this can be used as an upload to an Excalibur Material
or other ImageSource
.
const drawer = new PerlinDrawer2D(generator, (value: number) => {
const rainbow = [
ex.Color.Red,
ex.Color.Orange,
ex.Color.Yellow,
ex.Color.Green,
ex.Color.Blue,
ex.Color.Violet
]
const colorIndex = Math.floor((value * rainbow.length));
return rainbow[colorIndex];
});
const image = drawer.image(200, 200);
document.body.appendChild(image);
FAQs
Perlin noise generator for the Excalibur game engine
The npm package @excaliburjs/plugin-perlin receives a total of 6 weekly downloads. As such, @excaliburjs/plugin-perlin popularity was classified as not popular.
We found that @excaliburjs/plugin-perlin demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.