In the example given in the meme.go demonstration for text with stroke width, the code inefficiently loops in an O(n^2) loop.
|
n := 6 // "stroke" size |
|
for dy := -n; dy <= n; dy++ { |
|
for dx := -n; dx <= n; dx++ { |
|
if dx*dx+dy*dy >= n*n { |
|
// give it rounded corners |
|
continue |
|
} |
|
x := S/2 + float64(dx) |
|
y := S/2 + float64(dy) |
|
dc.DrawStringAnchored(s, x, y, 0.5, 0.5) |
|
} |
|
} |
In this case, when n=6, the maximum iterations that this could use is (6*2)^2 = 144 calls to DrawStringAnchored! This is wildly inefficient and requires a lot of CPU power.
I am wondering if there is an alternative and less intensive way to create a similar text stroke effect, or if such a function could be added. Thanks!
In the example given in the meme.go demonstration for text with stroke width, the code inefficiently loops in an O(n^2) loop.
gg/examples/meme.go
Lines 15 to 26 in 8febc0f
In this case, when n=6, the maximum iterations that this could use is (6*2)^2 = 144 calls to
DrawStringAnchored! This is wildly inefficient and requires a lot of CPU power.I am wondering if there is an alternative and less intensive way to create a similar text stroke effect, or if such a function could be added. Thanks!