cmd
This commit is contained in:
BIN
cmd/mesh/8.clock.png
Normal file
BIN
cmd/mesh/8.clock.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 MiB |
41
cmd/mesh/9p.go
Normal file
41
cmd/mesh/9p.go
Normal file
@@ -0,0 +1,41 @@
|
||||
//go:build ignore
|
||||
|
||||
package main
|
||||
|
||||
func ListenAndServe(addr string, filesystem fs.FS) error {
|
||||
styx.HandlerFunc(func(s *styx.Session) {
|
||||
for s.Next() {
|
||||
switch msg := s.Request.(type) {
|
||||
case styx.Twalk:
|
||||
msg.Rwalk(fs.Stat(filesystem, msg.Path()))
|
||||
case styx.Topen:
|
||||
msg.Ropen(filesystem.Open(msg.Path()))
|
||||
case styx.Tstat:
|
||||
msg.Rstat(fs.Stat(filesystem, msg.Path()))
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
type FS struct {
|
||||
meshFile
|
||||
}
|
||||
|
||||
type meshFile struct {
|
||||
}
|
||||
|
||||
type meshFileInfo struct {
|
||||
bufio.Reader
|
||||
time.Time
|
||||
}
|
||||
|
||||
func (f meshFileInfo) Name() string { return "mesh" }
|
||||
func (f meshFileInfo) Size() int64 { return f.Reader.Size() }
|
||||
func (f meshFileInfo) Mode() fs.FileMode { return fs.ModePerm }
|
||||
func (f meshFileInfo) ModTime() time.Time { return f.Time }
|
||||
func (f meshFileInfo) IsDir() bool { return false }
|
||||
func (f meshFileInfo) Sys() any { return nil }
|
||||
|
||||
func (f meshFile) Stat() (fs.FileInfo, error) {
|
||||
}
|
||||
91
cmd/mesh/mesh.go
Normal file
91
cmd/mesh/mesh.go
Normal file
@@ -0,0 +1,91 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
"image/png"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/golang/freetype/truetype"
|
||||
"golang.org/x/image/font"
|
||||
"golang.org/x/image/font/gofont/gomono"
|
||||
"golang.org/x/image/math/fixed"
|
||||
// "github.com/droyo/styx"
|
||||
// "io/fs"
|
||||
)
|
||||
|
||||
type Mesh struct {
|
||||
image.Image
|
||||
X, Y int // divide
|
||||
}
|
||||
|
||||
// using source's color.Model
|
||||
func (mesh Mesh) ColorModel() color.Model { return mesh.Image.ColorModel() }
|
||||
|
||||
// using source's image.Rectangle
|
||||
func (mesh Mesh) Bounds() image.Rectangle { return mesh.Image.Bounds() }
|
||||
func (mesh Mesh) At(x, y int) color.Color {
|
||||
dx, dy := mesh.Image.Bounds().Dx(), mesh.Image.Bounds().Dy()
|
||||
if (x%(dx/mesh.X)) == 0 || (y%(dy/mesh.Y)) == 0 {
|
||||
return color.Black
|
||||
}
|
||||
return mesh.Image.At(x, y)
|
||||
}
|
||||
|
||||
func render(img image.Image) draw.Image {
|
||||
dst := image.NewRGBA(img.Bounds())
|
||||
draw.Draw(dst, dst.Bounds(), img, image.Point{}, draw.Src)
|
||||
return dst
|
||||
}
|
||||
|
||||
func main() {
|
||||
// x := flag.Int("x", 2, "use to grid by x axis")
|
||||
// y := flag.Int("y", 2, "use to grid by y axis")
|
||||
flag.Parse() // now flags is ready to use
|
||||
|
||||
img, err := png.Decode(os.Stdin)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// Mesh{ // our image modifyer
|
||||
// Image: img,
|
||||
// X: *x,
|
||||
// Y: *y,
|
||||
// },
|
||||
|
||||
dst := render(
|
||||
img,
|
||||
)
|
||||
|
||||
f, err := truetype.Parse(gomono.TTF)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
face := truetype.NewFace(f, &truetype.Options{
|
||||
Size: float64(img.Bounds().Dx() / 19),
|
||||
DPI: 72,
|
||||
Hinting: font.HintingNone,
|
||||
})
|
||||
|
||||
d := &font.Drawer{
|
||||
Dst: dst,
|
||||
Src: image.NewUniform(color.Black),
|
||||
Face: face,
|
||||
Dot: fixed.Point26_6{fixed.Int26_6(img.Bounds().Dx() /
|
||||
9*64,
|
||||
),
|
||||
fixed.Int26_6(img.Bounds().Dy() /
|
||||
5*64,
|
||||
),
|
||||
},
|
||||
}
|
||||
d.DrawString(time.Now().Format(time.Kitchen))
|
||||
|
||||
err = png.Encode(os.Stdout, dst)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user