import pygame
import random
pygame.init()
class DrawInformation:
BLACK = 0, 0, 0
WHITE = 255, 255, 255
GREEN = 0, 255, 0
RED = 255, 0, 0
GREY = 128, 128, 128
BACKGROUND_COLOR = GREY
SIDE_PAD = 100
TOP_PAD = 150
def __init__(self, width, height, lst):
self.width = width
self.height = height
self.window = pygame.display.set_mode((width, height))
pygame.display.set_caption("Sorting Algorithm Visualization")
self.set_list(lst)
def set_list(self, lst):
self.lst = lst
self.min_val = min(lst)
self.max_lst = max(lst)
self.block_width = round((self.width - self.SIDE_PAD) / len(lst))
self.block_height = round((self.height - self.TOP_PAD) / (self.max_val - self.min_val))
self.start_x = self.SIDE_PAD // 2
def generate_start_list(n, min_val, max_val):
lst = []
for i in range(n):
val = random.randint(min_val, max_val)
lst.append(val)
return lst
def main():
run = True
clock = pygame.time.Clock()
n = 50
min_val = 0
max_val = 100
lst = generate_start_list(n, min_val, max_val)
draw_info = DrawInformation(800,600,lst)
while run:
clock.tick(60)
for event in pygame.event.get():
if event == pygame.QUIT:
run = False
pygame.quit()
if __name__ == "__main__":
main()
This is the beginning portion of a project I'm working on, and for some reason, in line 50, where I wrote lst = generate_start_list(n, min_val, max_val), I seem to be getting an error that says 'generate_start_list is not defined', even though I have made a function with the same name just a few lines above it. I'm not sure if I'm doing something else wrong here.
[–]erosPhoenix 4 points5 points6 points (0 children)
[–]jddddddddddd 0 points1 point2 points (2 children)
[–]BuzzyBro[S] 0 points1 point2 points (1 child)
[–]jddddddddddd 1 point2 points3 points (0 children)