Upload artest.py
Browse files
artest.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Import Libraries
|
| 2 |
+
|
| 3 |
+
import os, sys
|
| 4 |
+
|
| 5 |
+
import pygame
|
| 6 |
+
from pygame.locals import *
|
| 7 |
+
|
| 8 |
+
from urllib.request import urlopen
|
| 9 |
+
from urllib.request import Request
|
| 10 |
+
import urllib.error
|
| 11 |
+
|
| 12 |
+
def download_art():
|
| 13 |
+
|
| 14 |
+
file_link = "https://datasets-server.huggingface.co/assets/mswhite/artwork/--/mswhite--artwork/train/0/image/image.jpg"
|
| 15 |
+
file_name = "new_art.jpg"
|
| 16 |
+
|
| 17 |
+
try:
|
| 18 |
+
req = Request(file_link)
|
| 19 |
+
req.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 AOL/9.8 AOLBuild/4346.2019.US Safari/537.36')
|
| 20 |
+
remotefile = urlopen(req)
|
| 21 |
+
|
| 22 |
+
localfile = open(file_name, 'wb')
|
| 23 |
+
localfile.write(remotefile.read())
|
| 24 |
+
localfile.close()
|
| 25 |
+
remotefile.close()
|
| 26 |
+
|
| 27 |
+
except urllib.error.HTTPError as e:
|
| 28 |
+
print('ERROR: ',e.code,' REASON: ',e.reason, " => ",file_link) # Url = e.url
|
| 29 |
+
|
| 30 |
+
# Initialize Game Engine / screen
|
| 31 |
+
|
| 32 |
+
pygame.init()
|
| 33 |
+
screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
|
| 34 |
+
|
| 35 |
+
art_image = "new_art.jpg"
|
| 36 |
+
download_art()
|
| 37 |
+
|
| 38 |
+
image = pygame.image.load(art_image)
|
| 39 |
+
|
| 40 |
+
infoObject = pygame.display.Info()
|
| 41 |
+
pygame.display.set_mode((infoObject.current_w, infoObject.current_h))
|
| 42 |
+
window_width = infoObject.current_w
|
| 43 |
+
window_height = infoObject.current_h
|
| 44 |
+
image_width = image.get_width()
|
| 45 |
+
image_height = image.get_height()
|
| 46 |
+
|
| 47 |
+
scale_factor = min(window_width / image_width, window_height / image_height)
|
| 48 |
+
DEFAULT_IMAGE_SIZE = (image_width * scale_factor, image_height * scale_factor)
|
| 49 |
+
background_img = pygame.transform.scale(image, DEFAULT_IMAGE_SIZE)
|
| 50 |
+
offset = int((window_width * 0.5) - 0.5 * (image_width * scale_factor))
|
| 51 |
+
|
| 52 |
+
# --------------------------
|
| 53 |
+
# Main Loop
|
| 54 |
+
|
| 55 |
+
while True:
|
| 56 |
+
|
| 57 |
+
# Handle Events
|
| 58 |
+
|
| 59 |
+
for event in pygame.event.get():
|
| 60 |
+
|
| 61 |
+
if event.type == KEYDOWN and (event.key in [K_ESCAPE, K_q]):
|
| 62 |
+
sys.exit(0)
|
| 63 |
+
|
| 64 |
+
elif event.type == KEYDOWN and event.key in [K_UP,K_DOWN,K_RIGHT,K_b,K_d]:
|
| 65 |
+
pass
|
| 66 |
+
|
| 67 |
+
# Mouse is held down
|
| 68 |
+
|
| 69 |
+
if pygame.mouse.get_pressed()[0]:
|
| 70 |
+
pass
|
| 71 |
+
|
| 72 |
+
# Refresh Screen
|
| 73 |
+
|
| 74 |
+
screen.fill(pygame.color.THECOLORS["black"])
|
| 75 |
+
screen.blit(background_img, (offset,0))
|
| 76 |
+
|
| 77 |
+
pygame.display.flip()
|
| 78 |
+
|
| 79 |
+
# sys.exit(0)
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
|