20 Feb 2013

C/C++ programs for boundary fill with 4 connect


C/C++ programs for boundary fill with 4 connect 

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void b_fill(int x,int y,int newc,int boundc)
{
          int g;
          g=getpixel(x,y);
          if((g!=boundc)&&(g!=newc))
          {

                   putpixel(x,y,newc);
                   delay(1);
                   b_fill(x+1,y,newc,boundc);
                   //b_fill(x-1,y,newc,boundc);
                   b_fill(x,y-1,newc,boundc);
                    b_fill(x,y+1,newc,boundc);     
          }
}

void main()
{
          int gd=DETECT,gm;
          initgraph(&gd,&gm,"C:\\tc\\bgi");
          rectangle(50,50,150,150);
          b_fill(51,51,GREEN,WHITE);
          rectangle(150,150,250,250);
          b_fill(151,151,RED,WHITE);
          rectangle(250,250,350,350);
          b_fill(251,251,BLUE,WHITE);
          getch();
}

OUTPUT:

7 Feb 2013

C/C++ program for printing a pattern of an ellipse using bresenham algorithm and implementation of floodfill and setfillstyle


/* Program to Draw an Ellipse using Bresenham Algorithm  and implementation of floodfill and setfillstyle */
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
#include <graphics.h>
#include<dos.h>
//void ellipseMidpoint(float, float, float, float);
void drawEllipse(float, float, float, float);
void ellipseMidpoint(float xc, float yc, float rx, float ry)
{
float rxSq = rx * rx;
float rySq = ry * ry;
float x = 0, y = ry, p;
float px = 0, py = 2 * rxSq * y;
drawEllipse(xc, yc, x, y);
//Region 1
p = rySq - (rxSq * ry) + (0.25 * rxSq);
while (px < py)
{
x++;
px = px + 2 * rySq;
if (p < 0)
p = p + rySq + px;
else
{
y--;
py = py - 2 * rxSq;
p = p + rySq + px - py;
}
drawEllipse(xc, yc, x, y);
delay(30);
}
//Region 2
p = rySq*(x+0.5)*(x+0.5) + rxSq*(y-1)*(y-1) - rxSq*rySq;
while (y > 0)
{
y--;
py = py - 2 * rxSq;
if (p > 0)
p = p + rxSq - py;
else
{
x++;
px = px + 2 * rySq;
p = p + rxSq - py + px;
}
drawEllipse(xc, yc, x, y);
delay(30);
}
}
void drawEllipse(float xc, float yc, float x, float y)
{
putpixel(xc+x, yc+y, WHITE);
putpixel(xc-x, yc+y, WHITE);
putpixel(xc+x, yc-y, WHITE);
putpixel(xc-x, yc-y, WHITE);
}
void main()
{
float xc, yc, rx, ry;
int gd = DETECT, gm,i;
initgraph(&gd, &gm, "C:\\tc\\bgi");
ellipseMidpoint(200, 200, 60, 70);
ellipseMidpoint(300,300,60,70);
     
for(i=1;i<=10;i++)
{
setfillstyle(i,i+2);
floodfill(200,200,getmaxcolor());
delay(200);
setfillstyle(i,i+1);
floodfill(300,300,getmaxcolor());
delay(200);
}


setfillstyle(9,BLUE);
floodfill(1,1,getmaxcolor());

getch();
}

OUTPUT


6 Feb 2013

c/c++ Program for printing a circle using midpoint circle algorithm

/* Program in c/c++ for printing a circle using midpoint circle algorithm */


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void draw_circle(int xc,int yc,int x,int y)
{
putpixel(xc+x,yc+y,2);
putpixel(xc+x,yc-y,2);
putpixel(xc-x,yc+y,2);
putpixel(xc-x,yc-y,2);
putpixel(xc+y,yc+x,2);
putpixel(xc-y,yc+x,2);
putpixel(xc+y,yc-x,2);
putpixel(xc-y,yc-x,2);
}
void main()
{
int x=0,y,xc=200,yc=200,gd=DETECT,gm,p,r=100;
initgraph(&gd,&gm,"C:\\tc\\BGI");
y=r;
p=1-r;
while(x<y)
{
draw_circle(xc,yc,x,y);
x++;
if(p<0)
{
p=p+2*x+1;
}
else
{
y--;
p=p+2*(x-y)+1;
}
draw_circle(xc,yc,x,y);
}
getch();
}

OUTPUT 

Program in c/c++ for printing a pattern using dda algorithm


/* Program in c/c++ for printing a pattern using dda algorithm */
#include<graphics.h>
#include<conio.h>
void add(int x1,int y1,int x2,int y2)
{
  int dx,dy,m,s;
  float xi,yi,x,y;
   dx = x2 - x1;
    dy = y2 - y1;

    if (abs(dx) > abs(dy))
    {
s = abs(dx);
    }
    else
    {
s = abs(dy);
     }
    xi = dx / (float) s;
    yi = dy / (float) s;

    x = x1;
    y = y1;

    putpixel(x1, y1, 2);
delay(3);

    for (m = 0; m < s; m++)
{
x += xi;
y += yi;
putpixel(x, y, 2);
delay(3);
    }

}
void main ()
{
int gd=DETECT,gm;
clrscr();
initgraph(&gd,&gm,"C://tc/BGI");
add(20,50,250,50);
add(250,50,250,200);
add(250,200,20,200);
add(20,200,20,50);
add(40,70,80,70);
add(80,70,80,100);
add(80,100,40,100);
add(40,100,40,70);
add(190,70,230,70);
add(230,70,230,100);
add(230,100,190,100);
add(190,100,190,70);
add(115,150,155,150);
add(155,150,155,180);
add(155,180,115,180);
add(115,180,115,150);
getch();
}


OUTPUT:

DDA algorithm coding for printing a triangle


/* Program in c for printing a triangle with the help of DDA aglorithm */
#include <graphics.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>

void drawline(int x1,int y1,int x2,int y2)
{
  int dx,dy,m,s;
  float xi,yi,x,y;
   dx = x2 - x1;
    dy = y2 - y1;

    if (abs(dx) > abs(dy))
s = abs(dx);
    else
s = abs(dy);

    xi = dx / (float) s;
    yi = dy / (float) s;

    x = x1;
    y = y1;

    putpixel(x1, y1, WHITE);

    for (m = 0; m < s; m++)
{
x += xi;
y += yi;
putpixel(x, y, WHITE);
    }

}
void main()
{

    int gd = DETECT, gm = DETECT, x1, y1, x2, y2;

    clrscr();

    initgraph(&gd, &gm, "C:\\tc\\bgi");
    drawline(20,100,70,30);
    drawline(70,30,120,100);
    drawline(20,100,120,100);
    getch();
}

OUTPUT

The Internet

The Internet Facts

We all know that the internet is big. But did you know it's so big that it's practically impossible to measure!!! With so much information available at the touch of a button, It's easy to see how 70% of people feel that the amount of available data is overwhelming. Here's a little perspective on The Internet.

1. GOOGLE estimates the internet at about 5 million terabytes of data. Which is 5 billion gigabytes or 5 trillion megabytes.
The human brain could hold an estimated 1 to 10 terabytes. Using an estimate of 5 terabytes per brain, it would take a million human brains to store The Internet.

  • 212 DVD's can hold 1 terabytes ....so more than 1 billion could hold the internet.
  • 40 blu-ray discs can store 1 terabyte...so 200 million blu-ray discs could hold the internet.
2. The internet population:
  • 76.2% : North America         
  • 60.8% : Australia Oceania                       
  • 50.3% : Europe
  • 31.9% : Latin America and Caribbean 
  • 28.8% : Middle East
  • 20.1% : Asia
  • 8.7% : Africa
World average : 26.6%

3.  274 billion emails are sent every day. 81% are spam (200 billion spam emails every day). 90 trillion emails were sent every year.

4. Hours spent on the internet:

  • It is difficult to say if the leisure time on the internet surpasses television, because a growing majority of people use both at the same time. 59 % of Americans use the internet and television simultaneously. 
  • 2 hours are spent on youtube and in chat rooms.
  • 3.5 hours are spent IM-ING friends..like LOLZ! FML! TTY!
  • Teenagers spent on average 31 hours online every week, in comparison they spend 4 hours doing home work every week.
  • 2 hours are spent watching pornography
  • 1.5 hours are spent on family planing and pregnancy sites.
  • 35 minutes is spent on weight loss and diet sites.
  • more than 1 hour is spent looking up plastic and cosmetic surgery 
5. There are 234 million websites and 126 million blogs