func drawPolyLine(img *image.RGBA, color color.Color, coords [][]float64) { path := draw2d.NewPathStorage() for i, coord := range coords { if i == 0 { path.MoveTo(coord[0], coord[1]) } else { path.LineTo(coord[0], coord[1]) } } gc := draw2d.NewGraphicContext(img) gc.SetStrokeColor(color) gc.Stroke(path) }
func (s *PngDebugDraw) DrawShape(shape *figo.Shape, mass, vel, acc float32) { ps := draw2d.NewPathStorage() data := shape.TransformedVertices() _x, _y := 0.0, 0.0 for i := 0; i < len(data); i += 2 { x := float64((data[i] + s.offset.X) * s.DecToPix) y := float64((data[i+1] + s.offset.Y) * s.DecToPix) if i == 0 { _x, _y = x, y ps.MoveTo(x, y) } else { ps.LineTo(x, y) } } ps.LineTo(_x, _y) s.ctx.SetFillColor(color.RGBA{R: 255, A: 255}) s.ctx.FillStroke(ps) }
func (gc *GraphicContext) FillStroke(paths ...*draw2d.PathStorage) { gc.fillRasterizer.UseNonZeroWinding = gc.Current.FillRule.UseNonZeroWinding() gc.strokeRasterizer.UseNonZeroWinding = true filler := draw2d.NewVertexMatrixTransform(gc.Current.Tr, draw2d.NewVertexAdder(gc.fillRasterizer)) stroker := draw2d.NewLineStroker(gc.Current.Cap, gc.Current.Join, draw2d.NewVertexMatrixTransform(gc.Current.Tr, draw2d.NewVertexAdder(gc.strokeRasterizer))) stroker.HalfLineWidth = gc.Current.LineWidth / 2 demux := draw2d.NewDemuxConverter(filler, stroker) paths = append(paths, gc.Current.Path) pathConverter := draw2d.NewPathConverter(demux) pathConverter.ApproximationScale = gc.Current.Tr.GetScale() // From agg code pathConverter.Convert(paths...) gc.paint(gc.fillRasterizer, gc.Current.FillColor) gc.paint(gc.strokeRasterizer, gc.Current.StrokeColor) gc.Current.Path = draw2d.NewPathStorage() }