examples/hsv, examples/hue: Use wider screens

This commit is contained in:
Hajime Hoshi 2021-04-17 22:10:14 +09:00
parent c950e03fb1
commit ed4dded094
2 changed files with 12 additions and 8 deletions

View File

@ -31,8 +31,8 @@ import (
) )
const ( const (
screenWidth = 320 screenWidth = 640
screenHeight = 240 screenHeight = 480
) )
var ( var (
@ -103,7 +103,9 @@ func (g *Game) Draw(screen *ebiten.Image) {
// Center the image on the screen. // Center the image on the screen.
w, h := gophersImage.Size() w, h := gophersImage.Size()
op := &ebiten.DrawImageOptions{} op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(float64(screenWidth-w)/2, float64(screenHeight-h)/2) op.GeoM.Translate(-float64(w)/2, -float64(h)/2)
op.GeoM.Scale(2, 2)
op.GeoM.Translate(float64(screenWidth)/2, float64(screenHeight)/2)
// Change HSV. // Change HSV.
hue := float64(g.hue128) * 2 * math.Pi / 128 hue := float64(g.hue128) * 2 * math.Pi / 128
@ -151,7 +153,7 @@ func main() {
} }
gophersImage = ebiten.NewImageFromImage(img) gophersImage = ebiten.NewImageFromImage(img)
ebiten.SetWindowSize(screenWidth*2, screenHeight*2) ebiten.SetWindowSize(screenWidth, screenHeight)
ebiten.SetWindowTitle("HSV (Ebiten Demo)") ebiten.SetWindowTitle("HSV (Ebiten Demo)")
if err := ebiten.RunGame(NewGame()); err != nil { if err := ebiten.RunGame(NewGame()); err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -28,8 +28,8 @@ import (
) )
const ( const (
screenWidth = 320 screenWidth = 640
screenHeight = 240 screenHeight = 480
) )
var ( var (
@ -49,7 +49,9 @@ func (g *Game) Draw(screen *ebiten.Image) {
// Center the image on the screen. // Center the image on the screen.
w, h := gophersImage.Size() w, h := gophersImage.Size()
op := &ebiten.DrawImageOptions{} op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(float64(screenWidth-w)/2, float64(screenHeight-h)/2) op.GeoM.Translate(-float64(w)/2, -float64(h)/2)
op.GeoM.Scale(2, 2)
op.GeoM.Translate(float64(screenWidth)/2, float64(screenHeight)/2)
// Rotate the hue. // Rotate the hue.
op.ColorM.RotateHue(float64(g.count%360) * 2 * math.Pi / 360) op.ColorM.RotateHue(float64(g.count%360) * 2 * math.Pi / 360)
@ -77,7 +79,7 @@ func main() {
} }
gophersImage = ebiten.NewImageFromImage(img) gophersImage = ebiten.NewImageFromImage(img)
ebiten.SetWindowSize(screenWidth*2, screenHeight*2) ebiten.SetWindowSize(screenWidth, screenHeight)
ebiten.SetWindowTitle("Hue (Ebiten Demo)") ebiten.SetWindowTitle("Hue (Ebiten Demo)")
if err := ebiten.RunGame(&Game{}); err != nil { if err := ebiten.RunGame(&Game{}); err != nil {
log.Fatal(err) log.Fatal(err)