Showing posts with label graphics. Show all posts
Showing posts with label graphics. Show all posts

Tuesday 23 February 2016

Implementation of Flood fill algorithm

Q) Implementation of Flood Fill Algorithm.
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
void floodfill(int x,int y)
    { 
int a =getpixel(x,y);
    setcolor(3);
    if(a==0)
{
    putpixel(x,y,3);
     floodill(x+1,y);
     floodfill(x-1,y);
    floodfill(x,y+1);
     floodfill(x,y-1);
    }
    }

int main()
{

   int gdriver = DETECT, gmode;
   initgraph(&gdriver, &gmode, "C:\\TC\\bgi");
   setcolor(2);
   circle(250, 250, 50);
   bounfill(250,250);
   getch();
   closegraph();
   return 0;
}

Bresenham's circle drawing


Q)Circle generation using bresenham’s circle drawing algorithm.
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include<iostream.h>
void drawcir(float x,float y,float p,float q){
putpixel(x+p,y+q,3);
putpixel(x-p,y+q,3);
putpixel(x+p,y-q,3);
putpixel(x-p,y-q,3);
putpixel(x+q,y+p,3);
putpixel(x-q,y+p,3);
putpixel(x+q,y-p,3);
putpixel(x-q,y-p,3);
    }
int main()
{
   int gdriver = DETECT, gmode;
   initgraph(&gdriver, &gmode, "C:\\TC\\bgi");
   float gx,gy,grad;
   cout<<"enter the x coordinateof the centre";
   cin>>gx;
   cout<<"enter the y coor of the centre";
   cin>>gy;
  cout<<"enter the radious of the circle";
  cin>>grad;
  float p=0;
  float q=grad;
  float d=3-2*grad;
  while(p<q){
  drawcir(gx,gy,p,q);
p++;
if(d<0)
{d=d+4*p+6;
}
  else{
q--;
  d=d+4*(p-q)+10;
  }
drawcir(gx,gy,p,q);
  }
   getch();
   closegraph();
   return 0;
}

Implementation of boundary fill algorithm

Q)Boundary fill algorithm.
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
void bounfill(int x,int y)
    { 
int a =getpixel(x,y);
    setcolor(3);
    if(a!=2&&a!=3)
{
    putpixel(x,y,3);
    bounfill(x+1,y);
    bounfill(x-1,y);
    bounfill(x,y+1);
    bounfill(x,y-1);
    }
    }

int main()
{

   int gdriver = DETECT, gmode;
   initgraph(&gdriver, &gmode, "C:\\TC\\bgi");
   setcolor(2);
   circle(250, 250, 50);
   bounfill(250,250);
   getch();
   closegraph();
   return 0;
}

Friday 19 February 2016

Scenery using graphics in C++

    #include <graphics.h>
   #include <stdlib.h>
   #include <stdio.h>
   #include<conio.h>
   int main(void)
   {
      int gdriver = DETECT, gmode;
      initgraph(&gdriver, &gmode, "C:\\TC\\bgi");
      circle(150, 150, 20);
      circle(141,146,5);
      circle(160,146,5);
      arc(150,156,215,340,6);
      line(150,170,150,240);
      line(150,240,110,300) ;
      line(150,240,190,300);
      line(150,180,100,180);
      line(150,180,200,180);
     line(300,170,2000,170);
    line(300,170,400,100);
    line(400,100,500,170);
    line(500,170,800,50);
    arc(500,200,45,135,70);
   getch();
   closegraph();
   return 0;
}