Fig. 17.22
Paths used to draw stars on a form.
1
|
2
|
3 using System;
|
4 using System.Drawing;
|
5 using System.Drawing.Drawing2D;
|
6 using System.Windows.Forms;
|
7
|
8
|
9 public partial class DrawStarsForm : Form
|
10 {
|
11
|
12 public DrawStarsForm()
|
13 {
|
14 InitializeComponent();
|
15 }
|
16
|
17
|
18 private void DrawStarsForm_Paint(object sender, PaintEventArgs e)
|
19 {
|
20 Graphics graphicsObject = e.Graphics;
|
21 Random random = new Random();
|
22 SolidBrush brush =
|
23 new SolidBrush( Color.DarkMagenta );
|
24
|
25
|
26 int[] xPoints =
|
27 { 55, 67, 109, 73, 83, 55, 27, 37, 1, 43 };
|
28 int[] yPoints =
|
29 { 0, 36, 36, 54, 96, 72, 96, 54, 36, 36 };
|
30
|
31
|
32 GraphicsPath star = new GraphicsPath();
|
33
|
34
|
35 for ( int i = 0; i <= 8; i += 2 )
|
36 star.AddLine( xPoints[ i ], yPoints[ i ],
|
37 xPoints[ i + 1 ], yPoints[ i + 1 ] );
|
38
|
39
|
40 star.CloseFigure();
|
41
|
42
|
43 graphicsObject.TranslateTransform( 150, 150 );
|
44
|
45
|
46 for ( int i = 1; i <= 18; i++ )
|
47 {
|
48 graphicsObject.RotateTransform( 20 );
|
49
|
50 brush.Color = Color.FromArgb(
|
51 random.Next( 200, 255 ), random.Next( 255 ),
|
52 random.Next( 255 ), random.Next( 255 ) );
|
53
|
54 graphicsObject.FillPath( brush, star );
|
55 }
|
56 }
|
57 }
|
|
|