Posts

Showing posts from April, 2018

Traffic signal Using C graphics

Animate traffic signal using C graphics #include <stdio.h>   #include <conio.h>   #include <graphics.h>   #include <dos.h>   #include <string.h>   void main() {         /* request auto detection */         int gdriver = DETECT, gmode, err;         int i, j, k, x, y, color;         char str[64];         /* initialize graphic mode */         initgraph(&gdriver, &gmode, "C:/TC/BGI");         for (i = 0; i < 3; i++) {                 /* clears graphic screen */                 cleardevice();                 /* draw the signal post */                 setcolor(DARKGRAY);         ...

Sine Wave - Using C Graphics

Sine Wave -  Using C Graphics  #include <stdio.h>   #include <conio.h>   #include <math.h>   #include <graphics.h>   #include <dos.h>   void main() {         /* request auto detection */         int gdriver = DETECT, gmode, err;         int i = 0, fq, amp;         double x, y;         /* initialize graphic mode */         initgraph(&gdriver, &gmode, "C:/TC/BGI");         /* initialize the variables */         x = 0;         /* frequency is 2 here */         fq = 2;         /* setting amplitute to 100 */         amp = 100;         line(0, getmaxy() / 2, getmaxx(), getmaxy() / 2);         /* generate a sine...

Cosine Wave - Using C graphics

Cosine Wave - Animation using C graphics   #include <stdio.h>   #include <conio.h>   #include <math.h>   #include <graphics.h>   #include <dos.h>   void main() {         /* request auto detection */         int gdriver = DETECT, gmode, err;         int i = 0, fq, amp;         double x, y;         /* initialize graphic mode */         initgraph(&gdriver, &gmode, "C:/TC/BGI");         /* initialize the variables */         x = 0.5;         fq = 2;         /* setting the amplitute to 50 */         amp = 50;         line(0, getmaxy() / 2, getmaxx(), getmaxy() / 2);         /* draws cosine wave */         while (x ...

Walking Stickman -Using C graphics

    Walking Stickman - Animation using C graphics #include <stdio.h>   #include <conio.h>   #include <graphics.h>   #include <dos.h>   void main() {         /* request auto detection */         int gdriver = DETECT, gmode, err;         int radius = 10, x, y, midy;         /* initialize graphic mode */         initgraph(&gdriver, &gmode, "C:/TC/BGI");         x = 50;         midy = getmaxy() / 2;         y = midy - 100;         /*          * used 5 stick man (still/image)          * position to get walking animation          */         while (x < getmaxx() - 25) {                 /...

Bresenham's ellipse drawing algorithm in c with output(midpoint ellipse)

Bresenham's ellipse drawing algorithm in c  with output(midpoint ellipse)  #include <stdio.h>   #include <conio.h>   #include <graphics.h>   #include <dos.h>   void main() {         /* request auto detection */         int gdriver = DETECT, gmode, err;         long midx, midy, xradius, yradius;         long xrad2, yrad2, twoxrad2, twoyrad2;         long x, y, dp, dpx, dpy;         /* initialize graphic mode */         initgraph(&gdriver, &gmode, "C:/TC/BGI");         /* x axis radius and y axis radius of ellipse */         xradius = 100, yradius = 50;         /* finding the center postion to draw ellipse */         midx = getmaxx() / 2;         midy = getmaxy() ...

Bresenham's circle drawing algorithm in C Graphics

Bresenham's circle drawing algorithm in C Graphics   #include <stdio.h>   #include <conio.h>   #include <graphics.h>   #include <dos.h>   void main() {         /* request auto detection */         int gdriver = DETECT, gmode, err;         int midx, midy, x, y, radius, dp;         /* initialize graphic mode */         initgraph(&gdriver, &gmode, "C:/TC/BGI");         radius = 100;         /* mid position of x-axis */         midx = getmaxx() / 2;         /* mid position of y-axis */         midy = getmaxy() / 2;         dp = 1 - radius;         x = 0, y = radius;         /* draws a circle */         do {       ...

Bresenham's line drawing algorithm in C Graphics

Bresenham's line drawing algorithm in c with output  #include <stdio.h>   #include <conio.h>   #include <graphics.h>   #include <math.h>   #include <dos.h>   void main() {         /* request auto detection */         int gdriver = DETECT, gmode;         int x1 = 0, y1 = 0, x2, y2;         int err, x, y, dx, dy, dp, xEnd;         int twody, twodxdy;         /* initialize graphic driver */         initgraph(&gdriver, &gmode, "C:/TC/BGI");         /* max position in x and y axis */         x2 = getmaxx();         y2 = getmaxy();         /* draws line from (0, 0) to (x2, y2) */         dx = x2 - x1;         dy = y2 - y1;     ...

DDA line drawing algorithm in c

DDA line drawing algorithm in c with output #include <stdio.h>   #include <conio.h>   #include <graphics.h>   #include <math.h>   #include <dos.h>   void main() {         /* request auto detection */         int gdriver = DETECT, gmode, err;         int i, x1, y1, x2, y2, dx, dy, steps;         float x, y, xincr, yincr;         /* initialize graphic mode */         initgraph(&gdriver, &gmode, "C:/TC/BGI");         /* draw line from (0, 0) to x-axis & y-axis maximum */         x1 = y1 = 0;         x2 = getmaxx(), y2 = getmaxy();         dx = x2 - x1;         dy = y2 - y1;         x = x1, y = y1;         steps = abs(dx) > abs(dy) ? dx ...

Multiple bouncing balls using c graphics

Animate multiple bouncing balls using c graphics   #include <stdio.h>   #include <conio.h>   #include <graphics.h>   #include <dos.h>   /* color and movement of ball */   void ball_motion(int *x, int *y, int *flag, int *i, int val, int tmp) {                 int maxy = getmaxy();                 /* set the drawing color */                 setcolor(LIGHTRED);                 /* color of the ball */                 setfillstyle(SOLID_FILL, LIGHTRED);                 /* draw ball at the given position */                 pieslice(*x, *y, 0, 360, 10);                 /* subsequent position of ball...

Implement Bouncing Ball Animation Using C Graphics

Image
Implement Bouncing Ball Animation Using C Graphics   #include <stdio.h>   #include <conio.h>   #include <graphics.h>   #include <dos.h>   void main()  {         /* request auto detection */         int gdriver = DETECT, gmode, err;         int i = 0, x = 0, y = 0, flag = 0;         /* initialize graphic mode */         initgraph(&gdriver, &gmode, "C:/TC/BGI");         /* ball movement */         while (x <= getmaxx() && !kbhit()) {                 /* set the current drawing color */                 setcolor(LIGHTRED);                 /* fill the ball with given pattern & color */          ...