Amazon banner

Showing posts with label moving. Show all posts
Showing posts with label moving. Show all posts

Thursday, 30 August 2012

C PROGRAM TO DESIGN A MOVING WHEEL


/* C PROGRAM TO  DESIGN  A MOVING WHEEL                 */
/* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR  */

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

int xc = 50, yc = 200, r = 35;
int x[15], y[15];
void drawcircles() {
  setcolor(YELLOW);
  circle(xc, yc, r);
  circle(xc, yc, r + 5);
}
void main() {
  double angle = 0, theta;
  int i, a;
  int gd = DETECT, gm;
  initgraph( & gd, & gm, "C:\TC\BGI");
  a = xc + r;
  while (!kbhit()) {
    while (a <= 630) {
      theta = M_PI * angle / 180;
      cleardevice();
      drawcircles();
      for (i = 0; i < 18; i++) {
        theta = M_PI * angle / 180;
        x[i] = xc + r * cos(theta);
        y[i] = yc + r * sin(theta);
        angle += 20;
        line(xc, yc, x[i], y[i]);
      }
      angle += 2;
      xc += 2;
      a = xc + r;
      delay(50);
    }
    xc = 50;
    r = 35;
    a = xc + r;
  }
  getch();
  closegraph();
}

C PROGRAM TO DEMONSTRATE A MOVING FISH





/* C PROGRAM TO DEMONSTRATE A MOVING FISH *//* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR*/#include<stdio.h>

#include<time.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
#include<graphics.h>

void main()
{
int gd=DETECT,gm;
int x=10,y=200,x1=675,y1=380;
int stangle=35,endangle=140,radius=90;

initgraph(&gd,&gm,"C:/TC/BGI");

while(!kbhit())
{
cleardevice();
setbkcolor(BLACK);

if(x<640)
{
x+=5;
y+=1;
arc(x,y,stangle,endangle+35,radius);
arc(x,y-110,190,323,radius+2);
circle(x+40,y-60,5);
line(x-90,y-90,x-90,y-8);
}
else
{
x1-=5;
y1-=1;
arc(x1,y1,stangle-30,endangle+4,radius);
arc(x1,y1-110,217,350,radius+2);
circle(x1-40,y1-60,5);
line(x1+90,y1-90,x1+90,y1-10);
}
setcolor(YELLOW);
delay(90);
}
closegraph();
}

C PROGRAM TO DEMONSTRATE 3D REFLECTION



/* C PROGRAM TO DEMONSTRATE 3D REFLECTION *//* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR*/

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

#define ORG -50

double face1[5][2] = {
   { 250, 125 },
   { 350, 125 },
   { 350, 225 },
   { 250, 225 },
   { 250, 125 }
          };

double face2[5][2] = {
   { 250+ORG, 125-ORG },
   { 350+ORG, 125-ORG },
   { 350+ORG, 225-ORG },
   { 250+ORG, 225-ORG },
   { 250+ORG, 125-ORG }
          };

double angle = 5.0 * M_PI / 180;
double midx1, midy1, midx2, midy2;

void rotate (void)
{
    int i;
    for (i=0; i<5; i++)
    {
double xnew, ynew;

xnew = midx1 + (face1[i][0] - midx1) * cos (angle) -
      (face1[i][1] - midy1) * sin (angle);
ynew = midy1 + (face1[i][0] - midx1) * sin (angle) +
(face1[i][1] - midy1) * cos (angle);

face1[i][0] = xnew;
face1[i][1] = ynew;

xnew = midx2 + (face2[i][0] - midx2) * cos (angle) -
(face2[i][1] - midy2) * sin (angle);
ynew = midy2 + (face2[i][0] - midx2) * sin (angle) +
(face2[i][1] - midy2) * cos (angle);

face2[i][0] = xnew;
face2[i][1] = ynew;
    }

    cleardevice();

    for (i=0; i<4; i++)
    {
setcolor(7);
line (face1[i][0], face1[i][1], face1[i+1][0], face1[i+1][1]);
setcolor(8);
line (face2[i][0], face2[i][1], face2[i+1][0], face2[i+1][1]);
setcolor(9);
line (face1[i][0], face1[i][1], face2[i][0], face2[i][1]);
    }

    delay (125);
}

void main()
{
    int gd = DETECT, gm;

    midx1 = (face1[0][0] + face1[1][0]) / 2.0;
    midy1 = (face1[1][1] + face1[2][1]) / 2.0;
    midx2 = (face2[0][0] + face2[1][0]) / 2.0;
    midy2 = (face2[1][1] + face2[2][1]) / 2.0;

    initgraph (&gd, &gm, "..\\bgi");

    while (!kbhit())
rotate();

    closegraph();
}