Text appears in different positions

Isn’t this literally what your code says – to position things differently based on x and y, and to base x and y on a fixed offset from the centers of the window / sketch? If you haven’t already resolved this issue, perhaps you could share a brief complete sketch (e.g. with editor.p5js.org) showing what is happening now, and explaining what you want to happen instead.

If you resize windows / canvases, text must always appear in “different positions”. The question is what you want to hold constant – fixed distance from the edge? percent? It looks like you are trying to do both, which may mean that you are doing neither.