Перевести из Pascal В C# - C# (182558)
Формулировка задачи:
Работяги, пожалуйста помогите. В C# несеку вообще, но надо было сделать задание на С#, а я запилил на Pascal.
Вот код:
За ранее спасибо
uses graphABC;
const r = 90;
var sr, x, x1, y1, x2, y2, xi: integer; a: real;
procedure strelki(x1, y1: integer); {Процедура секунд}
begin
var i:integer;
for i := 0 to 11 do {Рисование чисел по окружности}
begin
a := pi * (i + 10) * 30 / 180;
x2 := 596 + round((r + 30) * cos(a));
y2 := 396 + round((r + 30) * sin(a));
if i > 9 then x2 := x2 - 3;
textout(x2, y2, IntToStr(i + 1));
end;
sr := 120;
setpencolor(clred);
a := pi * (x + 45) * 6 / 180;
x1 := 600 + round(sr * cos(a)); {Рисуется стрелка}
y1 := 400 + round(sr * sin(a));
line(600, 400, x1, y1);
setpencolor(clblack);
setpenwidth(3);
sr:=100;
a := pi * (((xi div 60) mod 12) * 5 + 45) * 6 / 180;
x1 := 600 + round(sr * cos(a)); {Рисуется часовая стрелка}
y1 := 400 + round(sr * sin(a));
line(600, 400, x1, y1);
setpencolor(clgreen);
setpenwidth(2);
sr:=110;
a := pi * ((xi mod 60) + 45) * 6 / 180;
x1 := 600 + round(sr * cos(a)); {Рисуется минутная стрелка}
y1 := 400 + round(sr * sin(a));
line(600, 400, x1, y1);
sleep(1000);
sr := 120;
setpencolor(clwhite);
a := pi * (x + 45) * 6 / 180;
x1 := 600 + round(sr * cos(a)); {Рисуется секундная стрелка (белым)}
y1 := 400 + round(sr * sin(a));
line(600, 400, x1, y1);
setpencolor(clwhite);
setpenwidth(3);
sr:=100;
a := pi * (((xi div 60) mod 12) * 5 + 45) * 6 / 180;
x1 := 600 + round(sr * cos(a)); {Рисуется часовая стрелка (белым)}
y1 := 400 + round(sr * sin(a));
line(600, 400, x1, y1);
setpencolor(clwhite);
setpenwidth(2);
sr:=110;
a := pi * ((xi mod 60) + 45) * 6 / 180;
x1 := 600 + round(sr * cos(a)); {Рисуется минутная стрелка (белым)}
y1 := 400 + round(sr * sin(a));
line(600, 400, x1, y1);
setpenwidth(1);
setpencolor(clblack);
a := pi * (x + 45) * 6 / 180;
x1 := 600 + round(r * cos(a)); {Закрашиваение секундных делений после прохода стрелки}
y1 := 400 + round(r * sin(a));
line(600, 400, x1, y1);
setpencolor(clblack); {Рисование круга поверх делений на секунды}
circle(600, 400, 80);
end;
BEGIN
maximizewindow;
circle(600, 400, 135); {Рисование круга поверх чисел}
for x := 0 to 60 do
begin
a := pi * x / 30;
x1 := 600 + round(r * cos(a)); {Рисование круга какого-то, из-за которого не рисуются деления в других частях}
y1 := 400 + round(r * sin(a));
line(600, 400, x1, y1);
circle(600, 400, 80);
end;
for xi := 0 to 1000 do
begin
for x := 0 to 60 do {Цикл стрелок}
begin
strelki(x1, y1);
end;
end;
END.Решение задачи: «Перевести из Pascal В C#»
textual
Листинг программы
using System;
using System.Drawing;
using System.Threading.Tasks;
using System.Windows.Forms;
static class Program
{
const int r = 90;
static int sr, x, x1, y1, x2, y2, xi;
static double a;
static Form form;
static Graphics graphics;
static Bitmap bitmap;
static void textout(int x2, int y2, string text)
{
const int fontWidth = 12;
var font = new Font(FontFamily.GenericSansSerif, fontWidth);
graphics.DrawString(text, font, Brushes.Black, x2 - fontWidth / 2, y2 - fontWidth / 2);
font.Dispose();
}
static void line(int x2, int y2, int x1, int y1, Color color, int penWidth)
{
var pen = new Pen(color, penWidth);
graphics.DrawLine(pen, x2, y2, x1, y1);
pen.Dispose();
}
static void circle(int x1, int y1, int r, Color color)
{
var pen = new Pen(color);
graphics.DrawEllipse(pen, x1 - r, y1 - r, r * 2, r * 2);
pen.Dispose();
}
static async Task strelki(int x1, int y1) // Процедура секунд
{
int i;
for (i = 0; i <= 11; i++) // Рисование чисел по окружности
{
a = Math.PI * (i + 10) * 30 / 180;
x2 = 596 + (int)Math.Round((r + 30) * Math.Cos(a));
y2 = 396 + (int)Math.Round((r + 30) * Math.Sin(a));
if (i > 9) x2 = x2 - 3;
textout(x2, y2, (i + 1).ToString());
}
sr = 120;
a = Math.PI * (x + 45) * 6 / 180;
x1 = 600 + (int)Math.Round(sr * Math.Cos(a)); // Рисуется стрелка
y1 = 400 + (int)Math.Round(sr * Math.Sin(a));
line(600, 400, x1, y1, Color.Red, 1);
sr = 100;
a = Math.PI * (((xi / 60) % 12) * 5 + 45) * 6 / 180;
x1 = 600 + (int)Math.Round(sr * Math.Cos(a)); // Рисуется часовая стрелка
y1 = 400 + (int)Math.Round(sr * Math.Sin(a));
line(600, 400, x1, y1, Color.Black, 3);
sr = 110;
a = Math.PI * ((xi % 60) + 45) * 6 / 180;
x1 = 600 + (int)Math.Round(sr * Math.Cos(a)); // Рисуется минутная стрелка
y1 = 400 + (int)Math.Round(sr * Math.Sin(a));
line(600, 400, x1, y1, Color.Green, 2);
form.Invalidate();
await Task.Delay(1000);
sr = 120;
a = Math.PI * (x + 45) * 6 / 180;
x1 = 600 + (int)Math.Round(sr * Math.Cos(a)); // Рисуется секундная стрелка(белым)
y1 = 400 + (int)Math.Round(sr * Math.Sin(a));
line(600, 400, x1, y1, Color.White, 1);
sr = 100;
a = Math.PI * (((xi / 60) % 12) *5 + 45) *6 / 180;
x1 = 600 + (int)Math.Round(sr * Math.Cos(a)); // Рисуется часовая стрелка(белым)
y1 = 400 + (int)Math.Round(sr * Math.Sin(a));
line(600, 400, x1, y1, Color.White, 3);
sr = 110;
a = Math.PI * ((xi % 60) +45) *6 / 180;
x1 = 600 + (int)Math.Round(sr * Math.Cos(a)); // Рисуется минутная стрелка(белым)
y1 = 400 + (int)Math.Round(sr * Math.Sin(a));
line(600, 400, x1, y1, Color.White, 2);
a = Math.PI * (x + 45) * 6 / 180;
x1 = 600 + (int)Math.Round(r * Math.Cos(a)); // Закрашиваение секундных делений после прохода стрелки
y1 = 400 + (int)Math.Round(r * Math.Sin(a));
line(600, 400, x1, y1, Color.Black, 1);
// Рисование круга поверх делений на секунды
circle(600, 400, 80, Color.Black);
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
form = new Form
{
Size = new Size(800, 600)
};
form.Load += async delegate
{
bitmap = new Bitmap(form.ClientSize.Width, form.ClientSize.Height);
graphics = Graphics.FromImage(bitmap);
graphics.Clear(Color.White);
form.BackgroundImage = bitmap;
circle(600, 400, 135, Color.Black); // Рисование круга поверх чисел
for (x = 0; x <= 60; x++)
{
a = Math.PI * x / 30;
x1 = 600 + (int)Math.Round(r * Math.Cos(a)); // Рисование круга какого - то, из - за которого не рисуются деления в других частях
y1 = 400 + (int)Math.Round(r * Math.Sin(a));
line(600, 400, x1, y1, Color.Black, 1);
circle(600, 400, 80, Color.Black);
}
for (xi = 0; xi <= 1000; xi++)
{
for (x = 0; x <= 60; x++)
{
await strelki(x1, y1);
}
}
};
Application.Run(form);
}
}