첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
------------------------------------------------------------------------------------------------------------------------------------------------------
728x90
728x170

TestProject.zip
다운로드

▶ 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
그리드형(광고전용)
Posted by icodebroker
,