Ejemplo n.º 1
0
 def __init__(self, Size, X, Y, Width, Height, CompleteArray=True):
     if Size > 1500: # Sizes bigger than 1000 take too much time sorting and displaying the array.
         raise ArraySizeError(f"Array size is too big, size can't be bigger than 1500. Selected size is {Size}.")
     else:
         self.x = X
         self.y = Y
         self.Width = Width
         self.Height = Height
         self.Size = Size
         self.Current_Accesses = 0 # Using that to know how many accesses to the array we have made.
         self.isComplete = CompleteArray
         self.Jumps = RGB_SIZE//Size
         self.Audio_Jumps = len(Sound_Frequency_Range)//Size
         self.Moving_Elements = []
         self.isSorted = False
         if CompleteArray: # If the array has to be complete.
             self.Array = [i for i in range(1, Size+1)] # Generating array with numbers from one to Size.
             random.shuffle(self.Array) # Moving the numbers to random positions.
         else:
             self.Array = []
             for _ in range(Size):
                 self.Array.append(random.randint(1, Size))
         self.Normalized_Array = [i/max(self.Array) for i in self.Array] # Creating an array with values between [0, 1].
Ejemplo n.º 2
0
    def __init__(self, Size, X, Y, Width, Height, Information_Text, CompleteArray=True, Sound=False):
        """

        :param Size: Number of elements on the array.
        :param X: Initial x position for the first element on the array.
        :param Y: Initial y position for the first element on the array.
        :param Width: Width of the biggest element on the array.
        :param Height: Height of the biggest element on the array.
        :param Information_Text: Array storing the current Sorting Algorithm and the array size.
        :param CompleteArray: Boolean value. If True, we are going to create the array with the numbers from 1 to Size randomly shuffled, if is False, we add 'Size' random numbers from 1 to Size, so numbers can be repeated.
        :param Sound: Boolean to know if we want to generate sounds.
        """
        if Size > 1500: # Sizes bigger than 1000 take too much time sorting and displaying the array.
            raise ArraySizeError(f"Array size is too big, size can't be bigger than 1500. Selected size is {Size}.")
        else:
            self.x = X
            self.y = Y
            self.Width = Width
            self.Height = Height
            self.Size = Size
            self.Current_Accesses = 0 # Using that to know how many accesses to the array we have made.
            self.isComplete = CompleteArray
            self.Jumps = RGB_SIZE//Size # Depending on the size of the array we acces to the RGB colours with more or less steps.
            self.Audio_Jumps = len(Sound_Frequency_Range)//Size # Same as RGB.
            self.Information_Text = Information_Text
            self.Moving_Elements = [] # Knowing the values of the current elements that we are moving.
            self.isSorted = False # Using it to know if we have to execute the sorting algorithm.
            self.Sound = Sound
            if CompleteArray: # If the array has to be complete.
                self.Array = [i for i in range(1, Size+1)] # Generating array with numbers from one to Size.
                random.shuffle(self.Array) # Moving the numbers to random positions.
            else: # If not, we just add Size times a random value between 1 and Size.
                self.Array = []
                for _ in range(Size):
                    self.Array.append(random.randint(1, Size))
            self.Normalized_Array = [i/max(self.Array) for i in self.Array] # Creating an array with values between [0, 1].
Ejemplo n.º 3
0
MAIN_LOOP = True


def isIntegrer(N):
    N = str(N)
    i = N.index(".")
    if N[i + 1] == "0" and len(N) == i + 2:
        return True
    else:
        return False


if AL == 4:
    if not isIntegrer(log(ARRAY_SIZE, 2)):
        raise ArraySizeError(
            "When using Tim Sort, array size should be power of two. (64, 128, 256, 512)"
        )
        MAIN_LOOP = False

MyArray = Visualized_Array(ARRAY_SIZE,
                           5,
                           WIN_SIZE[1],
                           1900 / ARRAY_SIZE,
                           WIN_SIZE[1] - 20,
                           CompleteArray=True)
while MAIN_LOOP:
    KEY = KEY_PRESSED()
    if KEY == "QUIT":
        MAIN_LOOP = False
        pygame.quit()
        sys.exit()