config.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. let emptyValue = {
  2. // 主题颜色
  3. themeColor: "#296BEF",
  4. // 头发颜色
  5. hairColor: '#483029',
  6. // 衣服颜色
  7. clothesColor: "#EDA20C",
  8. // 裤子颜色
  9. trousersColor: "#296BEF",
  10. // 鞋子颜色
  11. shoesColor: "#296BEF",
  12. // 物品颜色
  13. itemColor: "#483029",
  14. // 人物肤色
  15. skinColor: "#ffcda5",
  16. // 元素颜色
  17. elementColor: "#ffffff"
  18. };
  19. /**
  20. * 参数合并
  21. */
  22. function initEmptyConfig(config) {
  23. // 当主题色不为空时,将裤子和鞋子的颜色同步
  24. if(config.themeColor !== undefined){
  25. // 当裤子颜色为空时,默认主题色
  26. if(config.trousersColor == undefined){config.trousersColor = config.themeColor};
  27. // 当鞋子颜色为空时,默认主题色
  28. if(config.shoesColor == undefined){config.shoesColor = config.themeColor};
  29. };
  30. emptyValue = Object.assign(emptyValue, config);
  31. return emptyValue;
  32. };
  33. /**
  34. * 颜色解析
  35. */
  36. /**
  37. * 主题色渐变混色
  38. * @param c1 混色1
  39. * @param c2 混色2
  40. * @param weight 权重 0~1 之间
  41. * @returns hex规定颜色值为十六进制值颜色
  42. */
  43. function generateMixedColor(c1, c2, weight) {
  44. weight = Math.max(Math.min(weight, 1), 0);
  45. const r1 = parseInt(c1.substring(1, 3), 16);
  46. const g1 = parseInt(c1.substring(3, 5), 16);
  47. const b1 = parseInt(c1.substring(5, 7), 16);
  48. const r2 = parseInt(c2.substring(1, 3), 16);
  49. const g2 = parseInt(c2.substring(3, 5), 16);
  50. const b2 = parseInt(c2.substring(5, 7), 16);
  51. const r = Math.round(r1 * (1 - weight) + r2 * weight);
  52. const g = Math.round(g1 * (1 - weight) + g2 * weight);
  53. const b = Math.round(b1 * (1 - weight) + b2 * weight);
  54. return `rgb(${r}, ${g}, ${b})`;
  55. };
  56. /**
  57. * 主题颜色
  58. */
  59. function funThemeColor(coefficient = 1) {
  60. return generateMixedColor("#ffffff", `${emptyValue.themeColor}`, coefficient);
  61. };
  62. /**
  63. * 头发颜色
  64. */
  65. function funHairColor() {
  66. return `${emptyValue.hairColor}`;
  67. };
  68. /**
  69. * 衣服颜色
  70. */
  71. function funClothesColor(coefficient = 1) {
  72. return generateMixedColor("#ffffff", `${emptyValue.clothesColor}`, coefficient);
  73. };
  74. /**
  75. * 裤子颜色
  76. */
  77. function funTrousersColor(coefficient = 1) {
  78. return generateMixedColor("#ffffff", `${emptyValue.trousersColor}`, coefficient);
  79. };
  80. /**
  81. * 鞋子颜色
  82. */
  83. function funShoesColor(coefficient = 1) {
  84. return generateMixedColor("#ffffff", `${emptyValue.shoesColor}`, coefficient);
  85. };
  86. /**
  87. * 人物肤色
  88. */
  89. function funSkinColor(coefficient = 1) {
  90. return generateMixedColor("#ffffff", `${emptyValue.skinColor}`, coefficient);
  91. };
  92. /**
  93. * 元素颜色
  94. */
  95. function funElementColor() {
  96. return `${emptyValue.elementColor}`;
  97. };
  98. /**
  99. * 元素颜色
  100. */
  101. function funItemColor() {
  102. return `${emptyValue.itemColor}`;
  103. };
  104. export {
  105. funThemeColor,
  106. funHairColor,
  107. funClothesColor,
  108. funTrousersColor,
  109. funShoesColor,
  110. funSkinColor,
  111. funItemColor,
  112. funElementColor,
  113. initEmptyConfig
  114. }