Skip to content

Instantly share code, notes, and snippets.

@TorstenDittmann
Last active October 15, 2019 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TorstenDittmann/f67189693dae760a093791d71be9a8c4 to your computer and use it in GitHub Desktop.
Save TorstenDittmann/f67189693dae760a093791d71be9a8c4 to your computer and use it in GitHub Desktop.
JAVA - Weihnachtsbaum in Konsole
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package christmastree;
import java.util.Scanner;
/**
*
* @author torstendittmann
*/
public class ChristmasTree {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String green = "\033[32;1m";
String yellow = "\033[0;33m";
String purple = "\033[0;35m";
String reset = "\033[0m";
System.out.println("Bitte gib die Anzahl der Reihen ein:");
int y = sc.nextInt();
int x = ((y - 1) * 2) + 1;
int object = 1;
System.out.println("y: " + y);
System.out.println("x: " + x);
System.out.println();
// Baumkrone
for (int i = 1; i < y + 1; i++) {
System.out.print(new String(new char[(x - object) / 2]).replace('\0', ' '));
String row = new String(new char[object]).replace('\0', '*');
// row zu char array
char[] characters = row.toCharArray();
int rand = (int) (Math.random() * row.length());
// ersetze zufälliges Zeichen mit Licht
characters[rand] = (char) 0x2BCC;
// char array zu row
row = new String(characters);
row = row.replace(
String.valueOf(characters[rand]),
reset
+ yellow
+ String.valueOf(characters[rand])
+ reset
+ green);
System.out.print(green + row + reset);
System.out.println();
object += 2;
}
// Stamm
object = ((y - 1) / 2) + 1;
for (int i = 0; i < (y * 0.1); i++) {
System.out.print(new String(new char[(x - object) / 2]).replace('\0', ' '));
System.out.print(
purple
+ new String(new char[object]).replace('\0', '#')
+ reset);
System.out.println();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment