D3.js中的d3.hcl()函數用於構造新的HCL顏色,並返回指定顏色的HCL屬性作為該函數的參數。
用法:
d3.hcl(color);
參數:此函數接受用於指定CSS顏色的單個參數顏色。
返回值:該函數返回指定CSS顏色的HCL屬性作為該函數的參數。
以下程序說明了D3.js中的d3.hcl()函數:
示例1:
<!DOCTYPE html>
<html>
<head>
<title>d3.hcl() function</title>
<script src='https://d3js.org/d3.v4.min.js'></script>
</head>
<body>
<script>
// Calling the d3.hcl() function fuction
// with some parameters
var color1 = d3.hcl("red");
var color2 = d3.hcl("green");
var color3 = d3.hcl("blue");
// Getting the HCL properties
console.log(color1);
console.log(color2);
console.log(color3);
</script>
</body>
</html>
輸出:
{"h":39.99901061253295,"c":104.55176567686985,"l":53.24079414130722,"opacity":1} {"h":136.01595303206318,"c":71.8500499715016,"l":46.22743146876261,"opacity":1} {"h":306.2849380699878,"c":133.80761485376166,"l":32.297010932850725,"opacity":1}
示例2:
<!DOCTYPE html>
<html>
<head>
<title>d3.hcl() function</title>
<script src='https://d3js.org/d3.v4.min.js'></script>
</head>
<body>
<script>
// Calling the d3.hcl() function fuction
// without any parameters
var color = d3.hcl();
// Getting the HCL values
console.log(color);
</script>
</body>
</html>
輸出:
{"h":null,"c":null,"l":null,"opacity":1}
參考: https://devdocs.io/d3~5/d3-color#hcl
相關用法
- p5.js cos()用法及代碼示例
- d3.js d3.hsl()用法及代碼示例
- p5.js log()用法及代碼示例
- p5.js tan()用法及代碼示例
- PHP pos()用法及代碼示例
- d3.js d3.sum()用法及代碼示例
- PHP key()用法及代碼示例
- p5.js sin()用法及代碼示例
- p5.js second()用法及代碼示例
- PHP Ds\Map put()用法及代碼示例
- PHP each()用法及代碼示例
- PHP each()用法及代碼示例
注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 D3.js | d3.hcl() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。