Tuesday 24 December 2013

OPENGL PROGRAM TO DRAW GINGER BEARD MAN

#include<GL/glut.h>
#include<stdlib.h>
#include<math.h>

void myInit()
{
     glClearColor(1.0,1.0,1.0,0.0);
     glColor3f(1.0,0.0,0.0);
     glPointSize(4.0);
     glMatrixMode(GL_PROJECTION);
     glLoadIdentity();
     gluOrtho2D(0.0,640.0,0.0,480.0);
     }
    


      void myDisplay()
      {
           glClear(GL_COLOR_BUFFER_BIT);
           glColor3f(0.0,0.0,0.0);
           int m=40,l=3;
           unsigned long int i=0;
           int px=115,py=121;
           int qx=0,qy=0;
           glBegin(GL_POINTS);
           for(i=0;i<100000;i++)
           {
                         qx=m*(1+2*l)-py+abs(px-l*m);
                         qy=px;
                         glVertex2i(qx,qy);
                         px=qx;
                         py=qy;
                         }
                         glEnd();
                         glFlush();
                        
                         }   
         
          int main(int argc ,char **argv)
          {
               glutInit(&argc,argv);
               glutInitDisplayMode(GLUT_SINGLE| GLUT_RGB );
               glutInitWindowSize(640,480);
               //glutInitWindowPosition(200,200);
               glutCreateWindow("gingerbeard man");
               glutDisplayFunc(myDisplay);
               myInit();
               glutMainLoop();
               }


CONCENTRIC CIRCLE ANIMATION

#include <allegro.h>
#define R makecol(255,0,0)
#define G makecol(0,255,0)
#define B makecol(0,0,255)
#define K makecol(0,0,0)
#define W makecol(255,255,255)


float inner_circ_angle=0;
float cx=0,cy=0;
float sx=0,sy=0;
float r=30,angle=0;//rotating circle

BITMAP *buffer;

int draw_main_circles();
int draw_rotating_circles();


int main()
{   

   
    //int cirnum=0;
    //int rx=0,ry=0;//to detect the sign of directions
    //int dir=0;
   
   
   
    allegro_init();
    install_keyboard();
   
    set_color_depth(32);
    set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0);
    buffer=create_bitmap(SCREEN_W,SCREEN_H);
   
    cx=SCREEN_W/2;
    cy=SCREEN_H/2;
    //layernum=2;//one layer
   
   
    while(!key[KEY_ESC])
    {
                        draw_main_circles();
                       
                        //circle(buffer,cx,cy,r,K);
                        //draw_rotating_circles();
                         blit(buffer,screen,0,0,0,0,buffer->w,buffer->h);
                        clear_to_color(buffer,K);
                      
                        rest(100);
                        }
                       
                        destroy_bitmap(buffer);
                       
                        allegro_exit();
                       
                        }END_OF_MAIN();
                       
                        int  draw_main_circles()
                        {
                             int i=0,j=0;
                             int tx=0,ty=0;
                             //for main circle
                             circle(buffer,cx,cy,r,G);
                             //tx=cx+r*cos(inner_circ_angle);
                             //ty=cy+r*sin(inner_circ_angle);
                            
                             //circlefill(buffer,tx,ty,4,K);
                            
                             for(j=0;j<10;j++)
                             {
                             for(i=0;i<=10;i++)
                             {
                                              tx=cx+(j*r)*cos(i*36);
                                              ty=cy+(j*r)*sin(i*36);
                                              circle(buffer,tx,ty,r,G);
                                             
                                              //calculating for sub circle
                                              sx=tx+r*cos(inner_circ_angle);
                                              sy=ty+r*sin(inner_circ_angle);
                                              circlefill(buffer,sx,sy,3,makecol(rand()%255,rand()%255,rand()%255));
                                              inner_circ_angle+=0.1;
                                             
                                              }
                                              if(j>=10) j=0;
                                              if(inner_circ_angle>=360) inner_circ_angle=0;
                                             
                                              }
                                              return 1;
                                             
                                              }//end for main-circles drawing
                                             

/*int  draw_rotating_circles()
{
     sx=cx+r*cos(inner_circ_angle);
     sy=cy+r*sin(inner_circ_angle);
     inner_circ_angle++;
     circlefill(buffer,sx,sy,3,R);
     blit(buffer,screen,0,0,0,0,buffer->w,buffer->h);
    
     //inner_circ_angle++;
     if(inner_circ_angle>=360)
      inner_circ_angle=0;
     
      return 1;
     }*/