Page 1 of 1

loveCC: ColorCodes library for Love2D

Posted: Mon Jul 22, 2019 6:14 am
by YoungNeer
loveCC is a helper library for LOVE2D to help you with colors in general.
The library is available at github, make your contributions (anyone can contribute)
https://github.com/YoungNeer/lovelib/tree/master/lovecc
To use loveCC you simply have to require it like this-

Code: Select all

	lovecc=require 'lovecc'
Let's say you want to print red text on the screen, how would you do that?

Code: Select all

	love.graphics.setColor(1,0,0)
Right?
But the way you'd do the same using lovecc is-

Code: Select all

	lovecc:setColor('red')
Okay that was not very interesting. Let's say we have a color whose hex is 'ffd700' then how would you set the color WITHOUT USING lovecc? --No replies--
So the way you would do that USING lovecc is:

Code: Select all

	love.graphics.setColor(lovecc:getHex('ffd700'))
Note: You could also use '#ffd700' instead of 'ffd700' - lovecc treats both as same

And if you want to change the opacity then you can use setOpacity function,

Code: Select all

	lovecc:setOpacity(a)
In general you could set colors like this:-

Code: Select all

	lovecc:setColor(colorname,opacity)
	lovecc:setBackgroundColor(colorname,opacity)
	lovecc:setParticleColors(particle,...)
And of-course you could add your own colors very easily which makes it very flexible:-

Code: Select all

	lovecc:newColor(colorname,r,g,b)
	lovecc:newColor(colorname,hex)
And finally I'd like to talk about the default color-palette. So you don't have to redefine all the colors to use them. Common colors such as red,blue,crimson,maroon,lime,violet,purple,bla bla,bla have all been defined for you - Infact all the CSS Colors (except white) have been defined for you!!! And you just have to use them in setColor,etc functions.

Lastly let's talk about two new functions that has been added in the latest version of loveCC:-

Code: Select all

	lovecc:invert(colorname,opacity)
	--inverts the given color and sets opacity to given value (or 1 if nil)
	lovecc:invert(opacity)
	--inverts the current color and sets opacity to given value (or 1 if nil)
So if the current color is black and you used invert() then you will get white color!!
Please check out the github link for the library with the FULL DOCUMENTATION
Also note that Color-Picker is not discussed in this topic! It is discussed here ().

Re: loveCC: ColorCodes library for Love2D

Posted: Mon Jul 22, 2019 9:47 am
by yetneverdone
How are you making many libraries in a small amount of time.

Anyways, I'll take a look at this one

Re: loveCC: ColorCodes library for Love2D

Posted: Mon Jul 22, 2019 10:36 am
by raidho36
You just write. This stuff is pretty trivial to implement.

Re: loveCC: ColorCodes library for Love2D

Posted: Tue Jul 23, 2019 7:44 am
by YoungNeer
raidho36 wrote: Mon Jul 22, 2019 10:36 am You just write. This stuff is pretty trivial to implement.
Trivial yet useful!! :nyu:

Re: loveCC: ColorCodes library for Love2D

Posted: Tue Jul 23, 2019 8:24 am
by YoungNeer
yetneverdone wrote: Mon Jul 22, 2019 9:47 am How are you making many libraries in a small amount of time.
Anyways, I'll take a look at this one
I'd be happy if you do look and since it's so trivial I didn't waste time on making demos (like I do with other libraries). And regarding how I make so many libraries in a small amount of time - well as raidho36 pointed out I don't make very complicated stuff (the only complicated Library I ever wrote is Anima (https://love2d.org/forums/viewtopic.php?f=5&t=86885) - which is internally so complicated that I've quit working on that and even though it's undocumented it has good no of examples to get one started).

loveCC is one of those libraries which you can use in all of your projects. And it's also one of those libraries to which ANYONE CAN CONTRIBUTE. Either to contribute to the main library or you can contribute to the default color-palette. Just wikipedia important colors such as 'leafgreen',etc and add the hex code (or rgb triplet) to the database which is very easy to do.

Anyways thanks for showing interest on a no-one's library

Re: loveCC: ColorCodes library for Love2D

Posted: Mon Jul 29, 2019 4:04 am
by CrimsonGuy
The allcolors.lua file can be very useful, just wish it was in the love format of (1,0,0), but still good and today i learned that there's a color that has the same name as my country ^^

Re: loveCC: ColorCodes library for Love2D

Posted: Mon Jul 29, 2019 4:35 am
by YoungNeer
CrimsonGuy wrote: Mon Jul 29, 2019 4:04 am The allcolors.lua file can be very useful, just wish it was in the love format of (1,0,0), but still good
Well you could easily convert them into love format (and even the generic 8 byte rgb triplet format). For reference see viewtopic.php?f=5&t=86958.
CrimsonGuy wrote: Mon Jul 29, 2019 4:04 am today i learned that there's a color that has the same name as my country ^^
You mean peru?

Re: loveCC: ColorCodes library for Love2D

Posted: Mon Jul 29, 2019 10:54 am
by D0NM
I had to invent a wheel )))
But it looks pretty the same as yours.

Re: loveCC: ColorCodes library for Love2D

Posted: Mon Jul 29, 2019 1:09 pm
by YoungNeer
D0NM wrote: Mon Jul 29, 2019 10:54 am I had to invent a wheel )))
But it looks pretty the same as yours.
Yeah I know. Infact I believe every Love2D out there has it's counterpart somewhere buried in some part of github space. But that being said no two counter-parts are exactly the same (unless it was intentional). There is always some difference - either in the implementation or syntax