Skip to content

Instantly share code, notes, and snippets.

@Rand0mB0t
Last active April 18, 2024 17:40
Show Gist options
  • Save Rand0mB0t/99683685fa8fe45fde674b1f929a327b to your computer and use it in GitHub Desktop.
Save Rand0mB0t/99683685fa8fe45fde674b1f929a327b to your computer and use it in GitHub Desktop.
Simple Python script for flipping an ASCII- art
__author__ = 'Rand0mb0t'
# Code for ASCII-ART Flipper
img_file = str(input("select an input file : "))
save_file = str(input("Select an output file : "))
with open(img_file,"r") as file: # Open art- file
lines = file.read().split('\n')
while '' in lines: # Remove any empty lines from file
lines.remove('')
# Required variables
art = []
modified_art = []
save_art=[]
direction = str()
print("Current ascii-art")
# Print current ascii-art
for line in lines:
art.append(list(line))
print(line)
# Take input for direction
direction = str(input("Enter direction to flip Upside Down -> ud , left-right -> lr : "))
# logic to move image left to right
for i in range(len(art)):
modified_art.append([])
for j in range(len(art[i]),0,-1):
modified_art[i].append(art[i][j-1])
# logic to flip image upside down( For mirror image lr flip is necessary )
if direction == 'ud':
for i in range(len(modified_art),0,-1):
save_art.append(''.join(modified_art[i-1]))
# Logic for saveing lr-flip
if direction == 'lr':
for i in range(len(modified_art)):
save_art.append(''.join(modified_art[i]))
# Showing the flipped art
for line in save_art:
print(line)
# Savinf the flipped art
with open(save_file,"w") as saving:
for line in save_art:
saving.write(line)
saving.write('\n')
print("File Saved")
@Laiteux
Copy link

Laiteux commented Apr 18, 2024

thanks mate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment