Nv7 mod & Image generator

This commit is contained in:
Nv7-GitHub 2022-01-21 23:34:40 -08:00
parent 35399a58a1
commit c9ab77588f
5 changed files with 32694 additions and 0 deletions

32513
mods/nv7.js Executable file

File diff suppressed because it is too large Load Diff

116
scripts/im2elements/code.go Normal file
View File

@ -0,0 +1,116 @@
package main
import (
"fmt"
"image"
"strings"
)
const category = "special"
func genCode(im image.Image, name string) string {
out := &strings.Builder{}
fmt.Fprintf(out, `elements.%s_top = {
color: "#000000",
behavior: [
"XX|DL|XX",
"XX|DL%%5|XX",
"XX|XX|XX",
],
category: "special",
state: "solid",
density: 6942.0,
hidden: true,
}`+"\n\n", name)
for y := im.Bounds().Dy() - 1; y >= 0; y-- {
for x := 0; x < im.Bounds().Dx(); x++ {
r, g, b, _ := im.At(x, y).RGBA()
if r == 0 && g == 0 && b == 0 {
continue
}
r = r >> 8
g = g >> 8
b = b >> 8
// Get hex
hex := fmt.Sprintf("#%02x%02x%02x", r, g, b)
// Add code
nameNum := fmt.Sprintf("%s_%d_%d", name, x, y)
fall := "XX"
hidden := "true"
if y == im.Bounds().Dy()-1 && x == 0 {
nameNum = name
fall = "M1"
hidden = "false"
}
top := fmt.Sprintf("%s_%d_%d", name, x, y-1)
right := fmt.Sprintf("%s_%d_%d", name, x+1, y)
// On top and right?
if y == 0 && x == im.Bounds().Dx()-1 {
fmt.Fprintf(out, `elements.%s = {
color: "%s",
behavior: [
"XX|CR:%s_top AND CH:%s_top|XX",
"XX|XX|DL",
"XX|XX|XX",
],
category: "%s",
state: "solid",
density: 6942.0,
hidden: %s,
}`+"\n\n", nameNum, hex, name, name, category, hidden)
continue
}
// If on top?
if y == 0 {
fmt.Fprintf(out, `elements.%s = {
color: "%s",
behavior: [
"XX|CR:%s_top AND CH:%s_top|XX",
"XX|XX|CR:%s AND CH:%s",
"XX|XX|XX",
],
category: "%s",
state: "solid",
density: 6942.0,
hidden: %s,
}`+"\n\n", nameNum, hex, name, name, right, right, category, hidden)
continue
}
// If on far right?
if x == im.Bounds().Dx()-1 {
fmt.Fprintf(out, `elements.%s = {
color: "%s",
behavior: [
"XX|CR:%s AND CH:%s|XX",
"XX|XX|DL",
"XX|XX|XX",
],
category: "%s",
state: "solid",
density: 6942.0,
hidden: %s,
}`+"\n\n", nameNum, hex, top, top, category, hidden)
continue
}
fmt.Fprintf(out, `elements.%s = {
color: "%s",
behavior: [
"XX|CR:%s AND CH:%s|XX",
"XX|XX|CR:%s AND CH:%s",
"XX|%s|XX",
],
category: "%s",
state: "solid",
density: 6942.0,
hidden: %s,
}`+"\n\n", nameNum, hex, top, top, right, right, fall, category, hidden)
}
}
return out.String()
}

View File

@ -0,0 +1,5 @@
module im2elements
go 1.17
require github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646

View File

@ -0,0 +1,2 @@
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=

View File

@ -0,0 +1,58 @@
package main
import (
"image"
_ "image/jpeg"
_ "image/png"
"bufio"
"fmt"
"os"
"strconv"
"github.com/nfnt/resize"
)
var reader = bufio.NewReader(os.Stdin)
func getInput(par string) string {
fmt.Print(par)
text, _, err := reader.ReadLine()
if err != nil {
panic(err)
}
return string(text)
}
func toInt(val string) int {
v, err := strconv.Atoi(val)
if err != nil {
panic(err)
}
return v
}
func main() {
filename := getInput("Image: ")
f, err := os.Open(filename)
if err != nil {
panic(err)
}
defer f.Close()
im, _, err := image.Decode(f)
if err != nil {
panic(err)
}
width := toInt(getInput("Max Width (works best with 5-10): "))
height := toInt(getInput("Max Height (works best with 5-10, leave at 0 for scaling): "))
im = resize.Resize(uint(width), uint(height), im, resize.Lanczos3)
name := getInput("Name: ")
outF := getInput("Output file (JS): ")
err = os.WriteFile(outF, []byte(genCode(im, name)), os.ModePerm)
if err != nil {
panic(err)
}
}