如何在VB.NET中绘制爆炸图

如何在VB.NET中绘制爆炸图,vb.net,graphics,2d,Vb.net,Graphics,2d,我想画一个爆炸图。所谓绘图,我指的是使用e.graphics功能,而不是使用Picturebox(就像我上次做的那样) 现在我的问题是,我到底该怎么做?在我看来,我正在考虑使用e.graphics.fillrectangle(x,y,w,h),改变位置和颜色,创建一个类似爆炸的合成图像。然而,这个过程似乎有点偶然,因为我必须进行实验来尝试并做到这一点-有没有更有效的方法来做到这一点?您可能会发现FillPolygonPoint方法更有用 想象一下你爆炸的所有点是这样的: using System

我想画一个爆炸图。所谓绘图,我指的是使用
e.graphics
功能,而不是使用
Picturebox
(就像我上次做的那样)


现在我的问题是,我到底该怎么做?在我看来,我正在考虑使用
e.graphics.fillrectangle(x,y,w,h)
,改变位置和颜色,创建一个类似爆炸的合成图像。然而,这个过程似乎有点偶然,因为我必须进行实验来尝试并做到这一点-有没有更有效的方法来做到这一点?

您可能会发现FillPolygonPoint方法更有用

想象一下你爆炸的所有点是这样的:

using System;
using System.Drawing;
using System.Collections.Generic;

namespace Explosion
{
    class Program
    {
        static void Main(string[] args)
        {
            foreach (Point point in CreatePointsForStarShape(15, 200, 100))
            {
                Console.WriteLine(point);
            }
            Console.ReadLine();
        }

        public static IEnumerable<Point> CreatePointsForStarShape
                  (int numberOfPoints, int maxRadius, int minRadius)
        {
            List<Point> points = new List<Point>(numberOfPoints);

            for (
                 double angle = 0.0;
                 angle < 2* Math.PI;
                 angle += 2 * Math.PI / numberOfPoints
            )
            {
                // add outer point
                points.Add(CalculatePoint(angle, maxRadius));

                // add inner point
                points.Add(CalculatePoint
                    (angle + (Math.PI / numberOfPoints), minRadius));
            }

            return points;
        }

        public static Point CalculatePoint(double angle, int radius)
        {
            return new Point(
               (int)(Math.Sin(angle) * radius),
               (int)(Math.Cos(angle) * radius)
            );
        }
    }
}

然后,要绘制它的代码看起来如下所示:

Public Sub FillPolygonPoint(ByVal e As PaintEventArgs)

  ' Create solid brush. 
  Dim blueBrush As New SolidBrush(Color.Blue)

  ' Create points that define polygon. 
  Dim point1 As New Point(50, 50)
  Dim point2 As New Point(100, 25)
  Dim point3 As New Point(200, 5)
  Dim point4 As New Point(250, 50)
  Dim point5 As New Point(300, 100)
  Dim point6 As New Point(350, 200)
  Dim point7 As New Point(250, 250)
  Dim curvePoints As Point() = {point1, point2, point3, point4, _
    point5, point6, point7}

  ' Draw polygon to screen.
  e.Graphics.FillPolygon(blueBrush, curvePoints)
End Sub
作为

动态创建星形点的算法(C#)可能如下所示:

using System;
using System.Drawing;
using System.Collections.Generic;

namespace Explosion
{
    class Program
    {
        static void Main(string[] args)
        {
            foreach (Point point in CreatePointsForStarShape(15, 200, 100))
            {
                Console.WriteLine(point);
            }
            Console.ReadLine();
        }

        public static IEnumerable<Point> CreatePointsForStarShape
                  (int numberOfPoints, int maxRadius, int minRadius)
        {
            List<Point> points = new List<Point>(numberOfPoints);

            for (
                 double angle = 0.0;
                 angle < 2* Math.PI;
                 angle += 2 * Math.PI / numberOfPoints
            )
            {
                // add outer point
                points.Add(CalculatePoint(angle, maxRadius));

                // add inner point
                points.Add(CalculatePoint
                    (angle + (Math.PI / numberOfPoints), minRadius));
            }

            return points;
        }

        public static Point CalculatePoint(double angle, int radius)
        {
            return new Point(
               (int)(Math.Sin(angle) * radius),
               (int)(Math.Cos(angle) * radius)
            );
        }
    }
}

您必须将其转换为VisualBasic,并添加一些随机化,使其具有爆炸性的外观。你可以通过矩阵乘法变换(移动)和缩放点。

事实上,我确实在考虑使用这个。我已经用这个做三角形了!但是你仍然需要创建很多这样的多边形来创建一个像爆炸一样的图像-所以除了这个,还有没有更快的方法呢?当然!您可以创建一个算法来为您计算点。一般来说(假设我正确地推断了爆炸图像),您可以创建一种方法,该方法采用(要创建的点的数量、中心点、最大直径、最小直径、随机度),返回围绕中心辐射的点集合(如车轮的辐条),具有一定的随机性(角度,与中心的距离)。这有帮助吗?确实有帮助,但算法是什么样的?