hackerb9 / vt340test

Tests of VT340 compatibility
Creative Commons Zero v1.0 Universal
40 stars 5 forks source link

Palette animation #9

Open j4james opened 3 years ago

j4james commented 3 years ago

I've been playing around with Sixel palette animation, and have created an example of a rotating ball, based on the old Amiga Boing Ball demo.

This is the bash script I'm using: https://gist.github.com/j4james/a0a5747cc14aed60279e5ed31c37c459

If run normally, it just rotates the ball by cycling the palette, but if you run it as ./animation.sh bounce, it'll also attempt to bounce the ball (essentially just scrolling the screen up and down). The animation continues until you press any key.

I'm not sure if this is worth adding as one of our test cases, but it would be nice to at least try it out on the VT340 and see how well it works. If it can't keep up, you may need to play around with the timing by tweaking the -t parameter on the read calls in the spin_ball and bounce_ball functions.

If it's working correctly, I'm hoping it should look something like this:

https://user-images.githubusercontent.com/4181424/129489108-453146a0-e13f-4f6d-ac76-5a51ae41464e.mp4

hackerb9 commented 3 years ago

Heh! That's pretty fun. It does work, albeit slowly and with a bug or two.

  1. A platform is slowly drawn left to right under the spinning ball as it rotates in place. This does not appear to be intentional.
  2. The foreground and highlight color are changed during rotation. This is most noticeable in the platform under the ball and in the status line.
  3. There are black and yellow vertical lines marching across the red and white squares that I don't see in your video.
  4. The ball seems to reverse rotational direction when it hits the top of the screen. Is it supposed to? It seems odd that it ever starts rotating backwards.
  5. When bouncing, the read command in line 76 gives an error message: "error setting terminal attributes: Interrupted system call". Discarding stderr is a sufficient workaround. (read -sn1 -t 0.04 2>/dev/null && break). I'm not sure why it is giving that error. Perhaps it is a bug in bash when setting the termios timeout? Could it be using TCSADRAIN with tcsetattr, which would wait for all the data queued up to finish being sent? That doesn't make a lot of sense.
  6. Quitting when a key is hit doesn't work on a genuine VT340 because there is a large buffer of bouncing data that has already been sent and is slowly trickling through at 9600 baud. Instead, I have to use ^C to cancel, which flushes the termios buffer.
  7. When the script is cancelled with ^C, the terminal is not reset to a sane state. You can solve that by putting the final code in a function called "cleanup" (or whatever you wish) and having one of the first lines of the script says, trap cleanup EXIT. Bash will then run the cleanup function when the script exits for any reason.
hackerb9 commented 3 years ago

The "platform" was simply the error message from the read command being interpreted as sixels. Redirecting stderr to /dev/null for the read in spin_ball fixes problem number 0.

Also, I notice that the black and yellow lines do not show up when the balling is simply spinning. They only happen when it is also bouncing.

j4james commented 3 years ago

The foreground and highlight color are changed during rotation.

Yeah, the animation requires all 16 palette entries, so that was unavoidable. Palette entries 15 and 0 should at least be static, but 7 is going to be one of the ones that's cycling through red and white. I thought it wouldn't be a problem because there's no text on screen, but I forgot about the status bar. Maybe we could clear the status with DECSSDT (just while the animation is running).

The ball seems to reverse rotational direction when it hits the top of the screen. Is it supposed to? It seems odd that it ever starts rotating backwards.

Yeah, that was intentional. The idea being that the ball's spin would be altered when coming into contact with a wall, otherwise it looks a bit like the ball is just scrolling up and down (which of course it is!). The effect was better in the original demo because it was bouncing from side to side as well.

When the script is cancelled with ^C, the terminal is not reset to a sane state. You can solve that by putting the final code in a function called "cleanup" (or whatever you wish) and having one of the first lines of the script says, trap cleanup EXIT.

I like this! If I had known how to do that I wouldn't have bothered with the read and just used a sleep for the delay. This would also solve issues 5 and 4.

Also, I notice that the black and yellow lines do not show up when the balling is simply spinning. They only happen when it is also bouncing.

I guess that could be a hardware glitch? I know the MAME VT240 emulator has all sorts of weird artifacts when you scroll, but that could be bug in MAME. Anyway, we could just drop the bouncing part of the demo and only show the rotation (assuming that works reasonably well). I'll leave it up to you, though. It's not an essential test case - I just wanted to try it out for fun.