aboutsummaryrefslogtreecommitdiff
path: root/unicorn/FakeUnicorn2.go
diff options
context:
space:
mode:
authorMartin Ashby <martin@martin-laptop.lan>2018-05-28 16:29:18 +0100
committerMartin Ashby <martin@martin-laptop.lan>2018-05-28 16:29:18 +0100
commitf20896ef3b147ac07769eb36c67ba436c6d2ed22 (patch)
treecfc84980cf2de46784049191d5250fa1aa88f345 /unicorn/FakeUnicorn2.go
parent4ec7e493520d558dd05e911b58ea354d25f33f45 (diff)
downloadunicornpaint-f20896ef3b147ac07769eb36c67ba436c6d2ed22.tar.gz
unicornpaint-f20896ef3b147ac07769eb36c67ba436c6d2ed22.tar.bz2
unicornpaint-f20896ef3b147ac07769eb36c67ba436c6d2ed22.tar.xz
unicornpaint-f20896ef3b147ac07769eb36c67ba436c6d2ed22.zip
New unicorns for displaing animated gifs! Tests pass on both old & new for fakes
Diffstat (limited to 'unicorn/FakeUnicorn2.go')
-rw-r--r--unicorn/FakeUnicorn2.go70
1 files changed, 31 insertions, 39 deletions
diff --git a/unicorn/FakeUnicorn2.go b/unicorn/FakeUnicorn2.go
index 73ce8ab..27629d2 100644
--- a/unicorn/FakeUnicorn2.go
+++ b/unicorn/FakeUnicorn2.go
@@ -8,50 +8,42 @@ import (
type FakeUnicorn2 struct {
BaseUnicorn2
+ *BaseFakeUnicorn
}
-func renderImage(im image.Image) {
- // b := im.Bounds()
- // width := b.Dx()
- // height := b.Dy()
- // for x := 0; x < width; x++ {
- // for y := 0; y < height; y++ {
- // r, g, b, _ := im.At(x, y).RGBA()
- // un.SetPixel(uint8(x), uint8(y), uint8(r), uint8(g), uint8(b))
- // }
- // }
- // un.Show()
-}
-
-func render() {
- // for !stop {
- // for i := 0; i < len(gf.Image); i++ {
- // im := gf.Image[i]
- // delay := gf.Delay[i] //100ths of a second
- // renderImage(un, im)
- // time.Sleep(time.Duration(delay * 10000000)) // nanoseconds 10^-9 sec
- // }
- // }
-}
-
-func (u *FakeUnicorn2) StartRender() {
-
-}
-
-func MainLoop() {
- running := true
- for running {
- for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
- switch event.(type) {
- case *sdl.QuitEvent:
- println("Quit")
- running = false
- break
+func (u *FakeUnicorn2) renderImage(im image.Image) {
+ b := im.Bounds()
+ width, height := b.Dx(), b.Dy()
+ for x := 0; x < width; x++ {
+ for y := 0; y < height; y++ {
+ col := im.At(x, y)
+ r, g, b, _ := col.RGBA()
+ // Ignore alpha for now, not worked out how it should work on real unicorn
+ if err := u.renderer.SetDrawColor(uint8(r), uint8(g), uint8(b), uint8(255)); err != nil {
+ panic(err)
+ }
+ cellWidth := u.displayWidth / int32(width)
+ cellHeight := u.displayHeight / int32(height)
+ if err := u.renderer.FillRect(&sdl.Rect{
+ X: cellWidth * int32(x),
+ Y: u.displayHeight - (cellHeight * int32(y)) - cellHeight, // SDL Y coordinate is from the top
+ W: cellWidth,
+ H: cellHeight,
+ }); err != nil {
+ panic(err)
}
}
}
+ u.renderer.Present()
}
-func NewUnicorn2() *FakeUnicorn2 {
- return &FakeUnicorn2{}
+func NewUnicorn2() (*FakeUnicorn2, error) {
+ baseFake, err := NewBaseFakeUnicorn(300, 300)
+ if err != nil {
+ return nil, err
+ }
+ return &FakeUnicorn2{
+ BaseUnicorn2{},
+ baseFake,
+ }, nil
}