Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.IO;
- namespace ConsoleApplication3
- {
- class Program
- {
- static void Main(string[] args)
- {
- Double xStart = 0.25;
- Double yStart = 0.92;
- Double startAngle = 169.51;
- Double sweepAngle = 123.78;
- Double Rx = 0.436;
- Double Ry = 0.593;
- Double centerX = xStart - Rx * Math.Cos(startAngle * Math.PI / 180.0);
- Double centerY = yStart - Ry * Math.Sin(startAngle * Math.PI / 180.0);
- Double endAngle = startAngle + sweepAngle;
- Double xEnd = centerX + Rx * Math.Cos(endAngle * Math.PI / 180.0);
- Double yEnd = centerY + Ry * Math.Sin(endAngle * Math.PI / 180.0);
- Console.WriteLine("x end = {0}", xEnd);
- Console.WriteLine("y end = {0}", yEnd);
- String savePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "ellipse.png");
- CreateEllipseBitmap(centerX, centerY, Rx, Ry, 1000, savePath);
- Console.ReadKey();
- }
- private static void CreateEllipseBitmap(Double centerX, Double centerY, Double rx, Double ry, Int32 factor, String savePath)
- {
- Int32 bitmapWidth = (Int32)(factor * (centerX + rx)) + 10;
- Int32 bitmapHeight = (Int32)(factor * (centerY + ry)) + 10;
- Bitmap bitmap = new Bitmap(bitmapWidth, bitmapHeight);
- for (Double angle = 2 * Math.PI; angle > 0; angle -= 2 * Math.PI / 3600)
- {
- Int32 x = (Int32)( factor * (centerX + rx * Math.Cos(angle)) );
- Int32 y = (Int32)( factor * (centerY + ry * Math.Sin(angle)) );
- bitmap.SetPixel(x - 1, y, Color.Red);
- bitmap.SetPixel(x, y, Color.Red);
- bitmap.SetPixel(x + 1, y, Color.Red);
- }
- bitmap.Save(savePath, ImageFormat.Png);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement