1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
import os, sys, pygame
from pygame.locals import *
class drawingArea:
#screen size
ysize = 600
xsize = 800
#image to repeatedly draw
image = None
#background colo
background = (255,255,255)
#the pygame window to draw the image on
screen = None
#the offsets so the image is centered on the drawing area
yoffset = 0
xoffset = 0
def __init__(self, xsize = 800, ysize = 600, numx = 12, numy = 12, image = "XO.png", backgroundColor = (255,255,255)):
#initialize the pygame display
self.screen = pygame.display.set_mode((xsize,ysize))
self.image = pygame.image.load(image)
(self.xsize,self.ysize) = self.screen.get_size()
self.screen.fill(self.background)
#resize the image to "fit" the drawing area
def resize_image(self,numx,numy):
(xx,yy) = self.image.get_size()
mult = min(float(self.xsize)/(xx*numx),float(self.ysize)/(yy*ysize))
self.image = pygame.transform.scale(self.image,(int(xx*mult),int(yy*mult)))
yoffset = (self.ysize-numx*self.image.get_width())/2
xoffset = (self.xsize-numy*self.image.get_height())/2
def draw(self,x,y):
self.screen.fill(self.background)
for i in range(0,x):
for j in range(0,y):
self.screen.blit(self.image,(i*self.image.get_width()+self.xoffset,j*self.image.get_height()+self.yoffset))
pygame.display.flip()
def set_background(self,background):
self.background = background
def resize_screen(self,xsize, ysize):
self.screen = pygame.display.set_mode((xsize,ysize))
(self.xsize,self.ysize) = self.screen.get_size()
self.screen.fill(background)
if __name__ == '__main__':
pygame.init()
da = drawingArea()
da.draw(4,3)
raw_input()
|