MCPcopy Create free account
hub / github.com/DavidHDev/react-bits / _applyNoise

Method _applyNoise

src/tools/texture-lab/renderer.js:1287–1322  ·  view source on GitHub ↗
(data, width, height, params, seed)

Source from the content-addressed store, hash-verified

1285 }
1286
1287 _applyNoise(data, width, height, params, seed) {
1288 const intensity = params.intensity;
1289
1290 for (let i = 0; i < data.length; i += 4) {
1291 const x = (i / 4) % width;
1292 const y = Math.floor(i / 4 / width);
1293
1294 let noise;
1295 if (params.monochrome) {
1296 noise = this._hash(x / params.scale, y / params.scale, seed);
1297 noise = (noise - 0.5) * 2 * intensity * 255;
1298 data[i] = Math.max(0, Math.min(255, data[i] + noise));
1299 data[i + 1] = Math.max(0, Math.min(255, data[i + 1] + noise));
1300 data[i + 2] = Math.max(0, Math.min(255, data[i + 2] + noise));
1301 } else {
1302 data[i] = Math.max(
1303 0,
1304 Math.min(255, data[i] + (this._hash(x / params.scale, y / params.scale, seed) - 0.5) * 2 * intensity * 255)
1305 );
1306 data[i + 1] = Math.max(
1307 0,
1308 Math.min(
1309 255,
1310 data[i + 1] + (this._hash(x / params.scale, y / params.scale, seed + 100) - 0.5) * 2 * intensity * 255
1311 )
1312 );
1313 data[i + 2] = Math.max(
1314 0,
1315 Math.min(
1316 255,
1317 data[i + 2] + (this._hash(x / params.scale, y / params.scale, seed + 200) - 0.5) * 2 * intensity * 255
1318 )
1319 );
1320 }
1321 }
1322 }
1323
1324 _getBayerValue(x, y, size) {
1325 if (size === 2) {

Callers 1

renderMethod · 0.95

Calls 1

_hashMethod · 0.95

Tested by

no test coverage detected