Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import turtle
- # Initialising starting point for the turtle graphic
- start_row = 150
- start_col = 90
- # Initialising distance value between rows and columns
- row_distance = 35
- col_distance = 35
- # Initialising colours list
- colors_list = ['#011F4B', '#1A355D', '#334B6E', '#4D6281', '#667893', '#808FA5', '#99A5B7', '#B2BBC9', '#CCD2DB',
- '#E5E8ED', '#B2D8D8', '#A0C2C2', '#8EACAC', '#7C9797', '#6A8181', '#596C6C', '#475656', '#354040',
- '#232B2B', '#111515', '#4B3832', '#5D4B46', '#6E5F5A', '#81736F', '#938784', '#A59B98', '#DBD7D6',
- '#EDEBEA', '#E50000', '#C00000', '#B20000', '#990000', '#7F0000', '#660000', '#4C0000', '#92AD9B',
- '#829A8A', '#728779', '#617367', '#516056', '#414D45', '#303933', '#E86AF0', '#D05FD8', '#B954C0',
- '#A24AA8', '#8B3F90', '#743578', '#5C2A60', '#451F48', '#4C516D', '#444862', '#3C4057', '#35384C',
- '#2D3041', '#262836', '#1E202B', '#A4FFFF', '#000000', '#A52A2A', '#A9A9A9', '#006400', '#9932CC',
- '#8B0000', '#FFD700', '#4B0082', '#F0E68C', '#ADD8E6', '#E0FFFF', '#90EE90', '#D3D3D3', '#FFB6C1',
- '#FFFFE0', '#00FF00', '#FFA500', '#800080', '#00755E', '#555555', '#E32636', '#E4D96F', '#98777B',
- '#98817B', '#3B444B', '#E9D66B', '#F8F8FF', '#318CE7', '#B2BEB5', '#89CFF0', '#BFFF00', '#013220',
- '#FFD12A', '#8DB600', '#FF7518', '#F5F5DC', '#3D2B1F', '#71A6D2', '#FF0800', '#FAF0BE', '#C04000',
- '#03C03C', '#E3A857', '#000080', '#B5A642', '#082567', '#5B92E5', '#C41E3A', '#FF007F', '#E5E4E2',
- '#008000', '#483C32', '#848482', '#4B5320', '#D2691E', '#01796F', '#986960', '#960018', '#FFB7C5',
- '#F4C2C2', '#E97451', '#734F96', '#BD33A4', '#79443B', '#FF7F50', '#006B3C', '#014421', '#702963',
- '#779ECB', '#F5DEB3', '#FC8EAC', '#DFFF00', '#8E4585', '#00CC99', '#FFDF00', '#99BADD', '#08E8DE',
- '#92A1CF', '#ACE1AF', '#614051', '#00FFFF', '#FFFF00', '#120A8F', '#F49AC2', '#FF00FF', '#3C1414',
- '#ED872D', '#E7FEFF', '#7B3F00', '#DEB887', '#F0E130', '#FDFD96', '#B39EB5', '#FAD6A5', '#F28500',
- '#A0785A', '#321414', '#9BDDFF', '#800000', '#8C92AC', '#9400D3', '#5D8AA8', '#00009C', '#893F45',
- '#FF6700', '#66FF00', '#4682B4', '#D19FE8', '#50C878', '#CD7F32', '#FFF8DC', '#FFDB58', '#002FA7',
- '#08457E', '#FBCCE7', '#5D3954', '#CE1620', '#FBEC5D', '#E4D00A', '#85BB65', '#008B8B', '#B8860B',
- '#0047AB', '#1A2421', '#BDB76B', '#808000', '#002366', '#CF71AF', '#E52B50', '#556B2F', '#CD5B45',
- '#414833', '#8F00FF', '#AEC6CF', '#C23B22', '#701C1C', '#F0F8FF', '#DE5D83', '#872657', '#E5AA70',
- '#FFE5B4', '#996515', '#FF5A36', '#ECD540', '#CD5C5C', '#8A3324', '#FFFAFA', '#003399', '#FFBF00',
- '#36454F', '#8A795D', '#696969', '#E30022', '#F7E7CE', '#FFEF00', '#007BA7', '#F7E98E', '#A1CAF1',
- '#FFF700', '#A40000', '#A7FC00', '#966FD6', '#DAA520', '#FFA700', '#2A52BE', '#C3B091', '#654321',
- '#E34234', '#6495ED', '#E25822', '#808080', '#FF5C5C', '#7CFC00', '#FCF75E', '#177245', '#138808',
- '#E75480', '#FFFF31', '#CFCFC4', '#D73B3E', '#B31B1B', '#FFFFF0', '#DE3163', '#E49B0F', '#FFC0CB',
- '#EDC9AF', '#D1E231', '#FFFDD0', '#007FFF', '#00FF6F', '#E6E200', '#DC143C', '#002E63', '#967117',
- '#826644', '#FF8C00', '#CB99C9', '#CC7722', '#87A96B', '#FF7F00', '#E0115F', '#CC0000', '#003366',
- '#0000FF', '#77DD77', '#A4C639', '#FFB347', '#FFD1DC', '#B22222', '#BF94E4', '#FFC1CC', '#E2725B',
- '#CCCCFF', '#C4C3D0', '#65000B', '#836953', '#FFA812', '#B2EC5D', '#E9967A', '#964B00', '#738678',
- '#30D5C8', '#E1A95F', '#FF6961', '#F0EAD6', '#E30B5D', '#C32148', '#FF0000', '#A3C1AD', '#93C572',
- '#CC4E5C', '#FF3800', '#CB410B', '#00008B', '#CC5500', '#69359C', '#7FFFD4', '#F4C430', '#C19A6B',
- '#00A86B', '#3EB489', '#FFF5EE', '#704214', '#78866B', '#918151', '#B7410E', '#87CEEB', '#8B008B',
- '#B87333', '#008080', '#536878', '#ED9121', '#F0DC82', '#0F4D92', '#FBCEB1', '#1560BD', '#EEE600',
- '#FF8C69', '#800020', '#560319', '#F3E5AB', '#FFF0F5', '#C0C0C0', '#191970', '#6D351A', '#F5F5F5',
- '#2F4F4F', '#6082B6', '#FF1C00', '#004225', '#002147', '#C2B280', '#B57EDC']
- # Creating colour counter t correspond to location of unique hex colours chosen for the turtles
- color_counter = 0
- # A function to get turtle position
- def GetTurtlePosition(index):
- # Getting the row number from the index
- row = start_row - (row_distance * (index % 10))
- # Getting the column number from the index
- col = start_col - (col_distance * (int(index / 10)))
- # Returning row and column position
- return row, col
- # Function to move the turtle
- def MoveTurtle(turtle_obj, index):
- # Getting row and column from the index
- row, col = GetTurtlePosition(index)
- turtle_obj.penup()
- # Moving the turtle object to the row and column position
- turtle_obj.setpos(row, col)
- # Printing the turtle object
- turtle_obj.pendown()
- # A function to remove the turtle
- def RemoveTurtle(turtle_queue, index):
- # Changing colour of turtle to white so it disappears
- turtle_queue[index].color("#FFFFFF")
- # Deleting the object from the queue
- del turtle_queue[index]
- # Looping though the queue
- for i in range(index, len(turtle_queue)):
- # Moving the turtles after the deleted turtle
- MoveTurtle(turtle_queue[i], i)
- # A function to add turtle object
- def AddTurtleObject(turtle_queue):
- # Getting turtle counter
- global color_counter
- color_counter += 1
- # Getting colour for the turtle
- if color_counter == len(colors_list):
- color_counter = 0
- # Getting index for current turtle
- index = len(turtle_queue)
- # Creating new turtle object
- turtle_obj = turtle.Turtle()
- # Assigning colour to turtle object
- turtle_obj.color(colors_list[color_counter])
- # Assigning turtle shape to object
- turtle_obj.shape("turtle")
- # Moving turtle to correct position
- MoveTurtle(turtle_obj, index)
- turtle_queue.append(turtle_obj)
- # Main function
- def main():
- # Initialising variables
- width = 400
- height = 250
- screen = turtle.Screen()
- screen.setup(width, height)
- LegalOptions = set("ANLPQ")
- fifo = []
- turtle_queue = []
- # Printing the menu
- print("Here are your options: \nA - Append\nN - Next\nL - Leave\nP - Print\nQ - Quit\n")
- print("Enter the corresponding character to execute an option")
- # Loop for system
- while True:
- # Taking inputs
- choice = input("You can now make a choice from the main options menu:\n")
- # Checking if choice entry is a subset of the legal values defined earlier
- if LegalOptions.issuperset(choice):
- # Calling the corresponding function based on user choice
- if choice == "A":
- # Checking if length of turtle queue is max and notifying user if it is
- if len(turtle_queue) == 60:
- print("The queue is full-please try again later.\n")
- else:
- # Checking if length of user input is 0 and printing empty queue
- # if it is not empty adding to front of fifo
- s = input("Please enter an item to add to the queue:\n")
- while s == "":
- s = input("Please enter a string that is not empty:\n")
- fifo.append(s)
- # Calling corresponding function
- AddTurtleObject(turtle_queue)
- # Checking if length of fifo if it is 0 and printing empty queue
- elif choice == "N":
- if len(fifo) == 0:
- print("EMPTY QUEUE\n")
- # Removing if it is and calling corresponding function
- else:
- fifo.pop(0)
- RemoveTurtle(turtle_queue, 0)
- # Taking entry of what to remove from fifo if item is not in queue printing output saying so
- elif choice == "L":
- if len(fifo) == 0:
- print("EMPTY QUEUE\n")
- else:
- # Taking entry of what to remove from fifo
- s = input("Please enter an item to remove from the queue:\n")
- # Checking if length of user input is 0 and printing empty queue
- while s == "":
- s = input("Please enter a string that is not empty:\n")
- # Printing error if not in fifo and breaking
- if fifo.count(s) == 0:
- print(s, "is not in the queue\n")
- index = -1
- for i in range(len(fifo)):
- if fifo[i] == s:
- index = i
- break
- # Removing if it is and calling corresponding removal function
- if index != -1:
- del fifo[index]
- RemoveTurtle(turtle_queue, index)
- # Printing queue if it is not empty, only spaced between
- elif choice == "P":
- if len(fifo) > 0:
- print(" ".join(fifo))
- print("\n")
- else:
- print("EMPTY QUEUE\n")
- elif choice == "Q":
- print("Goodbye.")
- break
- # if option is not subset of the defined superset print invalid option
- else:
- print(choice, "is an invalid option.\n")
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement