Posts

Showing posts from October, 2014

Program to plot Triangle Fan

Image
#include<GL/glut.h> #include<GL/glu.h> #include<GL/gl.h> void trianglefan() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1,0,0); glBegin(GL_TRIANGLE_FAN); glVertex2i(-60,0); glVertex2i(-30,0); glVertex2i(-30,30); glColor3f(0,1,0); glVertex2i(0,0); glColor3f(0,0,1); glVertex2i(30,30); glEnd(); glFlush(); } void init() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-65,50,-50,50); } int main(int argc,char **argv) { glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE); glutInitWindowSize(500,500); glutCreateWindow("Triangle Fan"); init(); glutDisplayFunc(trianglefan); glutMainLoop(); }

Program to plot Triangle Strip

Image
#include<GL/glut.h> #include<GL/glu.h> #include<GL/gl.h> void trianglestrip() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1,0,0); glBegin(GL_TRIANGLE_STRIP); glVertex2i(-60,0); glVertex2i(-30,0); glVertex2i(-30,30); glColor3f(0,1,0); glVertex2i(0,0); glColor3f(0,0,1); glVertex2i(30,30); glEnd(); glFlush(); } void init() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-65,50,-50,50); } int main(int argc,char **argv) { glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE); glutInitWindowSize(500,500); glutCreateWindow("Triangle Strip"); init(); glutDisplayFunc(trianglestrip); glutMainLoop(); }

Program to plot Triangle

Image
#include<GL/glut.h> #include<GL/glu.h> #include<GL/gl.h> void triangle() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1,0,0); glBegin(GL_TRIANGLES); glVertex2i(-60,-30); glVertex2i(60,-30); glVertex2i(0,60); glEnd(); glFlush(); } void init() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-100,100,-100,100); } int main(int argc,char **argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE); glutInitWindowSize(500,500); glutCreateWindow("Triangle"); init(); glutDisplayFunc(triangle); glutMainLoop(); }

Program to plot Quadrant strip

Image
#include<GL/glut.h> #include<GL/glu.h> #include<GL/gl.h> void quadstrip() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1,0,0); glBegin(GL_QUAD_STRIP); glVertex2i(-60,0); glVertex2i(-40,50); glVertex2i(60,30); glColor3f(0,1,0); glVertex2i(60,-50); glVertex2f(45,61); glEnd(); glFlush(); } void init() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-65,65,-65,65); } int main(int argc,char **argv) { glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE); glutInitWindowSize(500,500); glutCreateWindow("QUAD STRIP"); init(); glutDisplayFunc(quadstrip); glutMainLoop(); }

Program to plot a Quadrant

Image
#include<GL/glut.h> #include<GL/glu.h> #include<GL/gl.h> void quads() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1,0,0); glBegin(GL_QUADS); glVertex2i(-60,0); glVertex2i(-40,50); glVertex2i(60,30); glVertex2i(60,-50); glEnd(); glFlush(); } void init() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-65,65,-65,65); } int main(int argc,char **argv) { glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE); glutInitWindowSize(500,500); glutCreateWindow("QUADS"); init(); glutDisplayFunc(quads); glutMainLoop(); }

Program to plot a Line

Image
#include<GL/glut.h> #include<GL/glu.h> #include<GL/gl.h> void line() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0,0,0);       //glLineWidth(10);                                            //to change width of line. "1" is normal glBegin(GL_LINES); glVertex2f(-0.9,-0.8); glVertex2f(0.8,0.9); glEnd(); glFlush(); } int main(int argc, char **argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE); glutInitWindowSize(500,500); glutCreateWindow("Line"); glutDisplayFunc(line); glutMainLoop(); }

Program to plot a point

Image
#include<GL/glut.h> #include<Gl/glu.h> #include<Gl/gl.h> void point() { glClear(GL_COLOR_BUFFER_BIT);        //clear frame buffers bit glColor3f(1.0,0,0);                                       //color to point(red,green,blue); glPointSize(10);                                           // point size glBegin(GL_POINTS);                               glVertex2f(0.5,0);                                         //point location glVertex2f(0,0);                                           //point location glEnd();                                                       //glBegin() ends here glFlush();                                                    //function to display } int main(int argc, char **argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE); glutInitWindowSize(500,500);                                        //define window size glutCreateWindow("Plot point");                                    //Headin

+indexof(ch:char)

Return type int. Returns the index of the first occurrence of ch in the string. Returns-1 if not matched. import java.lang.String; class indexof{                         public static void main(String[] args){                          String str="Welcome to java";                         int i="welcome".indexOf('l');                        System.out.println("Index of l in \" "+str+"\"  is : "+i);                      } } Output :    Index of l in "Welcome to java is : 2

WAP to find greater number between two numbers.

import java.util.Scanner; class greater{ public static void main(String[] args){               int a,b;               Scanner input=new Scanner(System.in);               System.out.println("Enter A: ");               a=input.nextInt();               System.out.println("Enter B: ");               b=input.nextInt();               if(a>b)               System.out.println("A is greater");               else               System.out.println("B is greater");               } } Output  :     Enter A: 34                    Enter B: 35                   B is greater Here, if a is greater than b, then Output will be "A is greater". Otherwise, Output will be "B is greater". In no case are they both output display.

Java Selection Statement

Java Supports two selection statements: if and switch. These statements allow you to control the flow of your program’s execution based upon conditions known only during run time. You will be pleasantly surprised by the power and flexibility contained in these two statements.