예제 #1
0
def get_image_grid(img, rows, cols, x0, y0, scale) -> List[List[Sprite]]:
    oimage = ni.get_array_from_file(img) 
    img_rows, img_cols, _ = oimage.shape
    
    imag_grid = []
    rows_step = img_rows // rows
    cols_step = img_cols // cols

    for i in range(rows):
        pointf_row = []
        imag_row = [] 
        for j in range(cols): 
            mini = i * rows_step
            maxi = (i+1) * rows_step
            minj = j * cols_step
            maxj = (j+1) * cols_step

            sub_img = oimage [mini:maxi, minj:maxj, :]
            p = w.create_sprite(Drable)
            p.set_ij(i , j)
            z = w.create_sprite(Pointf)
            z.set_ij(i , j)
            p.texture = ni.get_texture_from_array(sub_img)
            p.scale = scale
            p.x = x0 + j*(1+p.width)
            p.y = y0 + i*(1+p.height)
            z.x = p.x
            z.y = p.y         
            pointf_row.append(z)
            imag_row.append(p)

        imag_grid.append(imag_row)
        pointf.append(pointf_row)
    
    return imag_grid, pointf
예제 #2
0
 def on_update(self, dt):
     if window.get_key_down(KeyCode._1):
         self.texture = Image.get_texture_from_array(original_image)
     if window.get_key_down(KeyCode._2):
         self.texture = max_rgb_image.texture
     if window.get_key_down(KeyCode._3):
         self.texture = luminance_image.texture
     if window.get_key_down(KeyCode._4):
         self.texture = complement_image.texture
 def on_update(self, dt):
     if w.get_key_down(KeyCode.UP):
         self.texture = Image.get_texture_from_array(original_image)
     if w.get_key_down(KeyCode.DOWN):
         self.texture = max_rgb_image.texture
     if w.get_key_down(KeyCode.LEFT):
         self.texture = luminance_image.texture
     if w.get_key_down(KeyCode.RIGHT):
         self.texture = complement_image.texture
     if w.get_key_down(KeyCode.Z):
         self.texture = ohman_image.texture
예제 #4
0
 def split_sprite_sheet(self, file: str):
     self.array = np.get_array_from_file(file)
     m, n, _ = self.array.shape  # pixels
     di = m // self.rows
     dj = n // self.cols
     sub_arrays = [[self.array[i*di:(i+1)*di, j*di:(j+1)*dj, :]
                   for j in range(self.cols)] for i in range(self.rows)]
     for i in range(self.rows):
         for j in range(self.cols):
             cell = self.__cells[i][j]
             cell.texture = np.get_texture_from_array(sub_arrays[i][j])
             cell.scale_to_width(self.scale)
예제 #5
0
def create_sprite(splited, scale, x0, y0, w: Window, Csprite=Sprite):
    rows, cols = len(splited), len(splited[0])
    grid = []
    for i in range(rows):
        row = []
        for j in range(cols):
            p = w.create_sprite(Csprite)
            p.texture = ni.get_texture_from_array(splited[i][j])
            p.scale = scale
            p.x = x0 + j * (2 + p.width)
            p.y = y0 + i * (2 + p.height)
            r = row.append(p)
        grid.append(r)
예제 #6
0
def create(w: Window,
           sub_array: List[List[ndarray]],
           scale=1,
           sprite_cls=Sprite):
    s, n = len(sub_array), len(sub_array[0])
    grid: List[List[Sprite]] = []
    for i in range(s):
        row = []
        for j in range(n):
            s = w.create_sprite(sprite_cls)
            s.texture = np.get_texture_from_array(sub_array[i][j])
            s.scale = scale
            s.x = s.width / 2 + (j * s.width)
            s.y = s.height / 2 + (i * s.height)
            row.append(s)
        grid.append(row)
예제 #7
0
 def create_from_data_file(cls,
                           file,
                           x: float = None,
                           y: float = None,
                           scale: float = 10,
                           cell_gap: float = 1,
                           cell_cls: Callable[..., T] = Sprite):
     size, texture_arrays, array_index = pickle.load(open(file, 'rb'))
     grid = cls(size[0], size[1], x, y, scale, cell_gap, cell_cls)
     m, n = size
     for i in range(m):
         for j in range(n):
             cell = grid.__cells[i][j]
             width = cell.width
             array = texture_arrays[array_index[i][j]]
             t = np.get_texture_from_array(array)
             cell.texture = t
             cell.scale_to_width(width)
     return grid
예제 #8
0
from turtle import position, window_height, window_width
from pycat.base import NumpyImage
from pycat.core import Window

w = Window(width=600, height=400)

oimage = NumpyImage.get_array_from_file("hummmm.png")
print(oimage.shape)

image01 = NumpyImage.get_texture_from_array(oimage[:84, :150:])
image02 = NumpyImage.get_texture_from_array(oimage[:84, 150::])
image03 = NumpyImage.get_texture_from_array(oimage[84:, :150:])
image04 = NumpyImage.get_texture_from_array(oimage[84:, 150::])

x0y0 = w.create_sprite(x=225, y=158)
x1y0 = w.create_sprite(x=375, y=158)
x0y1 = w.create_sprite(x=225, y=242)
x1y1 = w.create_sprite(x=375, y=242)

x0y0.texture = image01
x1y0.texture = image02
x0y1.texture = image03
x1y1.texture = image04

w.run()
예제 #9
0
w = Window()
image01 = Image.get_array_from_file("4_0.jpg")
image02 = Image.get_array_from_file("10_0.jpg")
image03 = Image.get_array_from_file("11_0.jpg")
image04 = Image.get_array_from_file("16_0.jpg")
image06 = Image.get_array_from_file("22_0.jpg")

rows1, cols1, channels1 = image01.shape
rows2, cols2, channels2 = image02.shape
rows3, cols3, channels3 = image03.shape
rows4, cols4, channels4 = image04.shape
rows6, cols6, channels6 = image06.shape

isprite1 = w.create_sprite()
isprite1.scale = 1.6
isprite1.texture = Image.get_texture_from_array(image01)
isprite1.position = (430, 460)

isprite2 = w.create_sprite()
isprite2.scale = 1.6
isprite2.texture = Image.get_texture_from_array(image02)
isprite2.position = (860, 460)

isprite3 = w.create_sprite()
isprite3.scale = 1.6
isprite3.texture = Image.get_texture_from_array(image03)
isprite3.position = (360, 290)

isprite4 = w.create_sprite()
isprite4.scale = 1.6
isprite4.texture = Image.get_texture_from_array(image04)
예제 #10
0
from pycat.core import Window
from pycat.base import NumpyImage

w = Window()
original_image = NumpyImage.get_array_from_file("view.PNG")
print(original_image.shape)

sub = original_image[:386, :567, :]
sub2 = original_image[386:, 567:, :]
# sub3 = original_image[386:, :567, :]
# sub4 = original_image[:386, 567:, :]

s = w.create_sprite(x=250, y=200)
s.texture = NumpyImage.get_texture_from_array(sub)
s2 = w.create_sprite(x=900, y=400)
s2.texture = NumpyImage.get_texture_from_array(sub2)
w.run()
 def on_create(self):
     self.texture = Image.get_texture_from_array(original_image)
     self.scale = 2
     self.position = w.center
예제 #12
0
    def on_left_click(self):
        original_image = Image.get_array_from_file(random.choice(face))

        image = original_image[self.i0:self.i1, self.j0:self.j1, :]
        self.texture = Image.get_texture_from_array(image)
예제 #13
0
        self.i1 = i1
        self.j0 = j0
        self.j1 = j1

    def on_left_click(self):
        original_image = Image.get_array_from_file(random.choice(face))

        image = original_image[self.i0:self.i1, self.j0:self.j1, :]
        self.texture = Image.get_texture_from_array(image)


left_eye_image = original_image[50:70, 20:40, :]
left_eye = window.create_sprite(MyCustomSprite)
left_eye.set_range(50, 70, 20, 40)
left_eye.position = (500, 500)
left_eye.texture = Image.get_texture_from_array(left_eye_image)
left_eye.scale = 10
original_image = Image.get_array_from_file(random.choice(face))

right_eye_image = original_image[50:70, 60:80, :]
right_eye = window.create_sprite(MyCustomSprite)
right_eye.set_range(50, 70, 60, 80)
right_eye.position = (700, 500)
right_eye.texture = Image.get_texture_from_array(right_eye_image)
right_eye.scale = 10
original_image = Image.get_array_from_file(random.choice(face))

nose_image = original_image[27:50, 33:63, :]
nose = window.create_sprite(MyCustomSprite)
nose.set_range(27, 50, 33, 63)
nose.position = (600, 330)
def load_images(img_dir: str):
    face_images = []
    dir_path = os.path.dirname(os.path.realpath(__file__))
    img_dir_path = dir_path + "/" + img_dir
    for file in os.listdir(img_dir_path):
        filepath = img_dir_path + file
        if filepath.lower().endswith(('.png', '.jpg', '.jpeg')):
            face_images.append(Image.get_array_from_file(img_dir + "/" + file))
    return face_images


face_images = load_images("resized_faces")
original_image = random.choice(face_images)

image_sprite = window.create_sprite()
image_sprite.texture = Image.get_texture_from_array(original_image)
image_sprite.position = (400, 400)
original_image = random.choice(face_images)
left_eye_image = original_image[50:70, 25:40, :]
left_eye = window.create_sprite()
left_eye.position = (600, 500)
left_eye.texture = Image.get_texture_from_array(left_eye_image)
left_eye.scale = 3
original_image = random.choice(face_images)
right_eye_image = original_image[50:70, 55:70, :]
right_eye = window.create_sprite()
right_eye.position = (700, 500)
right_eye.texture = Image.get_texture_from_array(right_eye_image)
right_eye.scale = 3
original_image = random.choice(face_images)
nose_image = original_image[27:55, 30:65, :]
예제 #15
0
 def set_texture(self, array: ndarray):
     self.texture = IP.get_texture_from_array(array)