Shapes

The hlg package provides functionality to create and render various shapes. These shapes include triangles, rectangles, circles, and lines. Each shape can be manipulated through transformations such as move, rotate, and scale.

1func Triangle(x1, y1, x2, y2, x3, y3 int, c color.Color) graphics.Shape 
2func Rectangle(x, y, width, height int, c color.Color) graphics.Shape 
3func Polygon(x, y int, width float32, sides int, c color.Color) graphics.Shape 
4func Circle(x, y int, radius float32, c color.Color) graphics.Shape 
5func Line(x1, y1, x2, y2 int, width float32, c color.Color) graphics.Shape 

Example Usage

 1package main
 2
 3import (
 4	"github.com/dfirebaugh/hlg"
 5	"golang.org/x/image/colornames"
 6)
 7
 8func main() {
 9	t := hlg.Triangle(0, 160, 120, 0, 240, 160, colornames.Green)
10	r := hlg.Rectangle(0, 0, 120, 60, colornames.Blue)
11	r2 := hlg.Rectangle(50, 50, 120, 60, colornames.Red)
12	c := hlg.Circle(120, 80, 20, colornames.Red)
13	l := hlg.Line(0, 0, 240, 160, 2, colornames.White)
14
15	c.SetColor(colornames.Purple)
16	c.Move(0, 0)
17
18	hlg.Run(nil, func() {
19		hlg.Clear(colornames.Skyblue)
20		t.Render()
21		r.Render()
22		c.Render()
23		l.Render()
24		r2.Render()
25		r2.Hide()
26	})
27}

Shape Interfaces

 1type Transformable interface {
 2	Move(screenX, screenY float32)
 3	Rotate(angle float32)
 4	Scale(sx, sy float32)
 5}
 6
 7type Renderable interface {
 8	Render()
 9	Dispose()
10	Hide()
11}
12
13type Shape interface {
14	Renderable
15	Transformable
16	SetColor(c color.Color)
17}