NAME

Data::Faker::Colour - Generate random colours

SYNOPSIS

  use Data::Faker::Colour;

  local $, = ' ';
  my $f = Data::Faker::Colour->new;
  say 'Random colour: ', $f->colour_hex;
  say 'Three random colours of 60% lightness: ',
      $f->colour_hsluv_hex(3, -1, -1, 60);
  say 'A colour with 70% saturation, in CSS format: ',
      $f->colour_hsluv_css(1, -1, 70);
  say '5 colours with hue 120 and lightness 45%: ',
      $f->colour_hsluv_hex(5, 150, -1, 45);

DESCRIPTION

This module is a plugin for Data::Faker for generating random colours. It uses the HSLuv colour space to permit generation of colours with specific hue, saturation, or lightness values. One use case would be generating colour schemes.

It is recommended to use this without Data::Faker, as Data::Faker does not currently pass arguments to methods.

DATA PROVIDERS

colour([$cnt])

Generate $cnt (default 1) random colours. Returns a list of 3-element arrayrefs, representing the R, G, and B components, each ranging 0-255.

colour_hex([$cnt])

As above, but returns a list of strings like #rrggbb.

colour_css([$cnt])

As above, but returns a list of strings like rgb(r, g, b).

colour_hsluv([$cnt, $H, $S, $L])

Generates $cnt (default 1) random colours using the HSLuv colour space. You can specify your desired hue, saturation and/or lightness, and all generated colours will have that hue/saturation/lightness.

Set $H, $S, $L to a positive value to request a specific hue/saturation/lightness, or to -1 for a randomly chosen one. They all default to -1.

colour_hsluv_hex([$cnt, $H, $S, $L])
colour_hsluv_css([$cnt, $H, $S, $L])

As above but with hex/css output.

color can be substituted for colour in any of the methods above.

SEE ALSO

Data::Faker, Convert::Colour, Convert::Colour::HSLuv

AUTHOR

Marius Gavrilescu, <marius@ieval.ro>

COPYRIGHT AND LICENSE

Copyright (C) 2017 by Marius Gavrilescu

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.24.1 or, at your option, any later version of Perl 5 you may have available.