From 9cdbd3a1d057e994c26870efe78a19338b4a50da Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 13 Oct 2018 00:10:41 +0900 Subject: [PATCH] Updated Cheat Sheet (markdown) --- Cheat-Sheet.md | 90 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 76 insertions(+), 14 deletions(-) diff --git a/Cheat-Sheet.md b/Cheat-Sheet.md index 17fdeee..408a9b2 100644 --- a/Cheat-Sheet.md +++ b/Cheat-Sheet.md @@ -96,8 +96,8 @@ When the given image is as same as `i`, DrawImage panics. `DrawImage` works more efficiently as batches when the successive calls of DrawImages satisfies the below conditions: -* All render targets are same (A in A.DrawImage(B, op)) -* All render sources are same (B in A.DrawImage(B, op)) +* All render targets are same (`A` in `A.DrawImage(B, op)`) +* All render sources are same (`B` in `A.DrawImage(B, op)`) * This is not a strong request since different images might share a same inner OpenGL texture in high possibility. This is not 100%, so using the same render source is safer. @@ -115,18 +115,6 @@ For more performance tips, see [[Performance Tips]]. type DrawImageOptions struct { // SourceRect is the region of the source image to draw. // If SourceRect is nil, whole image is used. - // - // It is assured that texels out of the SourceRect are never used. - // - // Calling DrawImage copies the content of SourceRect pointer. This means that - // even if the SourceRect value is modified after passed to DrawImage, - // the result of DrawImage doen't change. - // - // op := &ebiten.DrawImageOptions{} - // r := image.Rect(0, 0, 100, 100) - // op.SourceRect = &r - // dst.DrawImage(src, op) - // r.Min.X = 10 // This doesn't affect the previous DrawImage. SourceRect *image.Rectangle // GeoM is a geometry matrix to draw. @@ -169,3 +157,77 @@ const ( FilterLinear Filter = Filter(graphics.FilterLinear) ) ``` + +## `ebiten.GeoM` + +```go +type GeoM struct { + // contains filtered or unexported fields +} +``` + +`GeoM` represents a matrix to transform geometry when rendering an image. + +The initial value is identity. + +### `(*ebiten.GeoM).Translate` + +```go +func (g *GeoM) Translate(tx, ty float64) +``` + +`Translate` translates the matrix by (`tx`, `ty`). + +### `(*ebiten.GeoM).Scale` + +```go +func (g *GeoM) Scale(x, y float64) +``` + +`Scale` scales the matrix by (`x`, `y`). + +### `(*ebiten.GeoM).Rotate` + +```go +func (g *GeoM) Rotate(theta float64) +``` + +`Rotate` rotates the matrix by `theta`. The unit is radian. + +## `ebiten.ColorM` + +```go +type ColorM struct { + // contains filtered or unexported fields +} +``` + +`ColorM` represents a matrix to transform coloring when rendering an image. + +`ColorM` is applied to the straight alpha color while an Image's pixels' format is alpha premultiplied. Before applying a matrix, a color is un-multiplied, and after applying the matrix, the color is multiplied again. + +The initial value is identity. + +### `(*ebiten.ColorM).Scale` + +```go +func (c *ColorM) Scale(r, g, b, a float64) +``` + +`Scale` scales the matrix by (`r`, `g`, `b`, `a`). + +### `(*ebiten.ColorM).Translate` + +```go +func (c *ColorM) Translate(r, g, b, a float64) +``` + +`Translate` translates the matrix by (`r`, `g`, `b`, `a`). + +### `(*ebiten.ColorM).ChangeHSV` + +```go +func (c *ColorM) ChangeHSV(hueTheta float64, saturationScale float64, valueScale float64) +``` + +`ChangeHSV` changes HSV (Hue-Saturation-Value) values. `hueTheta` is a radian value to rotate hue. `saturationScale` is a value to scale saturation. `valueScale` is a value to scale value (a.k.a. brightness).