from psychopy import visual
import random
import sequences.params as pm

def shuffle_dict(d):
    items = list(d.items())
    random.shuffle(items)
    return dict(items)

def get_win_dict():
    '''Create a window object and a background object'''
    win = visual.Window(
        size=pm.win_size,
        fullscr=True,
        units="norm",
        color=pm.bg_color,
        screen=pm.screen,
    )
    aspect_ratio = win.size[0] / win.size[1]
    background = visual.ImageStim(
        win,
        size=(2, 2 * aspect_ratio),
        image=pm.bg_fn,
        units="norm"
    )
    d = {"win": win, "background": background, "aspect_ratio": aspect_ratio}
    return d

def get_photo_rects(win, aspect_ratio):
    '''Create a white and a black rectangle for the experiment'''
    rect_w = visual.Rect(
        win=win,
        width=pm.rect_w_size,
        height=pm.rect_w_size * aspect_ratio,
        pos=(1, 1),
        units='norm',
        fillColor=(255, 255, 255),
    )
    rect_b = visual.Rect(
        win=win,
        width=pm.rect_b_size,
        height=pm.rect_b_size * aspect_ratio,
        pos=(1, 1),
        units='norm',
        fillColor='#000000',
    )
    return rect_w, rect_b