Среда программирования:
Visual Studio 2012
Статья по теме:
Звезда вырисовывается при кликании на форме.
Код программы:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Star { public partial class Form1 : Form { Pen p; SolidBrush fon; Graphics gr; double pi = 3.14; void Draw_Pentagon(double x, double y, double r, double angle) { p = new Pen(Color.Orange, 2); gr = pictureBox1.CreateGraphics(); gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; int i; double[] x1 = new double[5]; double[] y1 = new double[5]; for (i = 0; i < 5; i++) { x1[i] = r * Math.Cos(angle + i * pi * 2 / 5); y1[i] = r * Math.Sin(angle + i * pi * 2 / 5); } for (i = 0; i < 4; i++) { gr.DrawLine(p, (int)Math.Round(x + x1[i]), (int)Math.Round(y + y1[i]), (int)Math.Round(x + x1[i + 1]), (int)Math.Round(y + y1[i + 1])); } } void Draw_Star(double x, double y, double r, double angle, int d) { int i; double h; h = 2 * r * Math.Cos(pi / 5); for (i = 0; i < 5; i++) { Draw_Pentagon(x - h * Math.Cos(angle + i * pi * 2 / 5), y - h * Math.Sin(angle + i * pi * 2 / 5), r, angle + pi + i * pi * 2 / 5); if (d > 0) Draw_Star(x - h * Math.Cos(angle + i * pi * 2 / 5), y - h * Math.Sin(angle + i * pi * 2 / 5), r / (2 * Math.Cos(pi / 5) + 1), angle + pi + (2 * i + 1) * pi * 2 / 10, d - 1); } Draw_Pentagon(x, y, r, angle); if (d > 0) Draw_Star(x, y, r / (2 * Math.Cos(pi / 5) + 1), angle + pi, d - 1); } public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void pictureBox1_Click(object sender, EventArgs e) { fon = new SolidBrush(Color.Black); gr = pictureBox1.CreateGraphics(); gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; gr.FillRectangle(fon, 0, 0, pictureBox1.Width, pictureBox1.Height); Draw_Star(300, 250, 85, pi / 2, 4); } } }