Skip to content

Instantly share code, notes, and snippets.

@dermotbalson
Last active December 19, 2015 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dermotbalson/5989826 to your computer and use it in GitHub Desktop.
Save dermotbalson/5989826 to your computer and use it in GitHub Desktop.
pool1
--# Main
--Main
function setup()
V={P1,P2,P3,P4,P5,P6,P7,P8,P9,P10}
parameter.integer('Version',1,10,2,function() setVersion() end)
end
function setVersion()
ver=V[Version]
ver.setup()
end
function draw()
ver.draw()
end
function touched(touch)
ver.touched(touch)
end
--# P1
-- Pool1
P1={}
function P1.setup()
P1.CreateEdges()
P1.CreateBalls()
end
function P1.CreateEdges()
sides={}
sides[1]=physics.body(EDGE,vec2(0,0),vec2(WIDTH,0))
sides[2]=physics.body(EDGE,vec2(0,0),vec2(0,HEIGHT))
sides[3]=physics.body(EDGE,vec2(0,HEIGHT),vec2(WIDTH,HEIGHT))
sides[4]=physics.body(EDGE,vec2(WIDTH,0),vec2(WIDTH,HEIGHT))
for i=1,4 do
sides[i].restitution=.8
end
end
function P1.CreateBalls()
local d,f=40,14
physics.gravity(0,0)
pushStyle()
fontSize(f)
font('GillSans-Bold')
local ballCols={color(255,255,0),color(0,0,255),color(255,0,0),color(146, 21, 226, 255),
color(223, 99, 37, 255),color(0,255,0),color(95, 70, 49, 255),color(0)}
balls={}
for i=0,15 do
balls[i]={}
local p=physics.body(CIRCLE,d/2)
p.x,p.y=math.random(1,600),math.random(1,600)
p.linearVelocity=vec2(200,250)
p.linearDamping=0.2
p.angularDamping=.2
p.restitution=.8
balls[i].body=p
local img=image(d,d)
setContext(img)
stroke(130, 125, 125, 255)
strokeWidth(1)
if i==0 then
fill(255)
ellipse(d/2,d/2,d)
elseif i<=8 then
fill(ballCols[i])
ellipse(d/2,d/2,d)
else
fill(227, 227, 221, 255)
ellipse(d/2,d/2,d)
fill(ballCols[i-8])
local a=math.rad(30)
local x,y=d/2*math.cos(a)-1,d/2*math.sin(a)-1
rect(d/2-x,d/2-y,x*2,y*2)
end
if i>0 then
strokeWidth(0)
fill(255)
ellipse(d/2,d/2,d/2)
fill(0)
text(i,d/2,d/2)
end
setContext()
balls[i].img=img
end
popStyle()
end
function P1.draw()
background(111, 181, 143, 255)
for i,p in pairs(balls) do
pushMatrix()
translate(p.body.x,p.body.y)
rotate(-p.body.angle)
sprite(p.img,0,0)
popMatrix()
end
end
function P1.touched(touch)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment