Created
April 9, 2013 14:36
-
-
Save dermotbalson/5346179 to your computer and use it in GitHub Desktop.
12. Mesh
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
function setup() | |
--set up normal sprite | |
img=readImage("Tyrian Remastered:Space Ice 3") | |
w,h=img.width,img.height | |
--set up mesh alternative | |
g=mesh() | |
g.texture="Tyrian Remastered:Flame 2" --name of the image we want to use | |
parameter.boolean("Mesh",false) | |
parameter.integer("NumberOfObjects",50,200,50) | |
end | |
function draw() | |
background(0) | |
output:clear() | |
print("This demo shows how to draw images using a mesh, rather than sprites, for speed.") | |
print("NB You won't see an obvious speed change when you switch between them, because this hasn't been set up as a speed test.") | |
if Mesh==false then --sprites | |
for i=1,NumberOfObjects do | |
--position and size randomly | |
sprite(img,math.random(0,WIDTH),math.random(0,HEIGHT-100),w*(math.random()*.4)) | |
end | |
else --Mesh | |
g:clear() | |
for i=1,NumberOfObjects do | |
local x=math.random()*.4 --pick a random size, as we did for sprites | |
--add a rectangle the same size as our sprite | |
local d=g:addRect(math.random(0,WIDTH),math.random(0,HEIGHT-100),w*x,h*x) | |
--the numbers 0,0,1,1 mean to use the whole image, explanation in a later demo | |
g:setRectTex(d,0,0,1,1) --apply the texture, ie image, but don't draw anything yet | |
end | |
g:draw() --draw the final result | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment