W3C home > Mailing lists > Public > whatwg@whatwg.org > October 2008

[whatwg] Canvas performance issue: setting colors

From: Greg Houston <gregory.houston@gmail.com>
Date: Fri, 3 Oct 2008 19:55:36 -0500
Message-ID: <29ae901a0810031755r1f03c5e6od0569b1cebe24c4d@mail.gmail.com>
On Fri, Oct 3, 2008 at 6:37 PM, Oliver Hunt <oliver at apple.com> wrote:
> <thinking out loud>
> Just had a thought (no idea how original) -- how about if fillStyle were
> able to accept a 3 or 4 number array? eg. fillStyle = [0, 0.3, 0.6, 1.0] ?
>
> That might work well if people are using arrays as vectors/colours
> </thinking out loud>

I have an application that allows the developer to set color options
for most of the canvas shapes in the application. The options are
stored as arrays:

	myColor:  [255, 0, 0]

When the colors are used then it takes a little JavaScript finessing
to apply them:

	ctx.fillStyle = 'rgb(' + myColor.join(',') + ')';

Being able to simply write the following, as would be the case with
your idea, would be nice.

	ctx.fillStyle = myColor;

Another example of using arrays for colors, both RGB and HSB can be
found in the Mootools JavaScript framework:
http://mootools.net/docs/Plugins/Color

Note that also like your example the Mootools color plugin does not
have separate rgb and rgba methods. It is smart enough to recognize
that if there is a fourth value in the array it refers to the alpha. I
never quite grasped why there is both an rgb() and rgba() in canvas.
It seems like rgb is all that would have been necessary, and if a
fourth value is passed it obviously refers to the alpha.

- Greg
Received on Friday, 3 October 2008 17:55:36 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:06 UTC