Codea uses OpenGL ES 2 for drawing. Lines, rects and all other primitives are implemented as individual fragment shaders in the backend.

One exception is noSmooth() lines: these are implemented using the GL_LINE primitive. Which duplicates the line pixels along the line axis based on the strokeWidth() — you can’t have a 0 width line using GL_LINE.

For your example:

rectMode(CORNERS)
rect(x, y, x + 10, y + 10)

Coordinates for rectMode(CORNERS) are computed as follows:

x = x, y = y, w = (x+10), h = (y+10)
//t is a temporary
if x > w
t = x
x = w
w = t
if y > h
t = y
y = h
h = t
w = w - x
h = h - y

These coordinates are then sent to OpenGL as vertex coordinates for a GL_TRIANGLE_STRIP primitive. The vertex data would look something like:

GLfloat rectVerts[] =
{
x, y,
x+w, y,
x, y+h,
x+w, y+h,
};

You can assume it will be 10 pixels wide if:

you use the noSmooth() shader path.

you are using the identity transform

You should expect slightly less than 10 pixels wide if you use the smooth() shader path — this is due to the anti-aliasing in the shader.

So why does there appear to be a glitch when drawing a simple rectangle with lines. Try running this and watching the top-left corner as you change the “Glitch” parameter from 0 to 1.

function setup()
iparameter ("glitch", -2, 2)
glitch = 0
end
function draw()
background(255, 255, 255)
noSmooth()
resetMatrix()
strokeWidth(1)
stroke (0, 0, 0, 255)
local x1, x2 = 100, 306
local y1, y2 = 220, 413
line (x1, y1, x2, y1) -- bottom line
line (x1, y2, x2, y2) -- top line
line (x1, y1, x1, y2 + glitch) -- left line
line (x2, y1, x2, y2) -- right side
end