https://github.com/y444/defold-color-lib
Hex Colors Library and Converter for Defold
https://github.com/y444/defold-color-lib
Last synced: 4 months ago
JSON representation
Hex Colors Library and Converter for Defold
- Host: GitHub
- URL: https://github.com/y444/defold-color-lib
- Owner: y444
- License: cc0-1.0
- Created: 2020-03-28T17:42:52.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-01-24T11:41:51.000Z (over 1 year ago)
- Last Synced: 2024-10-09T13:06:05.207Z (8 months ago)
- Language: Lua
- Size: 1.11 MB
- Stars: 11
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-defold - ColorsLib
README
# Hex Colors Library and Converter for Defold
## How to Start
1. Add https://github.com/y444/defold-color-lib/archive/master.zip as a dependency in your `game.project` file.
2. Fetch library using the main menu: **Project -> Fetch Libraries**.
3. Enable the module adding `local color = require("color-lib.color")` at the beginning of your script.## How to Use
### Set Color Properties in Hex
Define hex colors using the `set(new_color)` function, where `new_color` is a string formatted as `#00000000` or `#000000`. If you choose the latter, the alpha channel will default to `FF` (fully opaque). The module will throw an error if the string is formatted incorrectly.*Example:* `go.set("#label", "color", color.set("#ff00ff80")) -- sets label's color to purple with 50% opacity`
### Use Predefined Named Colors
The module contains all the named colors as defined [here](https://www.w3schools.com/colors/colors_names.asp). Use them by simply calling them by name.*Example:* `go.set("#label", "color", color.darkviolet) -- sets label's color to the predefined dark violet color`
### Add Custom Named Colors
You can add your own named colors to use them later in a more convinient way.Use the `add(new_color_name, new_color)` function, where `new_color_name` is a sting with the name of your new color and `new_color` is a string formatted as `#00000000`. The module will throw an error if the name already exists or the string is formatted incorrectly.
*Example:*
`color.add("half_red","#ff000080") -- defines a new color called half-red`
`go.set("#label", "color", color.half_red) -- sets label's color to the newly defined half-red color`
Uses photos by [Mika Baumeister](https://unsplash.com/@mbaumi?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText) on [Unsplash](https://unsplash.com/s/photos/paint-container?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)