mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
examples/minify: Add rotation
This commit is contained in:
parent
a321155ab5
commit
b02b2de626
@ -30,6 +30,7 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten"
|
"github.com/hajimehoshi/ebiten"
|
||||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||||
"github.com/hajimehoshi/ebiten/examples/resources/images"
|
"github.com/hajimehoshi/ebiten/examples/resources/images"
|
||||||
|
"github.com/hajimehoshi/ebiten/inpututil"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -39,6 +40,7 @@ const (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
gophersImage *ebiten.Image
|
gophersImage *ebiten.Image
|
||||||
|
rotate = false
|
||||||
counter = 0
|
counter = 0
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -48,17 +50,26 @@ func update(screen *ebiten.Image) error {
|
|||||||
counter = 0
|
counter = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if inpututil.IsKeyJustPressed(ebiten.KeyR) {
|
||||||
|
rotate = !rotate
|
||||||
|
}
|
||||||
|
|
||||||
if ebiten.IsDrawingSkipped() {
|
if ebiten.IsDrawingSkipped() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
s := 1.5 / math.Pow(1.01, float64(counter))
|
s := 1.5 / math.Pow(1.01, float64(counter))
|
||||||
ebitenutil.DebugPrint(screen, fmt.Sprintf("Minifying images (Nearest filter vs Linear filter)\nScale: %0.2f", s))
|
ebitenutil.DebugPrint(screen, fmt.Sprintf("Minifying images (Nearest filter vs Linear filter): Press R to rotate the images.\nScale: %0.2f", s))
|
||||||
|
|
||||||
for i, f := range []ebiten.Filter{ebiten.FilterNearest, ebiten.FilterLinear} {
|
for i, f := range []ebiten.Filter{ebiten.FilterNearest, ebiten.FilterLinear} {
|
||||||
w, _ := gophersImage.Size()
|
w, h := gophersImage.Size()
|
||||||
|
|
||||||
op := &ebiten.DrawImageOptions{}
|
op := &ebiten.DrawImageOptions{}
|
||||||
|
if rotate {
|
||||||
|
op.GeoM.Translate(-float64(w)/2, -float64(h)/2)
|
||||||
|
op.GeoM.Rotate(float64(counter) / 300 * 2 * math.Pi)
|
||||||
|
op.GeoM.Translate(float64(w)/2, float64(h)/2)
|
||||||
|
}
|
||||||
op.GeoM.Scale(s, s)
|
op.GeoM.Scale(s, s)
|
||||||
op.GeoM.Translate(32+float64(i*w)*s+float64(i*4), 64)
|
op.GeoM.Translate(32+float64(i*w)*s+float64(i*4), 64)
|
||||||
op.Filter = f
|
op.Filter = f
|
||||||
|
Loading…
Reference in New Issue
Block a user