Перевести с Паскаля на Си Шарп - C# (178852)

Узнай цену своей работы

Формулировка задачи:

program Vetka2;
 
uses Graph, CRT;
 
const
    min = 1;
  
var
    gd, gm : Integer;
 
procedure lineto1(x, y : Integer; l, u : real);
begin
    Line(x, y, Round(x + l * cos(u)), Round(y - l * sin(u)));
end;
 
procedure Draw(x, y : Integer; l, u : real);
begin
    if KeyPressed then 
        exit;
    if l > min then 
    begin
        lineto1(x, y, l, u);
        x := Round(x + l * cos(u));
        y := Round(y - l * sin(u));
        Draw(x, y, l*0.4, u - pi/4);
        Draw(x, y, l*0.4, u + pi/4);
        Draw(x, y, l*0.7, u);
    end;
end;
 
begin
    gd := Detect;
    InitGraph(gd, gm, 'c:\bp\bgi');
    Draw(320, 460, 120, pi/2);
    ReadKey;
    CloseGraph;
end.
...
procedure Draw(x, y : Integer; l, u : real);
begin
    if KeyPressed then 
        exit;
    if l > min then 
    begin
        lineto1(x, y, l, u);
        x := Round(x + l * cos(u));
        y := Round(y - l * sin(u));
        Draw(x, y, l*0.4, u - pi/4);
        Draw(x + Round(l*0.4*cos(u)), 
            y - Round(l*0.4*sin(u)), l*0.4, u + pi/4);
        Draw(x, y, l*0.7, u);
    end;
end;
...
program Tree3;
 
uses CRT, Graph;
 
var
    gd, gm: Integer;
 
procedure FrTree(x, y, l, u : Real; t : Integer);
begin
    if t > 0 then 
    begin
        l := l*0.5;
        Line(Round(x), Round(y), 
            Round(x + l*cos(u)), Round(y - l*sin(u)));
        x := Round(x + l * cos(u));
        y := Round(y - l * sin(u));
        FrTree(x, y, l, u, t-1);
        FrTree(x, y, l, u+pi/4, t-1);
        FrTree(x, y, l, u-pi/4, t-1);
    end;
end;
 
begin
    gd:=Detect;
    InitGraph(gd, gm, 'c:\bp\bgi');
    FrTree(320, 460, 350, pi/2,   6);
    FrTree(320, 460, 350, 3*pi/4, 6);
    FrTree(320, 460, 350, pi/4,   6);
    ReadKey;
    CloseGraph
end.
Помогите, пожалуйста,перевести.

Решение задачи: «Перевести с Паскаля на Си Шарп»

textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication1
{
    class Program
    {
const
    int min = 1;
 
   int  gd, gm;
 
   public void lineto1(int x, int y, float l, float u)
   {
            Graphics gr = e.Graphics;
            Pen p = new Pen(Color.Blue, 5);
            Point p1 = new Point(5,10);// первая точка
            Point p2 = new Point(40,100);// вторая точка
            gr.DrawLine(p, p1, p2);// рисуем линию
            Line(x, y, Round(x + l * cos(u)), Round(y - l * sin(u)));                     //Гемор переводить, добавь библию графа
            gr.Dispose();// освобождаем все ресурсы, связанные с отрисовкой
            }           
   }
 
public void Draw (int x, int y, float l, u){
 
    if (KeyPressed) { 
        exit;
    }
    if (l > min) { 
  
        lineto1(x, y, l, u);
        x := Round(x + l * cos(u));
        y := Round(y - l * sin(u));
        Draw(x, y, l*0.4, u - pi/4);
        Draw(x, y, l*0.4, u + pi/4);
        Draw(x, y, l*0.7, u);
}
 
}
 
 
void Draw(int x, int y, float l, u); overload;
{
    if KeyPressed then 
        exit;
    if (l > min)  
{
        lineto1(x, y, l, u);
        x := Round(x + l * cos(u));
        y := Round(y - l * sin(u));
        Draw(x, y, l*0.4, u - pi/4);
        Draw(x + Round(l*0.4*cos(u)), 
            y - Round(l*0.4*sin(u)), l*0.4, u + pi/4);
        Draw(x, y, l*0.7, u);
}
}
 
 
        static void Main(string[] args)
        {
 
    gd := Detect;
    InitGraph(gd, gm, "c:\\bp\bgi");
    Draw(320, 460, 120, pi/2);
    ReadKey;
    //CloseGraph;
}

Оцени полезность:

6   голосов , оценка 3.833 из 5