stone/examples/color/main.go

71 lines
1.7 KiB
Go
Raw Normal View History

2022-11-15 09:29:45 -07:00
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 () {
2022-11-16 09:08:30 -07:00
application.SetTitle("color demo")
2022-11-15 09:29:45 -07:00
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 })
2022-11-16 09:08:30 -07:00
application.OnStart(onStart)
application.OnResize(onResize)
2022-11-15 09:29:45 -07:00
2022-11-16 09:08:30 -07:00
err = application.Run()
if err != nil { panic(err) }
}
2022-11-15 09:29:45 -07:00
2022-11-16 09:08:30 -07:00
func onStart () {
redraw()
}
2022-11-15 09:29:45 -07:00
2022-11-16 09:08:30 -07:00
func onResize () {
redraw()
2022-11-15 09:29:45 -07:00
}
func redraw () {
2022-11-15 09:40:10 -07:00
text := "RAINBOW :D"
2022-11-15 09:29:45 -07:00
width, height := application.Size()
2022-11-15 15:41:08 -07:00
application.SetDot((width - len(text)) / 2, height / 2)
2022-11-15 09:29:45 -07:00
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 % 5 + 3))
2022-11-15 09:29:45 -07:00
}
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)
}
}