Hello, I’m Veronica

The sky is not completely dark at night. Were the sky absolutely dark, one would not be able to see the silhouette of an object against the sky.

  • no errors then run your project.

    •  program
    1. #include<Windows.h>    
    2. // first include Windows.h header file which is required    
    3. #include<stdio.h>    
    4. #include<gl/GL.h>   // GL.h header file    
    5. #include<gl/GLU.h> // GLU.h header file    
    6. #include<gl/glut.h>  // glut.h header file from freeglut\include\GL folder    
    7. #include<conio.h>    
    8. #include<stdio.h>    
    9. #include<math.h>    
    10. #include<string.h>    
    11. // Init_OpenGL() function    
    12. void Init_OpenGL()    
    13. {    
    14.     // set background color to Black    
    15.     glClearColor(0.0, 0.0, 0.0, 0.0);    
    16.     // set shade model to Flat    
    17.     glShadeModel(GL_FLAT);    
    18. }    
    19.     
    20. // Display_Objects() function    
    21. void Display_Objects(void)    
    22. {    
    23.     // clearing the window or remove all drawn objects    
    24.     glClear(GL_COLOR_BUFFER_BIT);    
    25.     /*glPushMatrix(), which copies the current matrix and adds  
    26.     the copy to the top of the stack, and  
    27.     glPopMatrix(), which discards the top matrix on the stack*/    
    28.     glPushMatrix();    
    29.     //the glTranslatef() routine in the display list alters the position of the next object to be drawn    
    30.     glTranslatef(0.0, 0.0, 0.0);    
    31.     // set color to object glColor3f(red,green,blue);    
    32.     glColor3f(1.0, 0.8, 0.0);    
    33.     // draw a wire tea pot    
    34.     glutWireTeapot(1.0);    
    35.     
    36.     // draw a wire sphere    
    37.     glTranslatef(-2.5, 0.0, 0.0);    
    38.     glColor3f(0.0, 1.0, 0.0);    
    39.     glutWireSphere(0.8, 30, 30);    
    40.     
    41.     // draw a wire cone    
    42.     glTranslatef(5.0, 0.0, 0.0);    
    43.     glColor3f(0.0, 0.6, 1.0);    
    44.     glutWireCone(0.8, 1.5, 20, 20);    
    45.     
    46.     // draw a wire cube    
    47.     glTranslatef(-1.0, 1.4, 0.0);    
    48.     glColor3f(1.0, 0.3, 0.0);    
    49.     glutWireCube(1.0);    
    50.     
    51.     // draw a wire torus    
    52.     glTranslatef(-3.0, 0.4, 0.0);    
    53.     glColor3f(1.0, 0.3, 1.0);    
    54.     glutWireTorus(0.2, 0.6, 20, 20);    
    55.     
    56.     // draw a text    
    57.     glTranslatef(-2.5, -4.0, 0.0);    
    58.     
    59.     char str[] = {“OpenGL Demo in Visual C++”};    
    60.     
    61.     glColor3f(1.0, 1.0, 1.0);    
    62.     // set position to text    
    63.     glRasterPos2f(2.0, 0.0);    
    64.     
    65.     for (int i = 0; i < strlen(str); i++)    
    66.     {    
    67.         // draw each character    
    68.         glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, str[i]);    
    69.     }    
    70.     
    71.     //you can draw many objects here like polygons,lines,triangles etc    
    72.     
    73.     glPopMatrix();    
    74.     glutSwapBuffers();    
    75. }    
    76. // Reshape() function    
    77. void Reshape(int w, int h)    
    78. {    
    79.     //adjusts the pixel rectangle for drawing to be the entire new window    
    80.     glViewport(0, 0, (GLsizei)w, (GLsizei)h);    
    81.     //matrix specifies the projection transformation    
    82.     glMatrixMode(GL_PROJECTION);    
    83.     // load the identity of matrix by clearing it.    
    84.     glLoadIdentity();    
    85.     gluPerspective(60.0, (GLfloat)w / (GLfloat)h, 1.0, 20.0);    
    86.     //matrix specifies the modelview transformation    
    87.     glMatrixMode(GL_MODELVIEW);    
    88.     // again  load the identity of matrix    
    89.     glLoadIdentity();    
    90.     // gluLookAt() this function is used to specify the eye.    
    91.     // it is used to specify the coordinates to view objects from a specific position    
    92.     gluLookAt(-0.3, 0.5, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);    
    93. }    
    94.     
    95. // main function    
    96. int main(int argc, char** argv)    
    97. {    
    98.     // initialize glut    
    99.     glutInit(&argc, argv);    
    100.     glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);    
    101.     // set window size    
    102.     glutInitWindowSize(700, 500);    
    103.     // set window location    
    104.     glutInitWindowPosition(250, 50);    
    105.     // create window with window text    
    106.     glutCreateWindow(“OpenGL Demo”);    
    107.     // call Init_OpenGL() function    
    108.     Init_OpenGL();    
    109.     // call glutDisplayFunc() function & pass parameter as Display_Objects() function    
    110.     glutDisplayFunc(Display_Objects);    
    111.     // call glutReshapeFunc() function & pass parameter as Reshape() function    
    112.     glutReshapeFunc(Reshape);    
    113.     //glutMainLoop() is used to redisplay the objects    
    114.     glutMainLoop();    
    115.     return 0;    
    116. }


    • output:-





  • snake game in c++

     Snake game in c++.

    • program:

    #include<iostream.h>

    #include<conio.h>

    #include<graphics.h>

    #include<dos.h>

    #include<stdlib.h>

    #include<stdio.h>

    #include<time.h>

    #include<string.h>

    class snake

    {

    int p1,p2,v1,v2,v3,e1,e2,prev,now,n,colr,dsp,cnt,dly,m;

    int stp, egGen;

    int xr, yr;

    void caught();

    public:

    long scr;

    int strX,strY,endXendY;

    int pos[100][2];

    void show();

    void init();

    void egg();

    void transpose();

    void gnrtCond();

    void gnrtUnCond();

    void check();

    void checkEgg();

    void move();

    void chngDir();

    void sndEt();

    void sndCgt();

    int test();

    void score();

    snake();

    snake(snake*);

    ~snake();

    };

    snake::snake()

    {

    }

    snake::~snake()

    {

    }

    void snake::checkEgg()

    {

    if((e1==p1)&&(e2==p2))

    {

    sndEt();

    egg();

    dly–;

    score();

    n++;

    }

    }

    void snake::sndEt()

    {

    nosound();

    sound(2500);

    delay(2);

    nosound();

    }

    void snake::sndCgt()

    {

    nosound();

    for(int x=1000; x>0; x–_

    {

    sound(x);

    delay(1);

    }

    nosound();

    }

    void snake::score()

    {

    char*p;

    ltoa(scr,p,10);

    settextstyle(8,0,1);

    setcolor(0);

    outtextxy(585,40,p);

    if(egGen !=1)

    {

    scr=scr+dly/10;

    }

    ltoa(scr,p,10);

    setcolor(10);

    outtextxy(585,40,p);

    }

    void snake::gnrtCond()

    {

    if(n<367)

    {

    if(now==8 && (prev!=8 && prev!=2))

    {

    pos[0][0]=p1;

    pos[0][1]=p2-dsp;

    prev=now;

    }

    if(now==4 && (prev!=4 && prev!=1))

    {

    pos[0][0]=p1+dsp;

    pos[0][1]=p2;

    prev=now;

    }

    if(now==2 && (prev!=8 && prev!=2))

    {

    pos[0][1]=p2;

    pos[0][0]=p1+dsp;

    prev=now;

    }

    if(now==1 && (prev!=1 && prev!=4))

    {

    pos[0][0]=p1+dsp;

    pos[0][1]=p2;

    prev=now;

    }

    }

    }

    void snake::gnrtUnCond()

    {

    if(prev==8)

    {pos[0][0]=p1;

    pos[0][1]=p2-dsp;

    }

    if(prev==4)

    {pos[0][0]=p+dsp;;

    pos[0][1]=p2;

    }

    if(prev==2)

    {pos[0][0]=p1;

    pos[0][1]=p2+dsp;

    }

    if(prev==1)

    {pos[0][0]=p1-dsp;;

    pos[0][1]=p2;

    }

    p1=pos[0][0];

    p2=pos[0][1];

    }

    void snake::check()

    {

    if(p1>endX)

    {p1=strX;}

    else if(p1<strX)

    {p1=endX;}

    if(p2>endY)

    {p2=strY;}

    else if(p2<strY)

    {p2=endY;}

    pos[0][0]=p1;

    pos[0][1]=p2;

    for(int i=1; i<n; i++)

    {if(p1==pos[i][0] && p2==pos[i][1])

    {caught();

    break;

    }

    }

    }

    void snake::show()

    {

    int x=getcolor();

    if(egGen!=1)

    {

    setcolor(getbkcolor());

    setfillstyle(1,getbkcolor());

    fillellipse(v1,v2,yr,yr);

    }

    else

    egGen=0;

    if(egGen==2)

    egGen–;

    setcolor(colr);

    setfillstyle(1,9);

    if(now==8|| now==2)

    fillellipse(pos[0][0],pos[0][1],xr,yr);

    setcolor(x);

    };  

     srand(time(&tm));  
     dsp = 20;  
     n = 5;  
     prev = 4;  
     for(int i = 4;i >= 0;i–)  
     { pos[i][0] = 201 + (n – i – 1) * dsp;  
      pos[i][1] = 301;  
      }  
      strtX = 21;  
      strtY = 21;  
      endX = 481;  
      endY = 361;  
      colr = 14;  
      now = prev;  
      dsp = 20;  
      stp = 111;  
      cnt = -1;  
      scr = 0;  
      dly = 150;  
       xr = 3;  
       yr = 9;  
      egg();  
      egGen = 1;  
      score();  
      int x = getcolor();  
      setlinestyle(0,1,3);  
      setcolor(15);  
      rectangle(strtX-15,strtY-15,endX+15,endY+15);  
      rectangle(endX+25,strtY-15,getmaxx()-15,endY+15);  
      rectangle(strtX-15,endY+25,getmaxx()-15,getmaxy()-5);  
      line(endX+25,strtY+75,getmaxx()-15,strtY+75);  
      line(endX+25,strtY+200,getmaxx()-15,strtY+200);  
      line(endX+25,strtY+275,getmaxx()-15,strtY+275);  
      setlinestyle(0,1,1);  
      settextstyle(8,0,1);  
      setcolor(11);  
      outtextxy(514,40,“SCORE”);  
      setcolor(14);  
      settextstyle(11,0,5);  
      outtextxy(524,110,” CONTROLS “);  
      outtextxy(522,135,“p = PAUSE”);  
      outtextxy(522,155,“g = RESUME”);  
      outtextxy(522,175,“e = EXIT”);  
      outtextxy(513,195,“ARROWS”);  
      outtextxy(512,205,”    -MOVEMENT”);  
      setcolor(14);  
      settextstyle(4,0,9);  
      outtextxy(getmaxx()-500,getmaxy()-110,“SNAKE”);  
      settextstyle(8,0,1);  
      setcolor(x);  
    }  
    void Snake::caught()  
    {  
     stp = 0;  
     sndCgt();  
    for(int i=0;i<=7;i++)  
     { if(i%2)  
      { setcolor(10);  
       outtextxy(512,250,“GAME OVER”);  
       delay(900);  
       }  
      else  
      {setcolor(0);  
       outtextxy(512,250,“GAME OVER”);  
       delay(500);  
      }  
      }  
    sleep(1);  
    }  
    void Snake::chngDir()  
     { int clr;  
     fillsettingstype *p;  
     char x = getch();  
     if(x == 72)  
      now = 8;  
     else if(x == 77)  
      now = 4;  
     else if(x == 80)  
      now = 2;  
     else if(x == 75)  
      now = 1;  
     else if(x == ‘e’)  
      caught();  
     else if(x == ‘p’)  
     { //int y = getcolor();  
      int twnkl = 1;  
      settextstyle(11,0,9);  
      while(1)  
      {if(kbhit())  
       { int c = getch();  
        if(c == ‘g’)  
        { clr = getcolor();  
         setcolor(0);  
         rectangle(endX+40,endY-10,getmaxx()-35,getmaxy()-160);  
         outtextxy(endX+60,endY-29,“PAUSE”);  
         break;  
         }  
        }  
       else  
       { if(twnkl%2)  
        { clr = getcolor();  
         setcolor(10);  
         rectangle(endX+40,endY-10,getmaxx()-35,getmaxy()-160);  
         outtextxy(endX+60,endY-29,“PAUSE”);  
         setcolor(clr);  
          delay(1000);  
         }  
        else  
        {  
         clr = getcolor();  
         setcolor(0);  
         rectangle(endX+40,endY-10,getmaxx()-35,getmaxy()-160);  
         outtextxy(endX+60,endY-29,“PAUSE”);  
         delay(1000);  
        }  
       }  
       twnkl++;  
      }  
        settextstyle(8,0,1);  
     }  
    }  
    Snake::Snake(Snake *p)  
    {  
     *p=NULL;  
    }  
    void Snake::egg()  
    do  
      { e1 = (rand() % 100) * dsp + strtX;  
       e2 = (rand() % 100) * dsp + strtY;  
       } while(test());  
      int x = getcolor();  
      setcolor(7);  
      setfillstyle(1,random(15)+1);  
      fillellipse(e1,e2,xr+2,xr+2);  
      setcolor(x);  
      egGen = 2;  
    }  
    int Snake::test()  
    {   
    for(int i=0;i<n;i++)  
      { if(e1 == pos[i][0] && e2 == pos[i][1])  
        break;  
       if(v1 == e1 && v2 == e2)  
        break;  
       if((e1 >= endX+1) || (e2 >= endY+1))  
        break;  
       }  
     if(i != n)  
      return 1;  
     else  
      return 0;  
    }  
    void main()  
    {  
    Snake snk;  
     int gd=DETECT,gm,i,j,k,x,y;  
     clrscr();  
     initgraph(&gd,&gm,“C:\\Turboc3\\bgi”);  
     snk.init();  
     snk.move();  
     closegraph();  
     restorecrtmode();  
     }

    • output:




  • Animation circles filled with different colors and patterns.

     Write a program to draw animation using increasing circles filled with different patterns.

    • program:

    #include<graphics.h>

    #include<conio.h>

    void main()

    {

    intgd=DETECT, gm, i, x, y;

    intigraph(&gd, &gm, “C:\\TC\\BGI”);

    x=getmax x()/3;

    y= getmax x()/3;

    setbkcolor(white);

    setcolor(blue);

    for(i=1;i<=8;i++)

          {

    setfillstyle(i,i);

    delay(20);

    circle(x, y, i*20);

    floodfill(x-2 + i*20, y, blue);

            }

    getch();

    closegraph();

    }

    • output:


  • display different size circles filled with different colors and at random places using c.

     program to make screen server in that display different size circle filled with different colors and at random places.

    • program:

    #include<stdio.h>

    #include<conio.h>

    #include”graphics.h”

    #include”stdlib.h”

    void main()

    {

    intgd=DETECT,gm,i=0, x,xx,y,yy,r;

    initgraph(&gd, &gm, “C:\\TC\\BGI”);

    x=getmaxx();

    y=getmaxy();

    while(!kbhit())

    {

    i++;

    circle(xx=random(x), yy=random(y), random(30));

    setfillstyle(random(i), random(30));

    floodfill(xx,yy,getmaxcolor());

    delay(200);

    }

    getch();

    }

    • output:


  • implement digital clock using c.

     write a program to implement digital clock.

    • program:

    #include<stdio.h>

    #include<conio.h>

    #include<graphics.h>

    #include<dos.h>

    struct time t;

    void display(int, int, int);

    void main()

    {

    int i=0,gd=DETECT,gm,hr,min,sec;

    clrscr();

    initgraph(&gd,&gm,”c:\\turboc3\\bgi”);

    setcolor(GREEN);

    settextstyle(4,0,7);

    while(!kbhit())

    {

    gettime(&t);

    hr=t.ti_hour;

    min=t.ti_min;

    sec=t.ti_sec

    i++,

    display(100,100,hr);

    display(200,100,min);

    display(300,100,sec);

          sound(400);

    delay(30);

    nosound();

    delay(930);

    cleardevice();

    }

    getch();

    }

    void display(int x,int y,int num)

    {

            char str[3];

    itoa(num,str,10);

    settextstyle(4,0,7);

    outtextxy(180,100,”:”);

    outtextxy(280,100,”:”);

    outtextxy(x,y,str);

    rectangle(90,90,380,200);

    rectangle(70,70,400,220);

    outtextxy(90,250,”Digital Clock”);

    }

    • Output:


About Me

The sky is not completely dark at night. Were the sky absolutely dark, one would not be able to see the silhouette of an object against the sky.

Follow Me On

Subscribe To My Newsletter

Subscribe for new travel stories and exclusive content.

Design a site like this with WordPress.com
Get started