- Notifications
You must be signed in to change notification settings - Fork4
Convert and manipulate colors in lua.
License
NotificationsYou must be signed in to change notification settings
Firanel/lua-color
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Convert and manipulate color values.
- Parse a variety ofcolor formats.
- Style Terminal output.
- Methods for common color manipulations.
- Generate color schemes from a base color.
- Supported color formats: rgb, hsv, hsl, hwb, ncol, cmyk
- Includes X11 colors.
Useluarocks install lua-color
or add folder to your project root.
Supports lua >= 5.1.
The documentation is availabalehereor from thedocs folder.
localColor=require"lua-color"-- Use x11 color namesColor.colorNames=require"lua-color.colors.X11"-- Use color names from filelocalcolors=require"lua-color.colors"Color.colorNames=colors.load"my-colors.conf"
-- With X11 colors enabledlocalcolor=Color"crimson"-- These create (roughly) the same color-- (full list of options in the docs @see Color:set)localcolor=Color"#41ba69"localcolor=Color"hsva 140 65% 73% 1"localcolor=Color"cmyk 65% 0% 44% 27%"localcolor=Color {r=0.255,g=0.729,b=0.412 }localcolor=Color {0.255,0.729,0.412 }localcolor=Color {h=0.389,s=0.65,v=0.73 }localnew_color=Color(color)
localcolor=Color"#ff0000"-- Print colorprint(color)-- prints: #ff0000-- Print color as hsvlocalh,s,v=color:hsv()print(h*360,s*100,v*100)-- prints: 0 100 100print(color:tostring"hsv")-- prints: hsv(0, 100%, 100%)-- Print color as hwblocalh,w,b=color:hsv()print(h*360,w*100,b*100)-- prints: 0 0 0print(color:tostring"hwb")-- prints: hwb(0, 0%, 0%)-- Print color as hslalocalh,s,l,a=color:hsla()print(h*360,s*100,l*100,a)-- prints: 0 100 50 1print(color:tostring"hsla")-- prints: hsla(0, 100%, 50%, 1)-- Print color as rgbalocalr,g,b,a=color:rgba()print(r*255,g*255,b*255,a)-- prints: 255 0 0 1print(color:tostring"rgba")-- prints: rgba(255, 0, 0, 1)-- Print color as cmykprint(color:cmyk())--prints: 0 1 1 0print(color:tostring"cmyk")-- prints: cmyk(0%, 100%, 100%, 0%)-- Print color as NColprint(color:tostring"ncol")-- prints: R0, 0%, 0%
-- Get complementary colorcolor:rotate(0.5)color:rotate {deg=180}color:rotate {rad=math.pi}-- Get inversecolor:invert()localnew_color=-color-- to greyscalecolor:grey()-- to black or white depending on lightnesscolor:blackOrWhite()-- Mix two colorscolor:mix(other_color,0.3)-- mix colors with 70:30 ratiolocalnew_color=color+other_color-- mix colors 50:50 and return newlocalnew_color=color-other_color-- complement of +-- Example: #ff0000 + #00ff00 = #808000 (you can use 'color:set {value = 1}' to get #ffff00)-- #ff0000 + #00ff00 = #000080-- Apply masklocalnew_color=color &0xff00ff-- Get color without green component
-- Complementarylocalcomplementary_color=color:complement()-- Analogouslocalnew_a,orig,new_b=color:analogous()-- Triadiclocalorig,new_a,new_b=color:triad()-- Tetradiclocalorig,new_a,new_b,new_c=color:tetrad()-- Compoundlocalnew_a,orig,new_b=color:compound()-- Pentadic (and so forth)localcols=color:evenlySpaced(5)-- Combine-- Example: Analogous color scheme around complementlocalnew_a,new_b,new_c=color:complement():analogous()
-- Check if variable is colorifColor.isColor(color)thenprint"It's a color!"end-- Compare lightness of colorsifColor"#000000">Color"#ffffff"thenprint"Black is lighter than white!"-- Never runsend-- Equate colorsassert(color==color:clone())
localtc=require"lua-color.terminal"-- Print red textio.write(tc.set {color=Color"rgb 255 0 0"})print("Hello world")io.write(tc.set {color="default"})-- Print red text (resets all styles afterward, not just color)print(tc.apply {color=Color"rgb 255 0 0",to="Hello world"})-- Make text italic and underlinedprint(tc.apply {tc.Effect.italic |tc.Effect.underline,to="Hello world"})-- Make text italic and underlinedprint(tc.apply {italic=true,underline=true,to="Hello world"})
About
Convert and manipulate colors in lua.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
No packages published
Contributors3
Uh oh!
There was an error while loading.Please reload this page.