Drawing a Christmas Tree in Java
⭐ Write in front
This is the learning road of wenwenwener
- If it is helpful to you, give the blogger a free praise to encourage QAQ
- Blog home pageWenwenel learning cabin
- ⭐ For more articles, please pay attention to wenwenwener's home page
- Article release date: December 16, 2021
- Java learning road!
- For more articles, please pay attention to the personal home page!
- List of popular articles (the following articles are on the hot list):
- [two or three things about redis] a set of super detailed redis learning tutorials (step pictures + practical operation) – Episode 1
- [redis II and III] a set of super detailed redis learning tutorials (step pictures + practical operation) – Episode II
- [source code] super detailed ArrayList underlying source code + classic interview questions
- HashMap underlying red black tree principle (super detailed diagram) + handwritten red black tree code
- HashMap underlying source code analysis (super detailed illustration + interview questions)
- HashMap underlying source code analysis (super detailed illustration)
Dangdang, Dangdang, Christmas is coming
Hello, everyone. This is wenwenwener⭐ ⒋ seeing that hot search is drawing Christmas trees and the language used is python, how can we avoid the participation of our Java players in such a lively scene?
⭐ Today, we use java to draw a color christmas tree. The effect picture is as follows!
christmas tree
Our Christmas tree needs a plug-in, ANSI, which can change the font in the console into the color font in our ideal state
First download the ANSI plug-in
It can be used after downloading. We only need to wrap the font with escape sequence to adjust the color. ANSI has used the specified transition sequence to adjust the text color. ANSI can convert that color. See this blog:
ANSI escape sequence
⭐ Here is the code
package com.wql.test; public class Tree { public static void main(String[] args) { String endcolor = "\ u001b[0m"; // end string //Background color String startyellowback = "\ 033[43m"; // yellow background String endBack = "3[m"; //1: Bold,;: Separate, 90 ~ 97 font color brightens String startstronggreen = "\ 033 [1; 92m"; // re light gray String startstrongpink = "\ 033 [1; 95m"; // heavy bright powder //Leaf height int height = 10; //Tree root height int rootHeight = 4; int blank = height-1; //Generate leaves for(int i=0;i<height;i++) { for(int j=0;j<blank;j++) { System.out.print(" "); } for(int z=0;z<=i*2;z++) { if(z%2==0) { System.out.print(startStrongGreen+"*"+endColor); }else { System.out.print(startStrongPink+"*"+endColor); } } System.out.println(); blank--; } //Generate tree root for(int i=0;i<rootHeight;i++) { for(int j=0;j<height-3;j++) { System.out.print(" "); } System.out.println(startYellowBack+" ~ ~ "+endBack); } } }
The height of leaves and roots can be adjusted by themselves
Finally, the commonly used escape sequences are presented
//Font color // System. out. Println ("\ 033 [(prefix), m (suffix), format: \ 033 [XX; XX; XXM"); String startpurpose = "\ 033 [1; 95m"; // Purple String startwhite = "\ 033 [30m"; // white String startred = "\ 033[31m"; // red String douRed = "3[1;31m"; String startgreen = "\ 033[32m"; // Green String startgrey = "\ 033[37m"; // gray String startyellow = "\ 033[33m"; // dark yellow String startblue = "\ 033[34m"; // blue String douqianblue = "\ 033 [1; 36m"; // blue String startjiured = "\ 033[35m"; // wine red String startqianblue = "\ 033[36m"; // light blue String startcolor = "\ 033[38m"; // Black String endcolor = "\ u001b[0m"; // end string //Background color String startyellowback = "\ 033[43m"; // yellow background String startblueback = "\ 033[44m"; // blue background String startpinkback = "\ 033[45m"; // pink background String startgreenback = "\ 033[46m"; // green background String startgreyback = "\ 033[47m"; // gray background String startdougreenback = "\ 033[42m"; // heavy green background String startredback = "\ 033[41m"; // crimson background String startblackback = "\ 033 [40m"; // dark black background String endBack = "3[m"; //1: Bold,;: Separate, 90 ~ 97 font color brightens String startstronggrey = "\ 033 [1; 90m"; // re light gray String startstrongbuy = "\ 033 [1; 94m"; // heavy bright blue String startstrongpink = "\ 033 [1; 95m"; // heavy bright powder String startstrongblack = "\ 033 [1; 97m"; // lighten black again String startStrongYellow = "3[1;93m"; //Mix yellow and pink background String YellowAndPurperBack = "3[1;93;45m"; String YellowAndBlueBack = "3[1;93;44m"; String RedAndBlueBack = "3[1;31;44m";
This is the learning road of wenwenwener
- If it is helpful to you, give the blogger a free praise to encourage QAQ
- Blog home pageWenwenel learning cabin
- ⭐ For more articles, please pay attention to wenwenwener's home page
- Article release date: December 16, 2021
- Java learning road!
- For more articles, please pay attention to the personal home page!
Source: https://developpaper.com/christmas-is-coming-3-minutes-to-teach-you-to-draw-a-colored-christmas-tree-in-java-and-give-it-to-others-as-christmas-gifts/
0 Response to "Drawing a Christmas Tree in Java"
Post a Comment