The most minimal, probably most lacking, but simple 2d drawing Go package
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Kasianov Nikolai Alekseevich a9901ed590 Initial commit 2 years ago
examples Initial commit 2 years ago
shapes Initial commit 2 years ago
.gitignore Initial commit 2 years ago
README.md Initial commit 2 years ago
d2d.go Initial commit 2 years ago
go.mod Initial commit 2 years ago

README.md

d2d - draw 2D

the most minimal, probably most lacking, but simple 2d drawing Go package

Example image

What can it do ?

Draw

  • Points
  • Lines
  • Rectangles (Filled and empty)
  • Circles (Filled and empty)

of any color that satisfies basic stdlib's color.Color interface

Installation

go get unbewohnte.su:3000/Unbewohnte/d2d - if it doesn't work, your best choice is to just download it manually or copy-paste the code into your project

Usage

The main part of the package - Canvas struct that is essentially just a wrapper to draw.Image. Though the drawing can be done via direct work with shapes, canvas comes with additional quality of life drawing functions such as Border, FillWhole, Grid, FloodFill.

Example

canvas := d2d.NewCanvas(1920, 1080)
canvas.FillWhole(color.RGBA{60, 180, 30, 255})
canvas.Border(5, color.Black)
canvas.DrawFilledCircle(shapes.NewCircle(image.Pt(500, 500), 80), color.Black)
canvas.DrawLine(shapes.NewLine(image.Pt(0, 0), image.Pt(1920, 1080)), color.Black)
canvas.DrawFilledTriangle(
    shapes.NewTriangle(
        image.Pt(900, 20),
        image.Pt(1400, 400),
        image.Pt(500, 300),
    ),
    color.Black,
)

err := canvas.SaveAsPNG("image.png")
if err != nil {
    panic(err)
}

License

MIT