Exemplo n.º 1
0
 )
 paser.add_argument(
     '--filename',
     type=str,
     default='1.jpg',
     help=
     'The file(*.jpg, *.png, *.bmp) name of the file you want to convert.')
 paser.add_argument(
     "-c",
     "--color",
     help=
     "How many colors you want to draw.(If the number is too large that the program may be very slow.)",
     type=int,
     default=32)
 args = paser.parse_args()
 K = args.color
 try:
     bitmapFile = open(args.filename, mode='r')
 except FileNotFoundError:
     print(__file__ + ': error: The file is not exists.')
     quit()
 if os.path.splitext(
         args.filename)[1].lower() not in ['.jpg', '.bmp', '.png']:
     print(__file__ + ': error: The file is not a bitmap file.')
     quit()
 bitmap = cv2.imread(args.filename)
 if bitmap.shape[0] > GetSystemMetrics(1):
     bitmap = cv2.resize(bitmap, (int(
         bitmap.shape[1] * ((GetSystemMetrics(1) - 50) / bitmap.shape[0])),
                                  GetSystemMetrics(1) - 50))
 drawBitmap(bitmap)
Exemplo n.º 2
0
def get_screen_size():
    """获取缩放后的分辨率"""
    w = GetSystemMetrics(0)
    h = GetSystemMetrics(1)
    return w, h
Exemplo n.º 3
0
def refreshPreview():
    sg.popup_animated(image_source=None)
    sg.popup_animated(image_source='files/thumbnail.png', title="Preview",
                      location=(GetSystemMetrics(0) / 5, GetSystemMetrics(1) / 2))
Exemplo n.º 4
0
def get_screen_size():
    from win32.win32api import GetSystemMetrics
    """获取缩放后的分辨率"""
    w = GetSystemMetrics(0)
    h = GetSystemMetrics(1)
    return w, h
Exemplo n.º 5
0
    [sg.Text('Create Card')],
    [sg.Text('Select Difficulty', size=(15, 1)), sg.Combo(diff, size=(15, 1), readonly=True, default_value='Easy'), sg.Text("Font"), 
        sg.Combo(os.listdir("fonts/"), size=(15, 1), readonly=True, default_value=os.listdir("fonts/")[0])],
    [sg.Text('Language 1', size=(15, 1)), sg.InputText()],
    [sg.Text('Language 2', size=(15, 1)), sg.InputText()],
    [sg.Text('Choose Filename', size=(15, 1)), sg.InputText(default_text="Filename")],
    [sg.Text('Save Location',  size=(15,1)), sg.Input(default_text=pickle.load(open( "save.p", "rb" ))) ,sg.FolderBrowse()],
    [sg.Save(), sg.Button('Refresh'), sg.Quit()]

]

# Create the window
window = sg.Window("DarePonger", layout)
#creates the perview image for the first time
sg.popup_animated(image_source='files/thumbnail.png', title="Preview",
                  location=(GetSystemMetrics(0) / 5, GetSystemMetrics(1) / 2), keep_on_top=False)
while True:  # The Event Loop
    event, values = window.read()
    save = values[5]
    pickle.dump(save, open("save.p", "wb"))
    if event == 'Save':
        font = values[1]
        print(event, values)
        drawImage(values[2], values[3], values[0], 50, values[4], values[5])
        refreshPreview()
        
    if event == 'Refresh':
        font = values[1]
        print(event, values)
        drawImage(values[2], values[3], values[0], 50, values[4], values[5])
        refreshPreview()
def getDisplayDimensions():
    displayWidth = GetSystemMetrics(0)
    displayHeight = GetSystemMetrics(1)
    return (displayWidth, displayHeight)
Exemplo n.º 7
0
def getScreenSize():

    w = GetSystemMetrics(0)
    h = GetSystemMetrics(1)

    return w, h
Exemplo n.º 8
0
def main():
    # Center the Screen
    os.environ['SDL_VIDEO_CENTERED'] = '1'

    # Get screen resolution
    screen_resolution = [int(GetSystemMetrics(0)), int(GetSystemMetrics(1))]
    screen_offset = [0, 0]

    # Reset screen after 300 Images drawn
    screen_reset = 300

    # Read jpg images from the /image direcotry 
    image_list = []
    for image_file in glob.glob("image/*.jpg"):
        image_list.append(image_file)

    # Initialize PygGame
    pygame.init()
    screen = pygame.display.set_mode(screen_resolution, pygame.NOFRAME)
    pygame.display.set_caption("Screensaver Image")
    pygame.mouse.set_visible(False)

    # Initialize Clock
    clock = pygame.time.Clock()

    # Set first screen background
    screen.fill((0, 136, 255))

    running = True
    while running:
        # Limit FPS to 4
        clock.tick(4)

        # Check for reset fill screen
        screen_reset -= 1
        if screen_reset <= 0:
            # Draw a rect over all to make a blur effect
            blur_surface = pygame.Surface((screen_resolution[0], screen_resolution[1]))
            blur_color = ((random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)))
            for alpha in range(100):
                blur_surface.set_alpha(alpha)
                blur_surface.fill(blur_color)
                screen.blit(blur_surface, (0, 0))
                pygame.display.flip()
            screen_reset = 300

        # Select Random Image from List
        image_index = random.randrange(len(image_list))

        # Load Image per Pygame.Image.Load
        image_py_loaded = pygame.image.load(image_list[image_index])
        image_py_rect = image_py_loaded.get_rect()

        # Allow Pictures to be offset to top, left, right and bottom
        screen_offset[0] = random.randint(-100, screen_resolution[0] - image_py_rect[2] + 100)
        screen_offset[1] = random.randint(-100, screen_resolution[1] - image_py_rect[3] + 100)
        
        # Set Random x and y position of the image
        image_py_rect[0] = screen_offset[0]
        image_py_rect[1] = screen_offset[1]

        # Draw image to screen
        screen.blit(image_py_loaded, image_py_rect)

        # Display screen content
        pygame.display.flip()


        ### For closing the window # Don't change anything beyond this line ###
        for event in pygame.event.get():
            # Close game if a pygame.QUIT event is in queue
            if event.type == pygame.QUIT:
                running = False 

            # Close game if ESC is pressed
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    pygame.event.post(pygame.event.Event(pygame.QUIT)) 
Exemplo n.º 9
0
def main():
  height = GetSystemMetrics(1) - 200
  width = GetSystemMetrics(0) - 200

  print("""
EUCLIDEAN TSP SOLVER:

Author: Matt Houston
Last Edited: 18 NOVEMBER 2019
Filename: tsp.py
Input: .csv or .txt file, formatted in: City Name, Longitude, Latitude
Output: A hamiltonian cycle and complexity data

Enter a .csv or .txt file name ["example.csv or example.txt"]: 
""")
  fileList = ["6.csv", "11.csv", "14.csv", "26.csv", "29.csv", "48.csv", "52.csv", "76.csv", "100.csv", "105.csv", "107.csv", "120.csv", "152.txt", "195.csv", "200.txt", "225.txt", "280.txt", "299.txt", "318.txt", "439.txt"]
  # fileList = ["6.csv", "11.csv", "26.csv", "29.csv", "48.csv", "52.csv", "76.csv", "100.csv", "105.csv", "120.csv", "152.txt", "195.csv", "200.txt", "225.txt", "280.txt", "299.txt", "318.txt", "439.txt"]

  # inp = "./tests/" + input()
  # file = inp
  print("---------------------------------------------------------------------------------------------\n\n")
  # cityNames, coords, newCoords = reader(file, height, width)
  print("---------------------------------------------------------------------------------------------\n\n")
  print("""
1: Brute Force
2: Nearest Neighbor
3: Farthest Insertion
4: Two Opt Interchange
5: Three Opt Interchange (In Progress)
6: Lin-Kernighan


Enter an algorithm by its number:
""")
  algo = input()
  algoPicks = "1234567"

  print("\n")
  print("---------------------------------------------------------------------------------------------\n\n")

  if algo in algoPicks:
    if algo == "1":
      for f in fileList:
        file = "./tests/" + f
        cityNames, coords, newCoords = reader(file, height, width)
        bruteForce(coords, newCoords, cityNames, height, width) #path is the same as the path variable in the algorithm's file
    elif algo == "2":
      print("\n")
      print("---------------------------------------------------------------------------------------------\n\n")
      print("""
1: Run Graphics
2: Run Without Graphics

Enter whether or not to run with GUI
""")
      option = input()
      for f in fileList:
        file = "./tests/" + f
        print("--------------------------------------------------------------------------------------------\n")
        print("\n{}: \n\n".format(file))
        cityNames, coords, newCoords = reader(file, height, width)
        nearestNeighbor(coords, newCoords, cityNames, height, width, option)
    elif algo == "3":
      print("\n")
      print("---------------------------------------------------------------------------------------------\n\n")
      print("""
1: Run Graphics
2: Run Without Graphics

Enter whether or not to run with GUI
""")
      option = input()
      for f in fileList:
        file = "./tests/" + f
        print("--------------------------------------------------------------------------------------------\n")
        print("\n{}: \n\n".format(file))
        cityNames, coords, newCoords = reader(file, height, width)
        farthestInsertion(coords, newCoords, cityNames, height, width, option)
    elif algo == "4":
      print("\n")
      print("---------------------------------------------------------------------------------------------\n\n")
      print("""
1: Run Graphics
2: Run Without Graphics

Enter whether or not to run with GUI
""")
      option = input()
      for f in fileList:
        avgCost = 0.0
        avgTime = 0.0
        file = "./tests/" + f
        print("--------------------------------------------------------------------------------------------\n")
        print("\n{}: \n\n".format(file))
        for i in range(10):
          cityNames, coords, newCoords = reader(file, height, width)
          randPath, randCost, randTime = randomTour(coords, cityNames)          
          path, cost, runtime = twoOpt(coords, newCoords, cityNames, randPath, randCost, height, width, option)
          avgCost += cost
          avgTime += runtime
        avgCost = avgCost/10
        avgTime = avgTime/10
        print("Average cost and time over 10 trials: {}, {}".format(avgCost, avgTime))
    
    elif algo == "5":
      randPath, randCost = randomTour(coords, cityNames)
      threeOpt(coords, cityNames, randPath, randCost, height, width)
    elif algo == "6":
      print("""
1: Random Tour
2: Nearest Neighbor Tour
3: Farthest Insertion Tour

Enter the initial tour constructor by its number:
""")
      constructor = input()
      constPicks = "12"

      print("\n")
      print("---------------------------------------------------------------------------------------------\n\n")
      print("""
1: Run Graphics
2: Run Without Graphics

Enter whether or not to run with GUI
""")
      option = input()
      for f in fileList:
        file = "./tests/" + f
        print("--------------------------------------------------------------------------------------------\n")
        print("\n{}: \n\n".format(file))
        cityNames, coords, newCoords = reader(file, height, width)

        if constructor in constPicks:
          if constructor == "1":
            initPath, initCost, runtime = randomTour(coords, cityNames)
            linKernighan(coords, newCoords, cityNames, initPath, initCost, height, width, option)
          elif constructor == "2":
            initPath, initCost, runtime = nearestNeighbor(coords, newCoords, cityNames, height, width, option)
            linKernighan(coords, newCoords, cityNames, initPath, initCost, height, width, option)
          elif constructor == "3":
            initPath, initCost, runtime = farthestInsertion(coords, newCoords, cityNames, height, width, option)
            linKernighan(coords, newCoords, cityNames, initPath, initCost, height, width, option)
        else:
          print("Exiting. Must enter a constructor number given by the list above")
      
    elif algo == "7":
      for f in fileList:
        avgCost = 0.0
        avgTime = 0.0
        file = "./tests/" + f
        print("--------------------------------------------------------------------------------------------\n")
        print("\n{}: \n\n".format(file))
        for i in range(10):
          cityNames, coords, newCoords = reader(file, height, width)
          path, cost, runtime = randomTour(coords, cityNames)
          avgCost += cost
          avgTime += runtime
        avgCost = avgCost/10
        avgTime = avgTime/10
        print("Average cost and time over 10 trials: {}, {}".format(avgCost, avgTime))
        
        print("-----------------------------------------------------------------\n")
  else:
    print("Exiting. Must enter an algorithm number given by the list above")