//Render a polygon private static void Render(DnaPolygon polygon, Graphics g, int scale) { using (Brush brush = GetGdiBrush(polygon.Brush)) { Point[] points = GetGdiPoints(polygon.Points, scale); g.FillPolygon(brush, points); } }
public void AddPolygon() { var newPolygon = new DnaPolygon(tool); newPolygon.Init(); Shapes.Add(newPolygon); SetDirty(); }
//Render a Drawing internal static void Render(DnaDrawing drawing, Graphics g, int scale) { for (int i = 0; i < drawing.Polygons.Count; i++) { DnaPolygon polygon = drawing.Polygons[i]; Render(polygon, g, scale); } }
//Render a polygon private static void Render(DnaPolygon polygon, Graphics g, int scale) { Point[] points = GetGdiPoints(polygon.Points, scale); using (Brush brush = GetGdiBrush(polygon.Brush)) { g.FillPolygon(brush, points, FillMode.Winding); //g.FillClosedCurve(brush, points, FillMode.Winding); } }
public DnaShape Clone() { var newPolygon = new DnaPolygon(tool); newPolygon.Points = new List<DnaPoint>(); newPolygon.Brush = Brush.Clone(); foreach (DnaPoint point in Points) newPolygon.Points.Add(point.Clone()); return newPolygon; }
public static bool AddPolygon(this DnaDrawing dnaDrawing) { if (dnaDrawing.Polygons.Count < Settings.ActivePolygonsMax) { var newPolygon = DnaPolygon.GetRandom(dnaDrawing.Width, dnaDrawing.Height); int index = Tools.GetRandomNumber(0, dnaDrawing.Polygons.Count); dnaDrawing.Polygons.Insert(index, newPolygon); return(true); } return(false); }
private static bool RemovePoint(this DnaPolygon dnaPolygon, DnaDrawing drawing) { if (dnaPolygon.Points.Count > Settings.ActivePointsPerPolygonMin) { if (drawing.PointCount > Settings.ActivePointsMin) { int index = Tools.GetRandomNumber(0, dnaPolygon.Points.Count); dnaPolygon.Points.RemoveAt(index); return(true); } } return(false); }
public static bool MovePolygon(this DnaDrawing dnaDrawing) { if (dnaDrawing.Polygons.Count < 1) { return(false); } int index = Tools.GetRandomNumber(0, dnaDrawing.Polygons.Count); DnaPolygon poly = dnaDrawing.Polygons[index]; dnaDrawing.Polygons.RemoveAt(index); index = Tools.GetRandomNumber(0, dnaDrawing.Polygons.Count); dnaDrawing.Polygons.Insert(index, poly); return(true); }
//Render a polygon private static void Render(DnaPolygon polygon, Graphics g, int scale) { var brush = GetGdiBrush(polygon.Brush); var points = GetGdiPoints(polygon.Points, scale); try { g.FillPolygon(brush, points); //(brush, points); } catch (Exception e) { int i = 0; i++; } }
public static void Mutate(this DnaPolygon dnaPolygon, DnaDrawing drawing) { if (Tools.WillMutate(Settings.ActiveAddPointMutationRate)) { if (dnaPolygon.AddPoint(drawing)) { drawing.SetDirty(); } } if (Tools.WillMutate(Settings.ActiveRemovePointMutationRate)) { if (dnaPolygon.RemovePoint(drawing)) { drawing.SetDirty(); } } dnaPolygon.Brush.Mutate(drawing); dnaPolygon.Points.ForEach(p => p.Mutate(drawing)); }
//Render a polygon private static void Render(DnaPolygon polygon, Graphics g, int scale) { if (polygon.IsComplex) { return; } Point[] points = GetGdiPoints(polygon.Points, scale); using (Brush brush = GetGdiBrush(polygon.Brush)) { if (polygon.Splines) { if (polygon.Filled) { g.FillClosedCurve(brush, points, FillMode.Winding); } else { using (Pen pen = new Pen(brush, Math.Max(1, polygon.Width))) { g.DrawCurve(pen, points, 3F); } } } else { if (polygon.Filled) { g.FillPolygon(brush, points, FillMode.Winding); } else { using (Pen pen = new Pen(brush, Math.Max(1, polygon.Width))) { g.DrawPolygon(pen, points); } } } } }
private static bool AddPoint(this DnaPolygon dnaPolygon, DnaDrawing drawing) { if (dnaPolygon.Points.Count < Settings.ActivePointsPerPolygonMax) { if (drawing.PointCount < Settings.ActivePointsMax) { int index = Tools.GetRandomNumber(1, dnaPolygon.Points.Count - 1); DnaPoint prev = dnaPolygon.Points[index - 1]; DnaPoint next = dnaPolygon.Points[index]; var newPointX = (prev.X + next.X) / 2; var newPointY = (prev.Y + next.Y) / 2; var newPoint = new DnaPoint(newPointX, newPointY); dnaPolygon.Points.Insert(index, newPoint); return(true); } } return(false); }
internal virtual void WorkLoop(Intracommunicator comm) { startTime = DateTime.Now; Console.WriteLine("Starting worker {0} ", comm.Rank); var timer = new Stopwatch(); int partitionHeight = info.SourceImage.Height / comm.Size; int partitionY = partitionHeight * comm.Rank; for (int i = 0; i < info.Settings.PolygonsMax; i++) { var polygon = new DnaPolygon(); parentDrawing.Polygons.Add(polygon); polygon.Init(parentDrawing, info); //foreach (DnaPoint p in polygon.Points) //{ // p.Y = partitionY + partitionHeight / 2; //} } int waitTimer = 0; while (true) { if (comm.Rank == 0) { NotifyProgress(generation); } timer.Reset(); timer.Start(); while (timer.ElapsedMilliseconds < waitTimer) { var currentDrawing = parentDrawing.GetMutatedChild(info); var currentErrorLevel = GetFitnessForDrawing(currentDrawing); if (currentErrorLevel < parentErrorLevel) { parentErrorLevel = currentErrorLevel; parentDrawing = currentDrawing; } } if (waitTimer < 6000) { waitTimer += 500; } timer.Stop(); generation++; var drawingInfo = new MpiWorkerDrawingInfo { Drawing = parentDrawing }; // Stopwatch swSync = new Stopwatch(); // swSync.Start(); MpiWorkerDrawingInfo[] allResults = comm.Allgather(drawingInfo); if (bgImage != null) { bgImage.Dispose(); } bgImage = new Bitmap(info.SourceImage.Width, info.SourceImage.Height, PixelFormat.Format32bppArgb); var bgGraphics = Graphics.FromImage(bgImage); bgGraphics.Clear(Color.Black); bgGraphics.SmoothingMode = SmoothingMode.HighQuality; for (int i = 0; i < comm.Rank; i++) { Renderer.Render(allResults[i].Drawing, bgGraphics, 1); } if (fgImage != null) { fgImage.Dispose(); } fgImage = new Bitmap(info.SourceImage.Width, info.SourceImage.Height, PixelFormat.Format32bppArgb); var fgGraphics = Graphics.FromImage(fgImage); fgGraphics.Clear(Color.Transparent); fgGraphics.SmoothingMode = SmoothingMode.HighQuality; for (int i = comm.Rank + 1; i < comm.Size; i++) { Renderer.Render(allResults[i].Drawing, fgGraphics, 1); } fgGraphics.Dispose(); bgGraphics.Dispose(); //recalc the new parent error level parentErrorLevel = GetFitnessForDrawing(parentDrawing); // swSync.Stop(); // Console.WriteLine("sync {0}", swSync.Elapsed); } }