This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // I wrote a sobel edge detector in Javascript! | |
| // todo: try Laplacian of Gaussian (LoG) instead of Sobel | |
| // Example usage (taking the pxiels 1D): | |
| // const edge = createEdgeMapFromImageData(imageData); | |
| // for (const i in edge) { | |
| // let x = i % canvas.width; | |
| // let y = (i - x) / canvas.width; | |
| // ctx.fillStyle = `rgba(${edge[i]},${edge[i]},${edge[i]},255)`; | |
| // ctx.fillRect(x, y, 1, 1 ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export function listFactors(target) { | |
| let primes = listPrimes(target); | |
| let factors = []; | |
| for (let i = 0; i < primes.length; i++) { | |
| if ((target % primes[i]) === 0) factors.push(primes[i]); | |
| } | |
| return factors; | |
| } | |
| // list all prime numbers up to n |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // If you want to load an image but have it be scaled. | |
| // instead of 'new Image();' call this function, with onload being its 3rd argument. | |
| function createScaledImageFromSource(src, scaleFactor, callback = null) | |
| { | |
| let img = new Image(); | |
| img.src = src; | |
| let outImage = new Image(); | |
| img.onload = () => |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // In INITIALISATION: | |
| // create webcam stream | |
| let video = document.createElement('video'); | |
| video.width = 320; | |
| video.height = 240; | |
| video.autoplay = true; | |
| let constraints = {video: true}; | |
| navigator.mediaDevices.getUserMedia(constraints).then(stream => video.srcObject = stream); |
NewerOlder