Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <graphics.h>
- using namespace std;
- float x,y;
- float pi = 3.1415;
- int angle;
- int WIDTH = 900;
- int HEIGHT = 600;
- /// mareste unghiul la care este desenata o linie din fractal cu "alpha" de grade
- void Plus(int alpha)
- {
- angle += alpha;
- if( angle >= 360 )
- angle = angle - 360;
- }
- /// micsoreasa unghiul la care este desenata o linie din fractal cu "alpha" de grade
- void Minus(int alpha)
- {
- angle -= alpha;
- if( angle < 0 )
- angle = angle + 360;
- }
- /// deseneaza o linie din fractal la unghiul "angle"
- void DrawLine(float length)
- {
- float new_x,new_y;
- float angle_radians = 2*3.141592*angle/360;
- new_x = x + length*cos(angle_radians) ;
- new_y = y - length*sin(angle_radians);
- line(x,y,new_x,new_y);
- x = new_x;
- y = new_y;
- }
- /// functiile recursive care deseneaza fractalul
- void X(float length, int order);
- void Y(float length, int order);
- void X(float length, int order)
- {
- if( order >= 1 )
- {
- X(length,order-1);
- Plus(90);
- Y(length,order-1);
- DrawLine(length);
- Plus(90);
- }
- }
- void Y(float length, int order)
- {
- if( order >= 1 )
- {
- Minus(90);
- DrawLine(length);
- X(length,order-1);
- Minus(90);
- Y(length,order-1);
- }
- }
- int main()
- {
- initwindow(WIDTH,HEIGHT);
- for (int order = 1; order <= 12; order++)
- {
- x = 2*(WIDTH-20)/3;
- y = 2*HEIGHT/3;
- angle = 0;
- cleardevice();
- DrawLine(7);
- X(7,order);
- outtextxy(150, 30, "Press any key...");
- getch();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment