Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
convchain-gpu
Advanced tools
Readme
Vanilla javascript/WebGL2 (GPU) port of ConvChain.
Interactive example | Simple example 1 | Simple example 2 | Immutable example |
This implementation takes advantage of the GPU to allow the application of ConvChain on large fields. See benchmark results to see how it fares against the previous vanilla javascript (CPU) port.
Previous port (vanilla javascript / CPU) | Codegolfed version (js1k / CPU)
With npm do:
npm install convchain-gpu --save
Or with yarn do:
yarn add convchain-gpu
const ConvChainGPU = require('convchain-gpu');
const samplePattern = [
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 0, 0, 0, 0, 1, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 0, 0, 0, 0, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1
];
const width = 64;
const height = 32;
const convChain = new ConvChainGPU(samplePattern);
convChain.setField(width, height);
const generatedPattern = convChain.iterate(9, 3, 0.5).getUint8Array(); // a flat Uint8Array
// some code to display the result in the console
for (let y = 0; y < height; y++) {
let s = '';
for (let x = 0; x < width; x++) {
s += ' ' + generatedPattern[x + y * width];
}
console.log(s);
}
new ConvChain(sample[, sampleSize])
const testSample = [
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
]; //flat array
const convChain = new ConvChainGPU(testSample, [14, 10]);
const testSample = [
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
]; //2D array
const convChain = new ConvChainGPU(testSample);
convChain.setSample(sample[, sampleSize])
Same arguments as the constructor.
convChain.setField(fieldWidth, fieldHeight[, values])
Resize the field at the given width and height. Initialize it at the given values if provided, otherwise fill it with random values.
convChain.iterate(iterations, n, temperature[, seed])
Iterate on and update the cells. Returns an object implementing the getUint8Array()
method which can be used to retrieve
the field values as a flat array. This object can also be used with the internal WebGL2 context as used in some of
the examples.
ConvChainGPU.isSupported()
Return whether the current environment support the features required to use ConvChainGPU.
Tests the browser support for WebGL2 and the existence of the EXT_color_buffer_float
extension.
It is possible to set immutable cells in the field using setField()
by passing values above 1. Any cell with a value
greater than 1 will be left as is by ConvChainGPU. Odd values (2, 4, 6, ...) are considered immutable empty values and
even values (1, 3, 5, ...) are considered immutable full values.
This feature can be used to generate a labyrinth around a hardcoded dungeon, generate a forest around a hardcoded village, generate the inside of hardcoded houses, etc.
The repository of the original implementation documents how the algorithm works. This implementation was slightly modified in order to take advantage of the GPU.
Whereas the original implementation update one cell per iteration, here the field is divided in regions of n
x n
(receptor size) and at each iteration one cell of each region is updated. For example with a field of size 30x30 and
a receptor size of 3, the field is divided in 100 regions of 3x3 and at each iteration 100 cells are updated.
MIT
FAQs
Vanilla javascript/WebGL2 port of https://github.com/mxgmn/ConvChain
The npm package convchain-gpu receives a total of 2 weekly downloads. As such, convchain-gpu popularity was classified as not popular.
We found that convchain-gpu demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.