Saturday, March 2, 2013

Traffic System using GRAPHICS in C


//Traffic System
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>

void traf(int,int,int);
void car(int);

void main()
{
 int gd=DETECT,gm,i;
 initgraph(&gd,&gm,"c:\\tc\\bgi");
 for(i=0;i<650;i++)
 {
  if(i!=150)
  {
   traf(0,0,2);
   setcolor(6);
   car(i);
   delay(15);
   cleardevice();
  }
  else
  {
   traf(4,0,0);
   setcolor(6);
   car(i);
   delay(3500);
   traf(0,0,2);
  }
 }
 getch();
}

void traf(int r,int y,int g)
{
 cleardevice();
 setcolor(6);
 rectangle(490,50,530,110);
 setfillstyle(1,r);
 fillellipse(510,60,10,10);
 setfillstyle(1,y);
 fillellipse(510,80,10,10);
 setfillstyle(1,g);
 fillellipse(510,100,10,10);
 setcolor(4);
 line(505,110,505,200);
 line(515,110,515,200);
 setcolor(15);
 line(0,200,getmaxx(),200);
 line(0,416,getmaxx(),416);
}

void car(int i)
{
 ellipse(125+i,320,0,180,50,25);
 line(41+i,320,75+i,320);
 line(175+i,320,208+i,320);
 arc(75+i,328,165,216,36);
 line(45+i,350,205+i,350);
 arc(175+i,328,320,373,36);
 circle(80+i,360,10);
 circle(160+i,360,10);
}

Monday, February 11, 2013

JavaScript program to display todays date


<!--fms-->
<html>
<head>
<script>
function displayDate()
{
document.getElementById("demo").innerHTML=Date();
}
</script>
</head>
<body>

<h1>JavaScript to display date</h1>
<p id="demo">This is a paragraph.</p>

<button type="button" onclick="displayDate()">Display Date</button>

</body>
</html>

jsp to display todays day of the week


<!--fms-->
<html>
<body>

<p id="demo">Click the button to display todays day of the week.</p>

<button onclick="myFunction()">Try it</button>

<script>
function myFunction()
{
var d = new Date();
var weekday=new Array(7);
weekday[0]="Today is Sunday";
weekday[1]="Today is Monday";
weekday[2]="Today is Tuesday";
weekday[3]="Today is Wednesday";
weekday[4]="Today is Thursday";
weekday[5]="Today is Friday";
weekday[6]="Today is Saturday";

var x = document.getElementById("demo");
x.innerHTML=weekday[d.getDay()];
}
</script>

</body>
</html>

Sunday, February 10, 2013

jsp program to display clock


<!jsp program to display clock!>
<!DOCTYPE html>
<html>
<head>
<script>
function startTime()
{
  var today=new Date();
  var h=today.getHours();
  var m=today.getMinutes();
  var s=today.getSeconds();
  // add a zero in front of numbers<10
  m=checkTime(m);
  s=checkTime(s);
  document.getElementById('txt').innerHTML=h+":"+m+":"+s;
  t=setTimeout(function(){startTime()},500);
}

function checkTime(i)
{
   if (i<10)
   {
      i="0" + i;
   }
   return i;
}
</script>
</head>

<body onload="startTime()">
<div id="txt"></div>
</body>
</html>

Wednesday, January 30, 2013

Code for Program to rotate about reference point in C++ Programming


Code for Program to rotate about reference point in C++ Programming
# include <iostream.h>
# include <conio.h>
# include <graphics.h>
# include <math.h>

char IncFlag;
int PolygonPoints[4][2] =
    {{10,100},{110,100},{110,200},{10,200}};

int RefX = 10;
int RefY = 100;

void PolyLine()
{
    int iCnt;
    cleardevice();
    line(0,240,640,240);
    line(320,0,320,480);
    for (iCnt=0; iCnt<4; iCnt++)
    {
        line(PolygonPoints[iCnt][0],PolygonPoints[iCnt][1],
          PolygonPoints[(iCnt+1)%4][0],PolygonPoints[(iCnt+1)%4][1]);
    }
}

void Translate(int Direction)
{
    int iCnt;
    for (iCnt=0; iCnt<4; iCnt++)
    {
        PolygonPoints[iCnt][0] += Direction*RefX;
        PolygonPoints[iCnt][1] -= Direction*RefY;
    }
}

void Rotate()
{
    float Angle;
    int iCnt;
    int Tx,Ty;
    Translate(-1);
    cout<<endl;
    Angle = 30.0*(22.0/7.0)/180.0;
    for (iCnt=0; iCnt<4; iCnt++)
    {
        Tx = PolygonPoints[iCnt][0];
        Ty = PolygonPoints[iCnt][1];
        PolygonPoints[iCnt][0] = (Tx - 320)*cos(Angle) -
                     (Ty - 240)*sin(Angle) + 320;
        PolygonPoints[iCnt][1] = (Tx - 320)*sin(Angle) +
                     (Ty - 240)*cos(Angle) + 240;
    }
    Translate(1);
}

void main()
{
    int gDriver = DETECT, gMode;
    int iCnt;
    initgraph(&gDriver, &gMode, "C:\\TC\\BGI");
    for (iCnt=0; iCnt<4; iCnt++)
    {
        PolygonPoints[iCnt][0] += 320;
        PolygonPoints[iCnt][1] = 240 - PolygonPoints[iCnt][1];
    }
    PolyLine();
    getch();
    Rotate();
    PolyLine();
    getch();