aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/example/Main.java
blob: f5a9fb7ff7fb5159463d08a0fd654b25ed8f68c8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package org.example;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;

public class Main {

    static Random RNG = new Random();

    public static final String ANSI_RESET = "\u001B[0m";
    public static final String ANSI_BLACK = "\u001B[30m";
    public static final String ANSI_RED = "\u001B[31m";
    public static final String ANSI_GREEN = "\u001B[32m";
    public static final String ANSI_YELLOW = "\u001B[33m";
    public static final String ANSI_BLUE = "\u001B[34m";
    public static final String ANSI_PURPLE = "\u001B[35m";
    public static final String ANSI_CYAN = "\u001B[36m";
    public static final String ANSI_WHITE = "\u001B[37m";
    public static final String ANSI_ORANGE = "\033[38:5:208m";
    public static final String ANSI_BROWN = "\033[38:5:52m";

    public static void main(String[] args) {
        tree(25);
    }

    public static Map.Entry<Character, String> ornament() {
        var l = new ArrayList<>(List.of(
                Map.entry('O', ANSI_RED),
                Map.entry('^', ANSI_YELLOW),
                Map.entry('&', ANSI_ORANGE),
                Map.entry('@', ANSI_BLUE),
                Map.entry('!', ANSI_WHITE),
                Map.entry('~', ANSI_PURPLE),
                Map.entry('$', ANSI_CYAN)
        ));
        for (int i = 0; i < 21; i++) {
            l.add(Map.entry('*', ANSI_GREEN));
        }
        return l.get(RNG.nextInt(0, l.size()));
    }

    public static void tree(int size) {
        for (int i = 0; i < size; i++) {
            printSpace(size - i);
            printOrnament(i * 2 + 1);
            System.out.println();
        }
        for (int i = 0; i < (size/3); i++) {
            printSpace(size - size/6);
            printStump(size/3);
            System.out.println();
        }
    }

    public static void printOrnament(int count) {
        for (int i = 0; i < count; i++) {
            var o = ornament();
            System.out.print(o.getValue() + o.getKey() + ANSI_RESET);
        }
    }

    public static void printSpace(int count) {
        for (int i = 0; i < count; i++) {
            System.out.print(" ");
        }
    }

    public static void printStump(int count) {
        for (int i = 0; i < count; i++) {
            System.out.print(ANSI_BROWN + '#' + ANSI_RESET);
        }
    }
}