UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

35 lines (30 loc) 1.06 kB
/** * Edge detection condition generator * @param {number} channel * @param {number} threshold * @returns {(sampler:Sampler2D, x:number, y:number) => boolean} */ export function make_edge_condition_channel_threshold(channel, threshold) { /** * @param {Sampler2D} sampler * @param {number} x * @param {number} y * @returns {boolean} */ return function (sampler, x, y) { const v = sampler.readChannel(x, y, channel); if (v < threshold) { return false; } if ( (y > 0 && sampler.readChannel(x, y - 1, channel) < threshold) // up || (x > 0 && sampler.readChannel(x - 1, y, channel) < threshold) //left || (x < (sampler.width - 1) && sampler.readChannel(x + 1, y, channel) < threshold) //right || (y < (sampler.height - 1) && sampler.readChannel(x, y + 1, channel) < threshold) //bottom ) { return true; } // not edge, probably interior return false; } }