What was the reasoning for changing setColor from RGB 0-255 to 0-1 interval?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
slime
Solid Snayke
Posts: 3166
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: What was the reasoning for changing setColor from RGB 0-255 to 0-1 interval?

Post by slime »

It's not an implementation detail, it's consistency and extensibility. Previous love versions already had colors in the 0-1 range... but only in shaders, which is not consistent. love 11 also allows you to create and modify ImageData at different bit depths than 8 bits per color component (e.g. via ImageData:setPixel), whereas 0-255 only makes sense for 8 bits. Math on colors (such as interpolation, etc) is generally simplified when working in the 0-1 range as well.

0-255 (or hex) colors do make sense for certain scenarios, but they are not universally applicable, they have a narrower range of use than love's APIs, whereas 0-1 colors (or unbounded range colors in some scenarios) allow for a variety of inputs and outputs. Adding a simple function to convert 0-255 to 0-1 (and potentially other color conversion functions, although there are a lot of color spaces and few are really useful for games) might be helpful, but having love's base APIs take 0-1 colors was a necessary change.

Certain other engines have explicit float-color and byte-color objects, and have implicit conversions from byte-color to float-color objects. Unfortunately that's not feasible in Lua since the language doesn't have stack allocated value-type structures (tables would be far too expensive in terms of GC pressure).
User avatar
dusoft
Party member
Posts: 655
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: What was the reasoning for changing setColor from RGB 0-255 to 0-1 interval?

Post by dusoft »

slime wrote: Mon Oct 22, 2018 9:37 pm Adding a simple function to convert 0-255 to 0-1 (and potentially other color conversion functions, although there are a lot of color spaces and few are really useful for games) might be helpful, but having love's base APIs take 0-1 colors was a necessary change.
I understand the goal was to standardize. Maybe, it would be the right thing to add a conversion function (helper) for people using 0-255. (I know it's easy to code this, but that's one more reason this could have gotten into Love codebase).

Thanks for joining the discussion.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: What was the reasoning for changing setColor from RGB 0-255 to 0-1 interval?

Post by grump »

dusoft wrote: Wed Oct 24, 2018 10:30 pm Maybe, it would be the right thing to add a conversion function (helper) for people using 0-255.
I made this. It patches all relevant functions for you when you start your game and forces everything (not just the trivial functions) back to 0-255 in a transparent way, as if the change never happened.
User avatar
dusoft
Party member
Posts: 655
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: What was the reasoning for changing setColor from RGB 0-255 to 0-1 interval?

Post by dusoft »

grump wrote: Thu Oct 25, 2018 6:32 am
dusoft wrote: Wed Oct 24, 2018 10:30 pm Maybe, it would be the right thing to add a conversion function (helper) for people using 0-255.
I made this. It patches all relevant functions for you when you start your game and forces everything (not just the trivial functions) back to 0-255 in a transparent way, as if the change never happened.
Great, will check that!
User avatar
dusoft
Party member
Posts: 655
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: What was the reasoning for changing setColor from RGB 0-255 to 0-1 interval?

Post by dusoft »

BTW, found this game which I believe has been written by slime:
https://github.com/wesleywerner/nova-pi ... tag/v0.2.3

Unable to run as it only supports 10.x and crashes.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: What was the reasoning for changing setColor from RGB 0-255 to 0-1 interval?

Post by grump »

dusoft wrote: Thu Nov 01, 2018 5:16 pm BTW, found this game which I believe has been written by slime:
https://github.com/wesleywerner/nova-pi ... tag/v0.2.3

Unable to run as it only supports 10.x and crashes.
Runs fine with polyamory on Debian Stretch.

Thread's gone seriously off topic.
User avatar
pgimeno
Party member
Posts: 3673
Joined: Sun Oct 18, 2015 2:58 pm

Re: What was the reasoning for changing setColor from RGB 0-255 to 0-1 interval?

Post by pgimeno »

I guess dusoft's point is about cross-version compatibility, which is kinda on-topic. Yeah, there are lot more programs that break from one version to another. When a new version appears, I update my programs to adapt them to run in all versions, because they generally don't (T2R is already updated, but not pushed yet), but not everyone does the same.

On a side note, what makes you think Wesley Werner is Alex Szpakowski?
User avatar
dusoft
Party member
Posts: 655
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: What was the reasoning for changing setColor from RGB 0-255 to 0-1 interval?

Post by dusoft »

pgimeno wrote: Thu Nov 01, 2018 7:32 pm On a side note, what makes you think Wesley Werner is Alex Szpakowski?
Ah, It was just a guess based on this: https://github.com/wesleywerner/loveslime
User avatar
deströyer
Prole
Posts: 32
Joined: Thu Jun 27, 2013 7:59 pm
Contact:

Re: What was the reasoning for changing setColor from RGB 0-255 to 0-1 interval?

Post by deströyer »

A suggestion which has worked for me: 97% of my game is in pure lua, it never calls the Love API. Everything goes through a 'framework'-module that handles the actual API calls to things like reading/writing data, controller input, drawing stuff, etc. So when eg. love.graphics.drawq was removed I only needed to change ONE line of code! :3
User avatar
dusoft
Party member
Posts: 655
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: What was the reasoning for changing setColor from RGB 0-255 to 0-1 interval?

Post by dusoft »

So you built another framework :-) Or a connector. Or a bridge. Erm, smart, but thanks no thanks.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google Adsense [Bot] and 3 guests