simple tool for converting CSS color names to RGB/A

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
tristanmvh
Prole
Posts: 2
Joined: Fri Apr 10, 2020 6:29 pm
Contact:

simple tool for converting CSS color names to RGB/A

Post by tristanmvh » Fri Apr 10, 2020 7:01 pm

So I just switched from HTML5 Canvas to LÖVE and I'm used to typing the name of the color I want (I find it easier to use than using RGB or HEX because I'm not very good at remembering those kind of values) so I thought I'd create a simple function that converts CSS colors to RGB/RGBA. Let me know what you think :D
https://github.com/malmodev/love2d-css-colors
Last edited by tristanmvh on Sat Apr 11, 2020 5:19 pm, edited 1 time in total.

User avatar
yetneverdone
Party member
Posts: 370
Joined: Sat Sep 24, 2016 11:20 am
Contact:

Re: simple tool for converting CSS color names to RGB/A

Post by yetneverdone » Sat Apr 11, 2020 3:17 pm

I've taken a look at the code. I suggest the following:
1. Instead of making the library global, you could make it return a local table that contains the functions

Code: Select all

--yourlib.lua
local yourlib = {}
function yourlib.method() end
return yourlib

--usage
local color = require("yourlib")
color.method("red", 0.1)

2. Instead of creating a table per function call, you could define the colors ahead. Also, instead of calculating per function call, predefine the values. Another thing to add, you can skip a bunch of it statements by using table indexing.

Code: Select all

local yourlib = {}
local colors = {}
colors.red = {1, 0, 0}
function yourlib.method(color, a)
  assert(colors[color], "passed color does not exist")
  local r,g,b = colors[color]
  return {r,g,b,a or 1}
end

tristanmvh
Prole
Posts: 2
Joined: Fri Apr 10, 2020 6:29 pm
Contact:

Re: simple tool for converting CSS color names to RGB/A

Post by tristanmvh » Sat Apr 11, 2020 5:18 pm

Thanks for the feedback! I'll be looking in to it:)

User avatar
Ref
Party member
Posts: 690
Joined: Wed May 02, 2012 11:05 pm

Re: simple tool for converting CSS color names to RGB/A

Post by Ref » Sun Apr 12, 2020 1:11 am

yetneverdone really doesn't appreciate how much effort went in to your file.
My only interest is the opposite of yours - I really don't know the names of the various colors.
Some of the names really don't bring to mind the color.
Best
Attachments
ccsColors.love
Simple color viewer
(2.52 KiB) Downloaded 73 times

User avatar
yetneverdone
Party member
Posts: 370
Joined: Sat Sep 24, 2016 11:20 am
Contact:

Re: simple tool for converting CSS color names to RGB/A

Post by yetneverdone » Sun Apr 12, 2020 9:57 am

If I didnt appreciate his work, i would have just ignored the library. My suggestion was to make it "more usable" by other people as well. I mean, if a module/library wastes memory and processing, and is prone to conflict with your codebase, why use it?

User avatar
Ref
Party member
Posts: 690
Joined: Wed May 02, 2012 11:05 pm

Re: simple tool for converting CSS color names to RGB/A

Post by Ref » Sun Apr 12, 2020 9:18 pm

More power to you!
I tried to group the colors together but the names just don't convey the colors I expect.
Best
Attachments
csscolors.love
grouped colors
(3.55 KiB) Downloaded 69 times

Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests