Пример #1
0
def openFile(path):
    global grid
    
    file = open(path, 'r')
    f = file.readlines()
    if f[-1] == str(currentVersion):
       
       dimensions = f[0].split() #Dimesnions for the rows and cols
       columns = int(dimensions[0])
       rows = int(dimensions[1])
       
       if dimensions[2] == '0': #If the show grid attribute at the end of our dimensions line is 0 then don't show grid
          v = False
       else:
          v = True
       initalize(columns, rows, v) #Redraw the grid, tool bars, menu bars etc. 
       name = path.split("/")
       changeCaption(name[-1])
       
       line = 0
       for i in range(columns): # For every pixel, read the color and format it into a tuple
          for j in range(rows):
             line += 1
             nColor = []
             for char in f[line].strip().split(','):
                nColor.append(int(char))
                
             
             grid.getGrid()[i][j].show(win, tuple(nColor), 0) #Show the color on the grid
    else:
      window = Tk()
      window.withdraw()
      messagebox.showerror("Unsupported Version", "The file you have opened is created using a previous version of this program. Please open it in that version.")
Пример #2
0
def fill(spot, grid, color, c):
    if spot.color != c:
        pass
    else:
        spot.click(grid.screen, color)
        pygame.display.update()

        i = spot.col  #the var i is responsible for denoting the current col value in the grid
        j = spot.row  #the var j is responsible for denoting the current row value in the grid

        #Horizontal and vertical neighbors
        if i < cols - 1:  #Right
            fill(grid.getGrid()[i + 1][j], grid, color, c)
        if i > 0:  #Left
            fill(grid.getGrid()[i - 1][j], grid, color, c)
        if j < rows - 1:  #Up
            fill(grid.getGrid()[i][j + 1], grid, color, c)
        if j > 0:  #Down
            fill(grid.getGrid()[i][j - 1], grid, color, c)
Пример #3
0
def fill(spot, grid, color, c):  # 当前网格坐标,网格对象,填充色,点击位置的颜色
    if spot.color != c:  # 假设点击处是白色,这句话就是当前网格不是白色时pass,只对白色点染色
        pass
    else:
        spot.click(grid.screen, color)  # 当前网格点染成填充色
        pygame.display.update()

        i = spot.col  #the var i is responsible for denoting the current col value in the grid
        j = spot.row  #the var j is responsible for denoting the current row value in the grid

        #Horizontal and vertical neighbors
        if i < cols - 1:  #Right
            fill(grid.getGrid()[i + 1][j], grid, color, c)
        if i > 0:  #Left
            fill(grid.getGrid()[i - 1][j], grid, color, c)
        if j < rows - 1:  #Up
            fill(grid.getGrid()[i][j + 1], grid, color, c)
        if j > 0:  #Down
            fill(grid.getGrid()[i][j - 1], grid, color, c)
Пример #4
0
def initalize(cols, rows, showGrid=False):
    global pallet, grid, win, tools, lineThickness, saveMenu

    #if grid already exsists delete it then recreate it
    try:
        del grid
    except:
        pass

    pygame.display.set_icon(paintBrush)
    win = pygame.display.set_mode((int(wid), int(heigh) + 100))
    pygame.display.set_caption('Untitled')
    win.fill((255, 255, 255))

    #CREATION OF OBJECTS
    grid = pixelArt(win, int(wid), int(heigh), cols, rows, showGrid)
    grid.drawGrid()

    for x in range(len(grid.getGrid())):
        for y in range(len(grid.getGrid()[x])):
            if (x == 0 or x == len(grid.getGrid()) - 1 or y == 0
                    or y == len(grid.getGrid()[x]) - 1):
                grid.getGrid()[x][y].click(grid.screen, (0, 0, 0))

    pallet = colorPallet(win, 90, 90, 3, 3, True, 10, grid.height + 2)
    pallet.drawGrid()

    colorList = [(0, 0, 0), (255, 255, 255), (255, 0, 0), (0, 255, 0),
                 (0, 0, 255), (255, 255, 0), (255, 168, 0), (244, 66, 173),
                 (65, 244, 226)]
    pallet.setColor(colorList)

    tools = menu(win, 200, 40, 5, 1, True, grid.width - 210, grid.height + 50)
    tools.drawGrid()

    buttons = ['D', 'E', 'F', 'R', 'C']
    tools.setText(buttons)
    tools.drawGrid()

    l = tools.getGrid()
    l[0][0].show(grid.screen, (255, 0, 0), 1, True)

    lineThickness = menu(win, 180, 40, 4, 1, True, grid.width - 200,
                         grid.height + 10)
    lineThickness.drawGrid()

    buttons = ['1', '2', '3', '4']
    lineThickness.setText(buttons)

    saveMenu = menu(win, 140, 40, 2, 1, True, grid.width - 400,
                    grid.height + 25)
    saveMenu.drawGrid()

    buttons = ['Save', 'Open']
    saveMenu.setText(buttons)

    pygame.display.update()
Пример #5
0
while run:
    #Main loop for mouse collision
    ev = pygame.event.get()

    for event in ev:
        if event.type == pygame.QUIT:
            window = Tk()
            window.withdraw()
            #Ask the user if they want to save before closing
            if pygame.display.get_caption()[0].count('*') > 0:
                if messagebox.askyesno(
                        "Save Work?",
                        "Would you like to save before closing?"):
                    # If they have already saved the file simply save to that path otherwise they need to chose a location
                    if savedPath != "":
                        save(cols, rows, grid.showGrid, grid.getGrid(),
                             savedPath)
                    else:
                        path = showFileNav()
                        if path:
                            savedPath = path
                            save(cols, rows, grid.showGrid, grid.getGrid(),
                                 savedPath)
            run = False

        if pygame.mouse.get_pressed(
        )[0]:  #See if the user has clicked or dragged their mouse
            try:
                pos = pygame.mouse.get_pos()
                if pos[1] >= grid.height:  # If the mouse is below the main drawing grid
                    if pos[0] >= tools.startx and pos[
Пример #6
0
while run:
    #Main loop for mouse collision
    ev = pygame.event.get()

    for event in ev:
        if event.type == pygame.QUIT:
            window = Tk()
            window.withdraw()
            #Ask the user if they want to save before closing
            if pygame.display.get_caption()[0].count('*') > 0:
                if messagebox.askyesno(
                        "Save Work?",
                        "Would you like to save before closing?"):
                    # If they have already saved the file simply save to that path otherwise they need to chose a location
                    if savedPath != "":
                        save(cols, rows, grid.showGrid, grid.getGrid(),
                             savedPath)
                    else:
                        path = showFileNav()
                        if path:
                            savedPath = path
                            save(cols, rows, grid.showGrid, grid.getGrid(),
                                 savedPath)
            run = False

        if pygame.mouse.get_pressed(
        )[0]:  #See if the user has clicked or dragged their mouse
            try:
                pos = pygame.mouse.get_pos()
                if pos[1] >= grid.height:  # If the mouse is below the main drawing grid
                    if pos[0] >= tools.startx and pos[
Пример #7
0
run = True
while run:
    #Main loop for mouse collision
    ev = pygame.event.get()

    for event in ev:
        if event.type == pygame.QUIT:
            window = Tk()
            window.withdraw()
            #Ask the user if they want to save before closing
            if pygame.display.get_caption()[0].count('*') > 0: 
               if messagebox.askyesno("Save Work?", "Would you like to save before closing?"):
                  # If they have already saved the file simply save to that path otherwise they need to chose a location
                  if savedPath != "":
                     save(cols, rows, grid.showGrid, grid.getGrid(),savedPath)
                  else:
                     path = showFileNav()
                     if path:
                        savedPath = path
                        save(cols, rows, grid.showGrid, grid.getGrid(),savedPath)
            run = False
         
        if pygame.mouse.get_pressed()[0]: #See if the user has clicked or dragged their mouse
            try:
                pos = pygame.mouse.get_pos()
                if pos[1] >= grid.height: # If the mouse is below the main drawing grid
                    if pos[0] >= tools.startx and pos[0] <= tools.startx + tools.width and pos[1] >= tools.starty and pos[1] <+ tools.starty + tools.height: #If the mouse ic clicking on the tools grid
                        replace = False
                        doFill = False
                        tools.drawGrid() #Redraw the grid so that we dont see the red highlight