2012-08-22 5 views
0

나는 폭발하려고합니다. 무승부로, 나는 e.graphics 기능을 사용하여 Picturebox (이전에했던 것처럼)과 반대되는 의미입니다.VB.NET에서 폭발을 그리는 법

이제 내 질문은, 내가 어떻게이 일을 정확하게 수행하겠습니까? 내 마음 속에, 나는 e.graphics.fillrectangle(x,y,w,h)을 사용하는 것을 생각하고있다 ... 위치와 색상을 변경하여 폭발과 유사한 합성 이미지를 만든다. 그러나이 과정을 시도해보고 실험해야하기 때문에 약간의 충돌이 발생합니다. 더 효과적으로 처리 할 수있는 방법이 있습니까?

답변

2

FillPolygonPoint 메서드를 더 유용하게 사용할 수 있습니다.

이처럼 폭발의 모든 점을 상상해 outlined in the documentation provided by Microsoft으로

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 

:

Explosion as Polygon

그런 다음 코드는의 라인을 따라 뭔가를 보이는립니다.

(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) 
      ); 
     } 
    } 
} 

출력의 ...

{X=0,Y=200} 
{X=20,Y=97} 
{X=81,Y=182} 
{X=58,Y=80} 
{X=148,Y=133} 
{X=86,Y=50} 
{X=190,Y=61} 
{X=99,Y=10} 
{X=198,Y=-20} 
{X=95,Y=-30} 
{X=173,Y=-99} 
{X=74,Y=-66} 
{X=117,Y=-161} 
{X=40,Y=-91} 
{X=41,Y=-195} 
{X=0,Y=-100} 
{X=-41,Y=-195} 
{X=-40,Y=-91} 
{X=-117,Y=-161} 
{X=-74,Y=-66} 
{X=-173,Y=-99} 
{X=-95,Y=-30} 
{X=-198,Y=-20} 
{X=-99,Y=10} 
{X=-190,Y=61} 
{X=-86,Y=50} 
{X=-148,Y=133} 
{X=-58,Y=80} 
{X=-81,Y=182} 
{X=-20,Y=97} 
{X=0,Y=200} 
{X=20,Y=97} 

당신이 번역해야합니다 Visual Basic을 사용하고 무작위 화를 추가하여 폭발적인 시각을 보입니다. 행렬 곱셈을 통해 포인트를 조 변경 (이동) 및 스케일 조절할 수 있습니다.

+0

실제로 - 저는 이것을 실제로 사용하려고 생각했습니다. 이미 삼각형에 이것을 사용합니다! 그러나 폭발과 같은 이미지를 만들기 위해 여전히 이러한 폴리곤을 많이 만들어야합니다. 그렇기 때문에 이렇게 더 빨리 수행 할 수있는 방법이 있습니까? – Azerty560

+0

물론! 포인트를 계산하는 알고리즘을 만들 수 있습니다. 일반적으로 (폭발의 이미지를 정확하게 추측한다고 가정 할 때) 점들의 집합을 반환하는 (생성 점, 중심점, 최대 직경, 최소 직경, 임의성의 정도)을 취할 수있는 방법을 만들 수 있습니다 어느 정도의 임의성 (각도, 중심으로부터의 거리)으로 중심을 중심으로 (바퀴의 쐐기처럼) 방사합니다. 이게 도움이 되나요? – rtev

+0

실제로 도움이되지만 알고리즘은 어떻게 생겼을까요? – Azerty560

관련 문제