mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Change ColorMatrix's methods to functions
This commit is contained in:
parent
2c67a71a53
commit
6eaec92a4e
@ -81,6 +81,32 @@ func Monochrome() ColorMatrix {
|
||||
}
|
||||
}
|
||||
|
||||
// ScaleColor returns a color matrix that scales a color matrix by clr.
|
||||
func ScaleColor(clr color.Color) ColorMatrix {
|
||||
rf, gf, bf, af := rgba(clr)
|
||||
return ColorMatrix{
|
||||
[ColorMatrixDim - 1][ColorMatrixDim]float64{
|
||||
{rf, 0, 0, 0, 0},
|
||||
{0, gf, 0, 0, 0},
|
||||
{0, 0, bf, 0, 0},
|
||||
{0, 0, 0, af, 0},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// TranslateColor returns a color matrix that translates a color matrix by clr.
|
||||
func (c *ColorMatrix) Translate(clr color.Color) ColorMatrix {
|
||||
rf, gf, bf, af := rgba(clr)
|
||||
return ColorMatrix{
|
||||
[ColorMatrixDim - 1][ColorMatrixDim]float64{
|
||||
{1, 0, 0, 0, rf},
|
||||
{0, 1, 0, 0, gf},
|
||||
{0, 0, 1, 0, bf},
|
||||
{0, 0, 0, 1, af},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// RotateHue returns a color matrix to rotate the hue
|
||||
func RotateHue(theta float64) ColorMatrix {
|
||||
sin, cos := math.Sincos(theta)
|
||||
@ -106,22 +132,3 @@ func rgba(clr color.Color) (float64, float64, float64, float64) {
|
||||
af := float64(a) / float64(math.MaxUint16)
|
||||
return rf, gf, bf, af
|
||||
}
|
||||
|
||||
// Scale scales the color matrix by clr.
|
||||
func (c *ColorMatrix) Scale(clr color.Color) {
|
||||
rf, gf, bf, af := rgba(clr)
|
||||
for i, e := range []float64{rf, gf, bf, af} {
|
||||
for j := 0; j < 4; j++ {
|
||||
c.Elements[i][j] *= e
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Translate translates the color matrix by clr.
|
||||
func (c *ColorMatrix) Translate(clr color.Color) {
|
||||
rf, gf, bf, af := rgba(clr)
|
||||
c.Elements[0][4] = rf
|
||||
c.Elements[1][4] = gf
|
||||
c.Elements[2][4] = bf
|
||||
c.Elements[3][4] = af
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ func (d *debugPrintState) drawText(gr ebiten.GraphicsContext, str string, x, y i
|
||||
geom := ebiten.GeometryMatrixI()
|
||||
geom.Concat(ebiten.TranslateGeometry(float64(x)+1, float64(y)))
|
||||
clrm := ebiten.ColorMatrixI()
|
||||
clrm.Scale(clr)
|
||||
clrm.Concat(ebiten.ScaleColor(clr))
|
||||
gr.Texture(d.textTexture).Draw(parts, geom, clrm)
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ func drawText(context ebiten.GraphicsContext, textures *Textures, str string, x,
|
||||
geoMat.Concat(ebiten.ScaleGeometry(float64(scale), float64(scale)))
|
||||
geoMat.Concat(ebiten.TranslateGeometry(float64(x), float64(y)))
|
||||
clrMat := ebiten.ColorMatrixI()
|
||||
clrMat.Scale(clr)
|
||||
clrMat.Concat(ebiten.ScaleColor(clr))
|
||||
context.Texture(fontTextureId).Draw(parts, geoMat, clrMat)
|
||||
}
|
||||
|
||||
|
@ -119,7 +119,7 @@ func (s *GameScene) Draw(context ebiten.GraphicsContext, textures *Textures) {
|
||||
geoMat.Concat(ebiten.ScaleGeometry(float64(fieldWidth)/float64(emptyWidth), float64(fieldHeight)/float64(emptyHeight)))
|
||||
geoMat.Concat(ebiten.TranslateGeometry(20, 20)) // TODO: magic number?
|
||||
colorMat := ebiten.ColorMatrixI()
|
||||
colorMat.Scale(color.RGBA{0, 0, 0, 0x80})
|
||||
colorMat.Concat(ebiten.ScaleColor(color.RGBA{0, 0, 0, 0x80}))
|
||||
ebiten.DrawWhole(context.Texture(field), emptyWidth, emptyHeight, geoMat, colorMat)
|
||||
|
||||
geoMat = ebiten.GeometryMatrixI()
|
||||
|
@ -57,7 +57,7 @@ func (g *Game) Draw(gr ebiten.GraphicsContext) error {
|
||||
geo := ebiten.GeometryMatrixI()
|
||||
geo.Concat(ebiten.TranslateGeometry(float64(mx), float64(my)))
|
||||
clr := ebiten.ColorMatrixI()
|
||||
clr.Scale(color.RGBA{0xff, 0xff, 0x00, 0xff})
|
||||
clr.Concat(ebiten.ScaleColor(color.RGBA{0xff, 0xff, 0x00, 0xff}))
|
||||
theta := 2.0 * math.Pi * float64(g.count%60) / 60.0
|
||||
clr.Concat(ebiten.RotateHue(theta))
|
||||
ebiten.DrawWhole(gr.RenderTarget(g.brushRenderTarget), 1, 1, geo, clr)
|
||||
|
Loading…
Reference in New Issue
Block a user