canvas

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 26, 2024 License: BSD-2-Clause Imports: 16 Imported by: 0

Documentation

Overview

Example (Canvas_Circ)
package main

import (
	"fmt"
	"image"
	"image/color"

	"github.com/lucasepe/doodlekit/internal/canvas"
)

func main() {
	pal := color.Palette{
		color.NRGBA{0x00, 0x00, 0x00, 0x00},
		color.NRGBA{0x00, 0x00, 0x00, 0xFF},
		color.NRGBA{0xFF, 0xFF, 0xFF, 0xFF},
	}

	dst := image.NewPaletted(image.Rect(0, 0, 9, 9), pal)

	gc := canvas.New(dst)
	gc.Translate(4, 4)

	gc.Cls(0)
	gc.Color(1)
	gc.Circ(0, 0, 2)

	gc.Identity()

	for y := 0; y < dst.Bounds().Dy(); y++ {
		for x := 0; x < dst.Bounds().Dx(); x++ {
			if dst.ColorIndexAt(x, y) == 1 {
				fmt.Print("▓▓")
			} else {
				fmt.Print("░░")
			}
		}
		fmt.Println()
	}

}
Output:

░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░
░░░░░░▓▓▓▓▓▓░░░░░░
░░░░▓▓░░░░░░▓▓░░░░
░░░░▓▓░░░░░░▓▓░░░░
░░░░▓▓░░░░░░▓▓░░░░
░░░░░░▓▓▓▓▓▓░░░░░░
░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░
Example (Canvas_CircFill)
package main

import (
	"fmt"
	"image"
	"image/color"

	"github.com/lucasepe/doodlekit/internal/canvas"
)

func main() {
	pal := color.Palette{
		color.NRGBA{0x00, 0x00, 0x00, 0x00},
		color.NRGBA{0x00, 0x00, 0x00, 0xFF},
		color.NRGBA{0xFF, 0xFF, 0xFF, 0xFF},
	}

	dst := image.NewPaletted(image.Rect(0, 0, 9, 9), pal)

	gc := canvas.New(dst)
	gc.Cls(0)

	gc.Translate(4, 4)

	gc.Color(1)
	gc.CircFill(0, 0, 2)

	gc.Identity()

	for y := 0; y < dst.Bounds().Dy(); y++ {
		for x := 0; x < dst.Bounds().Dx(); x++ {
			if dst.ColorIndexAt(x, y) == 1 {
				fmt.Print("▓▓")
			} else {
				fmt.Print("░░")
			}
		}
		fmt.Println()
	}

}
Output:

░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░
░░░░░░▓▓▓▓▓▓░░░░░░
░░░░▓▓▓▓▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓▓▓▓▓░░░░
░░░░░░▓▓▓▓▓▓░░░░░░
░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░
Example (Canvas_GlyphBounds)
package main

import (
	"fmt"
	"os"

	"github.com/lucasepe/doodlekit/internal/canvas"
	"github.com/lucasepe/doodlekit/internal/fonts"
)

func main() {
	r := rune('A')

	face := canvas.MustLoadFont(fonts.Micro()).NewFace()

	bounds, advance, ok := face.GlyphBounds(r)
	if !ok {
		fmt.Fprintf(os.Stderr, "the face does not contain a glyph for '%v'", r)
		return
	}

	w := canvas.UnfixI(bounds.Max.X) - canvas.UnfixI(bounds.Min.X)
	h := canvas.UnfixI(bounds.Max.Y) - canvas.UnfixI(bounds.Min.Y)
	fmt.Printf("GlyphBounds: %dx%d\n", w, h)
	fmt.Printf("Advance: %v\n", canvas.UnfixI(advance))

}
Output:


	GlyphBounds: 4x5
Advance: 4
Example (Canvas_Line)
package main

import (
	"fmt"
	"image"
	"image/color"

	"github.com/lucasepe/doodlekit/internal/canvas"
)

func main() {
	pal := color.Palette{
		color.NRGBA{0x00, 0x00, 0x00, 0x00},
		color.NRGBA{0x00, 0x00, 0x00, 0xFF},
		color.NRGBA{0xFF, 0xFF, 0xFF, 0xFF},
	}

	dst := image.NewPaletted(image.Rect(0, 0, 8, 8), pal)

	gc := canvas.New(dst)
	gc.Cls(0)

	gc.Color(1)

	gc.Line(1, 1, 6, 6)

	for y := 0; y < dst.Bounds().Dy(); y++ {
		for x := 0; x < dst.Bounds().Dx(); x++ {
			if dst.ColorIndexAt(x, y) == 1 {
				fmt.Print("▓▓")
			} else {
				fmt.Print("░░")
			}
		}
		fmt.Println()
	}

}
Output:

░░░░░░░░░░░░░░░░
░░▓▓░░░░░░░░░░░░
░░░░▓▓░░░░░░░░░░
░░░░░░▓▓░░░░░░░░
░░░░░░░░▓▓░░░░░░
░░░░░░░░░░▓▓░░░░
░░░░░░░░░░░░▓▓░░
░░░░░░░░░░░░░░░░
Example (Canvas_Line_H)
package main

import (
	"fmt"
	"image"
	"image/color"

	"github.com/lucasepe/doodlekit/internal/canvas"
)

func main() {
	pal := color.Palette{
		color.NRGBA{0x00, 0x00, 0x00, 0x00},
		color.NRGBA{0x00, 0x00, 0x00, 0xFF},
		color.NRGBA{0xFF, 0xFF, 0xFF, 0xFF},
	}

	dst := image.NewPaletted(image.Rect(0, 0, 8, 3), pal)

	gc := canvas.New(dst)
	gc.Cls(0)

	gc.Color(1)
	gc.Line(1, 1, 6, 1)

	for y := 0; y < dst.Bounds().Dy(); y++ {
		for x := 0; x < dst.Bounds().Dx(); x++ {
			if dst.ColorIndexAt(x, y) == 1 {
				fmt.Print("▓▓")
			} else {
				fmt.Print("░░")
			}
		}
		fmt.Println()
	}

}
Output:

░░░░░░░░░░░░░░░░
░░▓▓▓▓▓▓▓▓▓▓▓▓░░
░░░░░░░░░░░░░░░░
Example (Canvas_Line_V)
package main

import (
	"fmt"
	"image"
	"image/color"

	"github.com/lucasepe/doodlekit/internal/canvas"
)

func main() {
	pal := color.Palette{
		color.NRGBA{0x00, 0x00, 0x00, 0x00},
		color.NRGBA{0x00, 0x00, 0x00, 0xFF},
		color.NRGBA{0xFF, 0xFF, 0xFF, 0xFF},
	}

	dst := image.NewPaletted(image.Rect(0, 0, 3, 8), pal)

	gc := canvas.New(dst)
	gc.Cls(0)

	gc.Color(1)
	gc.Line(1, 1, 1, 6)

	for y := 0; y < dst.Bounds().Dy(); y++ {
		for x := 0; x < dst.Bounds().Dx(); x++ {
			if dst.ColorIndexAt(x, y) == 1 {
				fmt.Print("▓▓")
			} else {
				fmt.Print("░░")
			}
		}
		fmt.Println()
	}

}
Output:

░░░░░░
░░▓▓░░
░░▓▓░░
░░▓▓░░
░░▓▓░░
░░▓▓░░
░░▓▓░░
░░░░░░
Example (Canvas_MustLoadFont)
package main

import (
	"fmt"

	"github.com/lucasepe/doodlekit/internal/canvas"
	"github.com/lucasepe/doodlekit/internal/fonts"
)

func main() {
	fnt := canvas.MustLoadFont(fonts.Micro())

	fmt.Printf("Name: %s\n", fnt.Name)
	fmt.Printf("Size: %d\n", fnt.Size)

}
Output:


Name: micro
Size: -1
Example (Canvas_Print)
package main

import (
	"fmt"
	"image"
	"image/color"

	"github.com/lucasepe/doodlekit/internal/canvas"
)

func main() {
	pal := color.Palette{
		color.NRGBA{0x00, 0x00, 0x00, 0x00},
		color.NRGBA{0x00, 0x00, 0x00, 0xFF},
		color.NRGBA{0xFF, 0xFF, 0xFF, 0xFF},
	}

	out := image.NewPaletted(image.Rect(0, 0, 21, 5), pal)

	gc := canvas.New(out)
	gc.Cls(1)

	gc.Color(2)
	gc.Print("Hello!", 1, 0)

	// //gc.Color(7)
	// //gc.Rect(0, 0, 3, 4)
	// gc.Save("before.gif")
	// letH := gc.Smake(0, 0, 3, 5, 12, 15)
	// gc.Reset()

	// gc.Cls(1)
	// gc.Translate(float64(gc.Width())*0.5, float64(gc.Height())*0.5)
	// gc.Rotate(0.785398)
	// gc.Sput(letH, 0, 0, 0.5, 0.5)
	// //gc.Record()
	// gc.Save("after.gif")

	for y := 0; y < out.Bounds().Dy(); y++ {
		for x := 0; x < out.Bounds().Dx(); x++ {
			if out.ColorIndexAt(x, y) == 2 {
				fmt.Print("▓▓")
			} else {
				fmt.Print("░░")
			}
		}
		fmt.Println()
	}

}
Output:

░░▓▓░░▓▓░░░░░░░░░░▓▓▓▓░░░░▓▓▓▓░░░░░░░░░░░░
░░▓▓░░▓▓░░▓▓▓▓▓▓░░░░▓▓░░░░░░▓▓░░░░▓▓▓▓▓▓░░
░░▓▓▓▓▓▓░░▓▓░░▓▓░░░░▓▓░░░░░░▓▓░░░░▓▓░░▓▓░░
░░▓▓░░▓▓░░▓▓▓▓░░░░░░▓▓░░░░░░▓▓░░░░▓▓░░▓▓░░
░░▓▓░░▓▓░░▓▓▓▓▓▓░░░░▓▓░░░░░░▓▓░░░░▓▓▓▓▓▓░░
Example (Canvas_Smake)
package main

import (
	"fmt"
	"image"
	"image/color"

	"github.com/lucasepe/doodlekit/internal/canvas"
)

func main() {
	pal := color.Palette{
		color.NRGBA{0x00, 0x00, 0x00, 0x00},
		color.NRGBA{0x00, 0x00, 0x00, 0xFF},
		color.NRGBA{0xFF, 0xFF, 0xFF, 0xFF},
	}

	out := image.NewPaletted(image.Rect(0, 0, 16, 10), pal)

	gc := canvas.New(out)
	gc.Cls(1)

	gc.Color(2)
	gc.Print("Hi!", 0, 0)

	out = gc.Smake(0, 0, 3, 5, 9, 10)

	for y := 0; y < out.Bounds().Dy(); y++ {
		for x := 0; x < out.Bounds().Dx(); x++ {
			if out.ColorIndexAt(x, y) == 2 {
				fmt.Print("▓▓")
			} else {
				fmt.Print("░░")
			}
		}
		fmt.Println()
	}

}
Output:

▓▓▓▓▓▓░░░░░░▓▓▓▓▓▓
▓▓▓▓▓▓░░░░░░▓▓▓▓▓▓
▓▓▓▓▓▓░░░░░░▓▓▓▓▓▓
▓▓▓▓▓▓░░░░░░▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
▓▓▓▓▓▓░░░░░░▓▓▓▓▓▓
▓▓▓▓▓▓░░░░░░▓▓▓▓▓▓
▓▓▓▓▓▓░░░░░░▓▓▓▓▓▓
▓▓▓▓▓▓░░░░░░▓▓▓▓▓▓
Example (Canvas_Sput)
package main

import (
	"fmt"
	"image"
	"image/color"

	"github.com/lucasepe/doodlekit/internal/canvas"
)

func main() {
	pal := color.Palette{
		color.NRGBA{0x00, 0x00, 0x00, 0x00},
		color.NRGBA{0x00, 0x00, 0x00, 0xFF},
		color.NRGBA{0xFF, 0xFF, 0xFF, 0xFF},
	}

	out := image.NewPaletted(image.Rect(0, 0, 22, 12), pal)

	gc := canvas.New(out)
	gc.Cls(1)

	gc.Color(2)
	gc.Print("Hi!", 0, 0)

	letH := gc.Smake(0, 0, 3, 5, 15, 10)
	gc.Cls(1)

	gc.Translate(10, 6)
	gc.Sput(letH, 0, 0, 0.5, 0.5)

	for y := 0; y < out.Bounds().Dy(); y++ {
		for x := 0; x < out.Bounds().Dx(); x++ {
			if out.ColorIndexAt(x, y) == 2 {
				fmt.Print("▓▓")
			} else {
				fmt.Print("░░")
			}
		}
		fmt.Println()
	}

}
Output:

░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░▓▓▓▓▓▓▓▓▓▓░░░░░░░░
░░░░░░▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░▓▓▓▓▓▓▓▓▓▓░░░░░░░░
░░░░░░▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░▓▓▓▓▓▓▓▓▓▓░░░░░░░░
░░░░░░▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░▓▓▓▓▓▓▓▓▓▓░░░░░░░░
░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░
░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░
░░░░░░▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░▓▓▓▓▓▓▓▓▓▓░░░░░░░░
░░░░░░▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░▓▓▓▓▓▓▓▓▓▓░░░░░░░░
░░░░░░▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░▓▓▓▓▓▓▓▓▓▓░░░░░░░░
░░░░░░▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░▓▓▓▓▓▓▓▓▓▓░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Example (Gfx_Rect)
package main

import (
	"fmt"
	"image"
	"image/color"

	"github.com/lucasepe/doodlekit/internal/canvas"
)

func main() {
	pal := color.Palette{
		color.NRGBA{0x00, 0x00, 0x00, 0x00},
		color.NRGBA{0x00, 0x00, 0x00, 0xFF},
		color.NRGBA{0xFF, 0xFF, 0xFF, 0xFF},
	}

	dst := image.NewPaletted(image.Rect(0, 0, 9, 11), pal)

	gc := canvas.New(dst)
	gc.Cls(0)

	gc.Translate(4, 5)

	gc.Color(1)
	gc.Rect(-2, -4, 4, 8)
	gc.Identity()

	for y := 0; y < dst.Bounds().Dy(); y++ {
		for x := 0; x < dst.Bounds().Dx(); x++ {
			if dst.ColorIndexAt(x, y) == 1 {
				fmt.Print("▓▓")
			} else {
				fmt.Print("░░")
			}
		}
		fmt.Println()
	}

}
Output:

░░░░░░░░░░░░░░░░░░
░░░░▓▓▓▓▓▓▓▓▓▓░░░░
░░░░▓▓░░░░░░▓▓░░░░
░░░░▓▓░░░░░░▓▓░░░░
░░░░▓▓░░░░░░▓▓░░░░
░░░░▓▓░░░░░░▓▓░░░░
░░░░▓▓░░░░░░▓▓░░░░
░░░░▓▓░░░░░░▓▓░░░░
░░░░▓▓░░░░░░▓▓░░░░
░░░░▓▓▓▓▓▓▓▓▓▓░░░░
░░░░░░░░░░░░░░░░░░
Example (Gfx_RectFill)
package main

import (
	"fmt"
	"image"
	"image/color"

	"github.com/lucasepe/doodlekit/internal/canvas"
)

func main() {
	pal := color.Palette{
		color.NRGBA{0x00, 0x00, 0x00, 0x00},
		color.NRGBA{0x00, 0x00, 0x00, 0xFF},
		color.NRGBA{0xFF, 0xFF, 0xFF, 0xFF},
	}

	dst := image.NewPaletted(image.Rect(0, 0, 9, 11), pal)

	gc := canvas.New(dst)
	gc.Cls(0)

	gc.Translate(4, 5)

	gc.Color(1)
	gc.RectFill(-2, -4, 4, 8)

	gc.Identity()

	for y := 0; y < dst.Bounds().Dy(); y++ {
		for x := 0; x < dst.Bounds().Dx(); x++ {
			if dst.ColorIndexAt(x, y) == 1 {
				fmt.Print("▓▓")
			} else {
				fmt.Print("░░")
			}
		}
		fmt.Println()
	}

}
Output:

░░░░░░░░░░░░░░░░░░
░░░░▓▓▓▓▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓▓▓▓▓░░░░
░░░░░░░░░░░░░░░░░░
Example (Gfx_Rect_2)
package main

import (
	"fmt"
	"image"
	"image/color"

	"github.com/lucasepe/doodlekit/internal/canvas"
)

func main() {
	pal := color.Palette{
		color.NRGBA{0x00, 0x00, 0x00, 0x00},
		color.NRGBA{0x00, 0x00, 0x00, 0xFF},
		color.NRGBA{0xFF, 0xFF, 0xFF, 0xFF},
	}

	dst := image.NewPaletted(image.Rect(0, 0, 11, 7), pal)

	gc := canvas.New(dst)
	gc.Cls(0)

	gc.Translate(5, 3)

	gc.Color(1)
	gc.Rect(-4, -2, 8, 4)

	gc.Identity()

	for y := 0; y < dst.Bounds().Dy(); y++ {
		for x := 0; x < dst.Bounds().Dx(); x++ {
			if dst.ColorIndexAt(x, y) == 1 {
				fmt.Print("▓▓")
			} else {
				fmt.Print("░░")
			}
		}
		fmt.Println()
	}

}
Output:

░░░░░░░░░░░░░░░░░░░░░░
░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░
░░▓▓░░░░░░░░░░░░░░▓▓░░
░░▓▓░░░░░░░░░░░░░░▓▓░░
░░▓▓░░░░░░░░░░░░░░▓▓░░
░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░
░░░░░░░░░░░░░░░░░░░░░░
Example (Gfx_RoundRect)
package main

import (
	"fmt"
	"image"
	"image/color"

	"github.com/lucasepe/doodlekit/internal/canvas"
)

func main() {
	pal := color.Palette{
		color.NRGBA{0x00, 0x00, 0x00, 0x00},
		color.NRGBA{0x00, 0x00, 0x00, 0xFF},
		color.NRGBA{0xFF, 0xFF, 0xFF, 0xFF},
	}

	dst := image.NewPaletted(image.Rect(0, 0, 17, 11), pal)

	gc := canvas.New(dst)
	gc.Cls(0)

	gc.Translate(8, 5)

	gc.Color(1)
	gc.RoundRect(-6, -4, 12, 8, 2)

	gc.Identity()

	for y := 0; y < dst.Bounds().Dy(); y++ {
		for x := 0; x < dst.Bounds().Dx(); x++ {
			if dst.ColorIndexAt(x, y) == 1 {
				fmt.Print("▓▓")
			} else {
				fmt.Print("░░")
			}
		}
		fmt.Println()
	}

}
Output:

░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░
░░░░░░▓▓░░░░░░░░░░░░░░░░░░▓▓░░░░░░
░░░░▓▓░░░░░░░░░░░░░░░░░░░░░░▓▓░░░░
░░░░▓▓░░░░░░░░░░░░░░░░░░░░░░▓▓░░░░
░░░░▓▓░░░░░░░░░░░░░░░░░░░░░░▓▓░░░░
░░░░▓▓░░░░░░░░░░░░░░░░░░░░░░▓▓░░░░
░░░░▓▓░░░░░░░░░░░░░░░░░░░░░░▓▓░░░░
░░░░░░▓▓░░░░░░░░░░░░░░░░░░▓▓░░░░░░
░░░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Example (Gfx_RoundRectFill)
package main

import (
	"fmt"
	"image"
	"image/color"

	"github.com/lucasepe/doodlekit/internal/canvas"
)

func main() {
	pal := color.Palette{
		color.NRGBA{0x00, 0x00, 0x00, 0x00},
		color.NRGBA{0x00, 0x00, 0x00, 0xFF},
		color.NRGBA{0xFF, 0xFF, 0xFF, 0xFF},
	}

	dst := image.NewPaletted(image.Rect(0, 0, 17, 11), pal)

	gc := canvas.New(dst)
	gc.Cls(0)

	gc.Translate(8, 5)

	gc.Color(1)
	gc.RoundRectFill(-6, -4, 12, 8, 2)

	gc.Identity()

	for y := 0; y < dst.Bounds().Dy(); y++ {
		for x := 0; x < dst.Bounds().Dx(); x++ {
			if dst.ColorIndexAt(x, y) == 1 {
				fmt.Print("▓▓")
			} else {
				fmt.Print("░░")
			}
		}
		fmt.Println()
	}

}
Output:

░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░
░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░
░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░
░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░
░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░
░░░░░░░░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Color

func Color(p color.Palette, n int) color.NRGBA

Color returns the color at index n.

func Fix added in v0.1.4

func Fix(x float64) fixed.Int26_6

func Unfix added in v0.1.4

func Unfix(x fixed.Int26_6) float64

func UnfixI added in v0.1.4

func UnfixI(x fixed.Int26_6) int

Types

type Align

type Align int
const (
	AlignLeft Align = iota
	AlignCenter
	AlignRight
)

type Canvas

type Canvas struct {
	// contains filtered or unexported fields
}

func New

func New(img *image.Paletted) *Canvas

func (*Canvas) At added in v0.1.2

func (ctx *Canvas) At(x, y int) int

func (*Canvas) Circ

func (ctx *Canvas) Circ(x0, y0, r int)

Circ draws a circle given a point and radius

func (*Canvas) CircFill

func (ctx *Canvas) CircFill(x, y, r int)

func (*Canvas) Cls

func (ctx *Canvas) Cls(idx int)

func (*Canvas) Color

func (ctx *Canvas) Color(idx int)

func (*Canvas) Height

func (ctx *Canvas) Height() int

func (*Canvas) Identity

func (dc *Canvas) Identity()

Identity resets the current transformation matrix to the identity matrix. This results in no translating, scaling, rotating, or shearing.

func (*Canvas) InvertY

func (dc *Canvas) InvertY()

InvertY flips the Y axis so that Y grows from bottom to top and Y=0 is at the bottom of the image.

func (*Canvas) Line

func (ctx *Canvas) Line(x1, y1, x2, y2 int)

Line draws a line between two points

func (*Canvas) MeasureString

func (ctx *Canvas) MeasureString(s string) (int, int)

func (*Canvas) Pix

func (ctx *Canvas) Pix(x, y int)

func (*Canvas) Print

func (ctx *Canvas) Print(s string, x, y int)

func (*Canvas) Record

func (ctx *Canvas) Record()

func (*Canvas) Rect

func (ctx *Canvas) Rect(x, y, w, h int)

(x1,y1) (x2,y1)

+----------------+
|                |
|                |
+----------------+

(x1,y2) (x2,y2)

func (*Canvas) RectFill

func (ctx *Canvas) RectFill(x, y, w, h int)

RectFill draws a filled rectangle given a point, width and height

func (*Canvas) Reset added in v0.2.0

func (ctx *Canvas) Reset()

func (*Canvas) Resize added in v0.2.0

func (ctx *Canvas) Resize(sf int)

func (*Canvas) Rotate

func (dc *Canvas) Rotate(angle float64)

Rotate updates the current matrix with a anticlockwise rotation. Rotation occurs about the origin. Angle is specified in radians.

func (*Canvas) RotateAbout

func (dc *Canvas) RotateAbout(angle, x, y float64)

RotateAbout updates the current matrix with a anticlockwise rotation. Rotation occurs about the specified point. Angle is specified in radians.

func (*Canvas) RoundRect

func (ctx *Canvas) RoundRect(x, y, w, h, r int)

func (*Canvas) RoundRectFill

func (ctx *Canvas) RoundRectFill(x, y, w, h, r int)

func (*Canvas) Save

func (ctx *Canvas) Save(fn string) error

func (*Canvas) Scale

func (dc *Canvas) Scale(x, y float64)

Scale updates the current matrix with a scaling factor. Scaling occurs about the origin.

func (*Canvas) ScaleAbout

func (dc *Canvas) ScaleAbout(sx, sy, x, y float64)

ScaleAbout updates the current matrix with a scaling factor. Scaling occurs about the specified point.

func (*Canvas) Shear

func (dc *Canvas) Shear(x, y float64)

Shear updates the current matrix with a shearing angle. Shearing occurs about the origin.

func (*Canvas) ShearAbout

func (dc *Canvas) ShearAbout(sx, sy, x, y float64)

ShearAbout updates the current matrix with a shearing angle. Shearing occurs about the specified point.

func (*Canvas) Smake added in v0.2.0

func (ctx *Canvas) Smake(cx, cy, cw, ch, sw, sh int) *image.Paletted

Smake creates a sprite from the specified rect on canvas. The sprits can be stretched if sw and/or sh are > 0.

cx: x coordinate of the upper left corner of the rectangle in the canvas. cy: y coordinate of the upper left corner of the rectangle in the canvas. cw: width of the rectangle in the canvas, as a number of pixels. ch: height of the rectangle in the canvas, as a number of pixels.

sw: width of the sprite. sh: height of sprite.

func (*Canvas) Sput added in v0.2.0

func (ctx *Canvas) Sput(im *image.Paletted, x, y int, ax, ay float64)

Sput draws the specified image at the specified anchor point. The anchor point is x - w * ax, y - h * ay, where w, h is the size of the image. Use ax=0.5, ay=0.5 to center the image at the specified point.

func (*Canvas) TransformPoint

func (dc *Canvas) TransformPoint(x, y float64) (tx, ty float64)

TransformPoint multiplies the specified point by the current matrix, returning a transformed position.

func (*Canvas) Translate

func (dc *Canvas) Translate(x, y float64)

Translate updates the current matrix with a translation.

func (*Canvas) Width

func (ctx *Canvas) Width() int

type Character

type Character struct {
	Name       string
	Encoding   rune
	Advance    [2]int
	Alpha      *image.Alpha
	LowerPoint [2]int
}

type Face

type Face struct {
	Font *Font
}

func (*Face) Close

func (f *Face) Close() error

func (*Face) Glyph

func (f *Face) Glyph(dot fixed.Point26_6, r rune) (dr image.Rectangle, mask image.Image, maskp image.Point, advance fixed.Int26_6, ok bool)

func (*Face) GlyphAdvance

func (f *Face) GlyphAdvance(r rune) (advance fixed.Int26_6, ok bool)

func (*Face) GlyphBounds

func (f *Face) GlyphBounds(r rune) (bounds fixed.Rectangle26_6, advance fixed.Int26_6, ok bool)

func (*Face) Kern

func (f *Face) Kern(_, _ rune) fixed.Int26_6

func (*Face) Metrics

func (f *Face) Metrics() font.Metrics

type Font

type Font struct {
	Name        string
	Size        int
	PixelSize   int
	DPI         [2]int
	BPP         int
	Ascent      int
	Descent     int
	CapHeight   int
	XHeight     int
	Characters  []Character
	CharMap     map[rune]*Character
	Encoding    string
	DefaultChar rune
}

func LoadFont

func LoadFont(data []byte) (*Font, error)

func MustLoadFont

func MustLoadFont(data []byte) *Font

func (*Font) NewFace

func (f *Font) NewFace() font.Face

type Matrix

type Matrix struct {
	XX, YX, XY, YY, X0, Y0 float64
}

func Identity

func Identity() Matrix

func Rotate

func Rotate(angle float64) Matrix

func Scale

func Scale(x, y float64) Matrix

func Shear

func Shear(x, y float64) Matrix

func Translate

func Translate(x, y float64) Matrix

func (Matrix) Multiply

func (a Matrix) Multiply(b Matrix) Matrix

func (Matrix) Rotate

func (a Matrix) Rotate(angle float64) Matrix

func (Matrix) Scale

func (a Matrix) Scale(x, y float64) Matrix

func (Matrix) Shear

func (a Matrix) Shear(x, y float64) Matrix

func (Matrix) TransformPoint

func (a Matrix) TransformPoint(x, y float64) (tx, ty float64)

func (Matrix) TransformVector

func (a Matrix) TransformVector(x, y float64) (tx, ty float64)

func (Matrix) Translate

func (a Matrix) Translate(x, y float64) Matrix

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL