poetaman / arttime

arttime is a CLI application that blends beauty of ASCII / text art with functionality of clock / timer / pattern-based time manager in terminal ⏰
Other
938 stars 15 forks source link

[Question] Is it possible to automatically cycle through art every X seconds? #61

Closed continue47 closed 6 months ago

continue47 commented 6 months ago

I have an old crt that I would like to use to display random ASCII art, I hooked it up to a raspberry pi and while I found that I can start arttime with --random I couldn't figure out a way to make it automatically change the art at a specific interval.

I ended up writing a python script to kind of do this - just reads from the arttime directory where the actual ascii files are stored and refreshes at an interval - but it's not ideal since it doesn't nicely center them as arttime.

Is there a way to achieve something like this with arttime?

Thanks.

poetaman commented 6 months ago

@continue47 There are four ways you can achieve this: 1) a simple one that wouldn't loop forever but is easy to test, 2) one where you can loop forever, the UI can be improved a bit, 3) more python code than 2) for silent remote updates, 4) if you just want to cycle arts and don't care about arttime's other functions just use artprint instead (it centers too).

1) Create a keypoem file with name like randomart_Xs (randomart_1s 1s stands for read rate of 1 byte/second), and put as long a sequence of js: jjjjjjjjjjj...y or jjjjjjjjjjj...n. Then start arttime like this:

arttime --nolearn -k /path/to/randomart_1s

The cycling would end when the last character is encountered (n is optional as EOF cancels the selection anyway). So, if you want to cycle for 1 hour, the file would have 3600 js. For people who can code... 2nd technique is more appealing:

2) Write a python program that creates a named pipe like randomartfifo (name can be anything) and write as many js to the named pipe in a loop, and pass that named pipe to arttime instead of file (like below)). The general specification for writing such programs is in the CONTRIBUTING. Here's are some links: feeder specification (manual can be opened with arttime -m or man arttime), keypoem file format (document needs some minor update, check the change that happened in the release link at the bottom of this comment).

arttime --nolearn -k /path/to/randomartfifo

Don't end the name with _Xs (you can but don't), and control the delays from python to insert even random delays if you want...

Pressing Ctrl-c (or equivalent interrupt keybinding for your computer) ends SCRIPT mode of arttime, and the control will be transferred to your computer again. You can restart the cycle again from within arttime by pressing k, and then passing the path to same file/fifo. I would recommended reading the section ORCHESTRATING too and seeing a GIF in the release notes that shows how arttime can be used to display dynamic information from external feeder programs (weather data in this case): https://github.com/poetaman/arttime/releases/tag/v2.3.0

  1. Alternative... At the moment, I have not added a silent remote update binding for j. Once I do that, you should be able to send J (capital J) and the UI won't show the line on top that asks user to make selection. If you don't want that line, then instead of sending js, send a sequence like Aartname1\nAartname2\n... from python script instead of js. You will have to load the names files from artdir, do a random shuffle in python before sending. The advantage is that it won't show that query string on top.

Side note: to learn/test key how arttime makes meaning of sequences, the easiest is to pipe it into arttime: printf 'jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjycccccccccccccccc' | arttime. Such examples are on the wiki, and in the manual.

  1. You can also use command artprint --random from python or artprint -a artname in case you want to do the random shuffle in python (ideal as it won't repeat same art till all are cycled), and pass appropriate terminal --width and --height. Optionally also pass -t- if you want to not print captions from your art files. Try artprint -m or man artprint to read its manual, it would center the arts.
continue47 commented 6 months ago

I took your advice and used artprint --random from python. It has all the options I needed including setting the colors for the art and title, centering the art, and setting a max width, great stuff!

Thank you for such a detailed reply!

poetaman commented 6 months ago

@continue47 You are welcome! Please feel free to share an image or video of your raspberry-pi + CRT + arttime setup. If it's a nice shot, I might consider pinning it in the wiki.

poetaman commented 5 months ago

@continue47 You might want to update to the latest commit https://github.com/poetaman/arttime/commit/2ef154544d31471e8cb33b7131c8b896b0b0f50b. It should be visibly faster on slow machines like raspberry pi.