From 1eceb53b940659abd6a5c194927b3bb062717881 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Tue, 15 Nov 2022 11:29:45 -0500 Subject: [PATCH] Added fun color example --- application.go | 2 +- examples/color/main.go | 75 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 examples/color/main.go diff --git a/application.go b/application.go index 9a41891..c966350 100644 --- a/application.go +++ b/application.go @@ -32,7 +32,7 @@ func (application *Application) Run () ( // foreground color.RGBA { R: 0xFF, G: 0xFF, B: 0xFF, A: 0xFF }, // red - color.RGBA { R: 0xFF, G: 0xFF, B: 0xFF, A: 0xFF }, + color.RGBA { R: 0xFF, G: 0x00, B: 0x00, A: 0xFF }, // orange color.RGBA { R: 0xFF, G: 0x80, B: 0x00, A: 0xFF }, // yellow diff --git a/examples/color/main.go b/examples/color/main.go new file mode 100644 index 0000000..07776e7 --- /dev/null +++ b/examples/color/main.go @@ -0,0 +1,75 @@ +package main + +import "os" +import "fmt" +import "image" +import _ "image/png" +import "git.tebibyte.media/sashakoshka/stone" +import _ "git.tebibyte.media/sashakoshka/stone/backends/x" + +var application = &stone.Application { } + +func main () { + application.SetTitle("hellorld") + application.SetSize(12, 7) + + iconFile16, err := os.Open("assets/scaffold16.png") + if err != nil { panic(err) } + icon16, _, err := image.Decode(iconFile16) + if err != nil { panic(err) } + iconFile16.Close() + iconFile32, err := os.Open("assets/scaffold32.png") + if err != nil { panic(err) } + icon32, _, err := image.Decode(iconFile32) + if err != nil { panic(err) } + iconFile16.Close() + + application.SetIcon([]image.Image { icon16, icon32 }) + + channel, err := application.Run() + if err != nil { panic(err) } + + redraw() + + for { + event := <- channel + switch event.(type) { + case stone.EventQuit: + os.Exit(0) + + case stone.EventResize: + redraw() + } + } +} + +func redraw () { + text :="RAINBOW :D" + width, height := application.Size() + + application.Dot.X = (width - len(text)) / 2 + application.Dot.Y = height / 2 + fmt.Fprintln(application, text) + + application.SetColor(0, 0, stone.ColorYellow) + application.SetColor(width - 1, 0, stone.ColorYellow) + application.SetColor(width - 1, height - 1, stone.ColorYellow) + application.SetColor(0, height - 1, stone.ColorYellow) + application.SetRune(0, 0, '+') + application.SetRune(width - 1, 0, '+') + application.SetRune(width - 1, height - 1, '+') + application.SetRune(0, height - 1, '+') + + for x := 0; x < width; x ++ { + application.SetColor(x, height / 2, stone.Color(x % 6 + 2)) + } + + for x := 1; x < width - 1; x ++ { + application.SetRune(x, 0, '=') + application.SetColor(x, 0, stone.ColorRed) + application.SetRune(x, height - 1, '=') + application.SetColor(x, height - 1, stone.ColorRed) + } + + application.Draw() +}