Circular Pattern Using C/C++ and Graphics

Hey guys, today I am going to show you how to generate simple circular pattern using c/c++ and graphics. Here's the screen shot of the out put.

Here is the code. Enjoy coding...

Note:
If the program is generating error in c  then please save the file with .cpp extension.


/*
    Programmer : Ashok Kumar Shrestha (ak007)
    Program details : Genetrates circular pattern
*/

#include<graphics.h>
#include<stdio.h>
#include<conio.h>
#include<dos.h>

void main()        //two moving balls
{

    int gd = DETECT, gm;
  
    int r=20;
    int x=400,y=300,x1,y1,x2=x-200,y2=y-200, x3=x2+250,y3=y2+250;
    int dx,dy;
    int a=x-100,b=y-150,a1,b1,dx1=3,dy1=4;
    initgraph(&gd,&gm,"..\\BGI");
   
    dx=dx1=5;
    dy=dy1=5;
    rectangle(x2-1,y2-1,x3+3,y3+4);
    x=300,y=200;
    a=320,b=160;
    while(!kbhit())
    {
        setcolor(2);
        circle(x,y,r);
        x1=x+dx;
        y1=y-dy;

        setcolor(3);
        circle(a,b,r);
        a1=a+dx1;
        b1=b+dy1;
        if(x1<x2+r+1||x1>x3-r)
            dx=-dx;
        if(y1<y2+r+1||y1>y3-r)
            dy=-dy;
        if(a1<x2+r+1||a1>x3-r)
            dx1=-dx1;
        if(b1<y2+r+1||b1>y3-r)
            dy1=-dy1;
        delay(80);
        setcolor(0);

        setcolor(0);
        x=x1;    y=y1;
        a=a1;    b=b1;
    }
    getch();
}

//End of the program


Comments

Popular posts from this blog

Wizard Quiz: Privacy Policy

Sorting Hat: Privacy Policy

mTranslator