Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified examples/GeoM/geom/gopher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions examples/drawing/drawing/drawing.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,23 @@ func (g *Game) Update() error {
}

if koebiten.IsKeyPressed(koebiten.Key0) {
g.draw(g.canvas, g.pointer.x, g.pointer.y, black)
g.draw(g.canvas, g.pointer.x, g.pointer.y, white) // eraser
}
if koebiten.IsKeyPressed(koebiten.Key1) || koebiten.IsKeyPressed(koebiten.Key2) ||
koebiten.IsKeyPressed(koebiten.Key3) || koebiten.IsKeyPressed(koebiten.Key4) ||
koebiten.IsKeyPressed(koebiten.Key5) || koebiten.IsKeyPressed(koebiten.Key6) ||
koebiten.IsKeyPressed(koebiten.Key7) || koebiten.IsKeyPressed(koebiten.Key8) ||
koebiten.IsKeyPressed(koebiten.Key9) || koebiten.IsKeyPressed(koebiten.Key10) ||
koebiten.IsKeyPressed(koebiten.Key11) {
g.draw(g.canvas, g.pointer.x, g.pointer.y, white)
g.draw(g.canvas, g.pointer.x, g.pointer.y, black)
}

return nil
}

func (g *Game) Draw(screen *koebiten.Image) {
g.canvas.DrawImage(screen, koebiten.DrawImageOptions{})
koebiten.DrawFilledCircle(screen, g.pointer.x, g.pointer.y, g.thick+1, white)
koebiten.DrawFilledCircle(screen, g.pointer.x, g.pointer.y, g.thick+1, black)
}

func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
Expand Down
4 changes: 2 additions & 2 deletions games/blocks/blocks/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
)

var (
backgroundColor = pixel.NewMonochrome(0x00, 0x00, 0x00)
frameColor = pixel.NewMonochrome(0xFF, 0xFF, 0xFF)
backgroundColor = pixel.NewMonochrome(0xFF, 0xFF, 0xFF)
frameColor = pixel.NewMonochrome(0x00, 0x00, 0x00)
)

const (
Expand Down
Binary file modified games/flappygopher/flappygopher/gopher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed games/flappygopher/flappygopher/sky.png
Binary file not shown.
Binary file modified games/flappygopher/flappygopher/wall.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified games/goradius/goradius/beam.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified games/goradius/goradius/enemy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified games/goradius/goradius/gopher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified games/jumpingopher/jumpingopher/cloud.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion games/jumpingopher/jumpingopher/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ func drawTitle() {
}

func drawGame() {
koebiten.DrawImageFS(nil, fsys, "sky.png", 0, 0)
koebiten.Println("Score", score)
koebiten.DrawImageFS(nil, fsys, "platform.png", 0, 60)

Expand Down
Binary file modified games/jumpingopher/jumpingopher/gopher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified games/jumpingopher/jumpingopher/gopher_r.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified games/jumpingopher/jumpingopher/platform.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed games/jumpingopher/jumpingopher/sky.png
Binary file not shown.
4 changes: 2 additions & 2 deletions games/snakegame/snakegame/snakegame.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ func (g *Game) Draw(screen *koebiten.Image) {
}

for _, s := range g.snake {
koebiten.DrawFilledRect(screen, s.x*gridSize, s.y*gridSize, gridSize, gridSize, white)
koebiten.DrawFilledRect(screen, s.x*gridSize, s.y*gridSize, gridSize, gridSize, black)
}
koebiten.DrawFilledRect(screen, g.food.x*gridSize, g.food.y*gridSize, gridSize, gridSize, white)
koebiten.DrawFilledRect(screen, g.food.x*gridSize, g.food.y*gridSize, gridSize, gridSize, black)
koebiten.Println("Score:", g.score)
}

Expand Down
2 changes: 1 addition & 1 deletion hardware/conf2025badge.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (z CONF2025BADGE) Init() error {
}

func (z CONF2025BADGE) GetDisplay() koebiten.Displayer {
return Display
return whiteBGDisplay{Display}
}

func (z CONF2025BADGE) KeyUpdate() error {
Expand Down
34 changes: 11 additions & 23 deletions hardware/gopher-badge.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func InitDisplay(dev *st7789.Device, width, height int) *Display {

ox, oy := d.getImageTopLeftForCentering()
w, h := d.img.Size()
tinydraw.Rectangle(dev, ox-1, oy-1, int16(w)+2, int16(h)+2, white)
tinydraw.Rectangle(dev, ox-1, oy-1, int16(w)+2, int16(h)+2, black)

return d
}
Expand All @@ -170,29 +170,17 @@ func (d *Display) Size() (x, y int16) {

func (d *Display) SetPixel(x, y int16, c color.RGBA) {
mx, my := d.Size()
if 0 <= x && x < int16(mx) && 0 <= y && y < int16(my) {
d.img.Set(int(x*2+0), int(y*2+0), pixelWhite)
d.img.Set(int(x*2+1), int(y*2+0), pixelWhite)
d.img.Set(int(x*2+0), int(y*2+1), pixelWhite)
d.img.Set(int(x*2+1), int(y*2+1), pixelWhite)
if x < 0 || x >= int16(mx) || y < 0 || y >= int16(my) {
return
}
return
cnt := 0
if c.R < 0x80 {
cnt++
px := pixelWhite
if int(c.R)+int(c.G)+int(c.B) <= 128*3 {
px = pixelBlack
}
if c.G < 0x80 {
cnt++
}
if c.B < 0x80 {
cnt++
}
if cnt >= 2 {
d.img.Set(int(x), int(y), pixelWhite)
} else {
d.img.Set(int(x), int(y), pixelBlack)
}
//d.d.SetPixel(x, y, c)
d.img.Set(int(x*2+0), int(y*2+0), px)
d.img.Set(int(x*2+1), int(y*2+0), px)
d.img.Set(int(x*2+0), int(y*2+1), px)
d.img.Set(int(x*2+1), int(y*2+1), px)
}

func (d *Display) Display() error {
Expand All @@ -201,7 +189,7 @@ func (d *Display) Display() error {
}

func (d *Display) ClearBuffer() {
d.img.FillSolidColor(pixelBlack)
d.img.FillSolidColor(pixelWhite)
}

func (d *Display) ClearDisplay() {
Expand Down
2 changes: 1 addition & 1 deletion hardware/gopher-board-i2c.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const (
)

func (z *device) GetDisplay() koebiten.Displayer {
return Display
return whiteBGDisplay{Display}
}

func (z *device) Init() error {
Expand Down
34 changes: 11 additions & 23 deletions hardware/gopher-board-spi.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func InitDisplay(dev *st7789.Device, width, height int) *Display {

ox, oy := d.getImageTopLeftForCentering()
w, h := d.img.Size()
tinydraw.Rectangle(dev, ox-1, oy-1, int16(w)+2, int16(h)+2, white)
tinydraw.Rectangle(dev, ox-1, oy-1, int16(w)+2, int16(h)+2, black)

return d
}
Expand All @@ -174,29 +174,17 @@ func (d *Display) Size() (x, y int16) {

func (d *Display) SetPixel(x, y int16, c color.RGBA) {
mx, my := d.Size()
if 0 <= x && x < int16(mx) && 0 <= y && y < int16(my) {
d.img.Set(int(x*2+0), int(y*2+0), pixelWhite)
d.img.Set(int(x*2+1), int(y*2+0), pixelWhite)
d.img.Set(int(x*2+0), int(y*2+1), pixelWhite)
d.img.Set(int(x*2+1), int(y*2+1), pixelWhite)
if x < 0 || x >= int16(mx) || y < 0 || y >= int16(my) {
return
}
return
cnt := 0
if c.R < 0x80 {
cnt++
px := pixelWhite
if int(c.R)+int(c.G)+int(c.B) <= 128*3 {
px = pixelBlack
}
if c.G < 0x80 {
cnt++
}
if c.B < 0x80 {
cnt++
}
if cnt >= 2 {
d.img.Set(int(x), int(y), pixelWhite)
} else {
d.img.Set(int(x), int(y), pixelBlack)
}
//d.d.SetPixel(x, y, c)
d.img.Set(int(x*2+0), int(y*2+0), px)
d.img.Set(int(x*2+1), int(y*2+0), px)
d.img.Set(int(x*2+0), int(y*2+1), px)
d.img.Set(int(x*2+1), int(y*2+1), px)
}

func (d *Display) Display() error {
Expand All @@ -205,7 +193,7 @@ func (d *Display) Display() error {
}

func (d *Display) ClearBuffer() {
d.img.FillSolidColor(pixelBlack)
d.img.FillSolidColor(pixelWhite)
}

func (d *Display) ClearDisplay() {
Expand Down
26 changes: 25 additions & 1 deletion hardware/macropad-rp2040.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,31 @@ var Device = &device{}

type device struct {
display *sh1106.Device
whiteBuf []byte
gpioPins []machine.Pin
state []State
cycle []int
keybuf [1]koebiten.Key
}

// whiteBGDisplay wraps sh1106.Device so that clearing the buffer fills the
// screen with white instead of black. koebiten draws ink in black on a white
// background. sh1106 does not expose its buffer, so an all-white buffer is
// copied in via SetBuffer.
type whiteBGDisplay struct {
*sh1106.Device
whiteBuf []byte
}

func (d whiteBGDisplay) ClearBuffer() {
d.SetBuffer(d.whiteBuf)
}

func (d whiteBGDisplay) ClearDisplay() {
d.ClearBuffer()
d.Display()
}

const (
debounce = 0
)
Expand Down Expand Up @@ -48,6 +67,11 @@ func (z *device) Init() error {
d.ClearDisplay()
z.display = &d

z.whiteBuf = make([]byte, 128*64/8)
for i := range z.whiteBuf {
z.whiteBuf[i] = 0xFF
}

gpioPins := []machine.Pin{
machine.KEY1,
machine.KEY2,
Expand Down Expand Up @@ -96,7 +120,7 @@ func (z *device) Init() error {
}

func (z *device) GetDisplay() koebiten.Displayer {
return z.display
return whiteBGDisplay{z.display, z.whiteBuf}
}

func (z *device) KeyUpdate() error {
Expand Down
28 changes: 8 additions & 20 deletions hardware/pybadge.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func InitDisplay(dev *st7735.Device, width, height int) *Display {

ox, oy := d.getImageTopLeftForCentering()
w, h := d.img.Size()
tinydraw.Rectangle(dev, ox-1, oy-1, int16(w)+2, int16(h)+2, white)
tinydraw.Rectangle(dev, ox-1, oy-1, int16(w)+2, int16(h)+2, black)

return d
}
Expand All @@ -160,26 +160,14 @@ func (d *Display) Size() (x, y int16) {

func (d *Display) SetPixel(x, y int16, c color.RGBA) {
mx, my := d.Size()
if 0 <= x && x < int16(mx) && 0 <= y && y < int16(my) {
d.img.Set(int(x), int(y), pixelWhite)
if x < 0 || x >= int16(mx) || y < 0 || y >= int16(my) {
return
}
return
cnt := 0
if c.R < 0x80 {
cnt++
px := pixelWhite
if int(c.R)+int(c.G)+int(c.B) <= 128*3 {
px = pixelBlack
}
if c.G < 0x80 {
cnt++
}
if c.B < 0x80 {
cnt++
}
if cnt >= 2 {
d.img.Set(int(x), int(y), pixelWhite)
} else {
d.img.Set(int(x), int(y), pixelBlack)
}
//d.d.SetPixel(x, y, c)
d.img.Set(int(x), int(y), px)
}

func (d *Display) Display() error {
Expand All @@ -188,7 +176,7 @@ func (d *Display) Display() error {
}

func (d *Display) ClearBuffer() {
d.img.FillSolidColor(pixelBlack)
d.img.FillSolidColor(pixelWhite)
}

func (d *Display) ClearDisplay() {
Expand Down
26 changes: 26 additions & 0 deletions hardware/ssd1306-white.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//go:build tinygo && (zero_kb02 || conf2025badge || gopher_board_i2c)

package hardware

import (
"tinygo.org/x/drivers/ssd1306"
)

// whiteBGDisplay wraps ssd1306.Device so that clearing the buffer fills the
// screen with white instead of black. koebiten draws ink in black on a white
// background.
type whiteBGDisplay struct {
*ssd1306.Device
}

func (d whiteBGDisplay) ClearBuffer() {
buf := d.GetBuffer()
for i := range buf {
buf[i] = 0xFF
}
}

func (d whiteBGDisplay) ClearDisplay() {
d.ClearBuffer()
d.Display()
}
2 changes: 1 addition & 1 deletion hardware/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (d *Display) ClearDisplay() {

func (d *Display) ClearBuffer() {
for i := range d.buf {
d.buf[i] = 0
d.buf[i] = 0xFF // white background
}
}

Expand Down
34 changes: 11 additions & 23 deletions hardware/wioterminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func InitDisplay(dev *ili9341.Device, width, height int) *Display {

ox, oy := d.getImageTopLeftForCentering()
w, h := d.img.Size()
tinydraw.Rectangle(dev, ox-1, oy-1, int16(w)+2, int16(h)+2, white)
tinydraw.Rectangle(dev, ox-1, oy-1, int16(w)+2, int16(h)+2, black)

return d
}
Expand All @@ -186,29 +186,17 @@ func (d *Display) Size() (x, y int16) {

func (d *Display) SetPixel(x, y int16, c color.RGBA) {
mx, my := d.Size()
if 0 <= x && x < int16(mx) && 0 <= y && y < int16(my) {
d.img.Set(int(x*2+0), int(y*2+0), pixelWhite)
d.img.Set(int(x*2+1), int(y*2+0), pixelWhite)
d.img.Set(int(x*2+0), int(y*2+1), pixelWhite)
d.img.Set(int(x*2+1), int(y*2+1), pixelWhite)
if x < 0 || x >= int16(mx) || y < 0 || y >= int16(my) {
return
}
return
cnt := 0
if c.R < 0x80 {
cnt++
px := pixelWhite
if int(c.R)+int(c.G)+int(c.B) <= 128*3 {
px = pixelBlack
}
if c.G < 0x80 {
cnt++
}
if c.B < 0x80 {
cnt++
}
if cnt >= 2 {
d.img.Set(int(x), int(y), pixelWhite)
} else {
d.img.Set(int(x), int(y), pixelBlack)
}
//d.d.SetPixel(x, y, c)
d.img.Set(int(x*2+0), int(y*2+0), px)
d.img.Set(int(x*2+1), int(y*2+0), px)
d.img.Set(int(x*2+0), int(y*2+1), px)
d.img.Set(int(x*2+1), int(y*2+1), px)
}

func (d *Display) Display() error {
Expand All @@ -217,7 +205,7 @@ func (d *Display) Display() error {
}

func (d *Display) ClearBuffer() {
d.img.FillSolidColor(pixelBlack)
d.img.FillSolidColor(pixelWhite)
}

func (d *Display) ClearDisplay() {
Expand Down
2 changes: 1 addition & 1 deletion hardware/zero-kb02.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (z ZERO_KB02) Init() error {
}

func (z ZERO_KB02) GetDisplay() koebiten.Displayer {
return Display
return whiteBGDisplay{Display}
}

func (z ZERO_KB02) KeyUpdate() error {
Expand Down
Loading
Loading