Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.73 KB | None | 0 0
  1. import turtle
  2.  
  3. # Initialising starting point for the turtle graphic
  4. start_row = 150
  5. start_col = 90
  6.  
  7. # Initialising distance value between rows and columns
  8. row_distance = 35
  9. col_distance = 35
  10.  
  11. # Initialising colours list
  12. colors_list = ['#011F4B', '#1A355D', '#334B6E', '#4D6281', '#667893', '#808FA5', '#99A5B7', '#B2BBC9', '#CCD2DB',
  13.                '#E5E8ED', '#B2D8D8', '#A0C2C2', '#8EACAC', '#7C9797', '#6A8181', '#596C6C', '#475656', '#354040',
  14.                '#232B2B', '#111515', '#4B3832', '#5D4B46', '#6E5F5A', '#81736F', '#938784', '#A59B98', '#DBD7D6',
  15.                '#EDEBEA', '#E50000', '#C00000', '#B20000', '#990000', '#7F0000', '#660000', '#4C0000', '#92AD9B',
  16.                '#829A8A', '#728779', '#617367', '#516056', '#414D45', '#303933', '#E86AF0', '#D05FD8', '#B954C0',
  17.                '#A24AA8', '#8B3F90', '#743578', '#5C2A60', '#451F48', '#4C516D', '#444862', '#3C4057', '#35384C',
  18.                '#2D3041', '#262836', '#1E202B', '#A4FFFF', '#000000', '#A52A2A', '#A9A9A9', '#006400', '#9932CC',
  19.                '#8B0000', '#FFD700', '#4B0082', '#F0E68C', '#ADD8E6', '#E0FFFF', '#90EE90', '#D3D3D3', '#FFB6C1',
  20.                '#FFFFE0', '#00FF00', '#FFA500', '#800080', '#00755E', '#555555', '#E32636', '#E4D96F', '#98777B',
  21.                '#98817B', '#3B444B', '#E9D66B', '#F8F8FF', '#318CE7', '#B2BEB5', '#89CFF0', '#BFFF00', '#013220',
  22.                '#FFD12A', '#8DB600', '#FF7518', '#F5F5DC', '#3D2B1F', '#71A6D2', '#FF0800', '#FAF0BE', '#C04000',
  23.                '#03C03C', '#E3A857', '#000080', '#B5A642', '#082567', '#5B92E5', '#C41E3A', '#FF007F', '#E5E4E2',
  24.                '#008000', '#483C32', '#848482', '#4B5320', '#D2691E', '#01796F', '#986960', '#960018', '#FFB7C5',
  25.                '#F4C2C2', '#E97451', '#734F96', '#BD33A4', '#79443B', '#FF7F50', '#006B3C', '#014421', '#702963',
  26.                '#779ECB', '#F5DEB3', '#FC8EAC', '#DFFF00', '#8E4585', '#00CC99', '#FFDF00', '#99BADD', '#08E8DE',
  27.                '#92A1CF', '#ACE1AF', '#614051', '#00FFFF', '#FFFF00', '#120A8F', '#F49AC2', '#FF00FF', '#3C1414',
  28.                '#ED872D', '#E7FEFF', '#7B3F00', '#DEB887', '#F0E130', '#FDFD96', '#B39EB5', '#FAD6A5', '#F28500',
  29.                '#A0785A', '#321414', '#9BDDFF', '#800000', '#8C92AC', '#9400D3', '#5D8AA8', '#00009C', '#893F45',
  30.                '#FF6700', '#66FF00', '#4682B4', '#D19FE8', '#50C878', '#CD7F32', '#FFF8DC', '#FFDB58', '#002FA7',
  31.                '#08457E', '#FBCCE7', '#5D3954', '#CE1620', '#FBEC5D', '#E4D00A', '#85BB65', '#008B8B', '#B8860B',
  32.                '#0047AB', '#1A2421', '#BDB76B', '#808000', '#002366', '#CF71AF', '#E52B50', '#556B2F', '#CD5B45',
  33.                '#414833', '#8F00FF', '#AEC6CF', '#C23B22', '#701C1C', '#F0F8FF', '#DE5D83', '#872657', '#E5AA70',
  34.                '#FFE5B4', '#996515', '#FF5A36', '#ECD540', '#CD5C5C', '#8A3324', '#FFFAFA', '#003399', '#FFBF00',
  35.                '#36454F', '#8A795D', '#696969', '#E30022', '#F7E7CE', '#FFEF00', '#007BA7', '#F7E98E', '#A1CAF1',
  36.                '#FFF700', '#A40000', '#A7FC00', '#966FD6', '#DAA520', '#FFA700', '#2A52BE', '#C3B091', '#654321',
  37.                '#E34234', '#6495ED', '#E25822', '#808080', '#FF5C5C', '#7CFC00', '#FCF75E', '#177245', '#138808',
  38.                '#E75480', '#FFFF31', '#CFCFC4', '#D73B3E', '#B31B1B', '#FFFFF0', '#DE3163', '#E49B0F', '#FFC0CB',
  39.                '#EDC9AF', '#D1E231', '#FFFDD0', '#007FFF', '#00FF6F', '#E6E200', '#DC143C', '#002E63', '#967117',
  40.                '#826644', '#FF8C00', '#CB99C9', '#CC7722', '#87A96B', '#FF7F00', '#E0115F', '#CC0000', '#003366',
  41.                '#0000FF', '#77DD77', '#A4C639', '#FFB347', '#FFD1DC', '#B22222', '#BF94E4', '#FFC1CC', '#E2725B',
  42.                '#CCCCFF', '#C4C3D0', '#65000B', '#836953', '#FFA812', '#B2EC5D', '#E9967A', '#964B00', '#738678',
  43.                '#30D5C8', '#E1A95F', '#FF6961', '#F0EAD6', '#E30B5D', '#C32148', '#FF0000', '#A3C1AD', '#93C572',
  44.                '#CC4E5C', '#FF3800', '#CB410B', '#00008B', '#CC5500', '#69359C', '#7FFFD4', '#F4C430', '#C19A6B',
  45.                '#00A86B', '#3EB489', '#FFF5EE', '#704214', '#78866B', '#918151', '#B7410E', '#87CEEB', '#8B008B',
  46.                '#B87333', '#008080', '#536878', '#ED9121', '#F0DC82', '#0F4D92', '#FBCEB1', '#1560BD', '#EEE600',
  47.                '#FF8C69', '#800020', '#560319', '#F3E5AB', '#FFF0F5', '#C0C0C0', '#191970', '#6D351A', '#F5F5F5',
  48.                '#2F4F4F', '#6082B6', '#FF1C00', '#004225', '#002147', '#C2B280', '#B57EDC']
  49.  
  50. # Creating colour counter t correspond to location of unique hex colours chosen for the turtles
  51. color_counter = 0
  52.  
  53.  
  54. # A function to get turtle position
  55. def GetTurtlePosition(index):
  56.     # Getting the row number from the index
  57.     row = start_row - (row_distance * (index % 10))
  58.     # Getting the column number from the index
  59.     col = start_col - (col_distance * (int(index / 10)))
  60.     # Returning row and column position
  61.     return row, col
  62.  
  63.  
  64. # Function to move the turtle
  65. def MoveTurtle(turtle_obj, index):
  66.     # Getting row and column from the index
  67.     row, col = GetTurtlePosition(index)
  68.     turtle_obj.penup()
  69.     # Moving the turtle object to the row and column position
  70.     turtle_obj.setpos(row, col)
  71.     # Printing the turtle object
  72.     turtle_obj.pendown()
  73.  
  74.  
  75. # A function to remove the turtle
  76. def RemoveTurtle(turtle_queue, index):
  77.     # Changing colour of turtle to white so it disappears
  78.     turtle_queue[index].color("#FFFFFF")
  79.     # Deleting the object from the queue
  80.     del turtle_queue[index]
  81.     # Looping though the queue
  82.     for i in range(index, len(turtle_queue)):
  83.         # Moving the turtles after the deleted turtle
  84.         MoveTurtle(turtle_queue[i], i)
  85.  
  86.  
  87. # A function to add turtle object
  88. def AddTurtleObject(turtle_queue):
  89.     # Getting turtle counter
  90.     global color_counter
  91.     color_counter += 1
  92.     # Getting colour for the turtle
  93.     if color_counter == len(colors_list):
  94.         color_counter = 0
  95.     # Getting index for current turtle
  96.     index = len(turtle_queue)
  97.     # Creating new turtle object
  98.     turtle_obj = turtle.Turtle()
  99.     # Assigning colour to turtle object
  100.     turtle_obj.color(colors_list[color_counter])
  101.     # Assigning turtle shape to object
  102.     turtle_obj.shape("turtle")
  103.     # Moving turtle to correct position
  104.     MoveTurtle(turtle_obj, index)
  105.     turtle_queue.append(turtle_obj)
  106.  
  107.  
  108. # Main function
  109. def main():
  110.     # Initialising variables
  111.     width = 400
  112.     height = 250
  113.     screen = turtle.Screen()
  114.     screen.setup(width, height)
  115.     LegalOptions = set("ANLPQ")
  116.     fifo = []
  117.     turtle_queue = []
  118.  
  119.     # Printing the menu
  120.     print("Here are your options: \nA - Append\nN - Next\nL - Leave\nP - Print\nQ - Quit\n")
  121.     print("Enter the corresponding character to execute an option")
  122.  
  123.     # Loop for system
  124.     while True:
  125.         # Taking inputs
  126.         choice = input("You can now make a choice from the main options menu:\n")
  127.         # Checking if choice entry is a subset of the legal values defined earlier
  128.         if LegalOptions.issuperset(choice):
  129.             # Calling the corresponding function based on user choice
  130.             if choice == "A":
  131.                 # Checking if length of turtle queue is max and notifying user if it is
  132.                 if len(turtle_queue) == 60:
  133.                     print("The queue is full-please try again later.\n")
  134.                 else:
  135.                     # Checking if length of user input is 0 and printing empty queue
  136.                     # if it is not empty adding to front of fifo
  137.                     s = input("Please enter an item to add to the queue:\n")
  138.                     while s == "":
  139.                         s = input("Please enter a string that is not empty:\n")
  140.                     fifo.append(s)
  141.                     # Calling corresponding function
  142.                     AddTurtleObject(turtle_queue)
  143.             # Checking if length of fifo if it is 0 and printing empty queue
  144.             elif choice == "N":
  145.                 if len(fifo) == 0:
  146.                     print("EMPTY QUEUE\n")
  147.                 # Removing if it is and calling corresponding function
  148.                 else:
  149.                     fifo.pop(0)
  150.                     RemoveTurtle(turtle_queue, 0)
  151.             # Taking entry of what to remove from fifo if item is not in queue printing output saying so
  152.             elif choice == "L":
  153.                 if len(fifo) == 0:
  154.                     print("EMPTY QUEUE\n")
  155.                 else:
  156.                     # Taking entry of what to remove from fifo
  157.                     s = input("Please enter an item to remove from the queue:\n")
  158.                     # Checking if length of user input is 0 and printing empty queue
  159.                     while s == "":
  160.                         s = input("Please enter a string that is not empty:\n")
  161.                     # Printing error if not in fifo and breaking
  162.                     if fifo.count(s) == 0:
  163.                         print(s, "is not in the queue\n")
  164.                     index = -1
  165.                     for i in range(len(fifo)):
  166.                         if fifo[i] == s:
  167.                             index = i
  168.                             break
  169.                     # Removing if it is and calling corresponding removal function
  170.                     if index != -1:
  171.                         del fifo[index]
  172.                         RemoveTurtle(turtle_queue, index)
  173.             # Printing queue if it is not empty, only spaced between
  174.             elif choice == "P":
  175.                 if len(fifo) > 0:
  176.                     print(" ".join(fifo))
  177.                     print("\n")
  178.                 else:
  179.                     print("EMPTY QUEUE\n")
  180.             elif choice == "Q":
  181.                 print("Goodbye.")
  182.                 break
  183.         # if option is not subset of the defined superset print invalid option
  184.         else:
  185.             print(choice, "is an invalid option.\n")
  186.  
  187.  
  188. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement