{"id":14966044,"url":"https://github.com/raku-community-modules/color","last_synced_at":"2026-03-12T17:04:21.653Z","repository":{"id":56290163,"uuid":"45693956","full_name":"raku-community-modules/Color","owner":"raku-community-modules","description":"Raku module for format conversion and math operations on colours","archived":false,"fork":false,"pushed_at":"2024-07-08T21:09:51.000Z","size":77,"stargazers_count":16,"open_issues_count":4,"forks_count":8,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-31T07:21:21.915Z","etag":null,"topics":["raku"],"latest_commit_sha":null,"homepage":"https://raku.land/zef:raku-community-modules/Color","language":"Raku","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"artistic-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/raku-community-modules.png","metadata":{"files":{"readme":"README.md","changelog":"Changes","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-11-06T16:40:13.000Z","updated_at":"2024-11-30T16:30:25.000Z","dependencies_parsed_at":"2024-09-14T01:22:17.281Z","dependency_job_id":"4d75e734-f303-472d-8fbf-bda8f88cc4de","html_url":"https://github.com/raku-community-modules/Color","commit_stats":{"total_commits":68,"total_committers":9,"mean_commits":7.555555555555555,"dds":0.5441176470588236,"last_synced_commit":"4130ce0c0e107a2fdc1a7ff279569dd55fe1f907"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raku-community-modules%2FColor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raku-community-modules%2FColor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raku-community-modules%2FColor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raku-community-modules%2FColor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/raku-community-modules","download_url":"https://codeload.github.com/raku-community-modules/Color/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238147571,"owners_count":19424286,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["raku"],"created_at":"2024-09-24T13:35:44.869Z","updated_at":"2025-10-25T13:30:56.465Z","avatar_url":"https://github.com/raku-community-modules.png","language":"Raku","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Actions Status](https://github.com/raku-community-modules/Color/workflows/test/badge.svg)](https://github.com/raku-community-modules/Color/actions)\n\nNAME\n====\n\nColor - Format conversion, manipulation, and math operations on colors\n\nSYNOPSIS\n========\n\n```raku\nuse Color;\n\nmy $white        = Color.new(255, 255, 255);\nmy $almost_black = Color.new('#111');\nsay Color.new(:hsv\u003c152 80 50\u003e).hex; # convert HSV to HEX\nsay \"$white is way lighter than $almost_black\";\n\nmy $lighter_pink = Color.new('#ED60A2').lighten(20);\nmy $lighter_pink = Color.new('#ED60A2') ◐ 20; # same as above\n\nmy $saturated_pink = Color.new('#ED60A2').saturate(20);\nmy $saturated_pink = Color.new('#ED60A2') 🞉 20; # same as above\n\n# Create an inverted colour scheme:\n$_ = .invert for @colours_in_my_colourscheme;\n\n# Some ops to use on Color objects\nmy $gray = $white / 2;\nsay $gray.hex; # prints \"#808080\"\nsay $almost_black + 25; # prints \"42, 42, 42\"\n```\n\nDESCRIPTION\n===========\n\nThis module allows you to perform mathematical operations on RGB color tuples, as well as convert them into other color formats, like hex, and manipulate them by, for example, making them lighter, darker, or more or less saturated.\n\nCONSTRUCTOR\n===========\n\n`new`\n-----\n\n```raku\nmy $rgb = Color.new('abc');\nColor.new('#abc');\nColor.new('face');\nColor.new('#face');\nColor.new('abcdef');\nColor.new('#abcdef');\nColor.new('abcdefaa');\nColor.new('#abcdefaa');\nColor.new(:hex\u003cabc\u003e); # same applies to all other hex variants\nColor.new( 255, 100, 25 ); # RGB\nColor.new( .5, .1, .3, .4 ); # CMYK\nColor.new( rgb =\u003e [ 255, 100, 25 ] );\nColor.new(:rgb\u003c255 100 25\u003e); # same works on other formats\nColor.new( rgbd =\u003e [.086, .165, .282] ); # decimal RGB\nColor.new( rgba =\u003e [ 22, 42, 72, 88 ] );\nColor.new( rgbad =\u003e [ .086, .165, .282, .345 ] );\nColor.new( cmyk =\u003e [.55, .25, .85, .12] );\nColor.new( hsl =\u003e [ 72, 78, 65] );\nColor.new( hsla =\u003e [ 72, 78, 65, 42] );\nColor.new( hsv =\u003e [ 90, 60, 70] );\nColor.new( hsva =\u003e [ 90, 60, 70, 88] );\n```\n\nCreates new `Color` object. All of the above formats are supported. **Note:** internally, the color will be converted to RGBA, which might incur slight precision loss when converting from other formats.\n\nATTRIBUTES\n==========\n\n`alpha-math`\n------------\n\n```raku\nmy $c = Color.new('abc');\n$c.alpha-math = True;\n\nmy $c = Color.new('abca');\n$c.alpha-math = False;\n```\n\nBoolean. Specifies whether operator math from `Color::Operators` should affect the alpha channel. Colors constructed from RGBA automatically get this attribute set to `True`, rest of formats have it set as `False`.\n\nMANIPULATION METHODS\n====================\n\n`alpha`\n=======\n\n```raku\nmy Color $c .= new('#ff0088');\nsay $c.alpha;                   # OUTPUT: 255\n$c.alpha(128);\nsay $c.alpha-math;              # OUTPUT: True\n```\n\nGet or set the alpha channel value.\n\n`darken`\n--------\n\n```raku\nsay $c.darken(10).cmyk; # darken by 10%\n```\n\nCreates a new `Color` object that is darkened by the percentage given as the argument.\n\n`desaturate`\n------------\n\n```raku\nsay $c.desaturate(20).cmyk;\n```\n\nCreates a new `Color` object that is desaturated by the percentage given as the argument.\n\n`invert`\n--------\n\n```raku\nsay $c.invert.cmyk;\n```\n\nCreates a new `Color` object that is inverted (black becomes white, etc).\n\n`lighten`\n---------\n\n```raku\nsay $c.lighten(10).cmyk; # lighten by 10%\n```\n\nCreates a new `Color` object that is lightened by the percentage given as the argument.\n\n`saturate`\n----------\n\n```raku\nsay $c.saturate(20).cmyk;\n```\n\nCreates a new `Color` object that is saturated by the percentage given as the argument.\n\n`rotate`\n--------\n\n```raku\n$inverse = $c.rotate( 180 );\n```\n\nCreates a new `Color` object, rotated around the HSL color wheel by the angle $α (in degrees).\n\nFor all methods `darken`, `desaturate`, `invert`, `lighten`, `saturate` and `rotate` the colors will have their alpha channel copied from the input color. The attribute alpha-math is copied as well.\n\nCONVERSION METHODS\n==================\n\n`to-string`\n-----------\n\n```raku\n$c.to-string('cmyk'); #   cmyk(0.954955, 0.153153, 0, 0.129412)\n$c.to-string('hsl');  #   hsl(189.622642, 91.379310, 45.490196)\n$c.to-string('hsla'); #   hsl(189.622642, 91.379310, 45.490196, 255)\n$c.to-string('hsv');  #   hsv(189.622642, 95.495495, 87.058824)\n$c.to-string('hsva'); #   hsva(189.622642, 95.495495, 87.058824, 255)\n$c.to-string('rgb');  #   rgb(10, 188, 222)\n$c.to-string('rgba'); #   rgba(10, 188, 222, 255)\n$c.to-string('rgbd'); #   rgb(0.039216, 0.737255, 0.870588)\n$c.to-string('rgbad');#   rgba(0.039216, 0.737255, 0.870588, 1)\n$c.to-string('hex');  #   #0ABCDE\n$c.to-string('hex3'); #   #1CE\n$c.to-string('hex8'); #   #0ABCDEFF\n```\n\nConverts the color to the format given by the argument and returns a string representation of it. See above for the format of the string for each color format.\n\n**Note:** the `.gist` and `.Str` methods of the `Color` object are equivalent to `.to-string('hex')`.\n\n`cmyk`\n------\n\n```raku\nsay $c.cmyk; # (\u003c106/111\u003e, \u003c17/111\u003e, 0.0, \u003c11/85\u003e)\n```\n\nConverts the color to CMYK format and returns a list containing each color (ranging `0`..`1`).\n\n`hex`\n-----\n\n```raku\nsay $c.hex; #  (0A BC DE);\n```\n\nReturns a list of 3 2-digit hex numbers representing the color.\n\n`hex3`\n------\n\n```raku\nsay $c.hex3; #  (1 C E);\n```\n\nReturns a list of 3 1-digit hex numbers representing the color. They will be rounded and they need to be doubled (i.e. the above would be `11CCEE`) to get the actual value.\n\n`hex4`\n------\n\n```raku\nsay $c.hex4; #  (1 C E F);\n```\n\nReturns a list of 4 1-digit hex numbers representing the color. They will be rounded and they need to be doubled (i.e. the above would be `11CCEEFF`) to get the actual value.\n\n`hex8`\n------\n\n```raku\nsay $c.hex8; #  (0A BC DE FF);\n```\n\nReturns a list of 4 2-digit hex numbers representing the color, including the Alpha space.\n\n`hsl`\n-----\n\n```raku\nsay $c.hsl; # (\u003c10050/53\u003e, \u003c10600/111\u003e, \u003c1480/17\u003e),\n```\n\nConverts the colour to HSL format and returns the three values (hue, saturation, lightness). The S/L are returned as percentages, not decimals, so 50% saturation is returned as `50`, not `.5`.\n\n`hsla`\n------\n\n```raku\nsay $c.hsla; # (\u003c10050/53\u003e, \u003c10600/111\u003e, \u003c1480/17\u003e, 255),\n```\n\nConverts the color to HSL format and returns the three values, and alpha channel.\n\n`hsv`\n-----\n\n```raku\nsay $c.hsv; # (\u003c10050/53\u003e, \u003c10600/111\u003e, \u003c1480/17\u003e),\n```\n\nConverts the colour to HSV format and returns the three values (hue, saturation, value). The S/V are returned as percentages, not decimals, so 50% saturation is returned as `50`, not `.5`.\n\n`hsva`\n------\n\n```raku\nsay $c.hsva; # (\u003c10050/53\u003e, \u003c10600/111\u003e, \u003c1480/17\u003e, 255),\n```\n\nConverts the color to HSV format and returns the three values, and alpha channel.\n\n`rgb`\n-----\n\n```raku\nsay $c.rgb; # (10, 188, 222)\n```\n\nConverts the color to RGB format and returns a list of the three colors.\n\n`rgba`\n------\n\n```raku\nsay $c.rgba; # (10, 188, 222, 255);\n```\n\nConverts the color to RGBA format and returns a list of the three colors, and alpha channel.\n\n`rgbd`\n------\n\n```raku\nsay $c.rgbd; # (\u003c2/51\u003e, \u003c188/255\u003e, \u003c74/85\u003e)\n```\n\nConverts the color to RGB format ranging `0`..`1` and returns a list of the three colours.\n\n`rgbad`\n-------\n\n```raku\nsay $c.rgbad; # (\u003c2/51\u003e, \u003c188/255\u003e, \u003c74/85\u003e, 1.0)\n```\n\nConverts the color to RGBA format ranging `0`..`1` and returns a list of the three colours, and alpha channel.\n\nOPERATORS\n=========\n\n`+`\n---\n\n```raku\nColor.new('424') + 10;\n10 + Color.new('424');\nColor.new('424') + Color.new('424');\n```\n\nAdd individual RGB values of each color. Plain numbers are added to each value. If [/alpha-math](/alpha-math) is turned on, alpha channel is affected as well. The operation returns a new `Color` object.\n\n`-`\n---\n\n```raku\nColor.new('424') - 10;\n10 - Color.new('424');\nColor.new('424') - Color.new('666');\n```\n\nSubtract individual RGB values of each color. Plain numbers are subtracted from each value. If [/alpha-math](/alpha-math) is turned on, alpha channel is affected as well. The operation returns a new `Color` object.\n\n`*`\n---\n\n```raku\nColor.new('424') * 10;\n10 * Color.new('424');\nColor.new('424') * Color.new('424');\n```\n\nMultiply individual RGB values of each color. Plain numbers are multiplied with each value. If [/alpha-math](/alpha-math) is turned on, alpha channel is affected as well. The operation returns a new `Color` object.\n\n`/`\n---\n\n```raku\nColor.new('424') / 10;\nColor.new('424') / 0; # doesn't die; sets values to 0\n10 / Color.new('424');\nColor.new('424') / Color.new('424');\n```\n\nDivide individual RGB values of each color. Plain numbers are divided with each value. If [/alpha-math](/alpha-math) is turned on, alpha channel is affected as well. The operation returns a new `Color` object. Illegal operation of division by zero, doesn't die and simply sets the value to `0`.\n\n`◐`\n---\n\n```raku\nsay $c ◐ 20; # lighten by 20%\n```\n\n`U+25D0 (e2 97 90): CIRCLE WITH LEFT HALF BLACK [◐]`. Same as `/lighten`\n\n`◑`\n---\n\n```raku\nsay $c ◑ 20; # darken by 20%\n```\n\n`U+25D1 (e2 97 91): CIRCLE WITH RIGHT HALF BLACK [◑]`. Same as `/darken`\n\n`🞉`\n---\n\n```raku\nsay $c 🞉 20; # saturate by 20%\n```\n\n`U+1F789 (f0 9f 9e 89): EXTREMELY HEAVY WHITE CIRCLE [🞉]`. Same as `/desaturate`\n\n`¡`\n---\n\n```raku\nsay $c¡; # invert colour\n```\n\n`U+00A1 (c2 a1): INVERTED EXCLAMATION MARK [¡]`. Same as `/invert`\n\nSTRINGIFICATION\n===============\n\n```raku\nsay $c;\nsay \"$c\";\n```\n\nThe `Color` object overrides `.Str` and `.gist` methods to be equivalent to `.to-string('hex')`.\n\nFunctional interface\n====================\n\nThe color conversion, manipulation and utility functions are defined within the modules `Color::Conversion`, `Color::Manipulation` and `Color::Utilities` and can be used without the OO interface. The names of functions are the same as those of methods.\n\nAUTHOR\n======\n\nZoffix Znet\n\nSource can be located at: https://github.com/raku-community-modules/Color . Comments and Pull Requests are welcome.\n\nCONTRIBUTORS\n============\n\nThanks to timotimo++, jnthn++, psch++, RabidGravy++, ab5tract++, moritz++, holli++, and anyone else who I forgot who helped me with questions on IRC.\n\nCOPYRIGHT AND LICENSE\n=====================\n\nCopyright 2015 - 2018 Zoffix Znet\n\nCopyright 2019 - 2022 Raku Community\n\nThis library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraku-community-modules%2Fcolor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fraku-community-modules%2Fcolor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraku-community-modules%2Fcolor/lists"}