I had an idea of creating an old tanks game using destructable terrain, one using an image, the other a polygon of vertices. Here is the concept of using an image and getting pixels to recreate a physics ball, on of the more simpler body shapes.
-- destructable img
-- Use this function to perform your initial setup
function setup()
img = image(WIDTH,HEIGHT)
setContext(img)
background(40,40,50)
pushStyle()
fill(150,150,150,255)
rect(0,0,WIDTH,HEIGHT/2)
popStyle()
setContext()
ply = vec2(WIDTH/2,HEIGHT-350)
vel = vec2()
rad = 10
r,g,b,a = 40,40,50,255
holding = false
parameter.action("Restart",Clear)
end
function touched(t)
if t.state == BEGAN and vec2(t.x,t.y):dist(ply)>30 then
r,g,b,a = img:get(t.x,t.y)
elseif t.state == BEGAN and vec2(t.x,t.y):dist(ply)<30 then
holding = true
end
if holding == false then
setContext(img)
pushStyle()
stroke(r,g,b,a)
strokeWidth(50)
line(t.x,t.y,t.prevX,t.prevY)
fill(r,g,b,a)
strokeWidth(0)
ellipse(t.x,t.y,50)
popStyle()
setContext()
else
ply = vec2(t.x,t.y)
vel = vec2()
end
if t.state == ENDED then
if holding then holding = false end
end
end
function Drag(mlt)
if mlt > 1 then
vel = vel-vec2(vel.x,vel.y)/(50*mlt)
end
end
function Clear()
setContext(img)
background(40,40,50)
pushStyle()
fill(150,150,150,255)
rect(0,0,WIDTH,HEIGHT/2)
popStyle()
setContext()
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(40, 40, 50,255)
-- This sets the line thickness
strokeWidth(5)
-- Do your drawing here
sprite(img,WIDTH/2,HEIGHT/2,WIDTH,HEIGHT)
sprite("Documents:circle",ply.x,ply.y,20,20)
local nply = ply
local amnt = 200
local normal = vec2()
local n = 0
local impulse = 0
local d = false
for x=1,20 do
for y=1,20 do
local r,g,b,a = img:get(ply.x-10+x,ply.y-10+y)
if vec2(-10+x,-10+y):dist(vec2())<rad then
if color(r,g,b,255) == color(150,150,150,255) then
local ov = vel
--Drag(vec2(-10+x,-10+y):dist(vec2())*5)
vel = vel + (vec2()-vec2(-10+x,-10+y))/amnt
normal = normal + (vec2()-vec2(-10+x,-10+y))
impulse = 10-vec2(-10+x,-10+y):dist(vec2())
nply = nply + -((vec2(-10+x,-10+y))/450)*impulse
n = n + 1
d = true
end
end
end
end
normal = normal/n
if n>0 then
vel = vel -vec2(vel.x*n,vel.y*n)*0.0001
ply = nply
end
vel = vel + vec2(0,-0.1)
ply = ply + vec2(vel.x,vel.y)
end