package main
import (
"image"
"image/color"
"image/draw"
"log"
"golang.org/x/exp/shiny/driver"
"golang.org/x/exp/shiny/screen"
"golang.org/x/exp/shiny/widget"
"golang.org/x/image/math/fixed"
"github.com/srwiley/rasterx"
)
const (
S = 512
)
func main() {
log.SetFlags(0)
driver.Main(func(s screen.Screen) {
src := TestMultiFunctionGV() // image.NewRGBA(image.Rect(0, 0, sw, sh))
w := widget.NewSheet(widget.NewImage(src, src.Bounds()))
if err := widget.RunWindow(s, w, &widget.RunWindowOptions{
NewWindowOptions: screen.NewWindowOptions{
Title: "Rasterx Example",
Width: S,
Height: S,
},
}); err != nil {
log.Fatal(err)
}
})
}
//////////////////////////////////////////////////////
func toFixedP(x, y float64) (p fixed.Point26_6) {
p.X = fixed.Int26_6(x * 64)
p.Y = fixed.Int26_6(y * 64)
return
}
func GetTestPath() (testPath rasterx.Path) {
//Path for Q
//M210.08,222.97
testPath.Start(toFixedP(210.08, 222.97))
//L192.55,244.95
testPath.Line(toFixedP(192.55, 244.95))
//Q146.53,229.95,115.55,209.55
testPath.QuadBezier(toFixedP(146.53, 229.95), toFixedP(115.55, 209.55))
//Q102.50,211.00,95.38,211.00
testPath.QuadBezier(toFixedP(102.50, 211.00), toFixedP(95.38, 211.00))
//Q56.09,211.00,31.17,182.33
testPath.QuadBezier(toFixedP(56.09, 211.00), toFixedP(31.17, 182.33))
//Q6.27,153.66,6.27,108.44
testPath.QuadBezier(toFixedP(6.27, 153.66), toFixedP(6.27, 108.44))
//Q6.27,61.89,31.44,33.94
testPath.QuadBezier(toFixedP(6.27, 61.89), toFixedP(31.44, 33.94))
//Q56.62,6.00,98.55,6.00
testPath.QuadBezier(toFixedP(56.62, 6.00), toFixedP(98.55, 6.00))
//Q141.27,6.00,166.64,33.88
testPath.QuadBezier(toFixedP(141.27, 6.00), toFixedP(166.64, 33.88))
//Q192.02,61.77,192.02,108.70
testPath.QuadBezier(toFixedP(192.02, 61.77), toFixedP(192.02, 108.70))
//Q192.02,175.67,140.86,202.05
testPath.QuadBezier(toFixedP(192.02, 175.67), toFixedP(140.86, 202.05))
//Q173.42,216.66,210.08,222.97
testPath.QuadBezier(toFixedP(173.42, 216.66), toFixedP(210.08, 222.97))
//z
testPath.Stop(false)
//M162.22,109.69 M162.22,109.69
testPath.Start(toFixedP(162.22, 109.69))
//Q162.22,70.11,145.61,48.55
testPath.QuadBezier(toFixedP(162.22, 70.11), toFixedP(145.61, 48.55))
//Q129.00,27.00,98.42,27.00
testPath.QuadBezier(toFixedP(129.00, 27.00), toFixedP(98.42, 27.00))
//Q69.14,27.00,52.53,48.62
testPath.QuadBezier(toFixedP(69.14, 27.00), toFixedP(52.53, 48.62))
//Q35.92,70.25,35.92,108.50
testPath.QuadBezier(toFixedP(35.92, 70.25), toFixedP(35.92, 108.50))
//Q35.92,146.75,52.53,168.38
testPath.QuadBezier(toFixedP(35.92, 146.75), toFixedP(52.53, 168.38))
//Q69.14,190.00,98.42,190.00
testPath.QuadBezier(toFixedP(69.14, 190.00), toFixedP(98.42, 190.00))
//Q128.34,190.00,145.28,168.70
testPath.QuadBezier(toFixedP(128.34, 190.00), toFixedP(145.28, 168.70))
//Q162.22,147.41,162.22,109.69
testPath.QuadBezier(toFixedP(162.22, 147.41), toFixedP(162.22, 109.69))
//z
testPath.Stop(false)
return testPath
}
// TestMultiFunction tests a Dasher's ability to function
// as a filler, stroker, and dasher by invoking the corresponding anonymous structs
func TestMultiFunctionGV() image.Image {
img := image.NewRGBA(image.Rect(0, 0, S, S))
src := image.NewUniform(color.NRGBA{255, 0, 0, 255})
scannerGV := rasterx.NewScannerGV(S, S, img, img.Bounds(), src, image.ZP)
draw.Draw(img, img.Bounds(), image.White, image.ZP, draw.Src)
d := rasterx.NewDasher(S, S, scannerGV)
d.SetStroke(10*64, 4*64, rasterx.RoundCap, nil, rasterx.RoundGap, rasterx.ArcClip, []float64{33, 12}, 0)
p := GetTestPath()
p.AddTo(d)
d.Draw()
d.Clear()
return img
}
Note testPath.Stop(false) in GetTestPath.
Result is in attached file:
...
but i am not sure if this is correct fix.
Regards.