mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
Add RotateHue
This commit is contained in:
parent
d25d5f39b0
commit
d5f8e79c88
@ -68,9 +68,9 @@ func (c *ColorMatrix) setElement(i, j int, element float64) {
|
|||||||
|
|
||||||
// Monochrome returns a color matrix to make an image monochrome.
|
// Monochrome returns a color matrix to make an image monochrome.
|
||||||
func Monochrome() ColorMatrix {
|
func Monochrome() ColorMatrix {
|
||||||
const r float64 = 6968.0 / 32768.0
|
const r = 6968.0 / 32768.0
|
||||||
const g float64 = 23434.0 / 32768.0
|
const g = 23434.0 / 32768.0
|
||||||
const b float64 = 2366.0 / 32768.0
|
const b = 2366.0 / 32768.0
|
||||||
return ColorMatrix{
|
return ColorMatrix{
|
||||||
[ColorMatrixDim - 1][ColorMatrixDim]float64{
|
[ColorMatrixDim - 1][ColorMatrixDim]float64{
|
||||||
{r, g, b, 0, 0},
|
{r, g, b, 0, 0},
|
||||||
@ -81,6 +81,23 @@ func Monochrome() ColorMatrix {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RotateHue returns a color matrix to rotate the hue
|
||||||
|
func RotateHue(theta float64) ColorMatrix {
|
||||||
|
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
|
||||||
|
// TODO: Need to clamp the values between 0 and 1?
|
||||||
|
return ColorMatrix{
|
||||||
|
[ColorMatrixDim - 1][ColorMatrixDim]float64{
|
||||||
|
{v1, v2, v3, 0, 0},
|
||||||
|
{v3, v1, v2, 0, 0},
|
||||||
|
{v2, v3, v1, 0, 0},
|
||||||
|
{0, 0, 0, 1, 0},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func rgba(clr color.Color) (float64, float64, float64, float64) {
|
func rgba(clr color.Color) (float64, float64, float64, float64) {
|
||||||
r, g, b, a := clr.RGBA()
|
r, g, b, a := clr.RGBA()
|
||||||
rf := float64(r) / float64(math.MaxUint16)
|
rf := float64(r) / float64(math.MaxUint16)
|
||||||
|
@ -4,7 +4,9 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/hajimehoshi/ebiten"
|
"github.com/hajimehoshi/ebiten"
|
||||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||||
|
"image/color"
|
||||||
"log"
|
"log"
|
||||||
|
"math"
|
||||||
"runtime"
|
"runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -14,11 +16,15 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Game struct {
|
type Game struct {
|
||||||
|
count int
|
||||||
brushRenderTarget ebiten.RenderTargetID
|
brushRenderTarget ebiten.RenderTargetID
|
||||||
canvasRenderTarget ebiten.RenderTargetID
|
canvasRenderTarget ebiten.RenderTargetID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Game) Update() error {
|
func (g *Game) Update() error {
|
||||||
|
if ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) {
|
||||||
|
g.count++
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,7 +37,7 @@ func (g *Game) Draw(gr ebiten.GraphicsContext) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gr.PushRenderTarget(g.brushRenderTarget)
|
gr.PushRenderTarget(g.brushRenderTarget)
|
||||||
gr.Fill(0, 0, 0)
|
gr.Fill(0xff, 0xff, 0xff)
|
||||||
gr.PopRenderTarget()
|
gr.PopRenderTarget()
|
||||||
}
|
}
|
||||||
if g.canvasRenderTarget.IsNil() {
|
if g.canvasRenderTarget.IsNil() {
|
||||||
@ -50,7 +56,11 @@ func (g *Game) Draw(gr ebiten.GraphicsContext) error {
|
|||||||
gr.PushRenderTarget(g.canvasRenderTarget)
|
gr.PushRenderTarget(g.canvasRenderTarget)
|
||||||
geo := ebiten.GeometryMatrixI()
|
geo := ebiten.GeometryMatrixI()
|
||||||
geo.Translate(float64(mx), float64(my))
|
geo.Translate(float64(mx), float64(my))
|
||||||
ebiten.DrawWhole(gr.RenderTarget(g.brushRenderTarget), 1, 1, geo, ebiten.ColorMatrixI())
|
clr := ebiten.ColorMatrixI()
|
||||||
|
clr.Scale(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)
|
||||||
gr.PopRenderTarget()
|
gr.PopRenderTarget()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user