Skip to content

JavaScript – Get brightness of single character

I am making an image/video to ASCII converter. For this, I need to get the average darkness for each character I will use. I modified the answer to this question, which gets the average brightness of an image. But it keeps saying that the brightness is 0. What did I do wrong? Answer For starters, please don&#…

javascript Set with objects

When merging array of strings, I can use Set and ES6 to remove duplicates like so: But how do I compare and remove objects? Say I have this: How do I remove {id: “123”, name: “Hi”} from a combined array with Set? Answer Use a Map to deduplicate by the key name: Note that deduplicating …

Using mat4 attribute in WebGL2

I am trying to pass a 4×4 matrix as an attribute to WebGL2 vertex shader. After following closely this SO answer, I am stuck with wrapping my head around why I can’t successfully render and get a glDrawArrays: attempt to access out of range vertices in attribute 0 error in my console. It is my unde…