Last active
January 3, 2021 14:15
-
-
Save schollz/ebe3d758633c8f238f4678fa54d33362 to your computer and use it in GitHub Desktop.
pixelart_to_lua.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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