4 ms·
A very annoying part of the Canvas API is that colors are represented as (CSS) strings, except for the pixel array, obviously. This forces to write code like th
by agys 5y ago
A very annoying part of the Canvas API is that colors are represented as (CSS) strings, except for the pixel array, obviously. This forces to write code like this:
const fillColor = `rgb(${r},${g},${b})`
For the rest: long live the Canvas! <3
- mysteryDate 5y agoTypedOM CSSColor is coming soon!
- hmry 5y agoFun tip: If you have an array of RGB you can shorten that somewhat const color = [254, 134, 29]; ctx.fillStyle = `rgb(${color})`; ctx.fillStyle = `rgba(${color},0.5)`; // I use this one pretty often