-----------------------------------------------------------
--            (c) 2020 Mustafa Erkam Badin               --
-----------------------------------------------------------
-- Source: https://github.com/arthurealike/turtle.lua    --
-----------------------------------------------------------
package.path = package.path .. ";../../turtle/?.lua"
local Turtle = require "turtle"

local rainbow = Turtle()
rainbow:setsprite("spider.png")

local c, x = 0, 0
local colors = {
    --reddish colors
    {1.00, 0.00, 0.00},{1.00, 0.03, 0.00},{1.00, 0.05, 0.00},{1.00, 0.07, 0.00},{1.00, 0.10, 0.00},{1.00, 0.12, 0.00},{1.00, 0.15, 0.00},{1.00, 0.17, 0.00},{1.00, 0.20, 0.00},{1.00, 0.23, 0.00},{1.00, 0.25, 0.00},{1.00, 0.28, 0.00},{1.00, 0.30, 0.00},{1.00, 0.33, 0.00},{1.00, 0.35, 0.00},{1.00, 0.38, 0.00},{1.00, 0.40, 0.00},{1.00, 0.42, 0.00},{1.00, 0.45, 0.00},{1.00, 0.47, 0.00},
    --orangey colors
    {1.00, 0.50, 0.00},{1.00, 0.53, 0.00},{1.00, 0.55, 0.00},{1.00, 0.57, 0.00},{1.00, 0.60, 0.00},{1.00, 0.62, 0.00},{1.00, 0.65, 0.00},{1.00, 0.68, 0.00},{1.00, 0.70, 0.00},{1.00, 0.72, 0.00},{1.00, 0.75, 0.00},{1.00, 0.78, 0.00},{1.00, 0.80, 0.00},{1.00, 0.82, 0.00},{1.00, 0.85, 0.00},{1.00, 0.88, 0.00},{1.00, 0.90, 0.00},{1.00, 0.93, 0.00},{1.00, 0.95, 0.00},{1.00, 0.97, 0.00},
    --yellowy colors
    {1.00, 1.00, 0.00},{0.95, 1.00, 0.00},{0.90, 1.00, 0.00},{0.85, 1.00, 0.00},{0.80, 1.00, 0.00},{0.75, 1.00, 0.00},{0.70, 1.00, 0.00},{0.65, 1.00, 0.00},{0.60, 1.00, 0.00},{0.55, 1.00, 0.00},{0.50, 1.00, 0.00},{0.45, 1.00, 0.00},{0.40, 1.00, 0.00},{0.35, 1.00, 0.00},{0.30, 1.00, 0.00},{0.25, 1.00, 0.00},{0.20, 1.00, 0.00},{0.15, 1.00, 0.00},{0.10, 1.00, 0.00},{0.05, 1.00, 0.00},
    --greenish colors
    {0.00, 1.00, 0.00},{0.00, 0.95, 0.05},{0.00, 0.90, 0.10},{0.00, 0.85, 0.15},{0.00, 0.80, 0.20},{0.00, 0.75, 0.25},{0.00, 0.70, 0.30},{0.00, 0.65, 0.35},{0.00, 0.60, 0.40},{0.00, 0.55, 0.45},{0.00, 0.50, 0.50},{0.00, 0.45, 0.55},{0.00, 0.40, 0.60},{0.00, 0.35, 0.65},{0.00, 0.30, 0.70},{0.00, 0.25, 0.75},{0.00, 0.20, 0.80},{0.00, 0.15, 0.85},{0.00, 0.10, 0.90},{0.00, 0.05, 0.95},
    --blueish colors
    {0.00, 0.00, 1.00},{0.05, 0.00, 1.00},{0.10, 0.00, 1.00},{0.15, 0.00, 1.00},{0.20, 0.00, 1.00},{0.25, 0.00, 1.00},{0.30, 0.00, 1.00},{0.35, 0.00, 1.00},{0.40, 0.00, 1.00},{0.45, 0.00, 1.00},{0.50, 0.00, 1.00},{0.55, 0.00, 1.00},{0.60, 0.00, 1.00},{0.65, 0.00, 1.00},{0.70, 0.00, 1.00},{0.75, 0.00, 1.00},{0.80, 0.00, 1.00},{0.85, 0.00, 1.00},{0.90, 0.00, 1.00},{0.95, 0.00, 1.00}
}

function love.load()
    love.window.setTitle("Colorful")
    love.graphics.setBackgroundColor(.15, .15, .15)
    rainbow:pd():speed(1000)
    print(rainbow:isvisible())
    while x < 1000 do
        local idx = math.floor(c)
        color = colors[idx]
        rainbow:color(color)
        rainbow:forward(x / 2.5)
        rainbow:right(98)
        x = x + 1
        c = c + 0.1
    end
end

function love.draw()
    rainbow:draw()
end

function love.keypressed(key)
    if key == "space" then
        rainbow:toggle()
    elseif key == "c" then
        rainbow:reset()
    end
end
