v0 source pure
Package \`nft\` draws the Settlers, pixel-art gnomes. The art is dedicated to the public domain under CC0 1.0, see Cr...
View source
Settlers NTF
Package that draws the Settlers, small pixel-art gnomes, as an SVG.
Given the same traits, it always draws the same image, so it's safe and cheap for any realm to import and call directly.
Code also lives in jeronimoalbi/gnoland-settlers.
From a seed
1traits := nft.NewTraits("some-seed-string")
2svg := nft.RenderSVG(traits, nft.Options{Size: 512})
The traits (skin, hat, beard, clothes, glasses, background, and so on) are all worked out deterministically from the seed, so the same seed always gives the same gnome.
From packed traits
Traits are usually stored packed into a single uint32:
1packed := nft.Pack(traits)
2traits, err := nft.FromPacked(packed)
3svg := nft.RenderSVG(traits, nft.Options{})
Options also takes NoBackground (a transparent image) and BackgroundColor
(a custom one). RenderDataURI gives the same image as a data:image/svg+xml;... URI,
ready to use as an <img> source.
License
The art itself is dedicated to the public domain under CC0 1.0 Universal; see Credits.
Package `nft` draws the Settlers, pixel-art gnomes. The art is dedicated to the public domain under CC0 1.0, see Credits.
2
const CanonicalSize
CanonicalSize is the width and height in pixels of the image used for NFTs.
9
func BuildGrid
BuildGrid returns the pixel grid of a gnome, as 32 rows of 24 palette keys ('.' is transparent). Traits must be valid.
func DataURI
DataURI encodes an SVG document as a "data:image/svg+xml;base64," URI. It is slower than RenderDataURI, use it when Base64 is needed.
func Pack
Pack packs the traits in 20 bits.
func RenderDataURI
RenderDataURI renders the gnome as a "data:image/svg+xml;charset=utf-8," URI, percent-encoded.
Cheapest way to embed a gnome. SVG is written encoded, instead of encoding it afterwards. Traits must be valid.
func RenderSVG
RenderSVG renders the gnome as an SVG document. Traits must be valid. The same traits and options always give the same bytes.
func RenderSeed
RenderSeed renders the gnome of a seed as an SVG document.
func FromPacked
FromPacked unpacks traits and checks them.
func NewTraits
NewTraits derives the traits of the gnome from a seed. A single seed always generate the same traits. Use `Validate()` to check traits before drawing.
func Unpack
Unpack unpacks the traits. It does not check the values, use FromPacked for untrusted input.
3
type Attribute
structAttribute is a named trait of a gnome.
type Options
struct 1type Options struct {
2 // Size is the width and the height of the image in pixels, because the image is a square.
3 // Multiples of 32 keep every art pixel as a whole number of screen pixels.
4 // Zero omits the width and height, so that the image scales to its container.
5 Size int
6
7 // NoBackground omits the background.
8 NoBackground bool
9
10 // BackgroundColor replaces the color of the background, in "#rrggbb" format.
11 BackgroundColor string
12}Options are the options to render a gnome.
type Traits
structTraits describe a gnome.
Methods on Traits
func Attributes
method on TraitsAttributes returns the traits of a gnome with their names. It panics when traits are not valid.
func Normalized
method on TraitsNormalized returns the traits with the flip cleared when it has no effect. Two traits that draw the same gnome have the same normalized traits, so this is the value to compare and to keep when gnomes must be different.
func Validate
method on TraitsValidate checks that all the traits are in range.
4
- crypto/sha256 stdlib
- encoding/base64 stdlib
- errors stdlib
- strconv stdlib