Skip to content

Commit 9d0db23

Browse files
committed
feat: Use nearest-neighbor scaling in pi.Stretch
Because it is more accurate than the current algorithm and the performance is similar.
1 parent 69e5ac8 commit 9d0db23

File tree

16 files changed

+160
-14
lines changed

16 files changed

+160
-14
lines changed

_examples/stretchtest/gamepad.png

524 Bytes
Loading

_examples/stretchtest/main.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2025 Jacek Olszak
2+
// This code is licensed under MIT license (see LICENSE for details)
3+
4+
package main
5+
6+
import (
7+
_ "embed"
8+
"github.com/elgopher/pi"
9+
"github.com/elgopher/pi/piebiten"
10+
"github.com/elgopher/pi/pikey"
11+
"github.com/elgopher/pi/piscope"
12+
)
13+
14+
//go:embed "gamepad.png"
15+
var gamepadPNG []byte
16+
17+
func main() {
18+
pi.SetScreenSize(100, 60)
19+
pi.Palette = pi.DecodePalette(gamepadPNG)
20+
canvas := pi.DecodeCanvas(gamepadPNG)
21+
spr := pi.SpriteFrom(canvas, 58, 26, 9, 9)
22+
piscope.Start()
23+
posx := 0
24+
posy := 0
25+
pi.Update = func() {
26+
if pikey.Duration(pikey.Left) > 0 {
27+
posx--
28+
}
29+
if pikey.Duration(pikey.Right) > 0 {
30+
posx++
31+
}
32+
if pikey.Duration(pikey.Up) > 0 {
33+
posy--
34+
}
35+
if pikey.Duration(pikey.Down) > 0 {
36+
posy++
37+
}
38+
}
39+
pi.Draw = func() {
40+
pi.DrawSprite(spr, posx, posy)
41+
}
42+
piebiten.Run()
43+
}
211 Bytes
Loading
212 Bytes
Loading
223 Bytes
Loading
223 Bytes
Loading
223 Bytes
Loading
223 Bytes
Loading
226 Bytes
Loading
229 Bytes
Loading

0 commit comments

Comments
 (0)