UnicodePlot exercise

I’ve taken up a little challenge to reproduce a classic plot from Chorin 1973 (maybe the first computerized flow plot ever) and I hoped WaterLily.jl + UnicodePlots.jl could make short work of it.

However, to really nail this plot I need to limit myself to the the ‘x’ and ‘o’ characters, downgrading UnicodePlot.jl significantly. I can get the coordinates where the x’s and o’s should be. I’m not having any luck adding x’s and o’s to the plot at those points. Any ideas?

3 Likes

By the way - here is the UnicodePlot.jl output so far. It’s certainly cute, just not quite the right aesthetic.

Screen Shot 2021-05-13 at 20.03.49

Related question! Is there an easy way to repeatedly update the terminal output, making this into a video? I saw GitHub - IanButterworth/VideoInTerminal.jl: Video playback in terminal via. ImageInTerminal.jl and VideoIO.jl, and the code to refresh the REPL output must be in there somewhere… but I’m not seeing where.

This looks great!

1 Like

Wouldn’t it be easier to do this manually? Like a simple sweep through the mesh that prints spaces, Xs, and Os, depending on the values? I feel like trying to simplify UnicodePlots would be more work than that.
(I assume O is for positive vorticity, X negative. Never seen that plot before, so thanks for that =])

Yes, the x’s denotes positive vorticity and o’s are negative.

Is there an easy way to reproduce the nuts and bolts of UnicodePlots display without the package? It must be some kind of specialized print output.

No idea, but why can’t you just print the results of the mesh to the terminal? You’d have to do too much interpolation or something?
In other words, which feature of UnicodePlots is needed for this?

I am generally trying to use other people’s code instead of just writing my own where possible in Julia. In this case, it is easy enough:

function print_vort(a)
    width,height = size(a)
    for w in 2:4:width-1
        s = ""
        for h in 2:2:height-1
            v = sum(a[w:w+4,h:h+1])/8
            s*= v<-1 ? "O" : v>1 ? "X" : " "
        end
        println(s)
    end
end

julia> print_vort(a)

                             
            XXX  OO             
           XX     OO            
          XX       OO           
          XX       OO           
          XX OOOO  OOO          
           XXXXXX  OOO          
           XXXXXXX OOO          
            XXXXXXXOOO          
                   OOO          
                 OOOOO          
            OOOOOOOOO           
          OOOOOOOOO             
           OOOO                 
                                
                                
                                
           XXXXXXXXXX           
         XXXXXXXXXXX            
        XXXXXXXXX               
         XXXX                   
                                
                                
                                
                  OOOOO         
                OOOOOOO         
               OOOOOOOO         
               OOOOOO           
3 Likes

Gnuplot can plot using the characters you specify. An example with X and O with Gaston:

using Gaston
x1 = randn(10); y1 = randn(10);
x2 = randn(10); y2 = randn(10);
plot(x1, y1, w = "points", marker = "X", lc = :black);
plot!(x2, y2, w = "points", marker = "O", lc = :black)

image

Gnuplot can also plot using ASCII text on the terminal by setting the terminal to dumb:

      +--------------------------------------------------------------------+
      |  X   +      +      +       +      +      +       +      +      +   |
  1.5 |-+                                                                +-|
      |                                 X                                  |
    1 |-+                                                                +-|
      |                                  X          X                      |
  0.5 |-+                           O                                    +-|
      |                          X              O     O                    |
      |                                              O       O             |
    0 |-+                                      X                         +-|
      |                     O                                              |
 -0.5 |-+                         O              O       X               +-|
      |                                                                    |
   -1 |-+                                         X                      +-|
      |                                                                    |
 -1.5 |-+                                       X                        +-|
      |                                                                    |
      |           O                                                        |
   -2 |-+                                                               X+-|
      |      +      +      +     O +      +      +       +      +      +   |
 -2.5 +--------------------------------------------------------------------+
            -2    -1.5    -1     -0.5     0     0.5      1     1.5     2

There are two julia front-ends to Gnuplot I’m aware of: Gnuplot.jl and Gaston.

4 Likes

looks nice. i’ll check it out.