UNPKG

imagerot

Version:

A lightweight, cross-environment image library for applying unique effects via raw image buffers.

37 lines (36 loc) 1.93 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.rainbow = void 0; const math_1 = require("../../../constants/math"); const global = (_a) => __awaiter(void 0, [_a], void 0, function* ({ data, width, height }) { const rPhase = (0, math_1.random)() * 2 * math_1.PI; const gPhase = (0, math_1.random)() * 2 * math_1.PI; const bPhase = (0, math_1.random)() * 2 * math_1.PI; for (let i = 0; i < data.length; i += 4) { const x = (i / 4) % width; const y = (0, math_1.floor)((i / 4) / width); const grayscale = data[i]; const rWave = grayscale * (0.75 + 0.25 * (0, math_1.sin)(2 * math_1.PI * (x / width) + rPhase)); const gWave = grayscale * (0.75 + 0.25 * (0, math_1.sin)(2 * math_1.PI * (y / height) + gPhase)); const bWwave = grayscale * (0.75 + 0.25 * (0, math_1.sin)(2 * math_1.PI * ((x / width + y / height) + bPhase))); data[i] = (0, math_1.pow)(rWave / 255, 0.75) * 255; data[i + 1] = (0, math_1.pow)(gWave / 255, 0.75) * 255; data[i + 2] = (0, math_1.pow)(bWwave / 255, 0.75) * 255; } return data; }); const rainbow = { name: 'rainbow', browser: global, node: global }; exports.rainbow = rainbow;