Added fun color example

This commit is contained in:
Sasha Koshka 2022-11-15 11:29:45 -05:00
parent de3e4b528b
commit 1eceb53b94
2 changed files with 76 additions and 1 deletions

View File

@ -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

75
examples/color/main.go Normal file
View File

@ -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()
}