Skip to content

Instantly share code, notes, and snippets.

@mmurdoch
Created August 11, 2013 18:54
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 mmurdoch/6206314 to your computer and use it in GitHub Desktop.
Save mmurdoch/6206314 to your computer and use it in GitHub Desktop.
-- Copyright Matthew Murdoch
-- Remix under the terms of the MIT license (see http://opensource.org/licenses/MIT)
bounds = nil
circles = {}
function setup()
displayMode(FULLSCREEN)
physics.gravity(0, 0)
addBounds()
end
function addBounds()
bounds = physics.body(CHAIN,
vec2(50, 50),
vec2(WIDTH-50, 50),
vec2(WIDTH-50, HEIGHT-50),
vec2(50, HEIGHT-50),
vec2(50, 50))
bounds.type = STATIC
bounds.restitution = 1
end
function addCircle(x, y, vx, vy)
local radius = 20
local circle = physics.body(CIRCLE, radius)
circle.interpolate = true
circle.sleepingAllowed = false
circle.x = x
circle.y = y
circle.type = DYNAMIC
circle.restitution = 1
circle.linearVelocity = vec2(vx, vy)
circle.info = color(math.random(0, 255), math.random(0, 255), math.random(0, 255))
local p1 = { radius = math.random(20, 40) }
local p2 = { radius = math.random(40, 60) }
tween.path( 4.0, circle, {p1,p2,p1}, {loop=tween.loop.forever} )
table.insert(circles, circle)
end
function draw()
background(40, 40, 50)
strokeWidth(1)
local points = bounds.points
for j = 1, #points do
a = points[j]
b = points[(j % #points)+1]
line(a.x, a.y, b.x, b.y)
end
strokeWidth(0)
for _, circle in ipairs(circles) do
fill(circle.info)
ellipse(circle.x, circle.y, circle.radius*2)
end
end
function touched(touch)
if touch.state == BEGAN then
local vx = math.random(-200, 200)
local vy = math.random(-200, 200)
addCircle(touch.x, touch.y, vx, vy)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment