Based on a seminar I went to yesterday.
displayMode(FULLSCREEN)
function setup()
local n = {2,3}
local picture = "Documents:Snowman" -- REPLACE THIS LINE
meshes = {}
pics = {}
nmeshes = 0
local w = math.min(WIDTH,HEIGHT)
if w == WIDTH then
ox,oy = 0,(HEIGHT-WIDTH)/2
else
ox,oy = (WIDTH-HEIGHT)/2,0
end
local ver,tex,l,img,m
for _,v in ipairs(n) do
m = mesh()
table.insert(meshes,m)
local img = image(w,w)
table.insert(pics,img)
m.texture = img
nmeshes = nmeshes + 1
ver = {}
tex = {}
l = w/v
for i=1,v do
for j=1,v do
for _,u in ipairs({
{1,1,1,0},
{1,0,0,0},
{0,0,0,1},
{1,1,1,0},
{0,0,0,1},
{0,1,1,1}
}) do
table.insert(ver,vec2((i-u[1])*l,(j-u[2])*l))
table.insert(tex,vec2((i-u[3])/v,(j-u[4])/v))
end
end
end
m.vertices = ver
m.texCoords = tex
m:setColors(255,255,255,255)
end
cmesh = 0
m = mesh()
img = image(w,w)
m.texture = img
m:addRect(w/2,w/2,w,w)
m:setRectTex(1,0,0,1,1)
meshes[0] = m
setContext(img)
background(255, 255, 255, 255)
noSmooth()
sprite(picture,w/2,w/2)
setContext()
stime = ElapsedTime
end
function draw()
background(51, 51, 51, 255)
pushMatrix()
translate(ox,oy)
meshes[cmesh]:draw()
popMatrix()
if auto then
if ElapsedTime - stime > 1 then
nextmesh()
end
end
end
function touched(touch)
if touch.state == ENDED then
if touch.tapCount == 2 then
auto = not auto
else
nextmesh()
end
end
end
function nextmesh()
local n = cmesh
cmesh = cmesh%nmeshes + 1
setContext(pics[cmesh])
resetMatrix()
noSmooth()
background(255, 255, 255, 255)
meshes[n]:draw()
setContext()
stime = ElapsedTime
end
The image is chopped up into a grid of squares which are then rotated 90 degrees anticlockwise (I think!). This process repeats itself, but as it does so then it cycles through a list of different sized grids. The default is to alternate between a grid of size 2 and of size 3. You can manually advance the process by tapping the screen, or set it to auto by double tapping.
It works by setting the texture of each mesh to the result of rendering the previous one. But then the rectangles in each mesh are pre-rotated so when a mesh is drawn it does the necessary rotation.