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
:
그런 다음 코드는의 라인을 따라 뭔가를 보이는립니다.
(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을 사용하고 무작위 화를 추가하여 폭발적인 시각을 보입니다. 행렬 곱셈을 통해 포인트를 조 변경 (이동) 및 스케일 조절할 수 있습니다.
실제로 - 저는 이것을 실제로 사용하려고 생각했습니다. 이미 삼각형에 이것을 사용합니다! 그러나 폭발과 같은 이미지를 만들기 위해 여전히 이러한 폴리곤을 많이 만들어야합니다. 그렇기 때문에 이렇게 더 빨리 수행 할 수있는 방법이 있습니까? – Azerty560
물론! 포인트를 계산하는 알고리즘을 만들 수 있습니다. 일반적으로 (폭발의 이미지를 정확하게 추측한다고 가정 할 때) 점들의 집합을 반환하는 (생성 점, 중심점, 최대 직경, 최소 직경, 임의성의 정도)을 취할 수있는 방법을 만들 수 있습니다 어느 정도의 임의성 (각도, 중심으로부터의 거리)으로 중심을 중심으로 (바퀴의 쐐기처럼) 방사합니다. 이게 도움이 되나요? – rtev
실제로 도움이되지만 알고리즘은 어떻게 생겼을까요? – Azerty560