Created
January 24, 2014 19:53
-
-
Save tnlogy/8604903 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--# Main | |
-- Infinite Grid | |
function setup() | |
displayMode(FULLSCREEN) | |
g = Grid() | |
end | |
function draw() | |
background(40, 40, 50) | |
translate(WIDTH/2, HEIGHT/2) | |
g:draw() | |
end | |
function touched(touch) | |
g:touched(touch) | |
end | |
--# Grid | |
Grid = class() | |
function Grid:init() | |
self.pos = vec2(0,0) | |
self.gs = 256 | |
self.m = mesh() | |
self.m:addRect(0,0,self.gs,self.gs) | |
self.tiles = {} | |
end | |
function Grid:draw() | |
checkqueue() | |
local s = 3 | |
for y=-s,s do | |
for x=-s,s do | |
local k = x.."-"..y | |
local a = self.tiles[k] | |
if not a then | |
a = asset(x,y) | |
self.tiles[k] = a | |
end | |
self.m.texture = a | |
pushMatrix() | |
translate(self.pos.x+x*self.gs,self.pos.y+y*self.gs) | |
self.m:draw() | |
popMatrix() | |
end | |
end | |
end | |
function Grid:touched(touch) | |
self.pos = self.pos + vec2(touch.deltaX, touch.deltaY) | |
end | |
--# LoadImage | |
local q = {} | |
local size = 128 | |
local hs = size/2 | |
function asset(x,y) | |
local img = image(size,size) | |
tween.delay(math.random()*2, function () | |
table.insert(q,img) | |
end) | |
return img | |
end | |
function checkqueue() | |
for i,img in ipairs(q) do | |
resetMatrix() | |
setContext(img) | |
sprite(CAMERA, hs,hs) | |
setContext() | |
table.remove(q,i) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment