Created
April 9, 2013 14:34
-
-
Save dermotbalson/5346165 to your computer and use it in GitHub Desktop.
10. Images
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
-- Use this function to perform your initial setup | |
function setup() | |
print("Please wait while I load the images from the internet") | |
http.request("https://img1.minebook.me/gallery/48755_mordor.png", | |
function(i,a,b) mordor=i print("loaded") end) | |
http.request("http://www.portent.com/images/2012/04/nazgul-cyclery-logo-long.png", | |
function(i,a,b) nazgul=i print("loaded") end) | |
state="LOADING" | |
end | |
-- This function gets called once every frame | |
function draw() | |
background(40, 40, 50) | |
if state=="LOADING" then | |
if mordor==nil or nazgul==nil then return --wait for internet image before drawing | |
else | |
scroll={img=mordor,x=0,y=0} | |
setupImages() | |
state="RUNNING" | |
end | |
end | |
spriteMode(CORNER) | |
sprite(mordor,scroll.x,scroll.y) | |
end | |
--copy the nazgul image onto the Mordor image to save us drawing it every time | |
function setupImages() | |
--clip nazgul to get rid of the logo | |
local img=nazgul:copy(0,0,nazgul.width/3,nazgul.height) | |
--local t={} | |
for i=1,img.width do | |
for j=1,img.height do | |
local r,g,b,a=img:get(i,j) | |
if a>0 and r+g+b==0 then img:set(i,j,110,38,38,255) end | |
--local x=r*256*256+g*256+b | |
--if t[x]==nil then t[x]=1 print(r,g,b) end | |
end | |
end | |
setContext(mordor) --draw to the mordor image, not the screen | |
sprite(img,mordor.width-img.width,300,100) | |
setContext() --back to normal | |
end | |
function touched(touch) | |
if scroll then | |
scroll.x=scroll.x+touch.deltaX | |
if scroll.x>0 then scroll.x=0 | |
elseif scroll.x+scroll.img.width<WIDTH then scroll.x=WIDTH-scroll.img.width end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment