Bezier Art: DrawBeziers : Graphics « 2D Graphics « C# / C Sharp






Bezier Art: DrawBeziers

 


using System;
using System.Drawing;
using System.Windows.Forms;
   
class BezierArt: Form
{
   
     public static void Main()
     {
          Application.Run(new BezierArt());
     }
     public BezierArt()
     {
          ResizeRedraw = true; 
     }
     protected override void OnPaint(PaintEventArgs pea)
     {
          DoPage(pea.Graphics, ForeColor,200, 200);
     }       
     protected void DoPage(Graphics grfx, Color clr, int cx, int cy)
     {
          Pen      pen  = new Pen(clr);
          PointF[] aptf = new PointF[4];
   
          int iNum = 100;
 
          for (int i = 0; i < iNum; i++)
          {
               double dAngle = 2 * i * Math.PI / iNum;
   
               aptf[0].X =     cx / 2 + cx /  2 * (float) Math.Cos(dAngle);
               aptf[0].Y = 5 * cy / 8 + cy / 16 * (float) Math.Sin(dAngle);
   
               aptf[1] = new PointF(cx / 2,    -cy);
               aptf[2] = new PointF(cx / 2, 2 * cy);
   
               dAngle += Math.PI;
   
               aptf[3].X = cx / 2 + cx /  4 * (float) Math.Cos(dAngle);
               aptf[3].Y = cy / 2 + cy / 16 * (float) Math.Sin(dAngle);
   
               grfx.DrawBeziers(pen, aptf);
          }
     }
}

 








Related examples in the same category

1.Graphics: TranslateClip
2.Graphics: SetClip
3.Scribble with MouseScribble with Mouse
4.FillPolygon: Alternate and Winding Fill Modes
5.One-Inch Ellipse
6.Graphics: FillRectangles
7.Graphics: FillRectangle
8.Graphics: FillEllipse
9.Wide Polyline: DrawLines
10.Line and Arc Combo
11.Graphics: FillClosedCurve
12.Graphics: MeasureString
13.Clear a Graphics
14.Graphics: DrawRectangles
15.Graphics: DrawRectangle
16.Draw Ellipse
17.Graphics: DrawArc
18.Graphics: DrawPie
19.Draw a Rectangle
20.Draw an Image
21.FillEllipse: Red Traffic Light
22.Graphics: Draw an Icon
23.Graphics: DrawString
24.Use different Font object to draw a line of text
25.Graphics: ScaleTransform
26.Graphics: Transform
27.Graphics: TranslateTransform
28.Graphics: Pen Alignment
29.Graphics: PageScale
30.Graphics: PageUnit
31.DpiY and DpiX
32.PixelOffsetMode
33.Paint along points in a list pointsPaint along points in a list points
34.Picture Cube: DrawImage
35.Clipping: ResetClip
36.Rotate the text 45 degrees clockwise then Translate the text 150 pixels horizontally
37.Transform and RotateTransform in a loop
38.Apply the scaling transformation(scale subsequent operations by 2x horizontally and 3x vertically)
39.Translate the text 150 pixels horizontally and 75 vertically
40.Reset the transformation Translate by 30 pixels in vertical direction
41.Rotate the text through 45 degrees
42.Fill the area 'bounded' by the path
43.DrawImage with destination points
44.DrawImage with size
45.Graphics.SmoothingMode
46.DrawPie with offset
47.TransformPoints
48.Fill a Rectangle with TextureBrush
49.Fill a Rectangle with LinearGradientBrush