Welcome to the mesmerizing world of ASCII animation, where art and code converge to create captivating visual experiences. In this blog post, we embark on an enchanting journey as we explore the creation of a delightful animation featuring a cute expression cat. Join us as we delve into the magic of ASCII art and the artistry of code, unraveling the process behind bringing this charming feline to life.
The Script:
#!/bin/bash
tput civis
display_frame(){
local text=("$@")
local rows=${#text[@]}
local cols=${#text[0]}
local start_row=$(( ( $(tput lines) - rows ) / 2 ))
local start_col=$(( ( $(tput cols) - cols ) / 2 ))
clear
for (( i=0; i<rows; i++ )); do
tput cup $(( start_row + i )) $start_col
echo -e "${text[$i]}"
done
sleep 0.5
}
animation_name=$(cat animation_name)
cd $animation_name/
frames=$(cat frameList)
while true; do
for frame in $frames; do
frameText=()
while IFS= read -r line; do
frameText+=("$line")
done < "$frame"
display_frame "${frameText[@]}"
done
done
tput cnorm
Code Explanation:
- tput civis: This command hides the cursor, ensuring a cleaner visual output during the animation.
- display_frame() function: This function is responsible for displaying each frame of the animation.
- local start_row=$(( ( $(tput lines) - rows ) / 2 )): The start_row variable calculates the starting row position for displaying the frame. It ensures that the frame is vertically centered on the terminal screen by subtracting the number of rows in the frame from the total number of lines in the terminal and dividing by 2.
- local start_col=$(( ( $(tput cols) - cols ) / 2 )): The start_col variable calculates the starting column position for displaying the frame. Similar to start_row, it ensures the frame is horizontally centered on the terminal screen by subtracting the number of columns in the frame from the total number of columns in the terminal and dividing by 2.
- tput cup $(( start_row + i )) $start_col: The tput cup command moves the cursor to the specified row and column position, allowing us to print the lines of the frame at the correct position.
- while IFS= read -r line; do: This loop reads each line from the current frame file.
- tput cnorm: Finally, this command restores the cursor.
Frame by Frame: Evoking Emotion
Unleashing Creativity: Customizing the Animation
One of the most exciting aspects of ASCII animation is the ability to customize and experiment. By modifying the frame files, artists and coders can create their own unique expressions, gestures, or even entirely new characters. This creative freedom allows for endless possibilities and encourages individuals to infuse their imagination into the animation.
Experiencing the Magic: The Video Showcase
Conclusion:
Remember, the beauty of ASCII animation lies not only in the final product but also in the process of creation. Embrace the magic, unleash your creativity, and let your characters dance across the screen, enchanting audiences with their whimsy.
Thanks,
Comments
Post a Comment