examples/minify: Improve minifying demonstration

This commit is contained in:
Hajime Hoshi 2018-07-29 22:19:22 +09:00
parent 056ed1c6db
commit a321155ab5

View File

@ -21,6 +21,7 @@ package main
import ( import (
"bytes" "bytes"
"fmt"
"image" "image"
_ "image/jpeg" _ "image/jpeg"
"log" "log"
@ -32,35 +33,36 @@ import (
) )
const ( const (
screenWidth = 640 screenWidth = 800
screenHeight = 800 screenHeight = 480
) )
var ( var (
gophersImage *ebiten.Image gophersImage *ebiten.Image
counter = 0
) )
func update(screen *ebiten.Image) error { func update(screen *ebiten.Image) error {
counter++
if counter == 480 {
counter = 0
}
if ebiten.IsDrawingSkipped() { if ebiten.IsDrawingSkipped() {
return nil return nil
} }
ebitenutil.DebugPrint(screen, "Minifying images (Nearest filter vs Linear filter)") 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))
for i, f := range []ebiten.Filter{ebiten.FilterNearest, ebiten.FilterLinear} { for i, f := range []ebiten.Filter{ebiten.FilterNearest, ebiten.FilterLinear} {
y := 0 w, _ := gophersImage.Size()
for j := 0; j < 12; j++ {
w, h := gophersImage.Size()
op := &ebiten.DrawImageOptions{} op := &ebiten.DrawImageOptions{}
s := 1.0 / math.Pow(2, float64(j)/2)
op.GeoM.Scale(s, s) op.GeoM.Scale(s, s)
op.GeoM.Translate(32+float64(i*(w+4)), 32+float64(y)) op.GeoM.Translate(32+float64(i*w)*s+float64(i*4), 64)
op.Filter = f op.Filter = f
screen.DrawImage(gophersImage, op) screen.DrawImage(gophersImage, op)
y += int(float64(h)*s) + 4
}
} }
return nil return nil