ColourHelper

基本信息

属性 值
类名 betterachievements.api.util.ColourHelper
类型 工具类(静态方法)
源文件 src/main/java/betterachievements/api/util/ColourHelper.java

功能

提供 packed int 颜色的生成、混合、Tone、彩虹算法。供 Configuration、ICustomArrows、ICustomBackgroundColour 使用。

公开方法

方法 签名 说明
RGB(int r, int g, int b) int 返回 RGBA(r, g, b, 255)
RGBA(int r, int g, int b, int a) int (a << 24) | ((r & 255) << 16) | ((g & 255) << 8) | (b & 255)
RGB(float red, float green, float blue) int RGBA((int)red*255, ..., 255)
RGB(float red, float green, float blue, float alpha) int RGBA((int)red*255, ..., (int)alpha*255)
RGB(String colour) int #RRGGBB 字符串解析。非法则记日志并返回黑色
blend(int... colours) int 多个 int 颜色平均混合
tone(int colour, float scale) int scale > 1 加亮,< 1 变暗(按 RGB 缩放,A 保持)
blendWithGreyScale(int colour, float greyScale) int blend(colour, RGB(greyScale, greyScale, greyScale))
getRainbowColour(float freqR, float freqG, float freqB, float phaseR, float phaseG, float phaseB, float center, float width, float length) int 基于 System.currentTimeMillis() 的彩虹色
getRainbowColour(float[] params) int 上面方法的数组重载,参数顺序同上
getRainbowSettings(String colourCode) float[] 解析 rainbow<freqR>,<freqG>,<freqB>,<phaseR>,<phaseG>,<phaseB>,<center>,<width>,<length> 字符串为 9 个 float

使用示例

静态颜色(来自 Demo mod)

ColourHelper.blendWithGreyScale(ColourHelper.RGB(0, 0, 255), greyScale)

彩虹(来自 Demo mod)

ColourHelper.getRainbowColour(0.3F, 0.3F, 0.3F, 0, 2, 4, 128, 127, 50)

参数含义:

参数 含义
freqR/G/B 各通道的正弦频率
phaseR/G/B 各通道的相位
center 中心亮度(0~255)
width 振幅
length 时间周期倍数(越大越慢)

相关条目

  • Configuration - cantUnlockArrowColour / canUnlockArrowColour / completeArrowColour 的 rainbow 解析
  • ICustomArrows - 推荐用 ColourHelper.RGB("#RRGGBB") 解析
  • ICustomBackgroundColour - 推荐用 ColourHelper.blendWithGreyScale / getRainbowColour