From d1ff3701a61c116846b5199d4f819e86112d3b52 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 6 Feb 2016 23:56:02 +0900 Subject: [PATCH] image: Deprecate RotateHue --- colorm.go | 19 ++++++++++++++++++- example/hue/main.go | 2 +- example/paint/main.go | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/colorm.go b/colorm.go index 0a91c1f02..761a66389 100644 --- a/colorm.go +++ b/colorm.go @@ -101,6 +101,23 @@ func (c *ColorM) Translate(r, g, b, a float64) { c.es[3][4] += a } +// RotateHue rotates the hue. +func (c *ColorM) RotateHue(theta float64) { + sin, cos := math.Sincos(theta) + v1 := cos + (1.0-cos)/3.0 + v2 := (1.0/3.0)*(1.0-cos) - math.Sqrt(1.0/3.0)*sin + v3 := (1.0/3.0)*(1.0-cos) + math.Sqrt(1.0/3.0)*sin + c.Concat(ColorM{ + initialized: true, + es: [ColorMDim - 1][ColorMDim]float64{ + {v1, v2, v3, 0, 0}, + {v3, v1, v2, 0, 0}, + {v2, v3, v1, 0, 0}, + {0, 0, 0, 1, 0}, + }, + }) +} + // SetElement sets an element at (i, j). func (c *ColorM) SetElement(i, j int, element float64) { if !c.initialized { @@ -151,7 +168,7 @@ func TranslateColor(r, g, b, a float64) ColorM { } } -// RotateHue returns a color matrix to rotate the hue +// Deprecated as of 1.2.0-alpha. Use RotateHue member function instead. func RotateHue(theta float64) ColorM { sin, cos := math.Sincos(theta) v1 := cos + (1.0-cos)/3.0 diff --git a/example/hue/main.go b/example/hue/main.go index 017cf5028..d1049d6b7 100644 --- a/example/hue/main.go +++ b/example/hue/main.go @@ -37,7 +37,7 @@ func update(screen *ebiten.Image) error { w, h := gophersImage.Size() op := &ebiten.DrawImageOptions{} op.GeoM.Translate(float64(screenWidth-w)/2, float64(screenHeight-h)/2) - op.ColorM.Concat(ebiten.RotateHue(float64(count%360) * 2 * math.Pi / 360)) + op.ColorM.RotateHue(float64(count%360) * 2 * math.Pi / 360) if err := screen.DrawImage(gophersImage, op); err != nil { return err } diff --git a/example/paint/main.go b/example/paint/main.go index a1fb2c7d8..aa373d38a 100644 --- a/example/paint/main.go +++ b/example/paint/main.go @@ -47,7 +47,7 @@ func update(screen *ebiten.Image) error { op.GeoM.Translate(float64(mx), float64(my)) op.ColorM.Scale(1.0, 0.25, 0.25, 1.0) theta := 2.0 * math.Pi * float64(count%60) / 60.0 - op.ColorM.Concat(ebiten.RotateHue(theta)) + op.ColorM.RotateHue(theta) if err := canvasImage.DrawImage(brushImage, op); err != nil { return err }