package.path=package.path..";C:\\Users\\micro\\AppData\\Roaming\\com.nesbox.tic\\TIC-80\\rift\\?.lua"	-- jtruk
package.path=package.path..";C:\\Users\\Ronan\\AppData\\Roaming\\com.nesbox.tic\\TIC-80\\rift\\?.lua"	-- Mantratronic

local vor={}
require("./tool/voronoi/voronoi")
vor=voronoilib:new(60,3,0,0,240,136)

function BOOT()
    
    local ostr=""
    -- PRINT OUT FOR DATA
    ostr="-- Generated by generate-voronoi.lua\n-- from voronoi.lua\n"
    ostr=ostr.."-- 60 polys 240x136\n\n"
    ostr=ostr.."return {\n"
    for i=1,#vor.polygons do
        local shard = {flags=0,divide_by=200,scale=1.0,origin={},vertices={},triangles={}}

        local p = vor.polygons[i]
        local cent = p.centroid
        local points = p.points
        local numPoints=1
        local numTriangles=0

        -- add points
        shard.origin = {cent.x-120,cent.y-68,0}
        shard.vertices = {0,0,0}
        for j=1,#points,2 do
            table.insert(shard.vertices,cent.x - points[j])
            table.insert(shard.vertices,cent.y - points[j+1])
            table.insert(shard.vertices,0)

            numPoints = numPoints+1
        end

        -- add triangles
        for j=2,numPoints-1 do
            table.insert(shard.triangles,1)
            table.insert(shard.triangles,j)
            table.insert(shard.triangles,j+1)

            numTriangles = numTriangles+1
        end
        table.insert(shard.triangles,1)
        table.insert(shard.triangles,numPoints)
        table.insert(shard.triangles,2)
        numTriangles = numTriangles+1
--[[
        trace(" =".. ..",")
--]]
        ostr=ostr.." {flags="..shard.flags..",\n"
        ostr=ostr.." divide_by="..shard.divide_by..",\n"
        ostr=ostr.." scale="..shard.scale..",\n"
        ostr=ostr.." origin={"..shard.origin[1]..","..shard.origin[2]..","..shard.origin[3].."},\n"
        ostr=ostr.." vertices={"
        for j=1,#shard.vertices do
            ostr=ostr..shard.vertices[j]..","
        end
        ostr=ostr.."},\n"
        ostr=ostr.." triangles={"
        for j=1,#shard.triangles do
            ostr=ostr..shard.triangles[j]..","
        end
        ostr=ostr.."}},\n"

    end
    ostr=ostr.."}\n"
    trace(ostr)
end
        



function TIC()
    exit()
end

-- <PALETTE>
-- 000:1a1c2c5d275db13e53ef7d57ffcd75a7f07038b76425717929366f3b5dc941a6f673eff7f4f4f494b0c2566c86333c57
-- </PALETTE>

