public class loveme {
    private static final HashMap<Integer,String> colorMap = new HashMap<>(){{
        put(36,"qingse");
    }};
    public static String getColor(int color, String con){
        return String.format("33[1m33[36m",6);
    }
    public static void main(String[] args) throws InterruptedException {
        int in=0;
        for(float y=2.5f; y>-2.0f;y-=0.12f) {
            for (float x = -2.3f; x < 2.3f; x += 0.041f) {
                float a = x * x + y * y - 4f;
                if ((a * a * a - x * x * y * y * y) < -0.0f) {
                    String str = "I LOVE YOU ";
                    int num = in % str.length();
                    System.err.print(str.charAt(num));

                    in++;
                } else {
                    System.err.print(" ");
                }
            }
            System.err.println();
            Thread.sleep(100);
        }
        System.out.println(getColor(6, colorMap.get(36)));
        System.out.println("你像火柴一般在夜空划过");
        System.out.println("刹那的烟火映照整个银河");
        System.out.println("你是烟火,我是泡沫、");
    }
}

java爱心代码,我觉得这可以了,基础是套壳来的,做了一点修改

改进版

import java.util.HashMap;

import static javax.swing.UIManager.put;

public class loveme {


    public enum setColor {

        //白色
        WGITE("33[0m", 0),
        //红色
        RED("33[1m33[31m", 1),
        //绿色
        GREEN("33[1m33[32m", 2),
        //黄色
        YELLOW("33[1m33[33m", 3),
        //蓝色
        BLUE("33[1m33[34m", 4),
        //粉色
        PINK("33[1m33[35m", 5),
        //青色
        CYAN("33[1m33[36m", 6);

        //局部变量
        private String name;
        private int index;

        // 构造方法
        private setColor(String name, int index) {
            this.name = name;
            this.index = index;
        }

        // 普通方法
        public static String getColor(int index) {
            for (setColor c : setColor.values()) {
                if (c.getIndex() == index) {
                    return c.name;
                }
            }
            return null;
        }

        // get set 方法
        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getIndex() {
            return index;
        }

        public void setIndex(int index) {
            this.index = index;
        }
    }

    public static void main(String[] args) throws InterruptedException {
        int in = 0;
        for (float y = 2.5f; y > -2.0f; y -= 0.12f) {
            for (float x = -2.3f; x < 2.3f; x += 0.041f) {
                float a = x * x + y * y - 4f;
                if ((a * a * a - x * x * y * y * y) < -0.0f) {
                    String str = "I LOVE YOU ";
                    int num = in % str.length();
                    //改进版:这里更改输出颜色,
                    System.out.print(setColor.getColor(1));
                    System.out.print(str.charAt(num));
                    in++;
                } else {
                    System.out.print(" ");
                }
            }
            System.err.println();
            Thread.sleep(100);
        }
        //这里更改文案颜色输出字段
        System.out.println(setColor.getColor(6) + "测试青色文字");
        System.out.println("你像火柴一般在夜空划过");
        System.out.println("刹那的烟火映照整个银河");
        System.out.println("你是烟火,我是泡沫、");
    }
}

改进版可以让爱心颜色也改变,我感觉还是很好的

更改爱心颜色在这一行

 

效果图

原文地址:https://blog.csdn.net/weixin_75190682/article/details/128860039

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_14613.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注