#!/usr/bin/env python
# -*- coding: utf-8 -*-

import math

from pygame.locals import *
import pygame

# Resolution
WIDTH = 800
HEIGHT = 800
screen = pygame.display.set_mode((WIDTH, HEIGHT))

# Image
background_img = pygame.image.load('ground.jpg')


def draw_repeating_background(background_img):
    background_rect = background_img.get_rect()
    background_rect_width = background_rect.width
    background_rect_height = background_rect.height
    for i in range(math.ceil(WIDTH / background_rect.width)):
        for j in range(math.ceil(HEIGHT / background_rect.height)):
            screen.blit(background_img, Rect(i * background_rect_width,
                                             j * background_rect_height,
                                             background_rect_width,
                                             background_rect_height))

pygame.init()
running = True
while running:
    draw_repeating_background(background_img)
    pygame.display.update()
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            running = False
