first test for displaying images
This commit is contained in:
parent
ee9f92d4fd
commit
c0ba73e5f8
93
imagetest.py
Normal file
93
imagetest.py
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
import pygame, sys
|
||||||
|
from pygame.locals import *
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
pygame.init()
|
||||||
|
|
||||||
|
def get_image_width(filepath):
|
||||||
|
return ((Image.open(filepath).size)[0])
|
||||||
|
|
||||||
|
def get_image_height(filepath):
|
||||||
|
return ((Image.open(filepath).size)[1])
|
||||||
|
|
||||||
|
FPS = 30 #frames per second setting
|
||||||
|
fpsClock = pygame.time.Clock()
|
||||||
|
|
||||||
|
#screen size
|
||||||
|
screenx = 400
|
||||||
|
screeny = 300
|
||||||
|
|
||||||
|
#set up the window
|
||||||
|
screen = pygame.display.set_mode((screenx, screeny), 0, 32)
|
||||||
|
pygame.display.set_caption('animation')
|
||||||
|
|
||||||
|
#set up the colors
|
||||||
|
white = (255, 255, 255)
|
||||||
|
black = ( 0, 0, 0)
|
||||||
|
green = (0, 255, 0)
|
||||||
|
blue = (0, 0, 180)
|
||||||
|
red = (255, 0, 0)
|
||||||
|
|
||||||
|
img_itlablogo = 'img/itlablogo.png'
|
||||||
|
img_itlablogo_image = pygame.image.load(img_itlablogo)
|
||||||
|
img_itlablogo_imagex = get_image_width(img_itlablogo)
|
||||||
|
img_itlablogo_imagey = get_image_height(img_itlablogo)
|
||||||
|
direction = 'left'
|
||||||
|
|
||||||
|
# text setting
|
||||||
|
font_obj = pygame.font.Font('freesansbold.ttf', 32)
|
||||||
|
text_surface_obj = font_obj.render('Hello World!', True, green, blue)
|
||||||
|
text_rect_obj = text_surface_obj.get_rect()
|
||||||
|
text_rect_obj.center = (0, 150)
|
||||||
|
|
||||||
|
while True: # the main game loop
|
||||||
|
screen.fill(white)
|
||||||
|
|
||||||
|
# draw a green polygon onto the surface
|
||||||
|
#pygame.draw.polygon(screen, green, ((146, 0), (291, 106), (236, 277), (56, 277), (0, 106)))
|
||||||
|
|
||||||
|
# draw some blue lines onto the surface
|
||||||
|
#pygame.draw.line(screen, blue, (60, 60), (120, 60), 4)
|
||||||
|
#pygame.draw.line(screen, blue, (120, 60), (60, 120))
|
||||||
|
#pygame.draw.line(screen, blue, (60, 120), (120, 120), 4)
|
||||||
|
|
||||||
|
# draw a blue circle onto the surface
|
||||||
|
#pygame.draw.circle(screen, blue, (300, 50), 20, 0)
|
||||||
|
|
||||||
|
# draw a red ellipse onto the surface
|
||||||
|
#pygame.draw.ellipse(screen, red, (100, 150, 40,80), 1)
|
||||||
|
|
||||||
|
# draw a red rectangle onto the surface
|
||||||
|
#pygame.draw.rect(screen,red, (200, 150, 100, 50))
|
||||||
|
|
||||||
|
# draw the text onto the surface
|
||||||
|
#screen.blit(text_surface_obj, text_rect_obj)
|
||||||
|
|
||||||
|
|
||||||
|
#the animation of the image
|
||||||
|
# if direction == 'right':
|
||||||
|
# imagex += 5
|
||||||
|
# if imagex == 360:
|
||||||
|
# direction = 'down'
|
||||||
|
# elif direction == 'down':
|
||||||
|
# imagey += 5
|
||||||
|
# if imagey == 260:
|
||||||
|
# direction = 'left'
|
||||||
|
# elif direction == 'left':
|
||||||
|
# imagex -= 5
|
||||||
|
# if imagex == 20:
|
||||||
|
# direction = 'up'
|
||||||
|
# elif direction == 'up':
|
||||||
|
# imagey -= 5
|
||||||
|
# if imagey == 20:
|
||||||
|
# direction = 'right'
|
||||||
|
screen.blit(img_itlablogo_image, (screenx-img_itlablogo_imagex-20, screeny-img_itlablogo_imagey-20))
|
||||||
|
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == QUIT:
|
||||||
|
pygame.quit()
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
pygame.display.update()
|
||||||
|
fpsClock.tick(FPS)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user