I am working on implimenting the ShaderToy.com API, if you aren’t familiar with ShaderToy.com, go there now, you are in for a treat.
So, the first thing you need to do is get an account there, and in your account you make an API key.
You do this in your profile page, I will gather more info if needed. There is info on the API if you hit the link at the very bottom of the page labeled “API”
Once you have your key, you can add it in the code I am working on, and I hope to polish this up and add full parsing along with my ShaderALL / GLSL library I have been working on and get a proper installer going on my git as soon as I can.
for now here is my class that will download a list of shaders, and parse the JSON of a shader:
main tab for testing:
function setup()
ShaderToy:init()
ShaderToy.key = '' -- INSERT YOUR API KEY
ShaderToy:getList()
ShaderToy:getShader('MdX3Rr')
end
ShaderToy tab for class:
ShaderToy = class()
function ShaderToy:init()
self.decoded = {}
self.list = {}
self.key = ''
end
function ShaderToy:getList(search, key)
http.request('https://www.shadertoy.com/api/v1/shaders?key='..self.key,
function(data, status, headers)
ShaderToy:gotList(data, status, headers)
end )
end
function ShaderToy:gotList(data, status, headers)
if data ~= nil then
print(data)
saveText("Documents:ShaderToyListFull",data)
local list = json.decode(data)
tablePrint(list)
end
end
function ShaderToy:getShader(sss, key)
http.request( "https://www.shadertoy.com/api/v1/shaders/"..sss.."?key="..self.key,
function(data, status, headers)
ShaderToy:decoder(data, status, headers)
end )
end
function ShaderToy:decoder(data, status, headers)
if data ~= nil then
local decoded = json.decode(data)
tablePrint(decoded)
elseif data == nil then
return false
end
end
function tablePrint(t)
if t ~= nil then
for k,v in pairs(t) do
if type(v) == 'table' then
tablePrint(v)
else
print(k..':'..v)
end
end
end
end