Advertisement
Guest User

Untitled

a guest
Mar 28th, 2011
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.00 KB | None | 0 0
  1. using System;
  2. using System.Drawing;
  3. using System.Drawing.Imaging;
  4. using System.IO;
  5.  
  6. namespace ConsoleApplication3
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Double xStart = 0.25;
  13.             Double yStart = 0.92;
  14.             Double startAngle = 169.51;
  15.             Double sweepAngle = 123.78;
  16.             Double Rx = 0.436;
  17.             Double Ry = 0.593;
  18.  
  19.             Double centerX = xStart - Rx * Math.Cos(startAngle * Math.PI / 180.0);
  20.             Double centerY = yStart - Ry * Math.Sin(startAngle * Math.PI / 180.0);
  21.             Double endAngle = startAngle + sweepAngle;
  22.             Double xEnd = centerX + Rx * Math.Cos(endAngle * Math.PI / 180.0);
  23.             Double yEnd = centerY + Ry * Math.Sin(endAngle * Math.PI / 180.0);
  24.  
  25.             Console.WriteLine("x end = {0}", xEnd);
  26.             Console.WriteLine("y end = {0}", yEnd);
  27.  
  28.             String savePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "ellipse.png");
  29.             CreateEllipseBitmap(centerX, centerY, Rx, Ry, 1000, savePath);
  30.  
  31.             Console.ReadKey();
  32.         }
  33.  
  34.         private static void CreateEllipseBitmap(Double centerX, Double centerY, Double rx, Double ry, Int32 factor, String savePath)
  35.         {
  36.             Int32 bitmapWidth = (Int32)(factor * (centerX + rx)) + 10;
  37.             Int32 bitmapHeight = (Int32)(factor * (centerY + ry)) + 10;
  38.  
  39.             Bitmap bitmap = new Bitmap(bitmapWidth, bitmapHeight);
  40.            
  41.             for (Double angle = 2 * Math.PI; angle > 0; angle -= 2 * Math.PI / 3600)
  42.             {
  43.                 Int32 x = (Int32)( factor * (centerX + rx * Math.Cos(angle)) );
  44.                 Int32 y = (Int32)( factor * (centerY + ry * Math.Sin(angle)) );
  45.  
  46.                 bitmap.SetPixel(x - 1, y, Color.Red);
  47.                 bitmap.SetPixel(x, y, Color.Red);
  48.                 bitmap.SetPixel(x + 1, y, Color.Red);
  49.             }
  50.  
  51.             bitmap.Save(savePath, ImageFormat.Png);
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement