static public uint parse_lion <T>(PathStorage <T> path, RGBA_Bytes[] colors, uint[] path_idx) where T : IEquatable <T>, IComparable <T>, IComputable <T>, IConvertible, IFormattable, ICommonNumericalOperations <T>, ITrigonometricOperations <T> { // Parse the lion and then detect its bounding // box and arrange polygons orientations (make all polygons // oriented clockwise or counterclockwise) uint npaths = 0; string[] splitOnNL = g_lion.Split('\n'); foreach (string LineString in splitOnNL) { int c; if (LineString.Length > 0 && LineString[0] != 'M' && Int32.TryParse(LineString, NumberStyles.HexNumber, null, out c)) { // New color. Every new color creates new path in the path object. path.ClosePolygon(); colors[npaths] = RGBA_Bytes.Rgb8Packed((uint)c); path_idx[npaths] = path.StartNewPath(); npaths++; } else { bool startedPoly = false; string[] splitOnSpace = LineString.Split(' '); for (int i = 0; i < splitOnSpace.Length; i++) { string[] splitOnComma = splitOnSpace[i].Split(','); if (splitOnComma.Length > 1) { double x = 0.0; double y = 0.0; double.TryParse(splitOnComma[0], NumberStyles.Number, null, out x); double.TryParse(splitOnComma[1], NumberStyles.Number, null, out y); if (!startedPoly) { startedPoly = true; path.ClosePolygon(); path.MoveTo(M.New <T>(x), M.New <T>(y)); } else { path.LineTo(M.New <T>(x), M.New <T>(y)); } } } } } path.ArrangeOrientationsAllPaths(Path.Flags.CW); return(npaths); }
static public int parse_lion(PathStorage path, RGBA_Bytes[] colors, int[] path_idx) { // Parse the lion and then detect its bounding // box and arrange polygons orientations (make all polygons // oriented clockwise or counterclockwise) int npaths = 0; string[] splitOnNL = g_lion.Split('\n'); foreach (string LineString in splitOnNL) { int c; if (LineString.Length > 0 && LineString[0] != 'M' && Int32.TryParse(LineString, NumberStyles.HexNumber, null, out c)) { // New color. Every new color creates new path in the path object. path.ClosePolygon(); colors[npaths] = RGBA_Bytes.rgb8_packed((int)c); path_idx[npaths] = path.start_new_path(); npaths++; } else { bool startedPoly = false; string[] splitOnSpace = LineString.Split(' '); for (int i = 0; i < splitOnSpace.Length; i++) { string[] splitOnComma = splitOnSpace[i].Split(','); if (splitOnComma.Length > 1) { double x = 0.0; double y = 0.0; double.TryParse(splitOnComma[0], NumberStyles.Number, null, out x); double.TryParse(splitOnComma[1], NumberStyles.Number, null, out y); if (!startedPoly) { startedPoly = true; path.ClosePolygon(); path.MoveTo(x, y); } else { path.LineTo(x, y); } } } } } path.arrange_orientations_all_paths(ShapePath.FlagsAndCommand.FlagCW); return(npaths); }
void DrawAATest() { PathStorage <T> PolgonToDraw = new PathStorage <T>(); T Angle = M.Zero <T>(); bool DrawTrinagle = true; if (DrawTrinagle) { PolgonToDraw.MoveTo(Angle.Cos(), Angle.Sin()); Angle.AddEquals(120.0 / 180.0 * Math.PI); PolgonToDraw.LineTo(Angle.Cos(), Angle.Sin()); Angle.AddEquals(120.0 / 180.0 * Math.PI); PolgonToDraw.LineTo(Angle.Cos(), Angle.Sin()); Angle.AddEquals(120.0 / 180.0 * Math.PI); //Triangle.line_to(Math.Cos(Angle), Math.Sin(Angle)); PolgonToDraw.ClosePolygon(); } else { PolgonToDraw.MoveTo(M.Zero <T>(), M.Zero <T>()); PolgonToDraw.LineTo(M.One <T>(), M.Zero <T>()); PolgonToDraw.LineTo(M.One <T>(), M.One <T>()); PolgonToDraw.LineTo(M.Zero <T>(), M.One <T>()); PolgonToDraw.ClosePolygon(); } IAffineTransformMatrix <T> tran = MatrixFactory <T> .NewScaling(VectorDimension.Two, M.New <T>(80)); tran.RotateAlong(MatrixFactory <T> .CreateVector2D(M.Zero <T>(), M.Zero <T>()), Math.PI / 8); tran.Translate(MatrixFactory <T> .CreateVector2D(M.New <T>(500), M.New <T>(100))); ConvTransform <T> TransformedPolygon = new ConvTransform <T>(PolgonToDraw, tran); ((RendererOpenGL <T>)GetRenderer()).m_ForceTexturedEdgeAntiAliasing = true; GetRenderer().Render(TransformedPolygon, new RGBA_Bytes(0, 0, 0)); Ellipse <T> testEllipse = new Ellipse <T>(M.New <T>(300), M.New <T>(250), M.New <T>(60), M.New <T>(60)); GetRenderer().Render(testEllipse, new RGBA_Bytes(205, 23, 12, 120)); ((RendererOpenGL <T>)GetRenderer()).m_ForceTexturedEdgeAntiAliasing = false; //conv_stroke OutLine = new conv_stroke(TransformedPolygon); //OutLine.width(2); //conv_transform TransformedOutLine = new conv_transform(OutLine, Affine.NewTranslation(100, 0)); //GetRenderer().Render(TransformedOutLine, new RGBA_Bytes(0, 0, 0)); //conv_transform TransformedOutLine2 = new conv_transform(OutLine, Affine.NewScaling(6) * Affine.NewTranslation(200, 0)); //conv_stroke OutLineOutLine = new conv_stroke(TransformedOutLine2); //GetRenderer().Render(OutLineOutLine, new RGBA_Bytes(0, 0, 0)); }
public static PathStorage PolygonToPathStorage(Polygons polygons) { PathStorage output = new PathStorage(); foreach (Polygon polygon in polygons) { bool first = true; foreach (IntPoint point in polygon) { if (first) { output.Add(point.X, point.Y, ShapePath.FlagsAndCommand.CommandMoveTo); first = false; } else { output.Add(point.X, point.Y, ShapePath.FlagsAndCommand.CommandLineTo); } } output.ClosePolygon(); } output.Add(0, 0, ShapePath.FlagsAndCommand.CommandStop); return(output); }
private void make_arrows(PathStorage ps) { ps.remove_all(); ps.MoveTo(1330.599999999999909, 1282.399999999999864); ps.LineTo(1377.400000000000091, 1282.399999999999864); ps.LineTo(1361.799999999999955, 1298.000000000000000); ps.LineTo(1393.000000000000000, 1313.599999999999909); ps.LineTo(1361.799999999999955, 1344.799999999999955); ps.LineTo(1346.200000000000045, 1313.599999999999909); ps.LineTo(1330.599999999999909, 1329.200000000000045); ps.ClosePolygon(); ps.MoveTo(1330.599999999999909, 1266.799999999999955); ps.LineTo(1377.400000000000091, 1266.799999999999955); ps.LineTo(1361.799999999999955, 1251.200000000000045); ps.LineTo(1393.000000000000000, 1235.599999999999909); ps.LineTo(1361.799999999999955, 1204.399999999999864); ps.LineTo(1346.200000000000045, 1235.599999999999909); ps.LineTo(1330.599999999999909, 1220.000000000000000); ps.ClosePolygon(); ps.MoveTo(1315.000000000000000, 1282.399999999999864); ps.LineTo(1315.000000000000000, 1329.200000000000045); ps.LineTo(1299.400000000000091, 1313.599999999999909); ps.LineTo(1283.799999999999955, 1344.799999999999955); ps.LineTo(1252.599999999999909, 1313.599999999999909); ps.LineTo(1283.799999999999955, 1298.000000000000000); ps.LineTo(1268.200000000000045, 1282.399999999999864); ps.ClosePolygon(); ps.MoveTo(1268.200000000000045, 1266.799999999999955); ps.LineTo(1315.000000000000000, 1266.799999999999955); ps.LineTo(1315.000000000000000, 1220.000000000000000); ps.LineTo(1299.400000000000091, 1235.599999999999909); ps.LineTo(1283.799999999999955, 1204.399999999999864); ps.LineTo(1252.599999999999909, 1235.599999999999909); ps.LineTo(1283.799999999999955, 1251.200000000000045); ps.ClosePolygon(); }
private PathStorage CombinePaths(IVertexSource a, IVertexSource b, ClipType clipType) { List <List <IntPoint> > aPolys = CreatePolygons(a); List <List <IntPoint> > bPolys = CreatePolygons(b); Clipper clipper = new Clipper(); clipper.AddPaths(aPolys, PolyType.ptSubject, true); clipper.AddPaths(bPolys, PolyType.ptClip, true); List <List <IntPoint> > intersectedPolys = new List <List <IntPoint> >(); clipper.Execute(clipType, intersectedPolys); PathStorage output = new PathStorage(); foreach (List <IntPoint> polygon in intersectedPolys) { bool first = true; foreach (IntPoint point in polygon) { if (first) { output.Add(point.X / 1000.0, point.Y / 1000.0, ShapePath.FlagsAndCommand.CommandMoveTo); first = false; } else { output.Add(point.X / 1000.0, point.Y / 1000.0, ShapePath.FlagsAndCommand.CommandLineTo); } } output.ClosePolygon(); } output.Add(0, 0, ShapePath.FlagsAndCommand.CommandStop); return(output); }
private void DrawImageGetDestBounds(IImageByte sourceImage, double DestX, double DestY, double HotspotOffsetX, double HotspotOffsetY, double ScaleX, double ScaleY, double AngleRad, out Affine destRectTransform) { destRectTransform = Affine.NewIdentity(); if (HotspotOffsetX != 0.0f || HotspotOffsetY != 0.0f) { destRectTransform *= Affine.NewTranslation(-HotspotOffsetX, -HotspotOffsetY); } if (ScaleX != 1 || ScaleY != 1) { destRectTransform *= Affine.NewScaling(ScaleX, ScaleY); } if (AngleRad != 0) { destRectTransform *= Affine.NewRotation(AngleRad); } if (DestX != 0 || DestY != 0) { destRectTransform *= Affine.NewTranslation(DestX, DestY); } int SourceBufferWidth = (int)sourceImage.Width; int SourceBufferHeight = (int)sourceImage.Height; drawImageRectPath.remove_all(); drawImageRectPath.MoveTo(0, 0); drawImageRectPath.LineTo(SourceBufferWidth, 0); drawImageRectPath.LineTo(SourceBufferWidth, SourceBufferHeight); drawImageRectPath.LineTo(0, SourceBufferHeight); drawImageRectPath.ClosePolygon(); }
public static PathStorage CreatePathStorage(List <List <IntPoint> > intersectedPolys, double scaling = 1000) { PathStorage output = new PathStorage(); foreach (List <IntPoint> polygon in intersectedPolys) { bool first = true; foreach (IntPoint point in polygon) { if (first) { output.Add(point.X / scaling, point.Y / scaling, ShapePath.FlagsAndCommand.CommandMoveTo); first = false; } else { output.Add(point.X / scaling, point.Y / scaling, ShapePath.FlagsAndCommand.CommandLineTo); } } output.ClosePolygon(); } return(output); }
public blur_application(PixelFormats format, ERenderOrigin RenderOrigin) : base(format, RenderOrigin) { m_rbuf2 = new RasterBuffer(); m_shape_bounds = new RectDouble <T>(); m_method = new rbox_ctrl <T>(10.0, 10.0, 130.0, 70.0); m_radius = new SliderWidget <T>(130 + 10.0, 10.0 + 4.0, 130 + 300.0, 10.0 + 8.0 + 4.0); m_shadow_ctrl = new polygon_ctrl <T>(4); m_channel_r = new cbox_ctrl <T>(10.0, 80.0, "Red"); m_channel_g = new cbox_ctrl <T>(10.0, 95.0, "Green"); m_channel_b = new cbox_ctrl <T>(10.0, 110.0, "Blue"); m_FlattenCurves = new cbox_ctrl <T>(10, 315, "Convert And Flatten Curves"); m_FlattenCurves.status(true); AddChild(m_method); m_method.text_size(8); m_method.add_item("Stack Blur"); m_method.add_item("Recursive Blur"); m_method.add_item("Channels"); m_method.cur_item(1); AddChild(m_radius); m_radius.range(0.0, 40.0); m_radius.value(15.0); m_radius.label("Blur Radius={0:F2}"); AddChild(m_shadow_ctrl); AddChild(m_channel_r); AddChild(m_channel_g); AddChild(m_channel_b); AddChild(m_FlattenCurves); m_channel_g.status(true); m_sl = new ScanlinePacked8(); m_path = new PathStorage <T>(); m_shape = new ConvCurve <T>(m_path); m_path.RemoveAll(); m_path.MoveTo(28.47, 6.45); m_path.Curve3(21.58, 1.12, 19.82, 0.29); m_path.Curve3(17.19, -0.93, 14.21, -0.93); m_path.Curve3(9.57, -0.93, 6.57, 2.25); m_path.Curve3(3.56, 5.42, 3.56, 10.60); m_path.Curve3(3.56, 13.87, 5.03, 16.26); m_path.Curve3(7.03, 19.58, 11.99, 22.51); m_path.Curve3(16.94, 25.44, 28.47, 29.64); m_path.LineTo(28.47, 31.40); m_path.Curve3(28.47, 38.09, 26.34, 40.58); m_path.Curve3(24.22, 43.07, 20.17, 43.07); m_path.Curve3(17.09, 43.07, 15.28, 41.41); m_path.Curve3(13.43, 39.75, 13.43, 37.60); m_path.LineTo(13.53, 34.77); m_path.Curve3(13.53, 32.52, 12.38, 31.30); m_path.Curve3(11.23, 30.08, 9.38, 30.08); m_path.Curve3(7.57, 30.08, 6.42, 31.35); m_path.Curve3(5.27, 32.62, 5.27, 34.81); m_path.Curve3(5.27, 39.01, 9.57, 42.53); m_path.Curve3(13.87, 46.04, 21.63, 46.04); m_path.Curve3(27.59, 46.04, 31.40, 44.04); m_path.Curve3(34.28, 42.53, 35.64, 39.31); m_path.Curve3(36.52, 37.21, 36.52, 30.71); m_path.LineTo(36.52, 15.53); m_path.Curve3(36.52, 9.13, 36.77, 7.69); m_path.Curve3(37.01, 6.25, 37.57, 5.76); m_path.Curve3(38.13, 5.27, 38.87, 5.27); m_path.Curve3(39.65, 5.27, 40.23, 5.62); m_path.Curve3(41.26, 6.25, 44.19, 9.18); m_path.LineTo(44.19, 6.45); m_path.Curve3(38.72, -0.88, 33.74, -0.88); m_path.Curve3(31.35, -0.88, 29.93, 0.78); m_path.Curve3(28.52, 2.44, 28.47, 6.45); m_path.ClosePolygon(); m_path.MoveTo(28.47, 9.62); m_path.LineTo(28.47, 26.66); m_path.Curve3(21.09, 23.73, 18.95, 22.51); m_path.Curve3(15.09, 20.36, 13.43, 18.02); m_path.Curve3(11.77, 15.67, 11.77, 12.89); m_path.Curve3(11.77, 9.38, 13.87, 7.06); m_path.Curve3(15.97, 4.74, 18.70, 4.74); m_path.Curve3(22.41, 4.74, 28.47, 9.62); m_path.ClosePolygon(); IAffineTransformMatrix <T> shape_mtx = MatrixFactory <T> .NewIdentity(VectorDimension.Two); shape_mtx.Scale(M.New <T>(4.0)); shape_mtx.Translate(MatrixFactory <T> .CreateVector2D(150, 100)); m_path.Transform(shape_mtx); BoundingRect <T> .BoundingRectSingle(m_shape, 0, ref m_shape_bounds); m_shadow_ctrl.SetXN(0, m_shape_bounds.x1); m_shadow_ctrl.SetYN(0, m_shape_bounds.y1); m_shadow_ctrl.SetXN(1, m_shape_bounds.x2); m_shadow_ctrl.SetYN(1, m_shape_bounds.y1); m_shadow_ctrl.SetXN(2, m_shape_bounds.x2); m_shadow_ctrl.SetYN(2, m_shape_bounds.y2); m_shadow_ctrl.SetXN(3, m_shape_bounds.x1); m_shadow_ctrl.SetYN(3, m_shape_bounds.y2); m_shadow_ctrl.line_color(new RGBA_Doubles(0, 0.3, 0.5, 0.3)); }
private void render_gpc(Graphics2D graphics2D) { switch (m_polygons.SelectedIndex) { case 0: { //------------------------------------ // Two simple paths // PathStorage ps1 = new PathStorage(); PathStorage ps2 = new PathStorage(); double x = m_x - Width / 2 + 100; double y = m_y - Height / 2 + 100; ps1.MoveTo(x + 140, y + 145); ps1.LineTo(x + 225, y + 44); ps1.LineTo(x + 296, y + 219); ps1.ClosePolygon(); ps1.LineTo(x + 226, y + 289); ps1.LineTo(x + 82, y + 292); ps1.MoveTo(x + 220, y + 222); ps1.LineTo(x + 363, y + 249); ps1.LineTo(x + 265, y + 331); ps1.MoveTo(x + 242, y + 243); ps1.LineTo(x + 268, y + 309); ps1.LineTo(x + 325, y + 261); ps1.MoveTo(x + 259, y + 259); ps1.LineTo(x + 273, y + 288); ps1.LineTo(x + 298, y + 266); ps2.MoveTo(100 + 32, 100 + 77); ps2.LineTo(100 + 473, 100 + 263); ps2.LineTo(100 + 351, 100 + 290); ps2.LineTo(100 + 354, 100 + 374); graphics2D.Render(ps1, new RGBA_Floats(0, 0, 0, 0.1).GetAsRGBA_Bytes()); graphics2D.Render(ps2, new RGBA_Floats(0, 0.6, 0, 0.1).GetAsRGBA_Bytes()); CreateAndRenderCombined(graphics2D, ps1, ps2); } break; case 1: { //------------------------------------ // Closed stroke // PathStorage ps1 = new PathStorage(); PathStorage ps2 = new PathStorage(); Stroke stroke = new Stroke(ps2); stroke.width(10.0); double x = m_x - Width / 2 + 100; double y = m_y - Height / 2 + 100; ps1.MoveTo(x + 140, y + 145); ps1.LineTo(x + 225, y + 44); ps1.LineTo(x + 296, y + 219); ps1.ClosePolygon(); ps1.LineTo(x + 226, y + 289); ps1.LineTo(x + 82, y + 292); ps1.MoveTo(x + 220 - 50, y + 222); ps1.LineTo(x + 265 - 50, y + 331); ps1.LineTo(x + 363 - 50, y + 249); ps1.close_polygon(ShapePath.FlagsAndCommand.FlagCCW); ps2.MoveTo(100 + 32, 100 + 77); ps2.LineTo(100 + 473, 100 + 263); ps2.LineTo(100 + 351, 100 + 290); ps2.LineTo(100 + 354, 100 + 374); ps2.ClosePolygon(); graphics2D.Render(ps1, new RGBA_Floats(0, 0, 0, 0.1).GetAsRGBA_Bytes()); graphics2D.Render(stroke, new RGBA_Floats(0, 0.6, 0, 0.1).GetAsRGBA_Bytes()); CreateAndRenderCombined(graphics2D, ps1, stroke); } break; case 2: { //------------------------------------ // Great Britain and Arrows // PathStorage gb_poly = new PathStorage(); PathStorage arrows = new PathStorage(); GreatBritanPathStorage.Make(gb_poly); make_arrows(arrows); Affine mtx1 = Affine.NewIdentity(); Affine mtx2 = Affine.NewIdentity(); mtx1 *= Affine.NewTranslation(-1150, -1150); mtx1 *= Affine.NewScaling(2.0); mtx2 = mtx1; mtx2 *= Affine.NewTranslation(m_x - Width / 2, m_y - Height / 2); VertexSourceApplyTransform trans_gb_poly = new VertexSourceApplyTransform(gb_poly, mtx1); VertexSourceApplyTransform trans_arrows = new VertexSourceApplyTransform(arrows, mtx2); graphics2D.Render(trans_gb_poly, new RGBA_Floats(0.5, 0.5, 0, 0.1).GetAsRGBA_Bytes()); Stroke stroke_gb_poly = new Stroke(trans_gb_poly); stroke_gb_poly.Width = 0.1; graphics2D.Render(stroke_gb_poly, new RGBA_Floats(0, 0, 0).GetAsRGBA_Bytes()); graphics2D.Render(trans_arrows, new RGBA_Floats(0.0, 0.5, 0.5, 0.1).GetAsRGBA_Bytes()); CreateAndRenderCombined(graphics2D, trans_gb_poly, trans_arrows); } break; case 3: { //------------------------------------ // Great Britain and a Spiral // spiral sp = new spiral(m_x, m_y, 10, 150, 30, 0.0); Stroke stroke = new Stroke(sp); stroke.width(15.0); PathStorage gb_poly = new PathStorage(); GreatBritanPathStorage.Make(gb_poly); Affine mtx = Affine.NewIdentity();; mtx *= Affine.NewTranslation(-1150, -1150); mtx *= Affine.NewScaling(2.0); VertexSourceApplyTransform trans_gb_poly = new VertexSourceApplyTransform(gb_poly, mtx); graphics2D.Render(trans_gb_poly, new RGBA_Floats(0.5, 0.5, 0, 0.1).GetAsRGBA_Bytes()); Stroke stroke_gb_poly = new Stroke(trans_gb_poly); stroke_gb_poly.width(0.1); graphics2D.Render(stroke_gb_poly, new RGBA_Floats(0, 0, 0).GetAsRGBA_Bytes()); graphics2D.Render(stroke, new RGBA_Floats(0.0, 0.5, 0.5, 0.1).GetAsRGBA_Bytes()); CreateAndRenderCombined(graphics2D, trans_gb_poly, stroke); } break; case 4: { //------------------------------------ // Spiral and glyph // spiral sp = new spiral(m_x, m_y, 10, 150, 30, 0.0); Stroke stroke = new Stroke(sp); stroke.width(15.0); PathStorage glyph = new PathStorage(); glyph.MoveTo(28.47, 6.45); glyph.curve3(21.58, 1.12, 19.82, 0.29); glyph.curve3(17.19, -0.93, 14.21, -0.93); glyph.curve3(9.57, -0.93, 6.57, 2.25); glyph.curve3(3.56, 5.42, 3.56, 10.60); glyph.curve3(3.56, 13.87, 5.03, 16.26); glyph.curve3(7.03, 19.58, 11.99, 22.51); glyph.curve3(16.94, 25.44, 28.47, 29.64); glyph.LineTo(28.47, 31.40); glyph.curve3(28.47, 38.09, 26.34, 40.58); glyph.curve3(24.22, 43.07, 20.17, 43.07); glyph.curve3(17.09, 43.07, 15.28, 41.41); glyph.curve3(13.43, 39.75, 13.43, 37.60); glyph.LineTo(13.53, 34.77); glyph.curve3(13.53, 32.52, 12.38, 31.30); glyph.curve3(11.23, 30.08, 9.38, 30.08); glyph.curve3(7.57, 30.08, 6.42, 31.35); glyph.curve3(5.27, 32.62, 5.27, 34.81); glyph.curve3(5.27, 39.01, 9.57, 42.53); glyph.curve3(13.87, 46.04, 21.63, 46.04); glyph.curve3(27.59, 46.04, 31.40, 44.04); glyph.curve3(34.28, 42.53, 35.64, 39.31); glyph.curve3(36.52, 37.21, 36.52, 30.71); glyph.LineTo(36.52, 15.53); glyph.curve3(36.52, 9.13, 36.77, 7.69); glyph.curve3(37.01, 6.25, 37.57, 5.76); glyph.curve3(38.13, 5.27, 38.87, 5.27); glyph.curve3(39.65, 5.27, 40.23, 5.62); glyph.curve3(41.26, 6.25, 44.19, 9.18); glyph.LineTo(44.19, 6.45); glyph.curve3(38.72, -0.88, 33.74, -0.88); glyph.curve3(31.35, -0.88, 29.93, 0.78); glyph.curve3(28.52, 2.44, 28.47, 6.45); glyph.ClosePolygon(); glyph.MoveTo(28.47, 9.62); glyph.LineTo(28.47, 26.66); glyph.curve3(21.09, 23.73, 18.95, 22.51); glyph.curve3(15.09, 20.36, 13.43, 18.02); glyph.curve3(11.77, 15.67, 11.77, 12.89); glyph.curve3(11.77, 9.38, 13.87, 7.06); glyph.curve3(15.97, 4.74, 18.70, 4.74); glyph.curve3(22.41, 4.74, 28.47, 9.62); glyph.ClosePolygon(); Affine mtx = Affine.NewIdentity(); mtx *= Affine.NewScaling(4.0); mtx *= Affine.NewTranslation(220, 200); VertexSourceApplyTransform trans = new VertexSourceApplyTransform(glyph, mtx); FlattenCurves curve = new FlattenCurves(trans); CreateAndRenderCombined(graphics2D, stroke, curve); graphics2D.Render(stroke, new RGBA_Floats(0, 0, 0, 0.1).GetAsRGBA_Bytes()); graphics2D.Render(curve, new RGBA_Floats(0, 0.6, 0, 0.1).GetAsRGBA_Bytes()); } break; } }
private void RenderPolygonToPathAgainst(Graphics2D graphics2D) { IVertexSource pathToUse = null; switch (shapeTypeRadioGroup.SelectedIndex) { case 0: // simple polygon map { PathStorage ps1 = new PathStorage(); ps1.MoveTo(85, 417); ps1.LineTo(338, 428); ps1.LineTo(344, 325); ps1.LineTo(399, 324); ps1.LineTo(400, 421); ps1.LineTo(644, 415); ps1.LineTo(664, 75); ps1.LineTo(98, 81); ps1.ClosePolygon(); ps1.MoveTo(343, 290); ps1.LineTo(159, 235); ps1.LineTo(154, 162); ps1.LineTo(340, 114); ps1.ClosePolygon(); ps1.MoveTo(406, 121); ps1.LineTo(587, 158); ps1.LineTo(591, 236); ps1.LineTo(404, 291); ps1.ClosePolygon(); pathToUse = ps1; } break; case 1: // multiple pegs { PathStorage ps2 = new PathStorage(); double x = 0; double y = 0; ps2.MoveTo(100 + 32, 100 + 77); ps2.LineTo(100 + 473, 100 + 263); ps2.LineTo(100 + 351, 100 + 290); ps2.LineTo(100 + 354, 100 + 374); pathToUse = ps2; } break; case 2: { // circle holes PathStorage ps1 = new PathStorage(); double x = 0; double y = 0; ps1.MoveTo(x + 140, y + 145); ps1.LineTo(x + 225, y + 44); ps1.LineTo(x + 296, y + 219); ps1.ClosePolygon(); ps1.LineTo(x + 226, y + 289); ps1.LineTo(x + 82, y + 292); ps1.ClosePolygon(); ps1.MoveTo(x + 220 - 50, y + 222); ps1.LineTo(x + 265 - 50, y + 331); ps1.LineTo(x + 363 - 50, y + 249); ps1.ClosePolygon(); pathToUse = ps1; } break; case 3: // Great Britain { PathStorage gb_poly = new PathStorage(); GreatBritanPathStorage.Make(gb_poly); Affine mtx1 = Affine.NewIdentity(); Affine mtx2 = Affine.NewIdentity(); mtx1 *= Affine.NewTranslation(-1150, -1150); mtx1 *= Affine.NewScaling(2.0); mtx2 = mtx1; mtx2 *= Affine.NewTranslation(Width / 2, Height / 2); VertexSourceApplyTransform trans_gb_poly = new VertexSourceApplyTransform(gb_poly, mtx1); pathToUse = trans_gb_poly; } break; case 4: // Arrows { PathStorage arrows = new PathStorage(); make_arrows(arrows); Affine mtx1 = Affine.NewIdentity(); mtx1 *= Affine.NewTranslation(-1150, -1150); mtx1 *= Affine.NewScaling(2.0); VertexSourceApplyTransform trans_arrows = new VertexSourceApplyTransform(arrows, mtx1); pathToUse = trans_arrows; } break; case 5: // Spiral { spiral sp = new spiral(Width / 2, Height / 2, 10, 150, 30, 0.0); Stroke stroke = new Stroke(sp); stroke.width(15.0); Affine mtx = Affine.NewIdentity();; mtx *= Affine.NewTranslation(-1150, -1150); mtx *= Affine.NewScaling(2.0); pathToUse = stroke; } break; case 6: // Glyph { //------------------------------------ // Spiral and glyph // PathStorage glyph = new PathStorage(); glyph.MoveTo(28.47, 6.45); glyph.curve3(21.58, 1.12, 19.82, 0.29); glyph.curve3(17.19, -0.93, 14.21, -0.93); glyph.curve3(9.57, -0.93, 6.57, 2.25); glyph.curve3(3.56, 5.42, 3.56, 10.60); glyph.curve3(3.56, 13.87, 5.03, 16.26); glyph.curve3(7.03, 19.58, 11.99, 22.51); glyph.curve3(16.94, 25.44, 28.47, 29.64); glyph.LineTo(28.47, 31.40); glyph.curve3(28.47, 38.09, 26.34, 40.58); glyph.curve3(24.22, 43.07, 20.17, 43.07); glyph.curve3(17.09, 43.07, 15.28, 41.41); glyph.curve3(13.43, 39.75, 13.43, 37.60); glyph.LineTo(13.53, 34.77); glyph.curve3(13.53, 32.52, 12.38, 31.30); glyph.curve3(11.23, 30.08, 9.38, 30.08); glyph.curve3(7.57, 30.08, 6.42, 31.35); glyph.curve3(5.27, 32.62, 5.27, 34.81); glyph.curve3(5.27, 39.01, 9.57, 42.53); glyph.curve3(13.87, 46.04, 21.63, 46.04); glyph.curve3(27.59, 46.04, 31.40, 44.04); glyph.curve3(34.28, 42.53, 35.64, 39.31); glyph.curve3(36.52, 37.21, 36.52, 30.71); glyph.LineTo(36.52, 15.53); glyph.curve3(36.52, 9.13, 36.77, 7.69); glyph.curve3(37.01, 6.25, 37.57, 5.76); glyph.curve3(38.13, 5.27, 38.87, 5.27); glyph.curve3(39.65, 5.27, 40.23, 5.62); glyph.curve3(41.26, 6.25, 44.19, 9.18); glyph.LineTo(44.19, 6.45); glyph.curve3(38.72, -0.88, 33.74, -0.88); glyph.curve3(31.35, -0.88, 29.93, 0.78); glyph.curve3(28.52, 2.44, 28.47, 6.45); glyph.ClosePolygon(); glyph.MoveTo(28.47, 9.62); glyph.LineTo(28.47, 26.66); glyph.curve3(21.09, 23.73, 18.95, 22.51); glyph.curve3(15.09, 20.36, 13.43, 18.02); glyph.curve3(11.77, 15.67, 11.77, 12.89); glyph.curve3(11.77, 9.38, 13.87, 7.06); glyph.curve3(15.97, 4.74, 18.70, 4.74); glyph.curve3(22.41, 4.74, 28.47, 9.62); glyph.ClosePolygon(); Affine mtx = Affine.NewIdentity(); mtx *= Affine.NewScaling(4.0); mtx *= Affine.NewTranslation(220, 200); VertexSourceApplyTransform trans = new VertexSourceApplyTransform(glyph, mtx); FlattenCurves curve = new FlattenCurves(trans); pathToUse = curve; } break; } graphics2D.Render(pathToUse, fillColor); PathStorage travelLine = new PathStorage(); travelLine.MoveTo(lineStart); travelLine.LineTo(mousePosition); Polygons polygonsToPathAround = VertexSourceToClipperPolygons.CreatePolygons(pathToUse, 1); polygonsToPathAround = FixWinding(polygonsToPathAround); Polygons travelPolysLine = VertexSourceToClipperPolygons.CreatePolygons(travelLine, 1); CreateAndRenderPathing(graphics2D, polygonsToPathAround, travelPolysLine); }