0

I'm trying to create a multi line ascii art animation using Intellij, and for that I'm creating an array of strings and I refer to each element of the array as a frame.
After that, in order for that to work, I need to change what was printed to the console each time unit x.

I do know that I can replace the last line printed to the console with "\r" like so:

for (int i = 0; i <= 100; i++)
    {
        Thread.sleep(200);
        System.out.printf("\r %s  ", i);
    }

however it doesn't delete the older lines printed.

The next thing that I've tried is to clear the console before each 'frame' printed but IntelliJ Idea doesn't have console like Visual Studio so, from what I understand, there is no way to clear the entire console from the code.

So I do know that there is no way to delete the console in intellij but is there any other solution or a workaround for that problem?

to make things more simple I'll add an example. Let's say I want to print this weight lifting animation (ascii art taken from - https://ascii.co.uk/art/stickman)

                                                                 O--,---,--O
                                          ._O_.     O--=-O-=--O     \ O /
    _._                      ,_O_,     O--<-+->--O      '-'          - -
   / O \        ,-O-,     O--(---)--O       X            v            -
   \| |/     O--=---=--O      >'>          / \          / )          / \
O--+=-=+--O      2"2          - -         -   -        ~  z         =   =

So I'm creating a 2d array of strings for the frames
(after that ill create the frame with String.join("\n", < frame elements >)).

String[][] frames = 
{
  {
     "           ",
     "           ",
     "    _._    ",
     "   / O \\   ",
     "   \\| |/   ",
     "O--+=-=+--O"
 },
 {
     "              ",
     "              ",
     "     ,-O-,    ",
     "  O--=---=--O ",
     "      2"2     "
 },
 {
     "              ",
     "     ,_O_,    ",
     "  O--(---)--O ",
     "      >'>      ",
     "      - -      "
 },
 {
     "     ._O_.    ",
     "  O--<-+->--O ",
     "       X      ",
     "      / \\     ",
     "     -   -    "
 },
 {
     "  O--=-O-=--O ",
     "      '-'     ",
     "       v      ",
     "      / )     ",
     "     ~   Z    "
 },
 {
     "  O--,---,--O ",
     "     \\ O /    ",
     "      - -     ",
     "       -      ",
     "      / \\     ",
     "     =   =    "
 }
}

and in each time unit x+1 I want the console to show frames[x+1] instead of frames[x].

any ideas?

Kfir Ettinger
  • 99
  • 1
  • 8
  • I know. I even wrote it in the question. I am looking for other ideas – Kfir Ettinger Jan 19 '22 at 15:05
  • what if you print "the frame" in one instruction using /n does it `System.out.printf("\r %s ", i);` still change the last line or it sees it as one line ??!! – Yasser CHENIK Jan 19 '22 at 15:06
  • clearing the console is not a good solution because you will lose the messages you already printed (unless you want to rewrite them too if you need them) and because it's very slow – Yasser CHENIK Jan 19 '22 at 15:10
  • I tried this ```System.out.printf("\r %s ", "a \n b");``` and only the last line -> ```b``` is deleted. – Kfir Ettinger Jan 19 '22 at 15:13
  • clearing the console indeed wasn't my first approach. however, as I said, it isn't even an option in intellij.. – Kfir Ettinger Jan 19 '22 at 15:14

0 Answers0