Пример #1
0
        bool ready = false;  // Flag for allowing sliders, etc., to influence display.

        public Window1()
        {
            InitializeComponent();
            InitializeCommands();

            // Now add some graphical items in the main Canvas, whose name is "GraphPaper"
            gp = this.FindName("Paper") as GraphPaper;

            // Build a table of vertices:
            const int nPoints = 8;
            const int nEdges  = 12;

            double[,] vtable = new double[nPoints, 3]
            {
                { -0.5, -0.5, 2.5 },
                { -0.5, 0.5, 2.5 },
                { 0.5, 0.5, 2.5 },
                { 0.5, -0.5, 2.5 },
                { -0.5, -0.5, 3.5 },
                { -0.5, 0.5, 3.5 },
                { 0.5, 0.5, 3.5 },
                { 0.5, -0.5, 3.5 }
            };

            // Build a table of edges
            int[,] etable = new int[nEdges, 2] {
                { 0, 1 }, { 1, 2 }, { 2, 3 }, { 3, 0 }, // one face
                { 0, 4 }, { 1, 5 }, { 2, 6 }, { 3, 7 }, // joining edges
                { 4, 5 }, { 5, 6 }, { 6, 7 }, { 7, 4 }
            };                                          // opposite face

            double xmin = -0.5;
            double xmax = 0.5;
            double ymin = -0.5;
            double ymax = 0.5;

            Point[] pictureVertices = new Point[nPoints];
            double  scale           = 100;

            for (int i = 0; i < nPoints; i++)
            {
                double x      = vtable[i, 0];
                double y      = vtable[i, 1];
                double z      = vtable[i, 2];
                double xprime = x / z;
                double yprime = y / z;
                pictureVertices[i].X = scale * (1 - (xprime - xmin) / (xmax - xmin));
                pictureVertices[i].Y = scale * (yprime - ymin) / (ymax - ymin); // x / z
                gp.Children.Add(new Dot(pictureVertices[i].X, pictureVertices[i].Y));
            }

            for (int i = 0; i < nEdges; i++)
            {
                int n1 = etable[i, 0];
                int n2 = etable[i, 1];
                gp.Children.Add(new Segment(pictureVertices[n1], pictureVertices[n2]));
            }

            ready = true; // Now we're ready to have sliders and buttons influence the display.
        }
Пример #2
0
        // Code to create and display objects goes here.
        public Window1()
        {
            InitializeComponent();
            InitializeCommands();

            // Now add some graphical items in the main drawing area, whose name is "Paper"
            gp = this.FindName("Paper") as GraphPaper;


            // Track mouse activity in this window
            MouseLeftButtonDown += MyMouseButtonDown;
            MouseLeftButtonUp   += MyMouseButtonUp;
            MouseMove           += MyMouseMove;

            #region Triangles, segments, dots
            // A triangle, whose top point can be moved using the slider.
            myTriangle = new Polygon();
            myTriangle.Points.Add(new Point(0, 10));
            myTriangle.Points.Add(new Point(10, 0));
            myTriangle.Points.Add(new Point(-10, 0));
            myTriangle.Stroke          = Brushes.Black;
            myTriangle.StrokeThickness = 1; // 1 mm thick line
            myTriangle.Fill            = Brushes.LightSeaGreen;
            gp.Children.Add(myTriangle);

            // A draggable Dot, which is the basepoint of an arrow.
            Dot dd = new Dot(new Point(-40, 60));
            dd.MakeDraggable(gp);
            gp.Children.Add(dd);

            Arrow ee = new Arrow(dd, new Point(10, 10), Arrow.endtype.END);
            gp.Children.Add(ee);

            // a dot and a segment that's attached to it; the dot is animated
            Dot p1 = new Dot(new Point(20, 20));
            gp.Children.Add(p1);
            Point   p2        = new Point(50, 50);
            Segment mySegment = new Segment(p1, p2);
            gp.Children.Add(mySegment);

            PointAnimation animaPoint1 = new PointAnimation(
                new Point(-20, -20),
                new Point(-40, 20),
                new Duration(new TimeSpan(0, 0, 5)));
            animaPoint1.AutoReverse    = true;
            animaPoint1.RepeatBehavior = RepeatBehavior.Forever;
            p1.BeginAnimation(Dot.PositionProperty, animaPoint1);
            #endregion
            #region Images

            // And a photo from a file, then another that's
            // created on-the-fly instead of read from a file.

            myImage1          = new GImage("./foo.jpg");
            myImage1.Width    = GraphPaper.wpf(200);
            myImage1.Position = new Point(10, 40);
            Point pq = new Point(10, 40);

            gp.Children.Add(myImage1);

            // Now add a second image, based on first building an array of color values
            // Create source array
            byte[, ,] stripes = createStripeImageArray();

            myImage2 = new GImage(stripes);

            // Establish the width and height for this image on the GraphPaper
            myImage2.Width  = GraphPaper.wpf(128);
            myImage2.Height = GraphPaper.wpf(128);

            myImage2.Position = new Point(-40, 20);
            gp.Children.Add(myImage2);
            #endregion
            #region Mesh, Quiver, and Text labels

            myMesh = this.createSampleMesh();
            gp.Children.Add(myMesh);

            Text myText = new Text("THIS IS TEXT");
            myText.Position = new Point(20, 50);
            gp.Children.Add(myText);

            myQuiver = makeQuiver();
            foreach (Shape q in myQuiver)
            {
                gp.Children.Add(q);
            }

            #endregion
            ready = true; // Now we're ready to have sliders and buttons influence the display.
        }