Dynamically printing characters on the screen

I saw a guy on YouTube programming a spinning ASCII cube in C, and I thought it would be a fun exercise to recreate it in Rust. Despite my initial attempts, I can only get one line of the "cube" to print out, although the "rotation" animation, as it were, looks fine for that one line. Is there some issue with the way Rust prints characters on the screen?

My code attempt here. The original C code is linked in the youtube video above.

I will add that using the libm::putchar function has the same functionality as my print!(...) code, so I don't think that is it.

The code appears to be using ANSI escape codes, which have to be properly supported by the terminal emulator you're using. Did you try running the original C code to see if it worked?

2 Likes

Try:

-                    let idx: i32 = xp + yp + (width as i32);
+                    let idx: i32 = xp + yp * (width as i32);
+//                                         ^
2 Likes

Yes, the C code works fine on my terminal (MacOS standard terminal).

Brilliant! I was trying hard not to make this a "catch my typo" question, but alas... it works great now. Thanks so much!!