adasd

mail@pastecode.io avatar
unknown
plain_text
3 years ago
1.7 kB
1
Indexable
Never
white = (255, 255, 255)
black = (0, 0, 0)

def make_array(w, h):
    return [[white for x in range(w)]for y in range(h)]


def fill_sprite(sprite):
    w = len(sprite[0])
    h = len(sprite)
    for a in range(h):
        for b in range(w // 2 + 1):
            sprite[a][b] = random.choice([black, white])
    
    
def fill_sprite4(sprite):
    w = len(sprite[0])
    h = len(sprite)
    for a in range(h):
        for b in range(w // 2 + 1):
            sprite[a][b] = random.choice([black, white])    
    
def mirror_sprite(sprite):
    w = len(sprite[0])
    h = len(sprite)
    for a in range(h):
        for b in range(w // 2 + 1):
            sprite[-a-1][-b-1] = sprite[a][b]
    
def mirror_sprite4(sprite):
    w = len(sprite[0])
    h = len(sprite)
    for a in range(h // 2 + 1):
        for b in range(w // 2 + 1):
            sprite[-a-1][-b-1] = sprite[a][b]
            sprite[-b-1][-a-1] = sprite[a][b]
    
    
def make_sprite(w,h):
    sprite = make_array(w,h)
    fill_sprite(sprite)
    mirror_sprite(sprite)
    return sprite


def copy_sprite(sprite, screen, x0, y0):
    for y in range(len(sprite)):
        for x in range(len(sprite[0])):
            screen[y0 + y][x0 + x] = sprite[y][x]
            
SCREEN_W = 250
SCREEN_H = 125

SPRITE_W = 5
SPRITE_H = 5
            
screen = [[white for x in range(SCREEN_W)] for y in range(SCREEN_H)] 

for y0 in range(0, SCREEN_H - SPRITE_H, SPRITE_H*2):
    for x0 in range(0, SCREEN_W - SPRITE_W, SPRITE_W*2):
        sprite = make_sprite(SPRITE_W,SPRITE_H)
        copy_sprite(sprite, screen, x0, y0)


plt.figure(figsize=(30,20))
plt.imshow(sprite)