first commit

This commit is contained in:
Octopus Octopus 2024-03-06 16:57:31 -06:00
commit d06cb9e2c7
6 changed files with 52 additions and 0 deletions

BIN
Hack-Regular.ttf Normal file

Binary file not shown.

10
go.mod Normal file
View File

@ -0,0 +1,10 @@
module map
go 1.22.0
require github.com/fogleman/gg v1.3.0
require (
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
golang.org/x/image v0.14.0 // indirect
)

6
go.sum Normal file
View File

@ -0,0 +1,6 @@
github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8=
github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
golang.org/x/image v0.14.0 h1:tNgSxAFe3jC4uYqvZdTr84SZoM1KfwdC9SKIFrLjFn4=
golang.org/x/image v0.14.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE=

BIN
hello.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

36
main.go Normal file
View File

@ -0,0 +1,36 @@
package main
import (
"github.com/fogleman/gg"
)
func main() {
dc := drawBubble("Hello World!", 16)
dc.SavePNG("hello.png")
}
// drawBubble draws text with a bubble around it.
// content must be greater than 0.
func drawBubble(s string, pt float64) *gg.Context {
inch := 72.272 //1 inch is 72.272 (font) points. or 72 points. im getting conflicting information here.
px := inch / 96 //1 px is 1/96th of an inch. According to some random website.
padX, padY := 0.0, 0.0 // left in case I change my mind on absolute padding vs relative padding
size := float64(len(s)) * (px * pt) /* this was incorrect but it does make for a nice amount of padding per text.
It gets wider as you add more text. This is because the program should be cursed. */
x, y := size+padX, (pt*2)+padY
dc := gg.NewContext(int(x), int(y))
err := dc.LoadFontFace("./Hack-Regular.ttf", pt)
if err != nil {
print("lol")
}
dc.DrawRoundedRectangle(0, 0, x, y, 10)
dc.SetRGB(1, 1, 1)
dc.Fill()
dc.DrawRoundedRectangle(0, 0, x, y, 10)
dc.SetRGB(256, 256, 256)
dc.SetLineWidth(3)
dc.Stroke()
dc.DrawStringAnchored(s, x/2, y/2, 0.5, 0.5)
return dc
}

BIN
map Executable file

Binary file not shown.