Here’s a demo using a mesh with a polygon where you can change its size. You can use this to make fixed size polygons.
function setup()
w1,w2,h1,h2=50,50,50,50
fill(255)
x,y=WIDTH/1.5,HEIGHT/2
tab={}
img=readImage(asset.builtin.Cargo_Bot.Startup_Screen)
m=mesh()
m.texture=img
xmin,xmax,ymin,ymax=9999,0,9999,0
parameter.integer("w1",20,400,150,change)
parameter.integer("w2",20,400,350,change)
parameter.integer("h1",20,400,140,change)
parameter.integer("h2",20,400,280,change)
change(w1,w2,h1,h2)
end
function draw()
background(0)
m.draw(m)
end
function change()
if w1>w2 and h1>h2 then return end
tab,tab2={},{}
xmin,xmax,ymin,ymax=9999,0,999,0
table.insert(tab2,vec2(x+w1/2,y+h2/2))
table.insert(tab2,vec2(x-w1/2,y+h2/2))
table.insert(tab2,vec2(x-w2/2,y+h1/2))
table.insert(tab2,vec2(x-w2/2,y-h1/2))
table.insert(tab2,vec2(x-w1/2,y-h2/2))
table.insert(tab2,vec2(x+w1/2,y-h2/2))
table.insert(tab2,vec2(x+w2/2,y-h1/2))
table.insert(tab2,vec2(x+w2/2,y+h1/2))
for z=1,#tab2 do
calcCoords(tab2[z].x,tab2[z].y)
end
end
function calcCoords(cx,cy)
table.insert(tab,vec2(cx,cy))
if cx<xmin then xmin=cx end
if cx>xmax then xmax=cx end
if cy<ymin then ymin=cy end
if cy>ymax then ymax=cy end
if #tab<3 then return end
xwid,yhei=xmax-xmin,ymax-ymin
tab1=triangulate(tab)
texTab={}
for a,b in pairs(tab1) do
table.insert(texTab,vec2((b.x-xmin)/xwid,(b.y-ymin)/yhei))
end
m.texCoords=texTab
m.vertices=tab1
end