Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Powder simulation

em2em2
edited August 12 in Code Sharing Posts: 23

Tapping on the screen will create random particles. To change the powder, tap on the buttons on the sides.
Material properties:
Water - flows around and through things randomly and spread out quickly
Grass - mostly stays in place but falls apart without dirt below it
Dirt - solid
Random - one powder, can be water, grass, dirt, powder, or acid
Acid - digs holes in solids and destroys water. Eventually disappears

--# Main

--Falling Sand Single Install
--Installer created by @Briarfox
--- This will pull the Falling Sand project into Codea for you
-- Instructions:
-- * Create a new project in Codea named Falling Sand If you chose another name please change the variable Below
--This is case sensitive
ProjectName = "Falling Sand"
-- * Paste this into the Main (not from the raw view, as iSafari will escape special characters)
-- * Make sure there is a single tab in the project
-- * Run and wait for success!
-- If all went well, you should have a Falling Sand project now


function setup()
    local jsonCode
    getJsonLib()
end

function getJsonLib()
    local tabs = listProjectTabs()
    if #tabs == 1 then
        print("Attempting to load json...")
        local handleSuccess = function(data)
            --saveProjectTab("json", data)
            jsonCode = data
            --sound(SOUND_POWERUP, 42179)
            print("json code loaded...")
            if jsonCode then
                print("Attempting to pull project...")
                l = loadstring(jsonCode)
                l()
               GetProject() 
            end
        end
        http.request("https://dl.dropboxusercontent.com/s/9e4nvqeu4hsux2q/Json.lua?token_hash=AAFyMB98j4bnt_1gawf9wSke52hsoC7hsIvARcTuZNeOEw&dl=1", handleSuccess)
        end
end

function GetProject()
    local projectCheck = listProjectTabs(ProjectName)
    if #projectCheck ~= 0 then
   local handleSuccess = function(data,i,j)
        local gist = json.decode(data)
        local projName = ProjectName
        if gist.files["1aTabOrder"] then
            print("***Tab Order Found***")
            local taborder = gist.files["1aTabOrder"].content
            local strStart =1
            local strEnd =0
            strStart = string.find(taborder,"#",strEnd)
            strEnd = string.find(taborder,"\n",strStart)
            while strStart do
                local tmp = string.sub(taborder,strStart+1,strEnd-1)
                local name = ProjectName..":"..tmp
                tmp = tmp..".lua"
                saveProjectTab(name,gist.files[tmp].content)
                strStart = string.find(taborder,"#",strEnd)
                strEnd = string.find(taborder,"\n",strStart)

            end    
        else
            for k,v in pairs(gist.files) do
                local name = ProjectName .. ":" .. string.gsub(k,".lua","")
                saveProjectTab(name, v.content)
            end
        end
        sound(SOUND_PICKUP, 11797)
        print("Success!")
    end
    local handleFailure = function(data)
        sound(SOUND_EXPLODE, 32351)
        print(data)

    end 
    http.request("https://api.github.com/gists/8564c41d3aefb0e54f6bfe44601141d7",handleSuccess, handleFailure)
    else
        output.clear()
            sound(SOUND_EXPLODE, 32351)
            print([[ERROR
Project name incorrect! 
Please make sure the variable ProjectName = "your project" matches the project name.
This is case sensitive!]])
        end
end

Suggestions on performance would be much appreciated. I want it to perform at least 40fps with grid size WIDTH,HEIGHT.

Comments

  • dave1707dave1707 Mod
    Posts: 5,996

    @em2 I get this error.

    Main:327: attempt to call a nil value (global 'hsl2rgb')
    stack traceback:
        Main:327: in function <Main:326>
    
  • em2em2
    Posts: 23

    Does it work now? The old link won't work anymore; use the installer.

  • Posts: 117

    It worked for me. That's a pretty neat simulator!
    Frame-rate tip: don't print stuff into the output every frame or the game will get increasingly laggy

Sign In or Register to comment.