mistic100/randomcolor

生成吸引人的随机颜色

1.1.0 2024-09-09 17:21 UTC

This package is auto-updated.

Last update: 2024-09-09 17:22:03 UTC


README

PHP version

用于生成吸引人的随机颜色。

这是一个 David Merfield 的 randomColor JavaScript 工具的 PHP 版本。

演示 上查看结果。

Demo

选项

您可以通过传递一个选项对象来影响生成的颜色类型。选项对象接受以下属性

色调 – 控制生成的颜色的色调。您可以传递表示颜色名称的字符串(例如,'橙色')。可能的颜色名称有 红色、橙色、黄色、绿色、蓝色、紫色、粉色和单色。您也可以传递多个色调的数组或特定的色调(0 到 360)。

亮度 – 控制生成的颜色的亮度。您可以传递包含 明亮、亮或暗 的字符串。

透明度 – 一个介于 0 和 1 之间的十进制数。仅在使用带有 alpha 通道的格式时相关。默认为随机值。

格式 – 指定生成颜色的格式的字符串。可能的值有 hsv、hsl、hslCss、rgb、rgbCss、hex 以及它们的 alpha 变体 hsva、hsla、hlsaCss、rgba、rgbaCss、hexa。默认为 hex

prng – 一个随机(或不随机)的数字生成器。默认使用 mt_rand

示例

use \Colors\RandomColor;

// Returns a hex code for an attractive color
RandomColor::one(); 

// Returns an array of ten green colors
RandomColor::many(10, array(
   'hue' => 'green',
));

// Returns a hex code for a light blue
RandomColor::one(array(
   'luminosity' => 'light',
   'hue' => 'blue',
));

// Returns one yellow or blue color
RandomColors::one(array(
    'hue' => array('yellow', 'blue'),
));

// Returns a hex code for a 'truly random' color
RandomColor::one(array(
   'luminosity' => 'random',
   'hue' => 'random',
));

// Returns a bright color in RGB
RandomColor::one(array(
   'luminosity' => 'bright',
   'format' => 'rgbCss', // e.g. 'rgb(225,200,20)'
));

// Returns a RGB color with random alpha
RandomColor::one(array(
   'format': 'rgbaCss', // e.g. 'rgba(9, 1, 107, 0.648)'
));

// Returns an hex color with specified alpha
RandomColor::one(array(
   'format': 'hexa',
   'alpha': 0.5, // e.g.: #c17d3480
));

其他语言

RandomColor 可用于 JavaScriptC#C++GoHaskellKotlinMathematicaPythonSwiftPerl6Objective-CJavaRReasonDartRubyRustSwift

许可协议

本项目遵循 MIT 许可协议。