bubble sizes now round up to the nearest multiple of 25.

This commit is contained in:
Octopus Octopus 2024-03-08 11:14:44 -06:00
parent d06cb9e2c7
commit 0799c916be
2 changed files with 15 additions and 3 deletions

18
main.go
View File

@ -15,22 +15,34 @@ 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. 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. 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 padX, padY := 0.0, 0.0 // left in case I change my mind on absolute padding vs relative padding
to := 25 // round up to the nearest 25th.
size := float64(len(s)) * (px * pt) /* this was incorrect but it does make for a nice amount of padding per text. 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. */ It gets wider as you add more text. This is because the program should be cursed. */
x, y := size+padX, (pt*2)+padY bx, by := size+padX, (pt*2)+padY // box x and box y
x, y := roundTo(bx, to), roundTo(by, to) //dc x and dc y
dc := gg.NewContext(int(x), int(y)) dc := gg.NewContext(int(x), int(y))
err := dc.LoadFontFace("./Hack-Regular.ttf", pt) err := dc.LoadFontFace("./Hack-Regular.ttf", pt)
if err != nil { if err != nil {
print("lol") print("lol")
} }
dc.DrawRoundedRectangle(0, 0, x, y, 10)
dc.DrawRoundedRectangle((x-bx)/2, (y-by)/2, bx, by, 10)
dc.SetRGB(1, 1, 1) dc.SetRGB(1, 1, 1)
dc.Fill() dc.Fill()
dc.DrawRoundedRectangle(0, 0, x, y, 10) dc.DrawRoundedRectangle((x-bx)/2, (y-by)/2, bx, by, 10)
dc.SetRGB(256, 256, 256) dc.SetRGB(256, 256, 256)
dc.SetLineWidth(3) dc.SetLineWidth(3)
dc.Stroke() dc.Stroke()
dc.DrawStringAnchored(s, x/2, y/2, 0.5, 0.5) dc.DrawStringAnchored(s, x/2, y/2, 0.5, 0.5)
return dc return dc
} }
// roundTo rounds base up to the next multiple of To.
func roundTo(base float64, To int) float64 {
i := int(base)
for i%To != 0 {
i++
}
return float64(i)
}

BIN
map

Binary file not shown.