Computer Graphics
Group B
Practical 5 a
Problem Statement : Write C++ program to generate snowflake using concept of fractals.
Check Out Code Here 👇
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream.h> | |
#include<graphics.h> | |
#include<conio.h> | |
#include<math.h> | |
void draw(int x1,int y1,int x2,int y2,int ite) | |
{ | |
int Sx=(x2-x1)/3; | |
int Sy=(y2-y1)/3; | |
float theta=60*M_PI/180; //Converting degree to radians | |
int x3=x1+Sx, y3=y1+Sy; | |
int x4=x1+2*Sx, y4=y1+2*Sy; | |
int x=(x3)+(x4-x3)*cos(theta)+(y4-y3)*sin(theta); | |
int y=(y3)-(x4-x3)*sin(theta)+(y4-y3)*cos(theta); | |
if(ite>0){ | |
draw(x1,y1,x3,y3,ite-1); | |
draw(x3,y3,x,y,ite-1); | |
draw(x,y,x4,y4,ite-1); | |
draw(x4,y4,x2,y2,ite-1); | |
} | |
else{ | |
line(x1,y1,x3,y3); | |
line(x3,y3,x,y); | |
line(x,y,x4,y4); | |
line(x4,y4,x2,y2); | |
} | |
} | |
void main() | |
{ | |
int gd=DETECT,gm; | |
initgraph(&gd,&gm,"C:\\TurboC3\\BGI"); | |
draw(500,300,200,300,6); | |
draw(200,300,350,40,6); | |
draw(350,40,500,300,6); | |
getch(); | |
} |
Outputs :
Iteration 0 :
Iteration 1 :
Code can get updated so also come back later to see if there is any changes. Also if there is any problem with code you can comment below. If you like it, do share with your friends.😊
Comments
Post a Comment