Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Центр помощи > [PascalDelphi] Обдуваемое дерево пифагора


Автор: pasha220992 12.11.2012, 04:44
Нашел реализацию дерева пифагора здесь http://www.fractalworld.xaoc.ru/Pythagoras_tree.
Как переделать первый участок кода, чтобы он отрисовывал обдуваемое дерево?
Код

program Pyth;
uses CRT, Graph;
procedure Draw(x, y, l, a: Real);
procedure Rect(x1, y1, l: Integer; a1: Real);
begin
    MoveTo(x1, y1);
    LineTo(x1 + Round(l * cos(a1)), y1 - Round(l * sin(a1)));
    LineTo(x1 + Round(l * sqrt(2) * cos(a1 + pi/4)), 
        y1 - Round(l * sqrt(2) * sin(a1 + pi/4)));
    LineTo(x1 + Round(l * cos(a1 + pi/2)), y1 - Round(l * sin(a1 + pi/2)));
    LineTo(x1, y1);
end;

begin
    if l > 4 then
    begin
        Rect(Round(x), Round(y), Round(l), a);
        Draw(x - l*sin(a), y - l * cos(a), l / sqrt(2), a + pi / 4);//что-то тут
        Draw(
            x - l * sin(a) + l / sqrt(2) * cos(a + pi/4),
            y - l * cos(a) - l / sqrt(2) * sin(a + pi/4), 
            l / sqrt(2), 
            a - pi/4);//и вот тут
    end;
end;

var
    gd, gm: Integer;
begin
    gd := detect;
    InitGraph(gd, gm, 'c:\bp\bgi');
    Draw(280, 460, 100, 0);
    ReadKey;
    CloseGraph;
end.

user posted image

Автор: Infesta 12.11.2012, 17:26
Код

#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <graphics.h>
 
const double Pi = 3.14159;
double n,m;
int max ;
int color;
 
void Draw(double x, double y, double L, double a) {          // функция рисования фрактала
  if(L > max) {
     L*=0.7;
     moveto(x,y);
     lineto((int)(x+L*cos(a)),(int)(y-L*sin(a)));
     x=x+L*cos(a);
     y=y-L*sin(a);
 
                                             
  // рекурсивный вызов

    Draw(x,y,L,a+Pi/n);
    Draw(x,y,L,a-Pi/m);
  }
}
int main() {
 
   printf("Введите параметры : \n");
   printf("угол по X  : Pi/");                 // ввести числа от 1 до 10
   scanf("%lf",&n);
   printf("угол по Y  :  Pi/");
   scanf("%lf",&m);
   printf("глубина рекурсии : ");              // чем больше коэф. тем меньше шагов рекурсии // ввести 1 
   scanf("%d",&max);
 
 
 
 
   int gdriver = DETECT, gmode, errorcode;            
   initgraph(&gdriver, &gmode, "");
   errorcode = graphresult();
   if (errorcode != grOk) {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1);
   }
   Draw(320, 460, 200, Pi/2);
   getch();
   closegraph();
   return 0;
}

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)