Skip to content

Instantly share code, notes, and snippets.

@schollz
Last active January 3, 2021 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schollz/ebe3d758633c8f238f4678fa54d33362 to your computer and use it in GitHub Desktop.
Save schollz/ebe3d758633c8f238f4678fa54d33362 to your computer and use it in GitHub Desktop.
pixelart_to_lua.go
package main
import (
"encoding/base64"
"fmt"
"image/png"
"strings"
)
func main() {
var b64 string
// CHANGE THIS TO WHATEVER YOU WANT
b64 = "iVBORw0KGgoAAAANSUhEUgAAAIAAAAATCAYAAABYzAUmAAAAO0lEQVRoge3SsQ0AIBADsd9/aWgRHSU6W8oEuZk36xgxzg9zfpwA4gQQt0YEaXcAYghyPgAAAAAA/GcDsdEe4hptOhUAAAAASUVORK5CYII="
img, err := png.Decode(base64.NewDecoder(base64.StdEncoding, strings.NewReader(b64)))
if err != nil {
panic(err)
}
fmt.Print(`function draw_object()
local pixels={
`)
for y := img.Bounds().Min.Y; y < img.Bounds().Max.Y; y++ {
for x := img.Bounds().Min.X; x < img.Bounds().Max.X; x++ {
c := img.At(x, y)
_, _, _, d := c.RGBA()
if d > 0 {
fmt.Printf("{%d,%d},", x+3, y)
}
}
}
fmt.Println(" ")
fmt.Print(`}
screen.level(8)
for _, p in ipairs(pixels) do
screen.pixel(p[1],p[2])
end
screen.fill()
end
`)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment