diff --git a/.gitignore b/.gitignore index b63da45..c2bde3d 100644 --- a/.gitignore +++ b/.gitignore @@ -39,4 +39,30 @@ bin/ .vscode/ ### Mac OS ### -.DS_Store \ No newline at end of file +.DS_Store +/.idea/sonarlint/issuestore/1/3/13ad24ecb3cad16943b287ea8fdd726d4faae459 +/.idea/sonarlint/issuestore/2/a/2a45a911a8f1836b0b6c5b758962572012d8f8c3 +/.idea/sonarlint/issuestore/5/0/50479d105b1683bafb047d72a7523003beb97ae9 +/.idea/sonarlint/issuestore/5/b/5bbfa66edb4db3c7c33c5181f43510990d3307f9 +/.idea/sonarlint/issuestore/6/4/6448ab291b77afb291c0abfecf51bcc9327ed4b2 +/.idea/sonarlint/issuestore/7/4/749edfcc96398253e5b3416184e95c46621da850 +/.idea/sonarlint/issuestore/8/d/8d223b365c5d38935d8c3b9629cbdb95ff99b32f +/.idea/sonarlint/issuestore/a/5/a5cc2925ca8258af241be7e5b0381edf30266302 +/.idea/sonarlint/issuestore/d/b/dbcff70658daf80b53ce624f6adcaa529df5ed8d +/.idea/sonarlint/issuestore/index.pb +/.idea/sonarlint/securityhotspotstore/1/3/13ad24ecb3cad16943b287ea8fdd726d4faae459 +/.idea/sonarlint/securityhotspotstore/2/a/2a45a911a8f1836b0b6c5b758962572012d8f8c3 +/.idea/sonarlint/securityhotspotstore/5/0/50479d105b1683bafb047d72a7523003beb97ae9 +/.idea/sonarlint/securityhotspotstore/5/b/5bbfa66edb4db3c7c33c5181f43510990d3307f9 +/.idea/sonarlint/securityhotspotstore/6/4/6448ab291b77afb291c0abfecf51bcc9327ed4b2 +/.idea/sonarlint/securityhotspotstore/7/4/749edfcc96398253e5b3416184e95c46621da850 +/.idea/sonarlint/securityhotspotstore/8/d/8d223b365c5d38935d8c3b9629cbdb95ff99b32f +/.idea/sonarlint/securityhotspotstore/a/5/a5cc2925ca8258af241be7e5b0381edf30266302 +/.idea/sonarlint/securityhotspotstore/d/b/dbcff70658daf80b53ce624f6adcaa529df5ed8d +/.idea/sonarlint/securityhotspotstore/index.pb +/.idea/.gitignore +/.idea/git_toolbox_prj.xml +/.idea/gradle.xml +/.idea/misc.xml +/.idea/uiDesigner.xml +/.idea/vcs.xml diff --git a/build.gradle.kts b/build.gradle.kts index e252e24..bb2798a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,7 +11,7 @@ repositories { } dependencies { - + implementation("com.google.code.gson:gson:2.11.0") } application.mainClass.set("wee.dev.Main") diff --git a/chars.json b/chars.json new file mode 100644 index 0000000..131f677 --- /dev/null +++ b/chars.json @@ -0,0 +1,198 @@ +{ + "A": [ + ["░", "█", "░"], + ["█", "░", "█"], + ["█", "█", "█"], + ["█", "░", "█"], + ["█", "░", "█"] + ], + "B": [ + ["█", "█", "░"], + ["█", "░", "█"], + ["█", "█", "░"], + ["█", "░", "█"], + ["█", "█", "░"] + ], + "C": [ + ["░", "█", "█"], + ["█", "░", "░"], + ["█", "░", "░"], + ["█", "░", "░"], + ["░", "█", "█"] + ], + "D": [ + ["█", "█", "░"], + ["█", "░", "█"], + ["█", "░", "█"], + ["█", "░", "█"], + ["█", "█", "░"] + ], + "E": [ + ["█", "█", "█"], + ["█", "░", "░"], + ["█", "█", "░"], + ["█", "░", "░"], + ["█", "█", "█"] + ], + "F": [ + ["█", "█", "█"], + ["█", "░", "░"], + ["█", "█", "░"], + ["█", "░", "░"], + ["█", "░", "░"] + ], + "G": [ + ["░", "█", "█"], + ["█", "░", "░"], + ["█", "░", "█"], + ["█", "░", "█"], + ["░", "█", "█"] + ], + "H": [ + ["█", "░", "█"], + ["█", "░", "█"], + ["█", "█", "█"], + ["█", "░", "█"], + ["█", "░", "█"] + ], + "I": [ + ["█", "█", "█"], + ["░", "█", "░"], + ["░", "█", "░"], + ["░", "█", "░"], + ["█", "█", "█"] + ], + "J": [ + ["░", "░", "█"], + ["░", "░", "█"], + ["░", "░", "█"], + ["█", "░", "█"], + ["░", "█", "░"] + ], + "K": [ + ["█", "░", "█"], + ["█", "█", "░"], + ["█", "░", "░"], + ["█", "█", "░"], + ["█", "░", "█"] + ], + "L": [ + ["█", "░", "░"], + ["█", "░", "░"], + ["█", "░", "░"], + ["█", "░", "░"], + ["█", "█", "█"] + ], + "M": [ + ["█", "░", "░", "░", "█"], + ["█", "█", "░", "█", "█"], + ["█", "░", "█", "░", "█"], + ["█", "░", "░", "░", "█"], + ["█", "░", "░", "░", "█"] + ], + "N": [ + ["█", "░", "░", "█"], + ["█", "█", "░", "█"], + ["█", "░", "█", "█"], + ["█", "░", "░", "█"], + ["█", "░", "░", "█"] + ], + "O": [ + ["░", "█", "░"], + ["█", "░", "█"], + ["█", "░", "█"], + ["█", "░", "█"], + ["░", "█", "░"] + ], + "P": [ + ["█", "█", "░"], + ["█", "░", "█"], + ["█", "█", "░"], + ["█", "░", "░"], + ["█", "░", "░"] + ], + "Q": [ + ["░", "█", "░"], + ["█", "░", "█"], + ["█", "░", "█"], + ["█", "█", "░"], + ["░", "█", "█"] + ], + "R": [ + ["█", "█", "░"], + ["█", "░", "█"], + ["█", "█", "░"], + ["█", "░", "█"], + ["█", "░", "█"] + ], + "S": [ + ["░", "█", "█"], + ["█", "░", "░"], + ["░", "█", "░"], + ["░", "░", "█"], + ["█", "█", "░"] + ], + "T": [ + ["█", "█", "█"], + ["░", "█", "░"], + ["░", "█", "░"], + ["░", "█", "░"], + ["░", "█", "░"] + ], + "U": [ + ["█", "░", "█"], + ["█", "░", "█"], + ["█", "░", "█"], + ["█", "░", "█"], + ["░", "█", "░"] + ], + "V": [ + ["█", "░", "█"], + ["█", "░", "█"], + ["█", "░", "█"], + ["░", "█", "░"], + ["░", "█", "░"] + ], + "W": [ + ["█", "░", "░", "░", "█"], + ["█", "░", "░", "░", "█"], + ["█", "░", "█", "░", "█"], + ["█", "█", "░", "█", "█"], + ["█", "░", "░", "░", "█"] + ], + "X": [ + ["█", "░", "█"], + ["█", "░", "█"], + ["░", "█", "░"], + ["█", "░", "█"], + ["█", "░", "█"] + ], + "Y": [ + ["█", "░", "█"], + ["█", "░", "█"], + ["░", "█", "░"], + ["░", "█", "░"], + ["░", "█", "░"] + ], + "Z": [ + ["█", "█", "█"], + ["░", "░", "█"], + ["░", "█", "░"], + ["█", "░", "░"], + ["█", "█", "█"] + ], + " ": [ + ["░"], + ["░"], + ["░"], + ["░"], + ["░"] + ], + "!": [ + ["░", "█", "░"], + ["░", "█", "░"], + ["░", "█", "░"], + ["░", "░", "░"], + ["░", "█", "░"] + ] +} \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..249e583 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..ec031e7 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Tue Jun 18 23:47:41 IDT 2024 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/src/main/java/wee/dev/ALPHABET.java b/src/main/java/wee/dev/ALPHABET.java deleted file mode 100644 index 9984846..0000000 --- a/src/main/java/wee/dev/ALPHABET.java +++ /dev/null @@ -1,328 +0,0 @@ -package wee.dev; - -import java.util.ArrayList; - -public class ALPHABET { - - public static final String[][] A = { - {"░", "█", "░"}, - {"█", "░", "█"}, - {"█", "█", "█"}, - {"█", "░", "█"}, - {"█", "░", "█"} - }; - - public static final String[][] B = { - {"█", "█", "░"}, - {"█", "░", "█"}, - {"█", "█", "░"}, - {"█", "░", "█"}, - {"█", "█", "░"} - }; - - public static final String[][] C = { - {"░", "█", "█"}, - {"█", "░", "░"}, - {"█", "░", "░"}, - {"█", "░", "░"}, - {"░", "█", "█"} - }; - - public static final String[][] D = { - {"█", "█", "░"}, - {"█", "░", "█"}, - {"█", "░", "█"}, - {"█", "░", "█"}, - {"█", "█", "░"} - }; - - public static final String[][] E = { - {"█", "█", "█"}, - {"█", "░", "░"}, - {"█", "█", "░"}, - {"█", "░", "░"}, - {"█", "█", "█"} - }; - - public static final String[][] F = { - {"█", "█", "█"}, - {"█", "░", "░"}, - {"█", "█", "░"}, - {"█", "░", "░"}, - {"█", "░", "░"} - }; - - public static final String[][] G = { - {"░", "█", "█"}, - {"█", "░", "░"}, - {"█", "░", "█"}, - {"█", "░", "█"}, - {"░", "█", "█"} - }; - - public static final String[][] H = { - {"█", "░", "█"}, - {"█", "░", "█"}, - {"█", "█", "█"}, - {"█", "░", "█"}, - {"█", "░", "█"} - }; - - public static final String[][] I = { - {"█", "█", "█"}, - {"░", "█", "░"}, - {"░", "█", "░"}, - {"░", "█", "░"}, - {"█", "█", "█"} - }; - - public static final String[][] J = { - {"░", "░", "█"}, - {"░", "░", "█"}, - {"░", "░", "█"}, - {"█", "░", "█"}, - {"░", "█", "░"} - }; - - public static final String[][] K = { - {"█", "░", "█"}, - {"█", "█", "░"}, - {"█", "░", "░"}, - {"█", "█", "░"}, - {"█", "░", "█"} - }; - - public static final String[][] L = { - {"█", "░", "░"}, - {"█", "░", "░"}, - {"█", "░", "░"}, - {"█", "░", "░"}, - {"█", "█", "█"} - }; - - public static final String[][] M = { - {"█", "░", "░", "░", "█"}, - {"█", "█", "░", "█", "█"}, - {"█", "░", "█", "░", "█"}, - {"█", "░", "░", "░", "█"}, - {"█", "░", "░", "░", "█"} - }; - - public static final String[][] N = { - {"█", "░", "░", "█"}, - {"█", "█", "░", "█"}, - {"█", "░", "█", "█"}, - {"█", "░", "░", "█"}, - {"█", "░", "░", "█"} - }; - - public static final String[][] O = { - {"░", "█", "░"}, - {"█", "░", "█"}, - {"█", "░", "█"}, - {"█", "░", "█"}, - {"░", "█", "░"} - }; - - public static final String[][] P = { - {"█", "█", "░"}, - {"█", "░", "█"}, - {"█", "█", "░"}, - {"█", "░", "░"}, - {"█", "░", "░"} - }; - - public static final String[][] Q = { - {"░", "█", "░"}, - {"█", "░", "█"}, - {"█", "░", "█"}, - {"█", "█", "░"}, - {"░", "█", "█"} - }; - - public static final String[][] R = { - {"█", "█", "░"}, - {"█", "░", "█"}, - {"█", "█", "░"}, - {"█", "░", "█"}, - {"█", "░", "█"} - }; - - public static final String[][] S = { - {"░", "█", "█"}, - {"█", "░", "░"}, - {"░", "█", "░"}, - {"░", "░", "█"}, - {"█", "█", "░"} - }; - - public static final String[][] T = { - {"█", "█", "█"}, - {"░", "█", "░"}, - {"░", "█", "░"}, - {"░", "█", "░"}, - {"░", "█", "░"} - }; - - public static final String[][] U = { - {"█", "░", "█"}, - {"█", "░", "█"}, - {"█", "░", "█"}, - {"█", "░", "█"}, - {"░", "█", "░"} - }; - - public static final String[][] V = { - {"█", "░", "█"}, - {"█", "░", "█"}, - {"█", "░", "█"}, - {"░", "█", "░"}, - {"░", "█", "░"} - }; - - public static final String[][] W = { - {"█", "░", "░", "░", "█"}, - {"█", "░", "░", "░", "█"}, - {"█", "░", "█", "░", "█"}, - {"█", "█", "░", "█", "█"}, - {"█", "░", "░", "░", "█"} - }; - - public static final String[][] X = { - {"█", "░", "█"}, - {"█", "░", "█"}, - {"░", "█", "░"}, - {"█", "░", "█"}, - {"█", "░", "█"} - }; - - public static final String[][] Y = { - {"█", "░", "█"}, - {"█", "░", "█"}, - {"░", "█", "░"}, - {"░", "█", "░"}, - {"░", "█", "░"} - }; - - public static final String[][] Z = { - {"█", "█", "█"}, - {"░", "░", "█"}, - {"░", "█", "░"}, - {"█", "░", "░"}, - {"█", "█", "█"} - }; - - - public static final String[][] SPACE = { - {"░"}, - {"░"}, - {"░"}, - {"░"}, - {"░"} - }; - public static final String[][] filled_space = { - {"█"}, - {"█"}, - {"█"}, - {"█"}, - {"█"} - }; - - public static final String[][] WARNING_MARK = { - {"░", "█", "░"}, - {"░", "█", "░"}, - {"░", "█", "░"}, - {"░", "░", "░"}, - {"░", "█", "░"} - }; - - public static String textToAscii26x13(String text) { - - ArrayList lettersInAsci = new ArrayList<>(); - for (char c : text.toUpperCase().toCharArray()) { - lettersInAsci.add(getLetter(c)); - } - // split it to lines, each line is 24 characters long (it starts with space, and ends with space so it's 26) - ArrayList> lines = new ArrayList<>(); - ArrayList currentLine = new ArrayList<>(); - - int totalAdded = 2; - currentLine.add(SPACE); - for (String[][] letter : lettersInAsci) { - int width = letter[0].length; - if (totalAdded + width > 26) { - lines.add(currentLine); - currentLine = new ArrayList<>(); - totalAdded = 2; - currentLine.add(SPACE); - } - currentLine.add(letter); - currentLine.add(SPACE); - totalAdded += width + 1; - } - - - lines.add(currentLine); - - // convert the lines to a string - StringBuilder result = new StringBuilder(); - for (ArrayList line : lines) { - int totalCharsAdded = 0; - for (int i = 0; i < 5; i++) { - for (String[][] letter : line) { - for (String s : letter[i]) { - result.append(s); - totalCharsAdded++; - } - } - if(totalCharsAdded < 26) { - result.append("░".repeat(Math.max(0, 26 - totalCharsAdded))); - } - totalCharsAdded = 0; - result.append("\n"); - } - - result.append("░░░░░░░░░░░░░░░░░░░░░░░░░░\n"); - - } - - return result.toString(); - } - - private static String[][] getLetter(char c) { - return switch (c) { - case 'A' -> A; - case 'B' -> B; - case 'C' -> C; - case 'D' -> D; - case 'E' -> E; - case 'F' -> F; - case 'G' -> G; - case 'H' -> H; - case 'I' -> I; - case 'J' -> J; - case 'K' -> K; - case 'L' -> L; - case 'M' -> M; - case 'N' -> N; - case 'O' -> O; - case 'P' -> P; - case 'Q' -> Q; - case 'R' -> R; - case 'S' -> S; - case 'T' -> T; - case 'U' -> U; - case 'V' -> V; - case 'W' -> W; - case 'X' -> X; - case 'Y' -> Y; - case 'Z' -> Z; - case ' ' -> SPACE; - case '!' -> WARNING_MARK; - default -> null; - }; - } - - - -} diff --git a/src/main/java/wee/dev/Main.java b/src/main/java/wee/dev/Main.java index 42e145f..ba5320a 100644 --- a/src/main/java/wee/dev/Main.java +++ b/src/main/java/wee/dev/Main.java @@ -1,18 +1,33 @@ package wee.dev; -import java.util.Scanner; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; -import static wee.dev.ALPHABET.textToAscii26x13; +import java.io.FileReader; +import java.io.IOException; +import java.util.Map; +import java.util.Scanner; public class Main { - public static void main(String[] args) { + public static void main(String[] args) throws IOException { + + Gson gson = new Gson(); + + FileReader reader = new FileReader("chars.json"); + + Map asciiArtMap = gson.fromJson(reader, new TypeToken>(){}.getType()); + reader.close(); + + ValorantTextToAscii valorantTextToAscii = new ValorantTextToAscii(asciiArtMap); + Scanner scanner = new Scanner(System.in); System.out.println("Enter text to convert to ASCII art (write 999 to leave):"); while(true) { + System.out.print("Text: "); String text = scanner.nextLine(); - System.out.println(textToAscii26x13(text)); + System.out.println(valorantTextToAscii.textToAscii26x13(text)); if(text.equals("999")) { break; } diff --git a/src/main/java/wee/dev/ValorantTextToAscii.java b/src/main/java/wee/dev/ValorantTextToAscii.java new file mode 100644 index 0000000..897228d --- /dev/null +++ b/src/main/java/wee/dev/ValorantTextToAscii.java @@ -0,0 +1,72 @@ +package wee.dev; + +import java.util.ArrayList; +import java.util.Map; + +public class ValorantTextToAscii { + final Map asciiArtMap; + public ValorantTextToAscii(Map asciiArtMap) { + this.asciiArtMap = asciiArtMap; + } + + public String textToAscii26x13(String text) { + ArrayList lettersInAsci = new ArrayList<>(); + for (char c : text.toUpperCase().toCharArray()) { + lettersInAsci.add(getLetter(c)); + } + // split it to lines, each line is 24 characters long (it starts with space, and ends with space so it's 26) + ArrayList> lines = new ArrayList<>(); + ArrayList currentLine = new ArrayList<>(); + + int totalAdded = 2; + currentLine.add(getLetter(' ')); + for (String[][] letter : lettersInAsci) { + int width = letter[0].length; + if (totalAdded + width > 26) { + lines.add(currentLine); + currentLine = new ArrayList<>(); + totalAdded = 2; + currentLine.add(getLetter(' ')); + } + currentLine.add(letter); + currentLine.add(getLetter(' ')); + totalAdded += width + 1; + } + + + lines.add(currentLine); + + // convert the lines to a string + StringBuilder result = new StringBuilder(); + for (ArrayList line : lines) { + int totalCharsAdded = 0; + for (int i = 0; i < 5; i++) { + for (String[][] letter : line) { + for (String s : letter[i]) { + result.append(s); + totalCharsAdded++; + } + } + if(totalCharsAdded < 26) { + result.append("░".repeat(Math.max(0, 26 - totalCharsAdded))); + } + totalCharsAdded = 0; + result.append("\n"); + } + + result.append("░░░░░░░░░░░░░░░░░░░░░░░░░░\n"); + + } + + return result.toString(); + } + + private String[][] getLetter(char c) { + String[][] letter = asciiArtMap.get(String.valueOf(c)); + if (letter == null) { + letter = asciiArtMap.get("░"); + } + return letter; + } + +}