Last active
August 29, 2015 14:06
-
-
Save pingbird/3b06381771b9aac970a9 to your computer and use it in GitHub Desktop.
love2d accelerometer visualization thingy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local socket=require("socket") | |
| local sv | |
| local cl | |
| function love.load() | |
| sv=socket.bind("*",13337) | |
| cl=sv:accept() | |
| love.window.setMode(500,500,{resizable=true}) | |
| end | |
| local txt="0,0,0" | |
| local c=0 | |
| local last={} | |
| local tme=0 | |
| function love.update(dt) | |
| tme=tme+dt | |
| txt=cl:receive() | |
| end | |
| function HSV(h, s, v) | |
| if s <= 0 then return v,v,v end | |
| h, s, v = h/256*6, s/255, v/255 | |
| local c = v*s | |
| local x = (1-math.abs((h%2)-1))*c | |
| local m,r,g,b = (v-c), 0,0,0 | |
| if h < 1 then r,g,b = c,x,0 | |
| elseif h < 2 then r,g,b = x,c,0 | |
| elseif h < 3 then r,g,b = 0,c,x | |
| elseif h < 4 then r,g,b = 0,x,c | |
| elseif h < 5 then r,g,b = x,0,c | |
| else r,g,b = c,0,x | |
| end return (r+m)*255,(g+m)*255,(b+m)*255 | |
| end | |
| local lmx=0 | |
| local lx,ly,lz=0,0,0 | |
| local fade=10 | |
| local smooth=3 | |
| function love.draw() | |
| local w,h=love.graphics.getDimensions() | |
| local x,y,z=txt:match("(.+),(.+),(.+)") | |
| x,y,z=tonumber(x),tonumber(y),tonumber(z) | |
| local r,g,b=0,0,0 | |
| table.insert(last,{x,y,z,r,g,b,255}) | |
| local smooth=(math.abs(x-lx)+math.abs(y-ly)+math.abs(z-lz))*20 | |
| for l1=1,smooth do | |
| local cst=(l1+1)/(smooth+2) | |
| local rcst=1-cst | |
| table.insert(last,{x*cst+lx*rcst,y*cst+ly*rcst,z*cst+lz*rcst,r,g,b,255-(fade*((l1+1)/(smooth+2)))}) | |
| end | |
| lx,ly,lz=x,y,z | |
| local mx=lmx*0.95 | |
| for k,v in pairs(last) do | |
| mx=math.max(mx,v[1],v[2],-v[1],-v[2]) | |
| end | |
| lmx=mx | |
| local rm={} | |
| for k,v in pairs(last) do | |
| local x,y,z,r,g,b,a=unpack(v) | |
| v[7]=v[7]-fade | |
| if v[7]<1 then | |
| rm[k]=true | |
| end | |
| local cx,cy=math.floor((x/mx)*(w/2))+(w/2),math.floor((y/mx)*(h/2))+(h/2) | |
| love.graphics.setLineWidth(3) | |
| if z<0 then | |
| love.graphics.setColor(0,0,0,a) | |
| love.graphics.circle("fill",cx,cy,math.abs(z*50)/mx,100) | |
| end | |
| love.graphics.setColor(r,g,b,a) | |
| love.graphics.circle(z>0 and "fill" or "line",cx,cy,math.abs(z*50)/mx,100) | |
| end | |
| for k,v in pairs(rm) do | |
| last[k]=nil | |
| end | |
| love.graphics.setColor(255,255,255,255) | |
| love.graphics.print("fps: "..love.timer.getFPS().." objects: "..#lasty,1,1) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment