728x90
728x170
▶ MainForm.cs
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : Form
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 주기
/// </summary>
private const int PERIOD = 21;
/// <summary>
/// 색상 배열
/// </summary>
private Color[] colorArray;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
#region 이벤트를 설정한다.
Load += Form_Load;
Paint += Form_Paint;
#endregion
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
//////////////////////////////////////////////////////////////////////////////// Event
#region 폼 로드시 처리하기 - Form_Load(sender, e)
/// <summary>
/// 폼 로드시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Form_Load(object sender, EventArgs e)
{
ResizeRedraw = true;
DoubleBuffered = true;
this.colorArray = new Color[]
{
Color.Pink,
Color.Red,
Color.Orange,
Color.Yellow,
Color.Lime,
Color.Cyan,
Color.Blue,
Color.Violet,
Color.Pink,
Color.Red,
Color.Orange,
Color.Yellow,
Color.Lime,
Color.Cyan,
Color.Blue,
Color.Violet,
Color.Pink,
Color.Red,
Color.Orange,
Color.Yellow,
Color.Lime,
Color.Cyan,
Color.Blue,
Color.Violet
};
}
#endregion
#region 폼 페인트시 처리하기 - Form_Paint(sender, e)
/// <summary>
/// 폼 페인트시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Form_Paint(object sender, PaintEventArgs e)
{
const float Y_MAXIMUM = -11;
const float Y_MINIMUM = 11;
const float HEIGHT = Y_MINIMUM - Y_MAXIMUM;
const float WIDTH = HEIGHT;
float scale = Math.Min
(
this.ClientSize.Width / WIDTH,
this.ClientSize.Height / HEIGHT
);
e.Graphics.ScaleTransform(scale, scale);
e.Graphics.TranslateTransform
(
ClientSize.Width / 2,
ClientSize.Height / 2,
MatrixOrder.Append
);
const long lineCount = 5000;
double t = 0;
double r = 5 * (1 + Math.Sin(11 * t / 5)) - 4 * Math.Pow(Math.Sin(17 * t / 3), 4) * Math.Pow(Math.Sin(2 * Math.Cos(3 * t) - 28 * t), 8);
PointF pt1 = new PointF((float)(r * Math.Sin(t)), (float)(-r * Math.Cos(t)));
using(Pen pen = new Pen(Color.Blue, 0))
{
for(int i = 0; i <= lineCount; i++)
{
t = i * PERIOD * Math.PI / lineCount;
r = 5 * (1 + Math.Sin(11 * t / 5)) - 4 * Math.Pow(Math.Sin(17 * t / 3), 4) * Math.Pow(Math.Sin(2 * Math.Cos(3 * t) - 28 * t), 8);
PointF pt0 = pt1;
pt1 = new PointF((float)(r * Math.Sin(t)), (float)(r * Math.Cos(t)));
pen.Color = GetColor(t);
e.Graphics.DrawLine(pen, pt0, pt1);
}
}
}
#endregion
//////////////////////////////////////////////////////////////////////////////// Function
#region 색상 구하기 - GetColor(t)
/// <summary>
/// 색상 구하기
/// </summary>
/// <param name="t">T</param>
/// <returns>색상</returns>
private Color GetColor(double t)
{
int index = (int)(t / Math.PI);
return this.colorArray[index % this.colorArray.Length];
}
#endregion
}
}
728x90
그리드형(광고전용)
'C# > WinForm' 카테고리의 다른 글
[C#/WINFORM] 좌표 시스템간 포인트 매핑하기 (0) | 2018.12.22 |
---|---|
[C#/WINFORM] 모달 컨텍스트 메뉴 사용하기 (0) | 2018.12.22 |
[C#/WINFORM] ListBox 클래스 : 사용자 정의 그리기 (0) | 2018.12.22 |
[C#/WINFORM] ListBox 클래스 : 사용자 정의 그리기 (0) | 2018.12.22 |
[C#/WINFORM] 국화 곡선(Chrysanthemum Curve) 칠하기 (0) | 2018.12.22 |
[C#/WINFORM] PictureBox 클래스 : 더블 버퍼링 사용하기 (0) | 2018.12.22 |
[C#/WINFORM] 에피트로코이드(Epitrochoid) 그리기 (애니메이션) (0) | 2018.12.22 |
[C#/WINFORM] 에피트로코이드(Epitrochoid) 그리기 (0) | 2018.12.22 |
[C#/WINFORM] TabControl 클래스 : 사용자 정의 그리기 (0) | 2018.12.22 |
[C#/WINFORM] 실시간 그래프 그리기 (0) | 2018.12.21 |