Sunday, 18 March 2018

Structure of Diamond in Computer Graphics using C


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
 int gd=DETECT,gm,midx,midy,i,j;
 initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
 midx=getmaxx()/2;midy=getmaxy()/2;

 /*rectangle(20,450,170,300);
 rectangle(60,400,210,250);
 rectangle(100,350,250,200);
 line(20,450,100,350);
 line(20,300,100,200);
 line(170,450,250,350);
 line(170,300,250,200);

 rectangle(170,450,320,300);
 rectangle(210,400,360,250);
 rectangle(250,350,400,200);
 line(320,450,400,350);
 line(320,300,400,200);

 rectangle(20,300,170,150);
 rectangle(60,250,210,100);
 rectangle(100,200,250,50);
 line(20,150,100,50);
 line(170,150,250,50);

 rectangle(170,300,320,150);
 rectangle(210,250,360,100);
 rectangle(250,200,400,50);
 line(320,150,400,50);

 for(i=0;i<=300;i=i+150)
 for(j=0;j<=300;j=j+150)
 {
  fillellipse(20+i,450-j,5,5);
  fillellipse(60+i,400-j,5,5);
  fillellipse(100+i,350-j,5,5);
 }
 getch();
 setcolor(BLUE);
 line(20,450,210,250);
 line(60,400,170,300);
 line(20,300,210,400);
 line(170,450,60,250);

 line(210,400,400,200);
 line(250,350,360,250);
 line(210,250,400,350);
 line(250,200,360,400);

 line(170,300,360,100);
 line(210,250,320,150);
 line(170,150,360,250);
 line(210,100,320,300);

 line(60,250,250,50);
 line(100,200,210,100);
 line(60,100,250,200);
 line(100,50,210,250);

 getch();

 */
 rectangle(20,450,320,150);
 rectangle(100,350,400,50);
 line(20,450,100,350);
 line(320,450,400,350);
 line(20,150,100,50);
 line(320,150,400,50);

 setcolor(YELLOW);
 setfillstyle(1,YELLOW);
 fillellipse(115,350,10,10);
 fillellipse(305,300,10,10);
 fillellipse(265,200,10,10);
 fillellipse(155,150,10,10);

 line(115,350,20,450);
 line(115,350,170,300);
 line(115,350,210,400);
 line(115,350,60,250);

 line(305,300,210,400);
 line(305,300,400,350);
 line(305,300,360,250);
 line(305,300,250,200);

 line(155,150,60,250);
 line(155,150,100,50);
 line(155,150,250,200);
 line(155,150,210,100);

 line(265,200,320,150);
 line(265,200,360,250);
 line(265,200,210,100);
 line(265,200,170,300);

 setcolor(MAGENTA);
 setfillstyle(1,MAGENTA);
 fillellipse(20,450,7,7);
 fillellipse(210,400,7,7);
 fillellipse(170,300,7,7);
 fillellipse(60,250,7,7);

 fillellipse(400,350,7,7);
 fillellipse(360,250,7,7);
 fillellipse(250,200,7,7);

 fillellipse(100,50,7,7);
 fillellipse(210,100,7,7);

 fillellipse(320,150,7,7);

 getch();
 closegraph();
}

1 comment:

Note: only a member of this blog may post a comment.