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
https://github.com/malmodev/love2d-css-colors
simple tool for converting CSS color names to RGB/A
-
- Prole
- Posts: 2
- Joined: Fri Apr 10, 2020 6:29 pm
- Contact:
simple tool for converting CSS color names to RGB/A
Last edited by tristanmvh on Sat Apr 11, 2020 5:19 pm, edited 1 time in total.
- yetneverdone
- Party member
- Posts: 448
- Joined: Sat Sep 24, 2016 11:20 am
- Contact:
Re: simple tool for converting CSS color names to RGB/A
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
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.
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
My GameDev Website
Going Home:A Pixelated Horror Game
My Repositories!
Follow me lovingly!
Nga pala, pinoy ako.
Going Home:A Pixelated Horror Game
My Repositories!
Follow me lovingly!
Nga pala, pinoy ako.
-
- Prole
- Posts: 2
- Joined: Fri Apr 10, 2020 6:29 pm
- Contact:
Re: simple tool for converting CSS color names to RGB/A
Thanks for the feedback! I'll be looking in to it:)
Re: simple tool for converting CSS color names to RGB/A
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
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 301 times
- yetneverdone
- Party member
- Posts: 448
- Joined: Sat Sep 24, 2016 11:20 am
- Contact:
Re: simple tool for converting CSS color names to RGB/A
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?
My GameDev Website
Going Home:A Pixelated Horror Game
My Repositories!
Follow me lovingly!
Nga pala, pinoy ako.
Going Home:A Pixelated Horror Game
My Repositories!
Follow me lovingly!
Nga pala, pinoy ako.
Re: simple tool for converting CSS color names to RGB/A
More power to you!
I tried to group the colors together but the names just don't convey the colors I expect.
Best
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 266 times
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 2 guests