Skip to content

Instantly share code, notes, and snippets.

@weswigham
Created March 4, 2014 05:07
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 weswigham/9340588 to your computer and use it in GitHub Desktop.
Save weswigham/9340588 to your computer and use it in GitHub Desktop.
Imma chargin mah lazor
local color = Color(255, 255, 255, 255)
Voxel.display.color = color
Voxel.display:zero()
local function toggleCore(center, size)
for x=center-size,center+size do
for y=center-size,center+size do
for z=center-size,center+size do
if math.sqrt((x-center)^2 + (y-center)^2 +(z-center)^2)<=size then
Voxel.display:toggleVoxel(x,y,z)
end
end
end
end
end
local function negativeCore(center, size)
for x=center-size,center+size do
for y=center-size,center+size do
for z=center-size,center+size do
if math.sqrt((x-center)^2 + (y-center)^2 +(z-center)^2)<=size then
Voxel.display:setVoxel(x,y,z,false)
end
end
end
end
end
local function randomInSphere(x,y,z,r)
local normal = Vector(math.random(), math.random(), math.random())
normal:Normalize()
return (normal*math.random(-1,1)*r)+Vector(x,y,z)
end
local frames = {}
local function capture()
Voxel.display:rebuild()
table.insert(frames, Voxel.display:snapshot())
end
local center = math.floor(Voxel.display.voxel_width/2)
toggleCore(math.floor(center/4), center*2)
negativeCore(center + math.floor(center/2), 9)
local cvec = Vector(center + math.floor(center/2),center + math.floor(center/2),center + math.floor(center/2))
local dest = Vector(cvec.x-9,cvec.y-9,cvec.z-9)
local particles = {}
for i=1,9 do
local vec = randomInSphere(cvec.x, cvec.y, cvec.z, 9)
local rounded = Vector(math.floor(vec.x),math.floor(vec.y),math.floor(vec.z))
table.insert(particles, rounded)
Voxel.display:setVoxel(rounded.x, rounded.y, rounded.z, true)
end
capture()
for i=1,50 do
if (i<42) then
local vec = randomInSphere(cvec.x, cvec.y, cvec.z, 9)
local rounded = Vector(math.floor(vec.x),math.floor(vec.y),math.floor(vec.z))
table.insert(particles, rounded)
Voxel.display:setVoxel(rounded.x, rounded.y, rounded.z, true)
end
for k,p in pairs(particles) do
Voxel.display:setVoxel(p.x, p.y, p.z, false)
if p:Distance(cvec) < 9 then
local new = (p-dest)
new:Normalize()
local t = p-(new*1.5)
p.x = math.floor(t.x)
p.y = math.floor(t.y)
p.z = math.floor(t.z)
Voxel.display:setVoxel(p.x, p.y, p.z, true)
end
end
capture()
end
for k,p in pairs(particles) do
Voxel.display:setVoxel(p.x, p.y, p.z, false)
end
capture()
capture() --A moment of silence...
capture()
capture()
capture()
local function ptLineDist(endp1, endp2, pt)
local cp = (pt-endp1):Cross(pt-endp2)
local ret = (cp):Length()/(endp2-endp1):Length()
return ret
end
local function laser(radius, state)
for x=dest.x-2,Voxel.display.voxel_width-1 do
for y=dest.y-2,Voxel.display.voxel_depth-1 do
for z=dest.z-2,Voxel.display.voxel_height-1 do
if ptLineDist(cvec, dest, Vector(x,y,z))<radius and Vector(x,y,z):Distance(cvec)<9 then
Voxel.display:setVoxel(x, y, z, state)
end
end
end
end
end
laser(3, true)
for i=0,10 do
capture()
end
laser(3, false)
for i=3,0,-1 do
laser(i, true)
capture()
capture()
capture()
capture()
capture()
laser(i, false)
end
Voxel.display:animate(frames)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment