Esempio n. 1
0
        void bImportDNA_Click(object sender, EventArgs e)
        {
            DNAImportWindow win = new DNAImportWindow();

            if (win.ShowDialog() == DialogResult.OK)
            {
                Reset();
                try {
                    string[] parts = win.DNA.Split(' ');
                    Stop();
                    State.Vertices  = Int32.Parse(parts[0]);
                    State.Shapes    = Int32.Parse(parts[1]);
                    nVertices.Value = State.Vertices;
                    nPolygons.Value = State.Shapes;
                    DNA importedDNA = new DNA {
                        Shapes = new Shape[State.Shapes]
                    };
                    int offset = 2;
                    for (int s = 0; s < State.Shapes; s++)
                    {
                        Shape shape = new Shape {
                            Points = new PointF[State.Vertices]
                        };
                        int r = Int32.Parse(parts[offset]);
                        int g = Int32.Parse(parts[offset + 1]);
                        int b = Int32.Parse(parts[offset + 2]);
                        int a = (int)(float.Parse(parts[offset + 3]) * 255);
                        shape.Color = Color.FromArgb(a, r, g, b);
                        offset     += 4;
                        for (int v = 0; v < State.Vertices; v++)
                        {
                            float X = float.Parse(parts[offset]);
                            float Y = float.Parse(parts[offset + 1]);
                            shape.Points[v] = new PointF(X, Y);
                            offset         += 2;
                        }
                        importedDNA.Shapes[s] = shape;
                    }
                    State.CurrentMatch = importedDNA;
                    State.BestMatch    = importedDNA;
                    State.SetEvaluator(State.Evaluator);
                    UpdateTick();
                    picBestMatch.Invalidate();
                    picDiff.Invalidate();
                } catch (FormatException ex) {
                    MessageBox.Show("Could not import DNA!" + Environment.NewLine + ex);
                }
            }
        }
Esempio n. 2
0
        void bImportDNA_Click(object sender, EventArgs e)
        {
            DNAImportWindow win = new DNAImportWindow();
            if (win.ShowDialog() == DialogResult.OK) {
                Reset();
                try {
                    string[] parts = win.DNA.Split(' ');
                    Stop();
                    State.Vertices = Int32.Parse(parts[0]);
                    State.Shapes = Int32.Parse(parts[1]);
                    nVertices.Value = State.Vertices;
                    nPolygons.Value = State.Shapes;
                    DNA importedDNA = new DNA {
                        Shapes = new Shape[State.Shapes]
                    };
                    int offset = 2;
                    for (int s = 0; s < State.Shapes; s++) {
                        Shape shape = new Shape {
                            Points = new PointF[State.Vertices]
                        };
                        int r = Int32.Parse(parts[offset]);
                        int g = Int32.Parse(parts[offset + 1]);
                        int b = Int32.Parse(parts[offset + 2]);
                        int a = (int)(float.Parse(parts[offset + 3])*255);
                        shape.Color = Color.FromArgb(a, r, g, b);
                        offset += 4;
                        for (int v = 0; v < State.Vertices; v++) {
                            float X = float.Parse(parts[offset]);
                            float Y = float.Parse(parts[offset + 1]);
                            shape.Points[v] = new PointF(X, Y);
                            offset += 2;
                        }
                        importedDNA.Shapes[s] = shape;
                    }
                    State.CurrentMatch = importedDNA;
                    State.BestMatch = importedDNA;
                    State.SetEvaluator(State.Evaluator);
                    UpdateTick();
                    picBestMatch.Invalidate();
                    picDiff.Invalidate();

                } catch (FormatException ex) {
                    MessageBox.Show("Could not import DNA!" + Environment.NewLine + ex);
                }
            }
        }