Must pixels be specified as integers?

I was wondering if pixels have to be programmed as an integer.

In the example for programming Shapes (psychopy.visual.ShapeStim — PsychoPy v2022.1.0) line width is specified in pixels and the specified value is 1.5

I was wondering how 1.5 pixels can be controlled or if psychopy will automatically round up or down to an integer.

Nope! PsychoPy is built on OpenGL and PsychoJS is built on WebGL, both of these allow non-integer pixel values. How this is handled depends on your specific computer setup I think, but you can test it fairly easily like this:

from psychopy import visual, event

win = visual.Window()

# Make one rectangle that's 1px wide, one that's 1.5px wide and one that's 2px wide
obj1 = visual.Rect(win, fillColor="white", units="pix", size=(1, 100), pos=(-100, 0))
obj2 = visual.Rect(win, fillColor="white", units="pix", size=(1.5, 100), pos=(0, 0))
obj3 = visual.Rect(win, fillColor="white", units="pix", size=(2, 100), pos=(100, 0))

# Draw all the rectangles
while not event.getKeys(['escape']):
1 Like