Skip to content

Instantly share code, notes, and snippets.

@willowiscool
Last active February 25, 2021 16:54
Show Gist options
  • Save willowiscool/83c2307b1379a876b80d4322e5b37c22 to your computer and use it in GitHub Desktop.
Save willowiscool/83c2307b1379a876b80d4322e5b37c22 to your computer and use it in GitHub Desktop.
Minecraft gradient skin creator. Change COLORONE and COLORTWO

Change the variables COLORONE and COLORTWO and run to get your skin in output.png

package main
import (
"fmt"
"image"
"image/color"
"image/png"
"os"
)
func main() {
skin := image.NewRGBA(image.Rect(0, 0, 64, 64))
COLORONE := color.RGBA{76, 151, 117, 255}
COLORTWO := color.RGBA{18, 53, 36, 255}
inbetweens := make([]color.RGBA, 32)
for i, _ := range inbetweens {
var r uint8 = uint8(float64(COLORONE.R) + float64(i)/31*(float64(COLORTWO.R)-float64(COLORONE.R)))
var g uint8 = uint8(float64(COLORONE.G) + float64(i)/31*(float64(COLORTWO.G)-float64(COLORONE.G)))
var b uint8 = uint8(float64(COLORONE.B) + float64(i)/31*(float64(COLORTWO.B)-float64(COLORONE.B)))
inbetweens[i] = color.RGBA{r, g, b, 255}
}
fmt.Println(inbetweens)
// top of head
drawOn(skin, image.Rect(8, 0, 15, 7), COLORONE)
// head
for h := 8; h < 16; h++ {
drawOn(skin, image.Rect(0, h, 31, h), inbetweens[h-8])
}
// bottom of head
drawOn(skin, image.Rect(16, 0, 23, 7), inbetweens[7])
//top of body, top of arms
drawOn(skin, image.Rect(20, 16, 27, 19), inbetweens[8])
drawOn(skin, image.Rect(44, 16, 47, 19), inbetweens[8])
drawOn(skin, image.Rect(36, 48, 39, 51), inbetweens[8])
//body and right arm
for h := 20; h < 32; h++ {
drawOn(skin, image.Rect(16, h, 55, h), inbetweens[h-12])
}
//left arm
for h := 52; h < 64; h++ {
drawOn(skin, image.Rect(32, h, 47, h), inbetweens[h-44])
}
// bottom of body and arms
drawOn(skin, image.Rect(28, 16, 35, 19), inbetweens[19])
drawOn(skin, image.Rect(48, 16, 51, 19), inbetweens[19])
drawOn(skin, image.Rect(40, 48, 43, 51), inbetweens[19])
// top of legs
drawOn(skin, image.Rect(4, 16, 7, 19), inbetweens[20])
drawOn(skin, image.Rect(20, 48, 23, 51), inbetweens[20])
//right leg
for h := 20; h < 32; h++ {
drawOn(skin, image.Rect(0, h, 15, h), inbetweens[h])
}
//left leg
for h := 52; h < 64; h++ {
drawOn(skin, image.Rect(15, h, 31, h), inbetweens[h-32])
}
//bottom of legs
drawOn(skin, image.Rect(8, 16, 11, 19), inbetweens[31])
drawOn(skin, image.Rect(24, 48, 27, 51), inbetweens[31])
fi, err := os.Create("output.png")
if err != nil {
panic(err)
}
err = png.Encode(fi, skin)
if err != nil {
panic(err)
}
fi.Close()
}
func drawOn(img *image.RGBA, rect image.Rectangle, c color.Color) {
rect = rect.Canon()
for x := rect.Min.X; x <= rect.Max.X; x++ {
for y := rect.Min.Y; y <= rect.Max.Y; y++ {
img.Set(x, y, c)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment