Advertisement
EdmundC

silly

Jul 22nd, 2024 (edited)
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.59 KB | None | 0 0
  1. import curses
  2.  
  3. ascii_art = r"""
  4.   _____      _                 _                    
  5.  / ____|    | |               | |                    
  6. | (___   ___| |__   ___   ___ | |                    
  7.  \___ \ / __| '_ \ / _ \ / _ \| |                    
  8.  ____) | (__| | | | (_) | (_) | |                    
  9. |_____/ \___|_| |_|\___/ \___/|_|               _    
  10. | |  | |                                       | |  
  11. | |__| | ___  _ __ ___   _____      _____  _ __| | __
  12. |  __  |/ _ \| '_ ` _ \ / _ \ \ /\ / / _ \| '__| |/ /
  13. | |  | | (_) | | | | | |  __/\ V  V / (_) | |  |   <
  14. |_|  |_|\___/|_| |_| |_|\___| \_/\_/ \___/|_|  |_|\_\
  15. | |  | |     | |                                    
  16. | |__| |_   _| |__                                  
  17. |  __  | | | | '_ \                                
  18. | |  | | |_| | |_) |                                
  19. |_|  |_|\__,_|_.__(_)                                
  20.                                                      
  21.                                                      
  22. """
  23.  
  24. footer_text = "CALCULATOR - GAMES - HELP"
  25. additional_ascii_art = r" ,`~─────────────────~,`"
  26. instruction_text = [
  27.     "Use the hyphen '-' for minus",
  28.     "Use the slash '/' for division",
  29.     "Type 'PI' for pi, 'SQR.R' for square root of typed number"
  30. ]
  31.  
  32. def main(stdscr):
  33.     # Clear screen
  34.     stdscr.clear()
  35.  
  36.     # Get the screen height and width
  37.     sh, sw = stdscr.getmaxyx()
  38.  
  39.     # Split the ASCII art into lines
  40.     lines = ascii_art.splitlines()
  41.  
  42.     # Calculate the starting column to center the ASCII art
  43.     start_col = (sw - max(len(line) for line in lines)) // 2
  44.  
  45.     # Display each line of the ASCII art at the top center
  46.     for i, line in enumerate(lines):
  47.         stdscr.addstr(i, start_col, line)
  48.  
  49.     # Calculate the position to display the footer text centered
  50.     footer_row = len(lines) + 2
  51.     footer_col = (sw - len(footer_text)) // 2
  52.  
  53.     # Display the footer text
  54.     stdscr.addstr(footer_row, footer_col, footer_text)
  55.  
  56.     # Refresh the screen to display the ASCII art and footer text
  57.     stdscr.refresh()
  58.  
  59.     while True:
  60.         # Get user input
  61.         curses.echo()
  62.         input_row = footer_row + 6  # Adjusting to make space for additional ASCII and instructions
  63.         input_col = (sw - 20) // 2
  64.         user_input = stdscr.getstr(input_row, input_col, 20).decode('utf-8').strip().lower()
  65.  
  66.         # Clear the input area
  67.         stdscr.move(input_row, input_col)
  68.         stdscr.clrtoeol()
  69.  
  70.         if user_input == "calculator":
  71.             # Display the additional ASCII art in place of the input
  72.             stdscr.addstr(footer_row + 2, (sw - len(additional_ascii_art)) // 2, additional_ascii_art)
  73.            
  74.             # Display the instructions
  75.             for i, instruction in enumerate(instruction_text):
  76.                 stdscr.addstr(footer_row + 4 + i, (sw - len(instruction)) // 2, instruction)
  77.  
  78.             stdscr.refresh()
  79.         else:
  80.             try:
  81.                 # Replace 'x' with '*' for multiplication
  82.                 user_input = user_input.replace('x', '*')
  83.  
  84.                 # Evaluate the expression and print the result
  85.                 result = eval(user_input)
  86.                 stdscr.addstr(input_row + 2, (sw - len(str(result))) // 2, str(result))
  87.                 stdscr.refresh()
  88.             except Exception as e:
  89.                 stdscr.addstr(input_row + 2, (sw - len("Error")) // 2, "Error")
  90.                 stdscr.refresh()
  91.  
  92.         # Wait for user input to exit
  93.         stdscr.getch()
  94.  
  95. # Initialize the curses application
  96. curses.wrapper(main)
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement