예제 #1
0
        public static void RenderDebugAABB(this WorldView worldView, Graphics2D graphics2D, AxisAlignedBoundingBox bounds)
        {
            Vector3 renderPosition           = bounds.Center;
            Vector2 objectCenterScreenSpace  = worldView.GetScreenPosition(renderPosition);
            Point2D screenPositionOfObject3D = new Point2D((int)objectCenterScreenSpace.X, (int)objectCenterScreenSpace.Y);

            graphics2D.Circle(objectCenterScreenSpace, 5, Color.Magenta);

            for (int i = 0; i < 4; i++)
            {
                graphics2D.Circle(worldView.GetScreenPosition(bounds.GetTopCorner(i)), 5, Color.Magenta);
                graphics2D.Circle(worldView.GetScreenPosition(bounds.GetBottomCorner(i)), 5, Color.Magenta);
            }

            RectangleDouble screenBoundsOfObject3D = RectangleDouble.ZeroIntersection;

            for (int i = 0; i < 4; i++)
            {
                screenBoundsOfObject3D.ExpandToInclude(worldView.GetScreenPosition(bounds.GetTopCorner(i)));
                screenBoundsOfObject3D.ExpandToInclude(worldView.GetScreenPosition(bounds.GetBottomCorner(i)));
            }

            graphics2D.Circle(screenBoundsOfObject3D.Left, screenBoundsOfObject3D.Bottom, 5, Color.Cyan);
            graphics2D.Circle(screenBoundsOfObject3D.Left, screenBoundsOfObject3D.Top, 5, Color.Cyan);
            graphics2D.Circle(screenBoundsOfObject3D.Right, screenBoundsOfObject3D.Bottom, 5, Color.Cyan);
            graphics2D.Circle(screenBoundsOfObject3D.Right, screenBoundsOfObject3D.Top, 5, Color.Cyan);
        }
예제 #2
0
        public FloodFillDemo()
        {
            BackgroundColor = RGBA_Bytes.White;
            imageToFillOn   = new ImageBuffer(400, 300, 32, new BlenderBGRA());
            Graphics2D imageToFillGraphics = imageToFillOn.NewGraphics2D();

            imageToFillGraphics.Clear(RGBA_Bytes.White);
            imageToFillGraphics.DrawString("Click to fill", 20, 30);
            imageToFillGraphics.Circle(new Vector2(200, 150), 35, RGBA_Bytes.Black);
            imageToFillGraphics.Circle(new Vector2(200, 150), 30, RGBA_Bytes.Green);
            imageToFillGraphics.Rectangle(20, 50, 210, 280, RGBA_Bytes.Black);
            imageToFillGraphics.Rectangle(imageToFillOn.GetBounds(), RGBA_Bytes.Blue);

            Random rand = new Random();

            for (int i = 0; i < 20; i++)
            {
                Ellipse elipse  = new Ellipse(rand.Next(imageToFillOn.Width), rand.Next(imageToFillOn.Height), rand.Next(10, 60), rand.Next(10, 60));
                Stroke  outline = new Stroke(elipse);
                imageToFillGraphics.Render(outline, RGBA_Bytes.Black);
            }


            m_slider1 = new Slider(new Vector2(80, 10), 510);
            m_slider2 = new Slider(new Vector2(80, 10 + 20), 510);

            m_slider1.ValueChanged += new EventHandler(NeedsRedraw);
            m_slider2.ValueChanged += new EventHandler(NeedsRedraw);

            AddChild(m_slider1);
            AddChild(m_slider2);

            m_slider1.Text = "Pixel size={0:F3}";
            m_slider1.SetRange(8, 100);
            m_slider1.NumTicks = 23;
            m_slider1.Value    = 32;

            m_slider2.Text = "gamma={0:F3}";
            m_slider2.SetRange(0.0, 3.0);
            m_slider2.Value = 1.0;
        }
예제 #3
0
        public RandomFillWidget(Point2D size)
        {
            LocalBounds = new RectangleDouble(0, 0, size.x, size.y);
            image       = new ImageBuffer(size.x, size.y, 32, new BlenderBGRA());

            Random     rand          = new Random();
            Graphics2D imageGraphics = image.NewGraphics2D();

            for (int i = 0; i < 30; i++)
            {
                imageGraphics.Circle(rand.NextDouble() * image.Width, rand.NextDouble() * image.Height, rand.NextDouble() * 10 + 5, RGBA_Bytes.Red);
            }
        }
예제 #4
0
		// and just for fun lets also draw a circle
		public override void OnDraw(Graphics2D graphics2D)
		{
			graphics2D.Circle(320, 100, 50, RGBA_Bytes.Blue);
			base.OnDraw(graphics2D);
		}
예제 #5
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			graphics2D.Circle(Width / 2, Height / 2, Width / 2, RGBA_Bytes.White);
			graphics2D.Circle(Width / 2, Height / 2, Width / 2 - 1, RGBA_Bytes.Red);
			graphics2D.FillRectangle(Width / 2 - 1, Height / 2 - 3, Width / 2 + 1, Height / 2 + 3, RGBA_Bytes.White);
			base.OnDraw(graphics2D);
		}
예제 #6
0
        public static void Main(string[] args)
        {
            // first we will show how to use the simple drawing functions in graphics 2D
            {
                ImageBuffer simpleImage           = new ImageBuffer(640, 480, 32, new BlenderBGRA());
                Graphics2D  simpleImageGraphics2D = simpleImage.NewGraphics2D();
                // clear the image to white
                simpleImageGraphics2D.Clear(Color.White);
                // draw a circle
                simpleImageGraphics2D.Circle(50, 50, 30, Color.Blue);
                // draw a line
                simpleImageGraphics2D.Line(10, 100, 520, 50, new Color(20, 200, 200));
                // draw a filled box
                simpleImageGraphics2D.FillRectangle(60, 260, 200, 280, Color.Yellow);
                // and an outline around it
                simpleImageGraphics2D.Rectangle(60, 260, 200, 280, Color.Magenta);
                // draw some text
                simpleImageGraphics2D.DrawString("A Simple Example", 300, 400, 20);

                // and save this image out
                ImageTgaIO.Save(simpleImage, "SimpleDrawAndSave.tga");
            }

            // now we will we will show how to use the render function to draw more complex things
            {
                ImageBuffer lessSimpleImage           = new ImageBuffer(640, 480, 32, new BlenderBGRA());
                Graphics2D  lessSimpleImageGraphics2D = lessSimpleImage.NewGraphics2D();
                // clear the image to white
                lessSimpleImageGraphics2D.Clear(Color.White);
                // draw a circle
                Ellipse ellipseTest = new Ellipse(0, 0, 100, 50);
                for (double angleDegrees = 0; angleDegrees < 180; angleDegrees += 22.5)
                {
                    VertexSourceApplyTransform rotatedTransform = new VertexSourceApplyTransform(ellipseTest, Affine.NewRotation(MathHelper.DegreesToRadians(angleDegrees)));
                    VertexSourceApplyTransform rotatedAndTranslatedTransform = new VertexSourceApplyTransform(rotatedTransform, Affine.NewTranslation(lessSimpleImage.Width / 2, 150));
                    lessSimpleImageGraphics2D.Render(rotatedAndTranslatedTransform, Color.Yellow);
                    Stroke ellipseOutline = new Stroke(rotatedAndTranslatedTransform, 3);
                    lessSimpleImageGraphics2D.Render(ellipseOutline, Color.Blue);
                }

                // and a little polygon
                VertexStorage littlePoly = new VertexStorage();
                littlePoly.MoveTo(50, 50);
                littlePoly.LineTo(150, 50);
                littlePoly.LineTo(200, 200);
                littlePoly.LineTo(50, 150);
                littlePoly.LineTo(50, 50);
                lessSimpleImageGraphics2D.Render(littlePoly, Color.Cyan);

                // draw some text
                TypeFacePrinter textPrinter    = new TypeFacePrinter("Printing from a printer", 30, justification: Justification.Center);
                IVertexSource   translatedText = new VertexSourceApplyTransform(textPrinter, Affine.NewTranslation(new Vector2(lessSimpleImage.Width / 2, lessSimpleImage.Height / 4 * 3)));
                lessSimpleImageGraphics2D.Render(translatedText, Color.Red);
                Stroke strokedText = new Stroke(translatedText);
                lessSimpleImageGraphics2D.Render(strokedText, Color.Black);

                IVertexSource rotatedText           = new VertexSourceApplyTransform(textPrinter, Affine.NewRotation(MathHelper.DegreesToRadians(90)));
                IVertexSource rotatedTranslatedText = new VertexSourceApplyTransform(rotatedText, Affine.NewTranslation(new Vector2(40, lessSimpleImage.Height / 2)));
                lessSimpleImageGraphics2D.Render(rotatedTranslatedText, Color.Black);

                // and save this image out
                ImageTgaIO.Save(lessSimpleImage, "LessSimpleDrawAndSave.tga");
            }
        }
예제 #7
0
 // and just for fun lets also draw a circle
 public override void OnDraw(Graphics2D graphics2D)
 {
     graphics2D.Circle(320, 100, 50, Color.Blue);
     base.OnDraw(graphics2D);
 }
예제 #8
0
 public override void OnDraw(Graphics2D graphics2D)
 {
     graphics2D.Circle(Width / 2, Height / 2, Width / 2, RGBA_Bytes.White);
     graphics2D.Circle(Width / 2, Height / 2, Width / 2 - 1, RGBA_Bytes.Red);
     graphics2D.FillRectangle(Width / 2 - 1, Height / 2 - 3, Width / 2 + 1, Height / 2 + 3, RGBA_Bytes.White);
     //graphics2D.DrawString("1", Width / 2, Height / 2 + 1, 8, Justification.Center, Baseline.BoundsCenter, RGBA_Bytes.White);
     base.OnDraw(graphics2D);
 }
예제 #9
0
 // and just for fun lets also draw a circle
 public override void OnDraw(Graphics2D graphics2D)
 {
     graphics2D.Circle(320, 100, 50, RGBA_Bytes.Blue);
     base.OnDraw(graphics2D);
 }