# 3350 tweens example

Here’s an example of 3350 Tweens. With some changes, this might be useful for something. Just tap the screen to start. Takes about 30 seconds to run.

``````
supportedOrientations(PORTRAIT_ANY)
displayMode(FULLSCREEN)

function setup()
twTab={}
for x=1,50 do
for y=1,67 do
table.insert(twTab,twn(30,math.random(WIDTH),
math.random(HEIGHT),x*15,y*15))
end
end
end

function draw()
background(0)
for a,b in pairs(twTab) do
b:draw()
end
end

function touched(t)
if t.state==BEGAN then
for a,b in pairs(twTab) do
b:tw()
end
end
end

twn=class()

function twn:init(t,xs,ys,xe,ye)
self.col=color(math.random(255),math.random(255),math.random(255))
self.starts={x=xs,y=ys}
self.ends={x=xe,y=ye}
self.time=t
end

function twn:tw()
tween(self.time,self.starts,self.ends,tween.easing.elasticInInOut)
end

function twn:draw()
fill(self.col)
rect(self.starts.x,self.starts.y,15,15)
end

``````

Here’s a slight variation of the above code. Again, tap the screen to start it. It’s set to run in 30 seconds.

``````
supportedOrientations(PORTRAIT_ANY)
displayMode(FULLSCREEN)

function setup()
str="This is an example of running 3350 tweens. I don't know if there is any use for this, but with some changes there might be."
twTab={}
count=0
for y=67,1,-1 do
for x=1,50 do
count=count+1
if count>string.len(str) then
count=1
end
table.insert(twTab,twn(30,math.random(WIDTH),
math.random(HEIGHT),x*15,y*15,string.sub(str,count,count)))
end
end
end

function draw()
background(0)
for a,b in pairs(twTab) do
b:draw()
end
end

function touched(t)
if t.state==BEGAN then
for a,b in pairs(twTab) do
b:tw()
end
end
end

twn=class()

function twn:init(t,xs,ys,xe,ye,l)
self.col=color(255)
self.starts={x=xs,y=ys}
self.ends={x=xe,y=ye}
self.time=t
self.l=l
end

function twn:tw()
tween(self.time,self.starts,self.ends,tween.easing.elasticInInOut)
end

function twn:draw()
fill(self.col)
text(self.l,self.starts.x,self.starts.y)
end

``````

Interesting. My iPad3 can’t handle that many, about 1/25 of that number still reduced it to 30FPS.

Out of interest, I tried the same thing just using ordinary loops, and it ran at the same speed. (It didn’t have the easing function, but to be honest, I couldn’t detect that effect anyway).

@Ignatz The first program ran smooth on the iPad Air. The second program ran a bit slower.

Here’s a smaller version of the first program, only 750 sprites.

``````
supportedOrientations(PORTRAIT_ANY)
displayMode(FULLSCREEN)

function setup()
twTab={}
for x=1,25 do
for y=1,30 do
table.insert(twTab,twn(30,math.random(WIDTH),
math.random(HEIGHT),x*15,y*15))
end
end
end

function draw()
background(0)
for a,b in pairs(twTab) do
b:draw()
end
end

function touched(t)
if t.state==BEGAN then
for a,b in pairs(twTab) do
b:tw()
end
end
end

twn=class()

function twn:init(t,xs,ys,xe,ye)
self.col=color(math.random(255),math.random(255),math.random(255))
self.starts={x=xs,y=ys}
self.ends={x=xe,y=ye}
self.time=t
end

function twn:tw()
tween(self.time,self.starts,self.ends,tween.easing.elasticInInOut)
end

function twn:draw()
fill(self.col)
rect(self.starts.x,self.starts.y,15,15)
end

``````

A smaller version of the second program.

``````
supportedOrientations(PORTRAIT_ANY)
displayMode(FULLSCREEN)

function setup()
str="This is an example of running 750 tweens. I don't know if there is any use for this, but with some changes there might be."
twTab={}
count=0
for y=50,1,-1 do
for x=1,25 do
count=count+1
if count>string.len(str) then
count=1
end
table.insert(twTab,twn(30,math.random(WIDTH),
math.random(HEIGHT),x*15,y*15,string.sub(str,count,count)))
end
end
end

function draw()
background(0)
for a,b in pairs(twTab) do
b:draw()
end
end

function touched(t)
if t.state==BEGAN then
for a,b in pairs(twTab) do
b:tw()
end
end
end

twn=class()

function twn:init(t,xs,ys,xe,ye,l)
self.col=color(255)
self.starts={x=xs,y=ys}
self.ends={x=xe,y=ye}
self.time=t
self.l=l
end

function twn:tw()
tween(self.time,self.starts,self.ends,tween.easing.elasticInInOut)
end

function twn:draw()
fill(self.col)
text(self.l,self.starts.x,self.starts.y)
end

``````

Here’s another version. Tap the screen to run the code. Set to run for 15 seconds.

``````
supportedOrientations(PORTRAIT_ANY)
displayMode(FULLSCREEN)

function setup()
spriteMode(CORNER)
tab={}
w=img.width/24
h=img.height/32
for x=1,24 do
for y=1,32 do
table.insert(tab,img:copy((x-1)*32+1,(y-1)*32+1,32,32))
end
end
twTab={}
count=0
for x=1,24 do
for y=1,32 do
count=count+1
table.insert(twTab,
twn(15,math.random(WIDTH),math.random(HEIGHT),
(x-1)*32+1,(y-1)*32+1,count))
end
end
end

function draw()
background(0)
for a,b in pairs(twTab) do
b:draw()
end
end

function touched(t)
if t.state==BEGAN then
for a,b in pairs(twTab) do
b:tw()
end
end
end

twn=class()

function twn:init(t,xs,ys,xe,ye,nbr)
self.col=color(math.random(255),math.random(255),math.random(255))
self.starts={x=xs,y=ys}
self.ends={x=xe,y=ye}
self.time=t
self.nbr=nbr
end

function twn:tw()
tween(self.time,self.starts,self.ends,tween.easing.elasticInInOut)
end

function twn:draw()
fill(self.col)
sprite(tab[self.nbr],self.starts.x,self.starts.y)
end

``````

Woah!