From 1a4517a49ff316aee0072f14302056355072e0df Mon Sep 17 00:00:00 2001 From: Logen Kain Date: Wed, 27 Sep 2017 03:59:31 -0700 Subject: [PATCH] go:pixel stuff --- go/pixel/draw-sprite/main.go | 68 ++++++++++++++++++++++++++++++++ go/pixel/draw-sprite/vim-go.png | Bin 0 -> 11795 bytes go/pixel/window/main.go | 36 +++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 go/pixel/draw-sprite/main.go create mode 100644 go/pixel/draw-sprite/vim-go.png create mode 100644 go/pixel/window/main.go diff --git a/go/pixel/draw-sprite/main.go b/go/pixel/draw-sprite/main.go new file mode 100644 index 0000000..468bea0 --- /dev/null +++ b/go/pixel/draw-sprite/main.go @@ -0,0 +1,68 @@ +package main + +import ( + "image" + _ "image/png" + "os" + + "github.com/faiface/pixel" + "github.com/faiface/pixel/pixelgl" + "golang.org/x/image/colornames" +) + +// Picture Loader helper +// If we wanted to decode more types, we'd have to import them +// Such as "image/jpeg" + +func loadPicture(path string) (pixel.Picture, error) { + file, err := os.Open(path) + if err != nil { + return nil, err + } + + defer file.Close() + img, _, err := image.Decode(file) + if err != nil { + return nil, err + } + + return pixel.PictureDataFromImage(img), nil +} + +func run() { + cfg := pixelgl.WindowConfig{ + Title: "Pixel Rocks!", + Bounds: pixel.R(0, 0, 1024, 768), + VSync: true, + } + + win, err := pixelgl.NewWindow(cfg) + if err != nil { + panic(err) + } + + pic, err := loadPicture("vim-go.png") + if err != nil { + panic(err) + } + + //We choose pic.Bounds() because we want + //The whole thing + sprite := pixel.NewSprite(pic, pic.Bounds()) + + win.Clear(colornames.Black) + // At this point just know that pixel.IM + // Means "no spacial transformations" + //sprite.Draw(win, pixel.IM) + + //We'll give it some changes this time + sprite.Draw(win, pixel.IM.Moved(win.Bounds().Center())) + + for !win.Closed() { + win.Update() + } +} + +func main() { + pixelgl.Run(run) +} diff --git a/go/pixel/draw-sprite/vim-go.png b/go/pixel/draw-sprite/vim-go.png new file mode 100644 index 0000000000000000000000000000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ccUP?n~Qyt?e0SoN>k(XPj}y8Rz=u{{g_^{n0?+?nM9q002ovPDHLkV1iIQ BT;2cx literal 0 HcmV?d00001 diff --git a/go/pixel/window/main.go b/go/pixel/window/main.go new file mode 100644 index 0000000..9603a96 --- /dev/null +++ b/go/pixel/window/main.go @@ -0,0 +1,36 @@ +package main + +import ( + "github.com/faiface/pixel" + "github.com/faiface/pixel/pixelgl" + "golang.org/x/image/colornames" +) + +func run() { + // All code goes here! + // Note: There are more options, but they have defaults + cfg := pixelgl.WindowConfig{ + Title: "Pixel Rocks!", + //rectangle, lower left xy, upper right xy + Bounds: pixel.R(0, 0, 1024, 768), + VSync: true, + } + + //Takes a config and returns a window or err + win, err := pixelgl.NewWindow(cfg) + if err != nil { + panic(err) + } + + win.Clear(colornames.Skyblue) + + // Main loop + for !win.Closed() { + win.Update() + } +} + +/* Nothing else happens in main*/ +func main() { + pixelgl.Run(run) +}