Initial structure

This commit is contained in:
Steven Polley 2018-07-23 20:05:33 -06:00
parent 743de1bc59
commit e07baca3a8
2 changed files with 557 additions and 0 deletions

346
color.go Normal file
View File

@ -0,0 +1,346 @@
package main
import (
"image/color"
)
type Color struct {
Step float64
Color color.Color
}
type ColorMap struct {
Keyword string
Colors []Color
}
var ColorPalettes = []ColorMap{
{"AfternoonBlue", []Color{
{0.0, color.RGBA{0x93, 0xd2, 0xca, 0xff}},
{0.2, color.RGBA{0x6c, 0x98, 0xb8, 0xff}},
{0.5, color.RGBA{0x38, 0x68, 0x85, 0xff}},
{0.8, color.RGBA{0x17, 0x4f, 0x72, 0xff}},
{1.0, color.RGBA{0x08, 0x2a, 0x4f, 0xff}},
}},
{"SummerBeach", []Color{
{0.0, color.RGBA{0xff, 0xf0, 0x94, 0xff}},
{0.3, color.RGBA{0xff, 0xb7, 0x2d, 0xff}},
{0.6, color.RGBA{0xff, 0x8d, 0x00, 0xff}},
{0.8, color.RGBA{0x2d, 0x69, 0xae, 0xff}},
{1.0, color.RGBA{0x1e, 0x2c, 0x60, 0xff}},
}},
{"Biochimist", []Color{
Color{Color: color.RGBA{0x51, 0x99, 0x25, 0xff}},
Color{Color: color.RGBA{0x50, 0xa6, 0x1c, 0xff}},
Color{Color: color.RGBA{0x4b, 0xb8, 0x0b, 0xff}},
Color{Color: color.RGBA{0x4d, 0xcd, 0x00, 0xff}},
Color{Color: color.RGBA{0x53, 0xdf, 0x00, 0xff}},
}},
{"Fiesta", []Color{
Color{Color: color.RGBA{0x03, 0x67, 0xa6, 0xff}},
Color{Color: color.RGBA{0x04, 0xad, 0xbf, 0xff}},
Color{Color: color.RGBA{0x93, 0xa6, 0x03, 0xff}},
Color{Color: color.RGBA{0xe5, 0xce, 0x1b, 0xff}},
Color{Color: color.RGBA{0xc8, 0x3f, 0x2a, 0xff}},
}},
{"Hippi", []Color{
Color{Color: color.RGBA{0x00, 0x04, 0x0f, 0xff}},
Color{Color: color.RGBA{0x03, 0x26, 0x28, 0xff}},
Color{Color: color.RGBA{0x07, 0x3e, 0x1e, 0xff}},
Color{Color: color.RGBA{0x18, 0x55, 0x08, 0xff}},
Color{Color: color.RGBA{0x5f, 0x6e, 0x0f, 0xff}},
Color{Color: color.RGBA{0x84, 0x50, 0x19, 0xff}},
Color{Color: color.RGBA{0x9b, 0x30, 0x22, 0xff}},
Color{Color: color.RGBA{0xb4, 0x92, 0x2f, 0xff}},
Color{Color: color.RGBA{0x94, 0xca, 0x3d, 0xff}},
Color{Color: color.RGBA{0x4f, 0xd5, 0x51, 0xff}},
Color{Color: color.RGBA{0x66, 0xff, 0xb3, 0xff}},
Color{Color: color.RGBA{0x82, 0xc9, 0xe5, 0xff}},
Color{Color: color.RGBA{0x9d, 0xa3, 0xeb, 0xff}},
Color{Color: color.RGBA{0xd7, 0xb5, 0xf3, 0xff}},
Color{Color: color.RGBA{0xfd, 0xd6, 0xf6, 0xff}},
Color{Color: color.RGBA{0xff, 0xf0, 0xf2, 0xff}},
}},
{"Vivid", []Color{
Color{Color: color.RGBA{0x02, 0x3b, 0x2b, 0xff}},
Color{Color: color.RGBA{0x36, 0x34, 0x48, 0xff}},
Color{Color: color.RGBA{0x04, 0x8b, 0x64, 0xff}},
Color{Color: color.RGBA{0x81, 0x6a, 0x6e, 0xff}},
Color{Color: color.RGBA{0x8d, 0x5e, 0x67, 0xff}},
Color{Color: color.RGBA{0x98, 0x52, 0x60, 0xff}},
Color{Color: color.RGBA{0xa4, 0x46, 0x59, 0xff}},
Color{Color: color.RGBA{0xd3, 0x17, 0x3d, 0xff}},
Color{Color: color.RGBA{0xe1, 0x08, 0x34, 0xff}},
Color{Color: color.RGBA{0xde, 0x17, 0x30, 0xff}},
Color{Color: color.RGBA{0xdc, 0x26, 0x2d, 0xff}},
Color{Color: color.RGBA{0xd9, 0x36, 0x2a, 0xff}},
Color{Color: color.RGBA{0xd7, 0x45, 0x27, 0xff}},
Color{Color: color.RGBA{0xd5, 0x55, 0x24, 0xff}},
Color{Color: color.RGBA{0xd2, 0x64, 0x21, 0xff}},
Color{Color: color.RGBA{0xd0, 0x74, 0x1e, 0xff}},
Color{Color: color.RGBA{0xce, 0x83, 0x1b, 0xff}},
Color{Color: color.RGBA{0xcb, 0x92, 0x18, 0xff}},
Color{Color: color.RGBA{0xc9, 0xa2, 0x15, 0xff}},
Color{Color: color.RGBA{0x11, 0x03, 0x12, 0xff}},
Color{Color: color.RGBA{0x33, 0x08, 0x35, 0xff}},
Color{Color: color.RGBA{0xf5, 0xca, 0xf7, 0xff}},
}},
{"Plan9", []Color{
Color{Color: color.RGBA{0x00, 0x00, 0x00, 0xff}},
Color{Color: color.RGBA{0x00, 0x00, 0x44, 0xff}},
Color{Color: color.RGBA{0x00, 0x00, 0x88, 0xff}},
Color{Color: color.RGBA{0x00, 0x00, 0xcc, 0xff}},
Color{Color: color.RGBA{0x00, 0x44, 0x00, 0xff}},
Color{Color: color.RGBA{0x00, 0x44, 0x44, 0xff}},
Color{Color: color.RGBA{0x00, 0x44, 0x88, 0xff}},
Color{Color: color.RGBA{0x00, 0x44, 0xcc, 0xff}},
Color{Color: color.RGBA{0x00, 0x88, 0x00, 0xff}},
Color{Color: color.RGBA{0x00, 0x88, 0x44, 0xff}},
Color{Color: color.RGBA{0x00, 0x88, 0x88, 0xff}},
Color{Color: color.RGBA{0x00, 0x88, 0xcc, 0xff}},
Color{Color: color.RGBA{0x00, 0xcc, 0x00, 0xff}},
Color{Color: color.RGBA{0x00, 0xcc, 0x44, 0xff}},
Color{Color: color.RGBA{0x00, 0xcc, 0x88, 0xff}},
Color{Color: color.RGBA{0x00, 0xcc, 0xcc, 0xff}},
Color{Color: color.RGBA{0x00, 0xdd, 0xdd, 0xff}},
Color{Color: color.RGBA{0x11, 0x11, 0x11, 0xff}},
Color{Color: color.RGBA{0x00, 0x00, 0x55, 0xff}},
Color{Color: color.RGBA{0x00, 0x00, 0x99, 0xff}},
Color{Color: color.RGBA{0x00, 0x00, 0xdd, 0xff}},
Color{Color: color.RGBA{0x00, 0x55, 0x00, 0xff}},
Color{Color: color.RGBA{0x00, 0x55, 0x55, 0xff}},
Color{Color: color.RGBA{0x00, 0x4c, 0x99, 0xff}},
Color{Color: color.RGBA{0x00, 0x49, 0xdd, 0xff}},
Color{Color: color.RGBA{0x00, 0x99, 0x00, 0xff}},
Color{Color: color.RGBA{0x00, 0x99, 0x4c, 0xff}},
Color{Color: color.RGBA{0x00, 0x99, 0x99, 0xff}},
Color{Color: color.RGBA{0x00, 0x93, 0xdd, 0xff}},
Color{Color: color.RGBA{0x00, 0xdd, 0x00, 0xff}},
Color{Color: color.RGBA{0x00, 0xdd, 0x49, 0xff}},
Color{Color: color.RGBA{0x00, 0xdd, 0x93, 0xff}},
Color{Color: color.RGBA{0x00, 0xee, 0x9e, 0xff}},
Color{Color: color.RGBA{0x00, 0xee, 0xee, 0xff}},
Color{Color: color.RGBA{0x22, 0x22, 0x22, 0xff}},
Color{Color: color.RGBA{0x00, 0x00, 0x66, 0xff}},
Color{Color: color.RGBA{0x00, 0x00, 0xaa, 0xff}},
Color{Color: color.RGBA{0x00, 0x00, 0xee, 0xff}},
Color{Color: color.RGBA{0x00, 0x66, 0x00, 0xff}},
Color{Color: color.RGBA{0x00, 0x66, 0x66, 0xff}},
Color{Color: color.RGBA{0x00, 0x55, 0xaa, 0xff}},
Color{Color: color.RGBA{0x00, 0x4f, 0xee, 0xff}},
Color{Color: color.RGBA{0x00, 0xaa, 0x00, 0xff}},
Color{Color: color.RGBA{0x00, 0xaa, 0x55, 0xff}},
Color{Color: color.RGBA{0x00, 0xaa, 0xaa, 0xff}},
Color{Color: color.RGBA{0x00, 0x9e, 0xee, 0xff}},
Color{Color: color.RGBA{0x00, 0xee, 0x00, 0xff}},
Color{Color: color.RGBA{0x00, 0xee, 0x4f, 0xff}},
Color{Color: color.RGBA{0x00, 0xff, 0x55, 0xff}},
Color{Color: color.RGBA{0x00, 0xff, 0xaa, 0xff}},
Color{Color: color.RGBA{0x00, 0xff, 0xff, 0xff}},
Color{Color: color.RGBA{0x33, 0x33, 0x33, 0xff}},
Color{Color: color.RGBA{0x00, 0x00, 0x77, 0xff}},
Color{Color: color.RGBA{0x00, 0x00, 0xbb, 0xff}},
Color{Color: color.RGBA{0x00, 0x00, 0xff, 0xff}},
Color{Color: color.RGBA{0x00, 0x77, 0x00, 0xff}},
Color{Color: color.RGBA{0x00, 0x77, 0x77, 0xff}},
Color{Color: color.RGBA{0x00, 0x5d, 0xbb, 0xff}},
Color{Color: color.RGBA{0x00, 0x55, 0xff, 0xff}},
Color{Color: color.RGBA{0x00, 0xbb, 0x00, 0xff}},
Color{Color: color.RGBA{0x00, 0xbb, 0x5d, 0xff}},
Color{Color: color.RGBA{0x00, 0xbb, 0xbb, 0xff}},
Color{Color: color.RGBA{0x00, 0xaa, 0xff, 0xff}},
Color{Color: color.RGBA{0x00, 0xff, 0x00, 0xff}},
Color{Color: color.RGBA{0x44, 0x00, 0x44, 0xff}},
Color{Color: color.RGBA{0x44, 0x00, 0x88, 0xff}},
Color{Color: color.RGBA{0x44, 0x00, 0xcc, 0xff}},
Color{Color: color.RGBA{0x44, 0x44, 0x00, 0xff}},
Color{Color: color.RGBA{0x44, 0x44, 0x44, 0xff}},
Color{Color: color.RGBA{0x44, 0x44, 0x88, 0xff}},
Color{Color: color.RGBA{0x44, 0x44, 0xcc, 0xff}},
Color{Color: color.RGBA{0x44, 0x88, 0x00, 0xff}},
Color{Color: color.RGBA{0x44, 0x88, 0x44, 0xff}},
Color{Color: color.RGBA{0x44, 0x88, 0x88, 0xff}},
Color{Color: color.RGBA{0x44, 0x88, 0xcc, 0xff}},
Color{Color: color.RGBA{0x44, 0xcc, 0x00, 0xff}},
Color{Color: color.RGBA{0x44, 0xcc, 0x44, 0xff}},
Color{Color: color.RGBA{0x44, 0xcc, 0x88, 0xff}},
Color{Color: color.RGBA{0x44, 0xcc, 0xcc, 0xff}},
Color{Color: color.RGBA{0x44, 0x00, 0x00, 0xff}},
Color{Color: color.RGBA{0x55, 0x00, 0x00, 0xff}},
Color{Color: color.RGBA{0x55, 0x00, 0x55, 0xff}},
Color{Color: color.RGBA{0x4c, 0x00, 0x99, 0xff}},
Color{Color: color.RGBA{0x49, 0x00, 0xdd, 0xff}},
Color{Color: color.RGBA{0x55, 0x55, 0x00, 0xff}},
Color{Color: color.RGBA{0x55, 0x55, 0x55, 0xff}},
Color{Color: color.RGBA{0x4c, 0x4c, 0x99, 0xff}},
Color{Color: color.RGBA{0x49, 0x49, 0xdd, 0xff}},
Color{Color: color.RGBA{0x4c, 0x99, 0x00, 0xff}},
Color{Color: color.RGBA{0x4c, 0x99, 0x4c, 0xff}},
Color{Color: color.RGBA{0x4c, 0x99, 0x99, 0xff}},
Color{Color: color.RGBA{0x49, 0x93, 0xdd, 0xff}},
Color{Color: color.RGBA{0x49, 0xdd, 0x00, 0xff}},
Color{Color: color.RGBA{0x49, 0xdd, 0x49, 0xff}},
Color{Color: color.RGBA{0x49, 0xdd, 0x93, 0xff}},
Color{Color: color.RGBA{0x49, 0xdd, 0xdd, 0xff}},
Color{Color: color.RGBA{0x4f, 0xee, 0xee, 0xff}},
Color{Color: color.RGBA{0x66, 0x00, 0x00, 0xff}},
Color{Color: color.RGBA{0x66, 0x00, 0x66, 0xff}},
Color{Color: color.RGBA{0x55, 0x00, 0xaa, 0xff}},
Color{Color: color.RGBA{0x4f, 0x00, 0xee, 0xff}},
Color{Color: color.RGBA{0x66, 0x66, 0x00, 0xff}},
Color{Color: color.RGBA{0x66, 0x66, 0x66, 0xff}},
Color{Color: color.RGBA{0x55, 0x55, 0xaa, 0xff}},
Color{Color: color.RGBA{0x4f, 0x4f, 0xee, 0xff}},
Color{Color: color.RGBA{0x55, 0xaa, 0x00, 0xff}},
Color{Color: color.RGBA{0x55, 0xaa, 0x55, 0xff}},
Color{Color: color.RGBA{0x55, 0xaa, 0xaa, 0xff}},
Color{Color: color.RGBA{0x4f, 0x9e, 0xee, 0xff}},
Color{Color: color.RGBA{0x4f, 0xee, 0x00, 0xff}},
Color{Color: color.RGBA{0x4f, 0xee, 0x4f, 0xff}},
Color{Color: color.RGBA{0x4f, 0xee, 0x9e, 0xff}},
Color{Color: color.RGBA{0x55, 0xff, 0xaa, 0xff}},
Color{Color: color.RGBA{0x55, 0xff, 0xff, 0xff}},
Color{Color: color.RGBA{0x77, 0x00, 0x00, 0xff}},
Color{Color: color.RGBA{0x77, 0x00, 0x77, 0xff}},
Color{Color: color.RGBA{0x5d, 0x00, 0xbb, 0xff}},
Color{Color: color.RGBA{0x55, 0x00, 0xff, 0xff}},
Color{Color: color.RGBA{0x77, 0x77, 0x00, 0xff}},
Color{Color: color.RGBA{0x77, 0x77, 0x77, 0xff}},
Color{Color: color.RGBA{0x5d, 0x5d, 0xbb, 0xff}},
Color{Color: color.RGBA{0x55, 0x55, 0xff, 0xff}},
Color{Color: color.RGBA{0x5d, 0xbb, 0x00, 0xff}},
Color{Color: color.RGBA{0x5d, 0xbb, 0x5d, 0xff}},
Color{Color: color.RGBA{0x5d, 0xbb, 0xbb, 0xff}},
Color{Color: color.RGBA{0x55, 0xaa, 0xff, 0xff}},
Color{Color: color.RGBA{0x55, 0xff, 0x00, 0xff}},
Color{Color: color.RGBA{0x55, 0xff, 0x55, 0xff}},
Color{Color: color.RGBA{0x88, 0x00, 0x88, 0xff}},
Color{Color: color.RGBA{0x88, 0x00, 0xcc, 0xff}},
Color{Color: color.RGBA{0x88, 0x44, 0x00, 0xff}},
Color{Color: color.RGBA{0x88, 0x44, 0x44, 0xff}},
Color{Color: color.RGBA{0x88, 0x44, 0x88, 0xff}},
Color{Color: color.RGBA{0x88, 0x44, 0xcc, 0xff}},
Color{Color: color.RGBA{0x88, 0x88, 0x00, 0xff}},
Color{Color: color.RGBA{0x88, 0x88, 0x44, 0xff}},
Color{Color: color.RGBA{0x88, 0x88, 0x88, 0xff}},
Color{Color: color.RGBA{0x88, 0x88, 0xcc, 0xff}},
Color{Color: color.RGBA{0x88, 0xcc, 0x00, 0xff}},
Color{Color: color.RGBA{0x88, 0xcc, 0x44, 0xff}},
Color{Color: color.RGBA{0x88, 0xcc, 0x88, 0xff}},
Color{Color: color.RGBA{0x88, 0xcc, 0xcc, 0xff}},
Color{Color: color.RGBA{0x88, 0x00, 0x00, 0xff}},
Color{Color: color.RGBA{0x88, 0x00, 0x44, 0xff}},
Color{Color: color.RGBA{0x99, 0x00, 0x4c, 0xff}},
Color{Color: color.RGBA{0x99, 0x00, 0x99, 0xff}},
Color{Color: color.RGBA{0x93, 0x00, 0xdd, 0xff}},
Color{Color: color.RGBA{0x99, 0x4c, 0x00, 0xff}},
Color{Color: color.RGBA{0x99, 0x4c, 0x4c, 0xff}},
Color{Color: color.RGBA{0x99, 0x4c, 0x99, 0xff}},
Color{Color: color.RGBA{0x93, 0x49, 0xdd, 0xff}},
Color{Color: color.RGBA{0x99, 0x99, 0x00, 0xff}},
Color{Color: color.RGBA{0x99, 0x99, 0x4c, 0xff}},
Color{Color: color.RGBA{0x99, 0x99, 0x99, 0xff}},
Color{Color: color.RGBA{0x93, 0x93, 0xdd, 0xff}},
Color{Color: color.RGBA{0x93, 0xdd, 0x00, 0xff}},
Color{Color: color.RGBA{0x93, 0xdd, 0x49, 0xff}},
Color{Color: color.RGBA{0x93, 0xdd, 0x93, 0xff}},
Color{Color: color.RGBA{0x93, 0xdd, 0xdd, 0xff}},
Color{Color: color.RGBA{0x99, 0x00, 0x00, 0xff}},
Color{Color: color.RGBA{0xaa, 0x00, 0x00, 0xff}},
Color{Color: color.RGBA{0xaa, 0x00, 0x55, 0xff}},
Color{Color: color.RGBA{0xaa, 0x00, 0xaa, 0xff}},
Color{Color: color.RGBA{0x9e, 0x00, 0xee, 0xff}},
Color{Color: color.RGBA{0xaa, 0x55, 0x00, 0xff}},
Color{Color: color.RGBA{0xaa, 0x55, 0x55, 0xff}},
Color{Color: color.RGBA{0xaa, 0x55, 0xaa, 0xff}},
Color{Color: color.RGBA{0x9e, 0x4f, 0xee, 0xff}},
Color{Color: color.RGBA{0xaa, 0xaa, 0x00, 0xff}},
Color{Color: color.RGBA{0xaa, 0xaa, 0x55, 0xff}},
Color{Color: color.RGBA{0xaa, 0xaa, 0xaa, 0xff}},
Color{Color: color.RGBA{0x9e, 0x9e, 0xee, 0xff}},
Color{Color: color.RGBA{0x9e, 0xee, 0x00, 0xff}},
Color{Color: color.RGBA{0x9e, 0xee, 0x4f, 0xff}},
Color{Color: color.RGBA{0x9e, 0xee, 0x9e, 0xff}},
Color{Color: color.RGBA{0x9e, 0xee, 0xee, 0xff}},
Color{Color: color.RGBA{0xaa, 0xff, 0xff, 0xff}},
Color{Color: color.RGBA{0xbb, 0x00, 0x00, 0xff}},
Color{Color: color.RGBA{0xbb, 0x00, 0x5d, 0xff}},
Color{Color: color.RGBA{0xbb, 0x00, 0xbb, 0xff}},
Color{Color: color.RGBA{0xaa, 0x00, 0xff, 0xff}},
Color{Color: color.RGBA{0xbb, 0x5d, 0x00, 0xff}},
Color{Color: color.RGBA{0xbb, 0x5d, 0x5d, 0xff}},
Color{Color: color.RGBA{0xbb, 0x5d, 0xbb, 0xff}},
Color{Color: color.RGBA{0xaa, 0x55, 0xff, 0xff}},
Color{Color: color.RGBA{0xbb, 0xbb, 0x00, 0xff}},
Color{Color: color.RGBA{0xbb, 0xbb, 0x5d, 0xff}},
Color{Color: color.RGBA{0xbb, 0xbb, 0xbb, 0xff}},
Color{Color: color.RGBA{0xaa, 0xaa, 0xff, 0xff}},
Color{Color: color.RGBA{0xaa, 0xff, 0x00, 0xff}},
Color{Color: color.RGBA{0xaa, 0xff, 0x55, 0xff}},
Color{Color: color.RGBA{0xaa, 0xff, 0xaa, 0xff}},
Color{Color: color.RGBA{0xcc, 0x00, 0xcc, 0xff}},
Color{Color: color.RGBA{0xcc, 0x44, 0x00, 0xff}},
Color{Color: color.RGBA{0xcc, 0x44, 0x44, 0xff}},
Color{Color: color.RGBA{0xcc, 0x44, 0x88, 0xff}},
Color{Color: color.RGBA{0xcc, 0x44, 0xcc, 0xff}},
Color{Color: color.RGBA{0xcc, 0x88, 0x00, 0xff}},
Color{Color: color.RGBA{0xcc, 0x88, 0x44, 0xff}},
Color{Color: color.RGBA{0xcc, 0x88, 0x88, 0xff}},
Color{Color: color.RGBA{0xcc, 0x88, 0xcc, 0xff}},
Color{Color: color.RGBA{0xcc, 0xcc, 0x00, 0xff}},
Color{Color: color.RGBA{0xcc, 0xcc, 0x44, 0xff}},
Color{Color: color.RGBA{0xcc, 0xcc, 0x88, 0xff}},
Color{Color: color.RGBA{0xcc, 0xcc, 0xcc, 0xff}},
Color{Color: color.RGBA{0xcc, 0x00, 0x00, 0xff}},
Color{Color: color.RGBA{0xcc, 0x00, 0x44, 0xff}},
Color{Color: color.RGBA{0xcc, 0x00, 0x88, 0xff}},
Color{Color: color.RGBA{0xdd, 0x00, 0x93, 0xff}},
Color{Color: color.RGBA{0xdd, 0x00, 0xdd, 0xff}},
Color{Color: color.RGBA{0xdd, 0x49, 0x00, 0xff}},
Color{Color: color.RGBA{0xdd, 0x49, 0x49, 0xff}},
Color{Color: color.RGBA{0xdd, 0x49, 0x93, 0xff}},
Color{Color: color.RGBA{0xdd, 0x49, 0xdd, 0xff}},
Color{Color: color.RGBA{0xdd, 0x93, 0x00, 0xff}},
Color{Color: color.RGBA{0xdd, 0x93, 0x49, 0xff}},
Color{Color: color.RGBA{0xdd, 0x93, 0x93, 0xff}},
Color{Color: color.RGBA{0xdd, 0x93, 0xdd, 0xff}},
Color{Color: color.RGBA{0xdd, 0xdd, 0x00, 0xff}},
Color{Color: color.RGBA{0xdd, 0xdd, 0x49, 0xff}},
Color{Color: color.RGBA{0xdd, 0xdd, 0x93, 0xff}},
Color{Color: color.RGBA{0xdd, 0xdd, 0xdd, 0xff}},
Color{Color: color.RGBA{0xdd, 0x00, 0x00, 0xff}},
Color{Color: color.RGBA{0xdd, 0x00, 0x49, 0xff}},
Color{Color: color.RGBA{0xee, 0x00, 0x4f, 0xff}},
Color{Color: color.RGBA{0xee, 0x00, 0x9e, 0xff}},
Color{Color: color.RGBA{0xee, 0x00, 0xee, 0xff}},
Color{Color: color.RGBA{0xee, 0x4f, 0x00, 0xff}},
Color{Color: color.RGBA{0xee, 0x4f, 0x4f, 0xff}},
Color{Color: color.RGBA{0xee, 0x4f, 0x9e, 0xff}},
Color{Color: color.RGBA{0xee, 0x4f, 0xee, 0xff}},
Color{Color: color.RGBA{0xee, 0x9e, 0x00, 0xff}},
Color{Color: color.RGBA{0xee, 0x9e, 0x4f, 0xff}},
Color{Color: color.RGBA{0xee, 0x9e, 0x9e, 0xff}},
Color{Color: color.RGBA{0xee, 0x9e, 0xee, 0xff}},
Color{Color: color.RGBA{0xee, 0xee, 0x00, 0xff}},
Color{Color: color.RGBA{0xee, 0xee, 0x4f, 0xff}},
Color{Color: color.RGBA{0xee, 0xee, 0x9e, 0xff}},
Color{Color: color.RGBA{0xee, 0xee, 0xee, 0xff}},
Color{Color: color.RGBA{0xee, 0x00, 0x00, 0xff}},
Color{Color: color.RGBA{0xff, 0x00, 0x00, 0xff}},
Color{Color: color.RGBA{0xff, 0x00, 0x55, 0xff}},
Color{Color: color.RGBA{0xff, 0x00, 0xaa, 0xff}},
Color{Color: color.RGBA{0xff, 0x00, 0xff, 0xff}},
Color{Color: color.RGBA{0xff, 0x55, 0x00, 0xff}},
Color{Color: color.RGBA{0xff, 0x55, 0x55, 0xff}},
Color{Color: color.RGBA{0xff, 0x55, 0xaa, 0xff}},
Color{Color: color.RGBA{0xff, 0x55, 0xff, 0xff}},
Color{Color: color.RGBA{0xff, 0xaa, 0x00, 0xff}},
Color{Color: color.RGBA{0xff, 0xaa, 0x55, 0xff}},
Color{Color: color.RGBA{0xff, 0xaa, 0xaa, 0xff}},
Color{Color: color.RGBA{0xff, 0xaa, 0xff, 0xff}},
Color{Color: color.RGBA{0xff, 0xff, 0x00, 0xff}},
Color{Color: color.RGBA{0xff, 0xff, 0x55, 0xff}},
Color{Color: color.RGBA{0xff, 0xff, 0xaa, 0xff}},
Color{Color: color.RGBA{0xff, 0xff, 0xff, 0xff}},
}},
}

211
main.go Normal file
View File

@ -0,0 +1,211 @@
package main
import (
"flag"
"fmt"
"image"
"image/color"
"image/png"
"math"
"os"
"sync"
"time"
)
var (
colorPalette string
colorStep float64
xpos, ypos float64
width, height int
imageSmoothness int
maxIteration int
escapeRadius float64
outputFile string
)
var waitGroup sync.WaitGroup
func init() {
flag.Float64Var(&colorStep, "step", 12000, "Color smooth step. Value should be greater than iteration count, otherwise the value will be adjusted to the iteration count.")
flag.IntVar(&width, "width", 480, "Rendered image width")
flag.IntVar(&height, "height", 270, "Rendered image height")
flag.Float64Var(&xpos, "xpos", -0.00275, "Point position on the real axis (defined on `x` axis)")
flag.Float64Var(&ypos, "ypos", 0.78912, "Point position on the imaginary axis (defined on `y` axis)")
flag.Float64Var(&escapeRadius, "radius", .125689, "Escape Radius")
flag.IntVar(&maxIteration, "iteration", 2400, "Iteration count")
flag.IntVar(&imageSmoothness, "smoothness", 8, "The rendered mandelbrot set smoothness. For a more detailded and clear image use higher numbers. For 4xAA (AA = antialiasing) use -smoothness 4")
flag.StringVar(&colorPalette, "palette", "Plan9", "Hippi | Plan9 | AfternoonBlue | SummerBeach | Biochimist | Fiesta")
flag.StringVar(&outputFile, "file", "mandelbrot.png", "The rendered mandelbrot image filname")
flag.Parse()
}
func main() {
done := make(chan struct{})
ticker := time.NewTicker(time.Millisecond * 100)
go func() {
for {
select {
case <-ticker.C:
fmt.Print(".")
case <-done:
ticker.Stop()
fmt.Printf("\n\nMandelbrot set rendered into `%s`\n", outputFile)
}
}
}()
if colorStep < float64(maxIteration) {
colorStep = float64(maxIteration)
}
colors := interpolateColors(&colorPalette, colorStep)
if len(colors) > 0 {
fmt.Print("Rendering image...")
render(maxIteration, colors, done)
}
time.Sleep(time.Second)
}
func interpolateColors(paletteCode *string, numberOfColors float64) []color.RGBA {
var factor float64
steps := []float64{}
cols := []uint32{}
interpolated := []uint32{}
interpolatedColors := []color.RGBA{}
for _, v := range ColorPalettes {
factor = 1.0 / numberOfColors
switch v.Keyword {
case *paletteCode:
if paletteCode != nil {
for index, col := range v.Colors {
if col.Step == 0.0 && index != 0 {
stepRatio := float64(index+1) / float64(len(v.Colors))
step := float64(int(stepRatio*100)) / 100 // truncate to 2 decimal precision
steps = append(steps, step)
} else {
steps = append(steps, col.Step)
}
r, g, b, a := col.Color.RGBA()
r /= 0xff
g /= 0xff
b /= 0xff
a /= 0xff
uintColor := uint32(r)<<24 | uint32(g)<<16 | uint32(b)<<8 | uint32(a)
cols = append(cols, uintColor)
}
var min, max, minColor, maxColor float64
if len(v.Colors) == len(steps) && len(v.Colors) == len(cols) {
for i := 0.0; i <= 1; i += factor {
for j := 0; j < len(v.Colors)-1; j++ {
if i >= steps[j] && i < steps[j+1] {
min = steps[j]
max = steps[j+1]
minColor = float64(cols[j])
maxColor = float64(cols[j+1])
uintColor := cosineInterpolation(maxColor, minColor, (i-min)/(max-min))
interpolated = append(interpolated, uint32(uintColor))
}
}
}
}
for _, pixelValue := range interpolated {
r := pixelValue >> 24 & 0xff
g := pixelValue >> 16 & 0xff
b := pixelValue >> 8 & 0xff
a := 0xff
interpolatedColors = append(interpolatedColors, color.RGBA{uint8(r), uint8(g), uint8(b), uint8(a)})
}
}
}
}
return interpolatedColors
}
func render(maxIteration int, colors []color.RGBA, done chan struct{}) {
width = width * imageSmoothness
height = height * imageSmoothness
ratio := float64(height) / float64(width)
xmin, xmax := xpos-escapeRadius/2.0, math.Abs(xpos+escapeRadius/2.0)
ymin, ymax := ypos-escapeRadius*ratio/2.0, math.Abs(ypos+escapeRadius*ratio/2.0)
image := image.NewRGBA(image.Rectangle{image.Point{0, 0}, image.Point{width, height}})
for iy := 0; iy < height; iy++ {
waitGroup.Add(1)
go func(iy int) {
defer waitGroup.Done()
for ix := 0; ix < width; ix++ {
var x = xmin + (xmax-xmin)*float64(ix)/float64(width-1)
var y = ymin + (ymax-ymin)*float64(iy)/float64(height-1)
norm, it := mandelIteration(x, y, maxIteration)
iteration := float64(maxIteration-it) + math.Log(norm)
if int(math.Abs(iteration)) < len(colors)-1 {
color1 := colors[int(math.Abs(iteration))]
color2 := colors[int(math.Abs(iteration))+1]
color := linearInterpolation(rgbaToUint(color1), rgbaToUint(color2), uint32(iteration))
image.Set(ix, iy, uint32ToRgba(color))
}
}
}(iy)
}
waitGroup.Wait()
output, _ := os.Create(outputFile)
png.Encode(output, image)
done <- struct{}{}
}
func cosineInterpolation(c1, c2, mu float64) float64 {
mu2 := (1 - math.Cos(mu*math.Pi)) / 2.0
return c1*(1-mu2) + c2*mu2
}
func linearInterpolation(c1, c2, mu uint32) uint32 {
return c1*(1-mu) + c2*mu
}
func mandelIteration(cx, cy float64, maxIter int) (float64, int) {
var x, y, xx, yy float64 = 0.0, 0.0, 0.0, 0.0
for i := 0; i < maxIter; i++ {
xy := x * y
xx = x * x
yy = y * y
if xx+yy > 4 {
return xx + yy, i
}
x = xx - yy + cx
y = 2*xy + cy
}
logZn := (x*x + y*y) / 2
return logZn, maxIter
}
func rgbaToUint(color color.RGBA) uint32 {
r, g, b, a := color.RGBA()
r /= 0xff
g /= 0xff
b /= 0xff
a /= 0xff
return uint32(r)<<24 | uint32(g)<<16 | uint32(b)<<8 | uint32(a)
}
func uint32ToRgba(col uint32) color.RGBA {
r := col >> 24 & 0xff
g := col >> 16 & 0xff
b := col >> 8 & 0xff
a := 0xff
return color.RGBA{uint8(r), uint8(g), uint8(b), uint8(a)}
}