#!/usr/bin/env julia

using Luxor, Colors

include("julia-logo.jl")

function spiral_logo()
    gsave()
    scale(.3, .3)
    r = 200
    setcolor("gray")
    for i in 0:pi/8:2pi
        gsave()
        translate(r * cos(i), r * sin(i))
        rotate(i)
        julialogo()
        grestore()
    end
    grestore()
end

function expandingspiral()
    gsave()
    scale(.3, .3)
    r = 200
    for i in pi:pi/12:6pi
        gsave()
        translate(i/3 * r * cos(i), i/3 * r * sin(i))
        scale(0.8, 0.8)
        rotate(i)
        julialogo()
        grestore()
    end
    grestore()
end

function dropshadow()
    steps=20
    # white-gray ramp
    gramp = linspace(colorant"white", colorant"gray60", steps)
    gsave()
    r = 200
    setopacity(0.1)
    for i in 1:steps
        sethue(gramp[i])
        translate(-0.6,-0.5)
        julialogo(false)
    end
    julialogo()
    grestore()
end

function colorgrid()
    #cols = colormap("RdBu", 5; mid=0.5, logscale=false)
    #cols = sequential_palette(rand(10:360), 5, b=0.1)
    cols = distinguishable_colors(25)
    gsave()
    c = 0
    for row in 100:100:500
        for column in 100:100:500
            gsave()
            setcolor(color(cols[c+=1]))
            translate(row, column)
            scale(0.3, 0.3)
            julialogo(false)
            grestore()
        end
    end
    grestore()
end

function draw_logo(fname)
    Drawing(1600,1600, fname)
    origin()
    background("white")

    translate(-500,-200)
    spiral_logo()

    translate(750,0)
    expandingspiral()

    translate(-1000,500)
    dropshadow()

    translate(700, -100)
    colorgrid()

    finish()
    println("finished test: output in $(fname)")
end

draw_logo("/tmp/julia-logo-draw-eps.eps")
