Monday, November 3, 2014

Sunday, July 27, 2014

OpenGl - Displays a BARN shape on the XY plane.



Source Code:
1:  #include <windows.h>  
2:  #include <gl/Gl.h>  
3:  #include <gl/glut.h>  
4:  #include <cmath>   
5:    
6:  int WinWidth = 500, WinHeight = 500;  
7:    
8:  typedef struct{float x;float y;}Point2D;  
9:  typedef struct{float x;float y;float z;}Point3D;  
10:    
11:    
12:  Point3D COP = {100,100,-200};  
13:    
14:  Point3D A,B,C,D,E,F,G,H,I,J;     // Vertices of the BARN  
15:    
16:  void InitBarn(){  
17:       A.x = 200; A.y = 100; A.z = 200;  
18:       B.x = 200; B.y = 00; B.z = 200;  
19:       C.x = 400; C.y = 00; C.z = 200;  
20:       D.x = 400; D.y = 100; D.z = 200;  
21:       E.x = 300; E.y = 200; E.z = 200;  
22:    
23:       F.x = 200; F.y = 100; F.z = 400;  
24:       G.x = 200; G.y = 00; G.z = 400;  
25:       H.x = 400; H.y = 00; H.z = 400;  
26:       I.x = 400; I.y = 100; I.z = 400;  
27:       J.x = 300; J.y = 200; J.z = 400;  
28:  }  
29:    
30:  void constructBarn(Point2D A, Point2D B, Point2D C, Point2D D, Point2D E, Point2D F, Point2D G, Point2D H,Point2D I,Point2D J){  
31:       glPointSize(1.0);  
32:    
33:       glBegin(GL_LINE_LOOP);       
34:       //DRAWING FRONT FACE  
35:       glVertex2i(A.x, A.y);  
36:       glVertex2i(B.x, B.y);  
37:       glVertex2i(C.x, C.y);  
38:       glVertex2i(D.x, D.y);  
39:       glVertex2i(E.x, E.y);  
40:    
41:       glEnd();  
42:    
43:       glBegin(GL_LINE_LOOP);  
44:       //DRAWING BACK FACE  
45:       glVertex2i(F.x, F.y);  
46:       glVertex2i(G.x, G.y);  
47:       glVertex2i(H.x, H.y);  
48:       glVertex2i(I.x, I.y);  
49:       glVertex2i(J.x, J.y);  
50:    
51:       glEnd();  
52:         
53:       glBegin(GL_LINES);  
54:    
55:       //DRAWING OTHER LINES  
56:       glVertex2i(A.x, A.y);  
57:       glVertex2i(F.x, F.y);  
58:    
59:       glVertex2i(B.x, B.y);  
60:       glVertex2i(G.x, G.y);  
61:    
62:       glVertex2i(C.x, C.y);  
63:       glVertex2i(H.x, H.y);  
64:    
65:       glVertex2i(D.x, D.y);  
66:       glVertex2i(I.x, I.y);  
67:    
68:       glVertex2i(E.x, E.y);  
69:       glVertex2i(J.x, J.y);  
70:    
71:       glEnd();  
72:    
73:       glFlush();  
74:    
75:  }  
76:    
77:  Point2D Project_Perspective(Point3D p, Point3D CoP){  
78:       Point2D p2;  
79:       float d = abs(CoP.z);     // The distance between the COP and orign  
80:         
81:        p2.x=(d*p.x)/(p.z+d);   
82:     p2.y=(d*p.y)/(p.z+d);  
83:         
84:       return p2;  
85:  }  
86:    
87:  Point2D translate2D(Point2D p, float tx, float ty){  
88:    Point2D tp2;  
89:       tp2.x=p.x+tx;  
90:       tp2.y=p.y+ty;  
91:         
92:       return tp2;  
93:  }   
94:    
95:  Point3D translate3D(Point3D p, float tx, float ty, float tz){  
96:    Point3D tp3;  
97:       tp3.x=p.x+tx;  
98:       tp3.y=p.y+ty;  
99:       tp3.z=p.z+tz;  
100:    
101:       return tp3;  
102:  }   
103:    
104:  void keyboard(unsigned char key, int x, int y)  
105:  {  
106:    if (key == 'q' || key == 'Q')  
107:      exit(EXIT_SUCCESS);  
108:  }  
109:    
110:  void myMouse(int button, int state, int x, int y) {  
111:       if(state == GLUT_DOWN)   
112:       {  
113:            if(button == GLUT_LEFT_BUTTON)   
114:            {  
115:                    
116:            }  
117:            else if (button == GLUT_RIGHT_BUTTON)   
118:            {  
119:                    
120:            }  
121:       }  
122:  }  
123:    
124:  void myDisplay()  
125:  {  
126:       glClearColor(0.2f, 0.3f, 0.1f, 0.0f);   
127:       glClear(GL_COLOR_BUFFER_BIT);  
128:       glColor3f(1.0f, 0.5f, 0.8f);  
129:    
130:             Point2D Projected_A=Project_Perspective(A,COP);       
131:            Point2D Projected_B=Project_Perspective(B,COP);  
132:            Point2D Projected_C=Project_Perspective(C,COP);  
133:            Point2D Projected_D=Project_Perspective(D,COP);  
134:            Point2D Projected_E=Project_Perspective(E,COP);  
135:            Point2D Projected_F=Project_Perspective(F,COP);  
136:            Point2D Projected_G=Project_Perspective(G,COP);  
137:            Point2D Projected_H=Project_Perspective(H,COP);  
138:            Point2D Projected_I=Project_Perspective(I,COP);  
139:            Point2D Projected_J=Project_Perspective(J,COP);  
140:         
141:       constructBarn(  
142:            Projected_A,  
143:            Projected_B,  
144:            Projected_C,  
145:            Projected_D,  
146:            Projected_E,  
147:            Projected_F,  
148:            Projected_G,  
149:            Projected_H,  
150:            Projected_I,  
151:            Projected_J  
152:       );  
153:  }  
154:    
155:    
156:  int main( int argc, char ** argv ) {  
157:       glutInit( &argc, argv );  
158:       glutInitWindowPosition( 0, 0 );  
159:       glutInitWindowSize( WinWidth, WinHeight );  
160:       glutCreateWindow( "Projection of a BARN" );  
161:    
162:       glMatrixMode( GL_PROJECTION );   
163:       glLoadIdentity();  
164:       gluOrtho2D( 0, WinWidth, 0, WinHeight );  
165:       glViewport(0, 0, WinWidth, WinHeight);  
166:    
167:       InitBarn();  
168:    
169:       glutKeyboardFunc(keyboard);   
170:       glutMouseFunc( myMouse );  
171:       glutDisplayFunc( myDisplay );  
172:       glutMainLoop();  
173:    
174:       return( 0 );  
175:  }  

Monday, July 21, 2014

Alpha Blending Matlab Code


Ibg=imread('E:\IP\codes\flower.jpg');
Ifg=imread('E:\IP\codes\beetle.jpg');

if length(size(Ibg))==3
        Ibg=rgb2gray(Ibg);
end
if length(size(Ifg))==3
        Ifg=rgb2gray(Ifg);
end

alpha = 0.2;

[row,col] = size(Ibg);
I = zeros(row,col);
I = uint8(I);
for i = 1:row
    for j = 1:col
        I(i,j) = alpha * Ibg(i,j) + (1 - alpha) * Ifg(i,j);
    end
end

subplot(1,3,1); imshow(Ibg);
subplot(1,3,2); imshow(Ifg);
subplot(1,3,3); imshow(I);

Auto Contrast Matlab Code


I=imread('E:\IP\imgs\lena.jpg');
amin = 0;
amax = 255;
if length(size(I))==3
        I=rgb2gray(I);
end
alow = min(min(I));
ahigh = max(max(I));

[r,c] = size(I);
J = zeros(r,c);

for m=1:r
    for n=1:c
        a = I(m,n);
        a1 = amin +((a - alow) * ((amax - amin) / (ahigh - alow)));
        J(m,n) = a1;
    end
end
J = uint8(J);
subplot(1,2,1); imshow(I);
subplot(1,2,2); imshow(J);

Sunday, July 20, 2014

Filters


  • Difference between Point Operation and Filters       
  1. Filters generally used   more than one pixel from the source image for computing each new pixel values.
  2. The capability of Point operation is limited. For example, In Point operation can't blur or sharpen an image.        

Wednesday, July 16, 2014

Definitions


Digital Image Processing: Manipulate a digitalized image using a computer.
Digital Image Editing: Manipulation of digital images using an existing software application such as Adobe Photoshop or Corel Paint
Pixel: The smallest addressable unit of an image.
Histogram: Frequency distribution of image intensities.

Thursday, July 10, 2014

AI Techniques


AI technique is a method of exploit knowledge. programs which are using AI technique are have disadvantages and advantages

         Disadvantage

  • AI technique programs are slower to execute 


         Advantages

  • They are much less fragile
  • People can easily understand what the program knowledge is
  • They can work for large problems where more direct methods break down
AI Techniques
  • Search
  • Use of Knowledge
  • Abstraction

Characteristics of AI technique



  • The knowledge capture generalization.
  • It can be understood by people who must provide it.
  • It can easily modified to correct errors and reflect changes in the world.
  • It can be used a great many situations.

AI PROBLEMS

           
         

                        Mundane Tasks

  • Perception
         -vision
         -speech

  • Natural language problem

          -Understanding
          -Generation
          -Translation

  • Commonsense reasoning
  • Robot Control


                      Formal Tasks

  • Games

         -Chess
         -Backgammon
         -Checkers-Go

  • Mathematics

         -Geometry
         -Logic
         -Integral calculus
         -Proving properties of programs

                      Expert Tasks

  • Engineering

        -Design
        -Fault finding
        -Manufacturing planning

  • Scientific analysis
  • Medical diagnosis
  • Financial analysis




Monday, July 7, 2014

Deffinitions


AI: Artificial intelligence(AI) is the study of how to make computer do things which, at the                   moment, people do better.

AI TECHNIQUE: AI technique is a method that exploits the knowledge

STATE SPACE: It contains all the possible configurations of the relevant object.

STATE SPACE SEARCH: Define a problem as states and search the solutions by starting with a initial state, using set of rules moving one state to another and attempting to end up in one of a set of final states

INITIAL STATES : Specify one or more states within the state space that describe possible situations to start problem-solving process

GOAL STATES : Specify one or more states that would be acceptable as solution to the problem

Wednesday, June 18, 2014

Php mysql connection class with oop


<?php
class dbConnect
{
var $host;
var $username;
var $password;
var $database;

function __construct($host,$username,$password,$database)
{
$this->host=$host;
$this->username=$username;
$this->password=$password;
$this->database=$database;
$this->connection();
}
function connection()
{
$conn=mysqli_connect($this->host,$this->username,$this->password,$this->database);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
else
echo "connected";
mysqli_close($conn);
}

}
$log=new dbConnect("localhost","root","","login");

?>

Thursday, June 12, 2014

Java-Loops


  • Loops are very useful mechanism to execute a code several times in java programming.
  • Java has 3 looping mechanisms. They are
    • For loop
    • While loop
    • do....while loop
                          For Loop
      For loop is very good choice if you know how many times a task wants to execute.
      Basic syntax:
                 for(initialization;expression;update)
                 {
                      //statements
                  }
      Example:
                   public class ForLoop
                  {
                  public static void main(String args [])
                 {
                       for(int x=1;x<10;x++)
                       {
                         System.out.println(x);
                       }
                  }
                   }

       You can get the answer like this....


                                 While loop
   Basic syntax: 
              while(expression)
              {
                  //statements
               }
    Example:
              public class WhileLoop
              {
                   public static void main(String args [])
                  {
                         int x=1;
 while(x<10)
 {
                        System.out.println(x);
 x++;
 }
                   }
                }

       You can get the answer like this..        



                    Do....While  loop
       Do while loop is similar to the while loop. The different thing is in while loop before                    executing the code check  the condition. But in do while loop after executing the code                check  the condition.

       Basic Syntax:
        do
         {
               //statements
          }
         while(expression);

         Example:
          
                public class DoWhileLoop
                {
                   public static void main(String args [])
                  {
                     int x=1;
                 do
                 {
                    System.out.println(x);
                    x++;
                  }
while(x<10);
                   }
                   }

             You can get the answer like this..   
         

Sunday, June 8, 2014

Rotate a square with respect to the origin



#include <windows.h>
#include <gl/Gl.h>
#include <gl/glut.h>
#include <cmath>

int screenheight = 600;
int screenwidth = 800;
int flag = 0;

double angle = 30;            

typedef struct{
    float x;
    float y;
}Point2D;

Point2D p1,p2,p3,p4;

void DrawSquare(Point2D pt1, Point2D pt2,Point2D pt3, Point2D pt4){
       glPointSize(2.0);
       glBegin(GL_LINE_LOOP);
       glVertex2i(pt1.x, pt1.y);
   glVertex2i(pt3.x, pt3.y);
  glVertex2i(pt2.x, pt2.y);

  glVertex2i(pt4.x, pt4.y);
       glEnd();

       glPointSize(5.0);
       glBegin(GL_POINTS);
       glVertex2i(pt2.x, pt2.y);
       glEnd();
       glFlush();
}

Point2D translate(Point2D p, float tx, float ty){
   p.x =p.x;
   p.y = p.y;
   return p;

}
Point2D  rotate(Point2D p, float ang){

    ang = ang * 3.14 / 180.0;                            
    Point2D ptemp;

    ptemp.x = p.x * cos(ang) - p.y * sin(ang);

    ptemp.y = p.x * sin(ang) + p.y * cos(ang);
    return ptemp;

}

 void myMouse(int button, int state, int x, int y) {
glPointSize(5.0);
if(state == GLUT_DOWN)
{
if(button == GLUT_LEFT_BUTTON)
{
  if (flag==0){
p1.x = x;
p1.y = screenheight - y;
p3.y=screenheight - y;
p4.x=x;
flag = 1;
} else if(flag==1){
p2.x = x;
p2.y = screenheight - y;
p3.x=x;
p4.y=screenheight - y;
flag = 0;
DrawSquare(p1,p2,p3,p4);


}

}
else if (button == GLUT_RIGHT_BUTTON)
{
Point2D Rotated_p2 = rotate(p2,angle);
Point2D Rotated_p1 = rotate(p1,angle);
Point2D Rotated_p3 = rotate(p3,angle);
Point2D Rotated_p4 = rotate(p4,angle);
                   DrawSquare(Rotated_p1,Rotated_p2,Rotated_p3,Rotated_p4);
}
}
}

void myDisplay()

{

       glClearColor(1.0f, 1.0f, 1.0f, 0.0f);

       glClear(GL_COLOR_BUFFER_BIT);

       glColor3f(0.0f, 0.0f, 0.0f);

}





int main( int argc, char ** argv ) {

       glutInit( &argc, argv );

       glutInitWindowPosition( 0, 0 );

       glutInitWindowSize( 800, 600 );

       glutCreateWindow( "Draw Dots" );



       glMatrixMode( GL_PROJECTION );

       glLoadIdentity();

       gluOrtho2D( 0, 800, 0, 600 );

       glViewport(0, 0, 800, 600);



       glutMouseFunc( myMouse );

       glutDisplayFunc( myDisplay );

       glutMainLoop();



       return( 0 );

}

Saturday, June 7, 2014

Rotate a square with respect to its centre


#include <windows.h>

#include <gl/Gl.h>

#include <gl/glut.h>

#include <cmath>



int screenheight = 600;

int screenwidth = 800;

bool flag = true;

int X1,Y1,X2,Y2,click;
float len;
float m;
double angle = 30;                //The angle for the rotation (in degrees)



typedef struct{

    float x;

    float y;

}Point2D;



Point2D p1,p2,p3,p4;



void DrawLineSegment(Point2D pt1, Point2D pt2){

       glPointSize(1.0);

       glBegin(GL_LINES);

       glVertex2i(pt1.x, pt1.y);

       glVertex2i(pt2.x, pt2.y);

       glEnd();



       glPointSize(6.0);

       glBegin(GL_POINTS);

  glVertex2i(pt1.x, pt1.y);
       glVertex2i(pt2.x, pt2.y);

       glEnd();

       glFlush();

}



Point2D translate(Point2D p, float tx, float ty){

       p.x =p.x+tx; //.....wite the equations for translation

       p.y = p.y+ty; //.....wite the equations for translation

       return p;

}



Point2D  rotate(Point2D p,float ang)
{
    ang = ang * 3.14 / 180.0;                                 //angle in radians

    Point2D ptemp;

    ptemp.x = p.x * cos(ang) - p.y * sin(ang);

    ptemp.y = p.x * sin(ang) + p.y * cos(ang);

    return ptemp;

}



void myMouse(int button, int state, int x, int y) {

       if(state == GLUT_DOWN)
       {

              if(button == GLUT_LEFT_BUTTON)
              {
if(click == 0)
{
X1=x;
Y1=screenheight - y;
p1.x = X1;
                p1.y = Y1;
click++;

}
else if(click ==1)
{
click++;
glClear(GL_COLOR_BUFFER_BIT);
            Point2D p1;
            p1.x = X1;
            p1.y = Y1;
            p2.x = x;
            p2.y = screenheight - y;
            p3.x = x;
            p3.y = Y1;
            p4.x = X1;
            p4.y = screenheight - y;
DrawLineSegment(p1, p3);
            DrawLineSegment(p3, p2);
DrawLineSegment(p2, p4);
DrawLineSegment(p1, p4);
}                
             }

              else if (button == GLUT_RIGHT_BUTTON)
              {
    m=(p2.y-p1.y)/(p2.x-p1.x);
len=sqrt((p2.y-p2.x)*(p2.y-p2.x)+(p1.y-p1.x)*(p1.y-p1.x));
Point2D Translated_p1 = translate(p1,-(p1.x+p2.x)/2,-(p1.y+p2.y)/2);
Point2D Translated_p2 = translate(p2,-(p1.x+p2.x)/2,-(p1.y+p2.y)/2);
Point2D Translated_p3 = translate(p3,-(p1.x+p2.x)/2,-(p1.y+p2.y)/2);
Point2D Translated_p4 = translate(p4,-(p1.x+p2.x)/2,-(p1.y+p2.y)/2);

                     Point2D Rotated_p1 = rotate(Translated_p1,angle);
Point2D Rotated_p2 = rotate(Translated_p2,angle);
Point2D Rotated_p3 = rotate(Translated_p3,angle);
Point2D Rotated_p4 = rotate(Translated_p4,angle);

Point2D Translated_p12 = translate(Rotated_p1,(p1.x+p2.x)/2,(p1.y+p2.y)/2);
Point2D Translated_p22 = translate(Rotated_p2,(p1.x+p2.x)/2,(p1.y+p2.y)/2);
Point2D Translated_p32 = translate(Rotated_p3,(p1.x+p2.x)/2,(p1.y+p2.y)/2);
Point2D Translated_p42 = translate(Rotated_p4,(p1.x+p2.x)/2,(p1.y+p2.y)/2);

                     DrawLineSegment(Translated_p12,Translated_p32);
DrawLineSegment(Translated_p32,Translated_p22);
DrawLineSegment(Translated_p22,Translated_p42);
DrawLineSegment(Translated_p12,Translated_p42);
              }

       }

}



void myDisplay()

{

       glClearColor(1.0f, 1.0f, 1.0f, 0.0f);

       glClear(GL_COLOR_BUFFER_BIT);

       glColor3f(0.0f, 0.0f, 0.0f);

}





int main( int argc, char ** argv ) {

       glutInit( &argc, argv );

       glutInitWindowPosition( 0, 0 );

       glutInitWindowSize( 800, 600 );

       glutCreateWindow( "Draw Dots" );



       glMatrixMode( GL_PROJECTION );

       glLoadIdentity();

       gluOrtho2D( 0, 800, 0, 600 );

       glViewport(0, 0, 800, 600);



       glutMouseFunc( myMouse );

       glutDisplayFunc( myDisplay );

       glutMainLoop();



       return( 0 );

}

Rotate a line



#include <windows.h>
#include <gl/Gl.h>
#include <gl/glut.h>
#include <cmath>
 
int screenheight = 600;
int screenwidth = 800;
bool flag = true;

double angle = 30;                //The angle for the rotation (in degrees)

typedef struct{
    float x;
    float y;
}Point2D;

Point2D p1,p2;

void DrawLineSegment(Point2D pt1, Point2D pt2){
       glPointSize(1.0);
       glBegin(GL_LINES);
       glVertex2i(pt1.x, pt1.y);
       glVertex2i(pt2.x, pt2.y);
       glEnd();

       glPointSize(6.0);
       glBegin(GL_POINTS);
       glVertex2i(pt2.x, pt2.y);
       glEnd();
       glFlush();

}

Point2D translate(Point2D p, float tx, float ty){
       p.x =p.x; //.....wite the equations for translation 
       p.y = p.y; //.....wite the equations for translation
       return p;
}

Point2D  rotate(Point2D p, float ang){
    ang = ang * 3.14 / 180.0;                                 //angle in radians
    Point2D ptemp;

    ptemp.x = p.x * cos(ang) - p.y * sin(ang);
    ptemp.y = p.x * sin(ang) + p.y * cos(ang);

 return ptemp;
}

void myMouse(int button, int state, int x, int y) {
       if(state == GLUT_DOWN) {
              if(button == GLUT_LEFT_BUTTON) {
                     glClear(GL_COLOR_BUFFER_BIT);
                     Point2D p1;
                     p1.x = 0;
                     p1.y = 0;

                     p2.x = x;
                     p2.y = screenheight - y;

                     DrawLineSegment(p1, p2);
              }
              else if (button == GLUT_RIGHT_BUTTON) {
                     Point2D Rotated_p2 = rotate(p2,angle);
                     DrawLineSegment(p1,Rotated_p2);
              }
       }
}

void myDisplay(){
       glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
       glClear(GL_COLOR_BUFFER_BIT);
       glColor3f(0.0f, 0.0f, 0.0f);
}
 
int main( int argc, char ** argv ) {
       glutInit( &argc, argv );
       glutInitWindowPosition( 0, 0 );
       glutInitWindowSize( 800, 600 );
       glutCreateWindow( "My Drawing Screen" );
    glMatrixMode( GL_PROJECTION );
       glLoadIdentity();
       gluOrtho2D( 0, 800, 0, 600 );
       glViewport(0, 0, 800, 600);

       glutMouseFunc( myMouse );
       glutDisplayFunc( myDisplay );

       glutMainLoop();
       return( 0 );
}

Friday, May 9, 2014

GL_TRIANGLE_FAN Example In OpenGl

#include <GL/glut.h>      
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,0.0);
glBegin(GL_TRIANGLE_FAN);
glVertex3f(0.1, 0.1,0.0);
glVertex3f(0.6, 0.1,0.0);
glVertex3f(0.8,0.3,0.0);
glVertex3f(0.6,0.6,0.0);
glVertex3f(0.1,0.6,0.0);
glVertex3f(0.0,0.3,0.0);
glEnd();
glFlush();
}
void init()
{
glClearColor(0.0,0.5,0.2,0.8);
}
int main(int argc, char** argv)
{
glutCreateWindow("simple 3D");
glutDisplayFunc(display);
init();
glutMainLoop();
}

GL_POLYGON Example In OpenGl

#include <GL/glut.h>      
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,0.0);
glBegin(GL_POLYGON);
glVertex3f(0.1, 0.1,0.0);
glVertex3f(0.6, 0.1,0.0);
glVertex3f(0.8,0.3,0.0);
glVertex3f(0.6,0.6,0.0);
glVertex3f(0.1,0.6,0.0);
glVertex3f(0.0,0.3,0.0);
glEnd();
glFlush();
}
void init()
{
glClearColor(0.0,0.5,0.2,0.8);
}
int main(int argc, char** argv)
{
glutCreateWindow("simple 3D");
glutDisplayFunc(display);
init();
glutMainLoop();
}

GL_QUAD_STRIP Example In OpenGl

#include <GL/glut.h>      
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,0.0);
glBegin(GL_QUAD_STRIP);
glVertex3f(0.2, 0.2,0.0);
glVertex3f(0.8, 0.2,0.0);
glVertex3f(0.2,0.4,0.0);
glVertex3f(0.8,0.4,0.0);
glVertex3f(0.2,0.8,0.0);
glVertex3f(0.8,0.8,0.0);
glEnd();
glFlush();
}
void init()
{
glClearColor(0.0,0.5,0.2,0.8);
}
int main(int argc, char** argv)
{
glutCreateWindow("simple 3D");
glutDisplayFunc(display);
init();
glutMainLoop();
}

GL_QUADS Example In OpenGl

#include <gl glut.h="">         
void display()
{
glClear(GL_COLOR_BUFFER_BIT); 
glColor3f(1.0,1.0,0.0);
glBegin(GL_QUADS);
glVertex3f(0.2, 0.2,0.0);
glVertex3f(0.8, 0.2,0.0);
glVertex3f(0.6,0.4,0.0);
glVertex3f(0.4,0.4,0.0);
glVertex3f(0.4,0.6,0.0);
glVertex3f(0.6,0.6,0.0);
glVertex3f(0.8,0.8,0.0);
glVertex3f(0.2,0.8,0.0);
glEnd();
glFlush(); 
}
void init()
{
glClearColor(0.0,0.5,0.2,0.8);
}
int main(int argc, char** argv)
{
glutCreateWindow("simple 3D"); 
glutDisplayFunc(display);
init();
glutMainLoop();
}

GL_TRIANGLES Example In OpenGl

#include <GL/glut.h>      
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,0.0);
glBegin(GL_TRIANGLES);
glVertex3f(0.2, 0.2,0.0);
glVertex3f(0.8, 0.2,0.0);
glVertex3f(0.2, 0.5,0.0);
//glVertex3f(0.8, 0.5,0.0);
//glVertex3f(0.2, 0.8,0.0);
//glVertex3f(0.8, 0.8,0.0);
glEnd();
glFlush();
}
void init()
{
glClearColor(0.0,0.5,0.2,0.8);
}
int main(int argc, char** argv)
{
glutCreateWindow("simple 3D");
glutDisplayFunc(display);
init();
glutMainLoop();
}

GL_TRIANGLE_STRIP Example In OpenGl

#include <GL/glut.h>         
void display()
{
glClear(GL_COLOR_BUFFER_BIT); 
glColor3f(1.0,1.0,0.0);
glBegin(GL_TRIANGLE_STRIP);
glVertex3f(0.2, 0.2,0.0);
glVertex3f(0.8, 0.2,0.0);
glVertex3f(0.2, 0.5,0.0);
glVertex3f(0.8, 0.5,0.0);
glVertex3f(0.2, 0.8,0.0);
glVertex3f(0.8, 0.8,0.0);
glEnd();
glFlush(); 
}
void init()
{
glClearColor(0.0,0.5,0.2,0.8);
}
int main(int argc, char** argv)
{
glutCreateWindow("simple 3D"); 
glutDisplayFunc(display);
init();
glutMainLoop();
}

GL_LINE_LOOP Example In OpenGl

#include <GL/glut.h>      
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,0.0);
glBegin(GL_LINE_LOOP);
glVertex3f(0.2, 0.2,0.0);
glVertex3f(0.8, 0.2,0.0);
glVertex3f(0.2, 0.5,0.0);
glVertex3f(0.8, 0.5,0.0);
glVertex3f(0.2, 0.8,0.0);
glVertex3f(0.8, 0.8,0.0);
glEnd();
glFlush();
}
void init()
{
glClearColor(0.0,0.5,0.2,0.8);
}
int main(int argc, char** argv)
{
glutCreateWindow("simple 3D");
glutDisplayFunc(display);
init();
glutMainLoop();
}

GL_LINE_STRIP Example In OpenGl


#include <GL/glut.h>         
void display()
{
glClear(GL_COLOR_BUFFER_BIT); 
glColor3f(1.0,1.0,0.0);
glBegin(GL_LINE_STRIP);
glVertex3f(0.2, 0.2,0.0);
glVertex3f(0.8, 0.2,0.0);
glVertex3f(0.2, 0.5,0.0);
glVertex3f(0.8, 0.5,0.0);
glVertex3f(0.2, 0.8,0.0);
glVertex3f(0.8, 0.8,0.0);
glEnd();
glFlush(); 
}
void init()
{
glClearColor(0.0,0.5,0.2,0.8);
}
int main(int argc, char** argv)
{
glutCreateWindow("simple 3D"); 
glutDisplayFunc(display);
init();
glutMainLoop();
}

Simple line drawing in OpenGl



#include <GL/glut.h>         

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT); 
glColor3f(1.0,1.0,0.0);
glBegin(GL_LINES);
glVertex2f(0.5, -0.5);
glVertex2f(-0.5, 0.5);
glEnd();
glFlush(); 
}
void init(){
glClearColor(0.0,0.5,0.2,0.8);
}

int main(int argc, char** argv)
{
glutCreateWindow("simple line"); 
glutDisplayFunc(display);
init();
glutMainLoop();

}

Tuesday, April 29, 2014

GL_POINTS In OpenGl


#include <GL/glut.h>
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);

glPointSize(3.0);
glBegin(GL_POINTS);
glColor3f(1.0,1.0,0.0);
glVertex2f(-0.5, -0.5);
glColor3f(1.0,0.0,0.0);
glVertex2f(-0.5, 0.5);
glColor3f(0.0,0.0,1.0);
glVertex2f(0.5, 0.5);
glColor3f(0.0,1.0,0.0);
glVertex2f(0.5, -0.5);
glEnd();
glFlush();
}
void init(){}
int main(int argc, char** argv)
{
glutCreateWindow("simple");
glutDisplayFunc(display);
init();
glutMainLoop();
}

Line drawing with mouse click event in OpenGl


#include <GL/glut.h> 
int ww = 600, wh = 400;
int first = 0;
int xi, yi, xf, yf;
void drawLine(int x1, int y1, int x2, int y2)
{
glClear(GL_COLOR_BUFFER_BIT);
glLineWidth(5.0);
glBegin(GL_LINES);
glVertex2i(x1, y1);
glVertex2i(x2, y2);
glEnd();
glFlush();
}
void display()
{
glClearColor(1.0, 1.0, 0.0, 1.0);
glColor3f(1.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
void mouse(int btn, int state, int x, int y)
{
if(btn==GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
switch(first)
{
case 0:
xi = x;
yi = (wh-y);
first = 1;
break;
case 1:
xf = x;
yf = (wh-y);
drawLine(xi,yi,xf,yf);
first = 0;
break;
}
}
}
void myinit()
{
glViewport(0,0,ww,wh);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,(GLdouble)ww,0.0,(GLdouble)wh);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(ww,wh);
glutCreateWindow("demo");
glutDisplayFunc(display);
myinit();
glutMouseFunc(mouse);
glutMainLoop();
return 0;
}

Wednesday, April 16, 2014

Delete collection in mongodb

Update document in mongodb

Basic syntax of update() method is as follows
db.COLLECTION_NAME.update
(SELECTIOIN_CRITERIA, UPDATED_DATA)

Insert And Find In MongoDb

To insert data into MongoDB collection, you need to use MongoDB's insert() or save()method.
Basic syntax of insert() command is as follows:
db.COLLECTION_NAME.insert(document)
To query data from MongoDB collection, you need to use MongoDB's find() method.
Basic syntax of find() method is as follows
db.COLLECTION_NAME.find()
To display the results in a pretty way, you can use pretty() method.
SYNTAX:
db.mycol.find().pretty()
Apart from find() method there is findOne() method, that reruns only one document.

Drop Collections

Basic syntax of drop collection command is as follows
db.COLLECTION_NAME.drop()

Tuesday, April 15, 2014

Create Collections

Basic syntax of createCollection() command is as follows
db.createCollection(name, options)
option is optional

drop database

dropDatabase() command is used to drop a database

Create database

Command use database_name is used to create a database. You can use any name for database_name.
If you want to show the database you must want to insert atleast one document into it.

show dbs

Command show dbs used to show all the databases

MongoDB Statistics

Command db.stats() gives the detais of the particular database

MongoDB Help

You can get mongodb commands and descriptions using db.help()

Getting start with mongoDb


1.
*open a cmd
*change the directotry as mongodb installation didirectory. eg:- C:\mongodb\bin>mongod

2.
*open another cmd
*change the directotry as mongodb installation didirectory. eg:- C:\mongodb\bin>mongo
Then you can work with the 2nd cmd

MongoDb Introduction

*MongoDb is a Nosql database.This is something different from the RDBMS. *Colloction-This is like a table of RDBMS.

Saturday, April 12, 2014

Time converting program in Java


import java.util.*;
public class TimeConvert
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
System.out.println("Enter the value of seconds: ");
int sec=s.nextInt();
int hr=sec/3600;
int min=(sec-hr*3600)/60;
sec=sec-(hr*3600+min*60);
System.out.println(hr+"hours"+" "+min+"minites"+" "+sec+"seconds");
}
}

Base Exponent program in Java


public class Rec
{
public static double power(double base, int exponent)
{
if(exponent>0)
{
return (base*power(base,exponent-1));
}
else if(exponent<0 data-blogger-escaped-br=""> {
exponent=-exponent;
return 1/(base*power(base,exponent-1));
}
else
{
return 1;
}
}
public static void main(String args [])
{
System.out.println(power(2,-3));
}
}

Gcd program in java


public class gcd1
{
public static int gcd(int x,int y)
{
if(y==0)
{
return x;
}
else
{
return gcd(y,x%y);
}
}
public static void main (String args [])
{
System.out.println(gcd(10,5));
}
}

Fibonacci program in Java


public class fibnocci
{
static int fib(int n)
{
if((n==1)|| (n==2))
return 1;
else
return fib(n-1)+fib(n-2);
}
public static void main(String [] args)
{
System.out.println("fibnocci(7)= "+ fib(7));
}
}

Base converting program in Java


public class Base
{
public void decTobase(int n,int b)
{
if(n>0)
{
decTobase(n/b,b);
System.out.print(n%b);
}
}
public static void main(String args [])
{
Base a=new Base();
a.decTobase(15,2);
System.out.println();
a.decTobase(65,4);
System.out.println();
a.decTobase(511,8);
System.out.println();
}

Factorial program in Java


public class factorial
{
static int fact(int n)
{
if(n==0 || n==1)
return 1;
else
return n*fact(n-1);
}
public static void main(String [] args)
{
System.out.println("Factorial(4)="+fact(4));
}
}

2D Array In Java


public class TwoDArray
{
public static void main(String args[])
{
int [][] a={{1,2,3},{4,5,6},{7,8,9}};
for(int row=0;row<3 data-blogger-escaped-br="" data-blogger-escaped-row=""> {
for(int col=0;col<3 data-blogger-escaped-br="" data-blogger-escaped-col=""> System.out.print(a[row][col]);
System.out.println();
}
}
}

Array Sums in Java


class RowSum
{
int A[][]={{1,0,0,1},{1,-2,0,1},{-1,2,2,1}};
int B[][]={{1,1,-1,1},{0,1,-1,1},{0,0,1,1}};
int C[][]=new int[3][4];
void printArray()
{
for(int i=0;i<3 data-blogger-escaped-br="" data-blogger-escaped-i=""> {
for(int j=0;j<4 data-blogger-escaped-br="" data-blogger-escaped-j=""> System.out.print(C[i][j]+" ");
System.out.println();
}
}
void Addition()
{
for(int i=0;i<3 data-blogger-escaped-br="" data-blogger-escaped-i=""> {
for(int j=0;j<4 data-blogger-escaped-br="" data-blogger-escaped-j=""> C[i][j]=A[i][j]+B[i][j];
}
}
public static void main(String args[])
{
RowSum m=new RowSum();
m.Addition();
System.out.println("\n Array elements after addition:");
m.printArray();
}
}

Metrix Operation In Java


class MetrixOperation
{
int A[][]={{1,0,0},{1,1,0},{0,1,1}};
int B[][]={{1,1,1},{0,1,0},{0,0,1}};
int C[][]=new int[3][3];
void printArrayA()
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
System.out.print(A[i][j]+" ");
System.out.println();
}
}
void printArrayB()
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
System.out.print(B[i][j]+" ");
System.out.println();
}
}
void printXORArray()
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
System.out.print(C[i][j]+" ");
System.out.println();
}
}
void XOROperation()
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
if(A[i][j]==B[i][j])
C[i][j]=0;
else
C[i][j]=1;
}
}
}
public static void main(String args[])
{
MetrixOperation m=new MetrixOperation();
m.XOROperation();
System.out.println("\t"+"Metrix A :");
m.printArrayA();
System.out.println("*******************************");
System.out.println("\t"+"Metrix B :");
m.printArrayB();
System.out.println("*******************************");
System.out.println("\t"+"Metrix A XOR Metrix B:");
m.printXORArray();
}
}

metrix program in Java


class metrix
{
int m[][]={{1,2,13,4,5},{2,3,24,5,6},{3,4,35,6,7},{4,5,46,7,8}};
void printArray()
{
for(int i=0;i<4;i++)
{
for(int j=0;j<5;j++)
System.out.print(m[i][j]+" ");
System.out.println();
}
}
public static void main(String a[])
{
metrix ab=new metrix();
ab.printArray();
}
}

Simple Array Program in Java


import java.util.*;
public class ArrayOrder
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
int a []={25,95,65,74,18};
int temp=0;
int sum=0;
double avg=0;
double S=0;
for(int i=0;i for(int j=0;j {
if(a[j]>a[j+1])
{
temp=a[j+1];
a[j+1]=a[j];
a[j]=temp;
}
}
for(int b=0;b {
sum=sum+a[b];
avg=sum/a.length;
System.out.println(a[b]);
S=S+Math.pow((a[b]-avg),2);
}
System.out.println("Meadian is: "+a[a.length/2]);
System.out.println("minimum is: "+a[0]);
System.out.println("Summation is: "+sum);
System.out.println("Average is: "+avg);
System.out.println("sd is:"+Math.sqrt(S/a.length-1));
}
}

Star Printing in Java-06


import java.util.*;
public class Star7
{
public static void main(String args[])
{
for(int row=1;row<=5;row++)
{
for(int s=row;s<=4;s++)
System.out.print(" ");
for(int col=1;col<=2*row-1;col++)
System.out.print("*");
System.out.println();
}
for(int r=1;r<=4;r++)
{
for(int S=1;S<=r;S++)
System.out.print(" ");
for(int c=9-2*r;c>=1;c--)
System.out.print("*");
System.out.println();
}
}
}

Star Printing in Java-05


import java.util.*;
public class Star6
{
public static void main(String args[])
{
for(int row=1;row<=6;row++)
{
for(int s=row;s<=5;s++)
System.out.print(" ");
for(int col=1;col<=2*row-1;col++)
System.out.print("*");
{
System.out.println();
}
}
}
}

Star Printing in Java-04


import java.util.*;
public class Star5
{
public static void main(String args[])
{
for(int row=1;row<=6;row++)
{
for(int s=1;s<=row;s++)
System.out.print(" ");
for(int col=row;col<=6;col++)
System.out.print("*");
{
System.out.println();
}
}
}
}

Star Printing in Java-03


import java.util.*;
public class Star4
{
public static void main(String args[])
{
for(int row=1;row<=6;row++)
{
for(int s=row;s<=6;s++)
System.out.print(" ");
for(int col=1;col<=row;col++)
System.out.print("*");
{
System.out.println();
}
}
}
}

Star printing in Java-02


import java.util.*;
public class Star3
{
public static void main(String args[])
{
for(int row=1;row<=6;row++)
{
for(int col=1;col<=row;col++)
{
System.out.print("*");
}
System.out.println();
}
}
}

Star printing in Java-01


import java.util.*;
public class Star2
{
public static void main(String args[])
{
for(int row=1;row<=6;row++)
{
for(int col=row;col<=6;col++)
{
System.out.print("*");
}
System.out.println();
}
}
}

2D Graphics with Java


import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
public class drawing2 extends JFrame
{
public drawing2()
{
super(" FAHIM");
setBackground(Color.blue);
setSize(600,600);
setVisible(true);
}
public void paint(Graphics g)
{
Graphics2D g2d=(Graphics2D)g;
Color c1 = new Color(255,175,175);
Color c2 = new Color(255,0,0);
g2d.setPaint(new GradientPaint(5,30,c1,35,100,c2,true));
g2d.setStroke(new BasicStroke(4.0f));
g2d.fill(new Ellipse2D.Double(50,50,50,50));
Color c3 = new Color(0,0,255);
Color c4 = new Color(255,0,0);
g2d.setPaint(new GradientPaint(5,30,c3,35,100,c4,true));
g2d.setStroke(new BasicStroke(4.0f));
g2d.fill(new Ellipse2D.Double(75,75,100,75));
g2d.setPaint(Color.red);
g2d.setStroke(new BasicStroke(6.0f));
g2d.draw(new Line2D.Double(10,75,50,60));
}
public static void main(String args[])
{
drawing2 d=new drawing2();
d.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

Drawing with Java


import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
public class drawing extends JFrame
{
public drawing()
{
super(" Graphics 2D Shapes");
setBackground(Color.blue);
setSize(600,500);
setVisible(true);
}
public void paint(Graphics g)
{
//super.paint(g);
Graphics2D g2d=(Graphics2D)g;
//------------------Line---------------------------------------------------//
g2d.setPaint(Color.red);
g2d.setStroke(new BasicStroke(6.0f));
g2d.draw(new Line2D.Double(100,150,500,300));
}
public static void main(String args[])
{
drawing d=new drawing();
d.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

Cylinder details


class Cylynder
{
double radius;
double height;
void volume()
{
double vol=Math.PI*radius*radius*height;
System.out.println("volume is: "+vol);
}
void CirfaceArea()
{
double A=(2*Math.PI*radius*radius+2*Math.PI*radius*height);
System.out.println("Cirface Area is: "+A);
}
public static void main(String args[])
{
Cylynder myCylynder=new Cylynder();
myCylynder.height=15;
myCylynder.radius=7;
myCylynder.volume();
myCylynder.CirfaceArea();
}
}

Circle detais with JOptionPane


import javax.swing.JOptionPane;
public class Circle{
private double radius, diameter, circleArea, circumference;
public static final String CN="Circle";
Circle(double radius){
this.radius=radius;
computeDiameter();
computeCircumference();
}
void computeDiameter(){
diameter=2*radius;
}
void computeCicleArea(){
circleArea=Math.PI*radius*radius;
}
void computeCircumference(){
circumference=2*Math.PI*radius;
}
public double getRadius(){
return radius;
}
public double getDiameter(){
return diameter;
}
public double getCircleArea(){
return circleArea;
}
public double getCircumference(){
return circumference;
}
public void setRadius(double newR){
radius= newR;
computeDiameter();
computeCicleArea();
computeCircumference();
}
public String toString(){
return "Circle's radius is "+radius+"\n Circumference is "+circumference + "\n Area is "+circleArea;
}
public static void main(String args[]){
Circle c1=new Circle(7.0);
Circle c2=new Circle(0.0);
JOptionPane.showMessageDialog(null, c2.toString(), "Circle Details", 1);
c2.setRadius(11.3);
String cDetails2=""+c2;
JOptionPane.showMessageDialog(null, c2.toString(), "Circle Details", 1);
JOptionPane.showMessageDialog(null, "=>"+c1, "Circle Details", 1);
}
}