UNPKG

konva

Version:

HTML5 2d canvas library.

13 lines (12 loc) 590 B
import { Factory } from "../Factory.js"; import { Node } from "../Node.js"; import { getNumberValidator } from "../Validators.js"; export const Noise = function (imageData) { const amount = this.noise() * 255, data = imageData.data, nPixels = data.length, half = amount / 2; for (let i = 0; i < nPixels; i += 4) { data[i + 0] += half - 2 * half * Math.random(); data[i + 1] += half - 2 * half * Math.random(); data[i + 2] += half - 2 * half * Math.random(); } }; Factory.addGetterSetter(Node, 'noise', 0.2, getNumberValidator(), Factory.afterSetFilter);