From 2348e0c45c9e7aa4b579551428a236abc75a3c7e Mon Sep 17 00:00:00 2001 From: 13766800364 <13766800364@qq.com> Date: Thu, 9 Oct 2025 16:12:03 +0800 Subject: [PATCH] Add File --- .../drinkjava2/frog/util/ColorUtils.java | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 core/src/main/java/com/gitee/drinkjava2/frog/util/ColorUtils.java diff --git a/core/src/main/java/com/gitee/drinkjava2/frog/util/ColorUtils.java b/core/src/main/java/com/gitee/drinkjava2/frog/util/ColorUtils.java new file mode 100644 index 0000000..bd4150e --- /dev/null +++ b/core/src/main/java/com/gitee/drinkjava2/frog/util/ColorUtils.java @@ -0,0 +1,83 @@ +/* Copyright 2018-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by + * applicable law or agreed to in writing, software distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS + * OF ANY KIND, either express or implied. See the License for the specific + * language governing permissions and limitations under the License. + */ +package com.gitee.drinkjava2.frog.util; + +import java.awt.Color; + +/** + * Color Utilities used in this project + * + * @author Yong Zhu + * @since 1.0 + */ +public class ColorUtils { + + public static Color[] rainbow; + + static { + rainbow = new Color[125]; + int i = 0; + for (int r = 0; r < 3; r++) + for (int b = 0; b < 3; b++) + for (int g = 0; g < 3; g++) { + { + { + if (!(r == b && r == g)) { + rainbow[i] = new Color(((r + 2) % 3) * 122, g * 100, ((b + 1) % 3) * 88); + i++; + } + } + + } + } + Color[] t = new Color[i]; + System.arraycopy(rainbow, 0, t, 0, i); + rainbow = t; + } + + private static int nextColor = 0; + + private ColorUtils() {// default private constr + } + + public static int nextColorCode() { + return nextColor++; + } + + public static Color nextRainbowColor() {// 返回下一个彩虹色 + if (nextColor >= rainbow.length) + nextColor = 0; + return rainbow[nextColor++]; + } + + public static Color colorByCode(int i) {// 数值取模后返回一个固定彩虹色 + return rainbow[i % rainbow.length]; + } + + public static Color rainbowColor(float i) { // 根据数值大小范围,在8种彩虹色中取值 + if (i <= 20) + return Color.GRAY; + if (i <= 30) + return Color.BLACK; + if (i <= 50) + return Color.RED; + return Color.MAGENTA; + } + + public static Color grayColor(float f) { // 根据数值大小范围0~1000,返回一个灰度色,越大越黑 + if (f > 1000) + f = 1000; + int i1 = 255 - (int) Math.round(f * .255); + int i2 = 200 - (int) Math.round(f * .200); + int i3 = 150 - (int) Math.round(f * .150); + return new Color(i1, i2, i3); + } +}