# This demo was written by Peter Scarfe and Max Sargent

# Import the various libraries that we will be using
import pyglet
from psychopy import visual, event, core
import numpy as np

# Define our colours
black = 0
white = 1
grey = white /  2

# Get a list of the screens avaliable
display = pyglet.canvas.get_display()
screens = display.get_screens()

# Get the length of the list of screens
numScreens = len(screens)

# We want to present on the secondary monitor (assuming two monitors connected). Note screens are counted from 0.
screenNum = numScreens - 1;

# Get the size of the screen in pixels
myScreen = screens[screenNum]
widthPix = myScreen.width
heightPix = myScreen.height

# Create a full screen window on our secondary monitor. We use pyglet as our screen backend. Note the rbg1 colour profile.
# We color our screen grey and will use pixel units.
mywin = visual.Window(fullscr = True, units = 'pix', color = [black, black, black], winType = 'pyglet', colorSpace = 'rgb1', screen = screenNum)

# Dimensions of squares in pixels
squareBaseDim = 200
squareDims = np.array([0.7, 1, 1.3]) * squareBaseDim

# Square positions
squarePos = np.array([[-widthPix * 0.25, 0], 
                      [0, 0],
                      [widthPix * 0.25, 0]])

# Number of squares we will be drawing
numSquares = squarePos.shape[0]

# Square colors: red, green and blue
squareColors = np.array([[white, black, black],
                        [black, white, black],
                        [black, black, white]])

# We create an ElementArrayStim which combined all of the attributes for all of our squares
allSquares = visual.ElementArrayStim(
    win = mywin,
    units = 'pix',
    nElements = numSquares,
    elementTex = None,
    elementMask = None,
    xys = squarePos,
    sizes = squareDims,
    colors = squareColors,
    colorSpace = 'rgb1'
)

# Draw all the squares
allSquares.draw()

# Flip to the screen
mywin.flip()

# Wait for key press before continuing. When pressed close the screen and exit PsychoPy.
event.waitKeys()
mywin.close()
core.quit()