commit d06cb9e2c73464976993c402e3df66082508af16 Author: Octopus Octopus Date: Wed Mar 6 16:57:31 2024 -0600 first commit diff --git a/Hack-Regular.ttf b/Hack-Regular.ttf new file mode 100644 index 0000000..92a90cb Binary files /dev/null and b/Hack-Regular.ttf differ diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..9d2bf5b --- /dev/null +++ b/go.mod @@ -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 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..58d18d5 --- /dev/null +++ b/go.sum @@ -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= diff --git a/hello.png b/hello.png new file mode 100644 index 0000000..0a7c2c6 Binary files /dev/null and b/hello.png differ diff --git a/main.go b/main.go new file mode 100644 index 0000000..2064a47 --- /dev/null +++ b/main.go @@ -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 +} diff --git a/map b/map new file mode 100755 index 0000000..da2a5a3 Binary files /dev/null and b/map differ