@UberGoober Here’s another try. This creates a textured mesh. Tap the screen in either a clockwise or counter clockwise direction, a triangulate requirement. Nothing will happen until the third tap. After that a texture will show on the mesh as you keep tapping the screen.
I might be able to create a version that doesn’t use triangulate, so you can tap just about anywhere.
viewer.mode=FULLSCREEN
function setup()
xmin,xmax,ymin,ymax=9999,0,999,0
tab={}
img=readImage(asset.builtin.Surfaces.Basic_Bricks_AO)
m=mesh()
m.texture=img
fill(255)
end
function draw()
background(0)
m.draw(m)
end
function touched(t)
if t.state==BEGAN then
calcCoords(t.x,t.y)
end
end
function calcCoords(tx,ty)
table.insert(tab,vec2(tx,ty))
if tx<xmin then xmin=tx end
if tx>xmax then xmax=tx end
if ty<ymin then ymin=ty end
if ty>ymax then ymax=ty 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