Can now save and load from json

Much improved speed over loading everything manually.
This commit is contained in:
Unknown
2018-03-22 20:11:51 -04:00
parent daac5bf3d2
commit 5b36b9193a
8 changed files with 264 additions and 90 deletions

57
colors.go Normal file
View File

@@ -0,0 +1,57 @@
package ps
import (
"encoding/hex"
)
var Colors map[string]Color = map[string]Color{
"Gray": &RGB{128, 128, 128},
"White": &RGB{255, 255, 255},
}
// Color represents a color.
type Color interface {
RGB() [3]int
}
func Compare(a, b Color) Color {
A := a.RGB()
B := b.RGB()
Aavg := (A[0] + A[1] + A[2]) / 3
Bavg := (B[0] + B[1] + B[2]) / 3
if Aavg > Bavg {
return a
}
return b
}
// Color is a color in RGB format.
type RGB struct {
Red int
Green int
Blue int
}
// RGB returns the color in RGB format.
func (r RGB) RGB() [3]int {
return [3]int{r.Red, r.Green, r.Blue}
}
// Hex is a color in hexidecimal format.
type Hex []uint8
func (h Hex) RGB() [3]int {
src := []byte(h)
dst := make([]byte, hex.DecodedLen(len(src)))
_, err := hex.Decode(dst, src)
if err != nil {
panic(err)
}
return [3]int{int(dst[0]), int(dst[1]), int(dst[2])}
}
// Stroke represents a layer stroke effect.
type Stroke struct {
Size float32
Color
}