# This demo was written by Max Sargent and Peter Scarfe

# 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
red = [white, black, black]

# 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. We do this here as PsychoPy has substaintial bugs related to macos displays
# If we poll the screen size of mywin once created it will be incorrect on macos.
# This will result in our positioning in terms of pixels being incorrect.
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 black and will use pixel units.
mywin = visual.Window(fullscr = True, units = 'pix', color = [black, black, black], winType = 'pyglet', colorSpace = 'rgb1', screen = screenNum)

# Make our rectangle: we will draw in in the centre of the screen
myRect = visual.Rect(
    win = mywin,
    width = 200,
    height = 250,
    units = 'pix',
    color = red,
    colorSpace = 'rgb1',
    pos = [0, 0]
)

# Draw the rectangle
myRect.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()