Posts

Showing posts from December, 2014

Ellipse using OpenGl

#include<gl/glut.h> #include<gl/glu.h> #include<gl/gl.h> #include<iostream> using namespace std; int xc=0,yc=0,rx=40,ry=60; void display() { float rxsq=rx*rx; float rysq=ry*ry; float x=0,y=ry,p; float px=0,py=2*rxsq*y; glClear(GL_COLOR_BUFFER_BIT); glPointSize(1); glBegin(GL_POINTS); glVertex2i(xc+x,yc+y); glVertex2i(-(xc+x),-(yc+y)); cout<<xc+x<<" "<<yc+y<<endl; p=rysq-(rxsq-ry)+(0.25*rxsq); while(px<py) { x++; px=px+2*rysq; if(p<0) p=p+rysq+px; else { y--; py=py-2*rxsq; p=p+rysq+px-py; } glVertex2i(xc+x,yc+y); glVertex2i(xc+x,-(yc+y)); glVertex2i(-(xc+x),yc+y); glVertex2i(-(xc+x),-(yc+y)); cout<<xc+x<<" "<<yc+y<<endl; } p=rysq*(x+0.5)*(x+0.5) + rxsq*(y-1)*(y-1) -rxsq*rysq; while(y>0) { y--; py=py-2*rxsq; if(p>0) { p=p+rxsq-py; } else { x++; px=px+2*rysq

Solar System Using OpenGl

#include<GL/glu.h> #include<GL/glut.h> #include<GL/gl.h> #include<math.h> #include<cstdlib> #include<iostream> using namespace std; float rotAngle=0; float rotAngle1=10; float theta=0; GLfloat randomFloat()  {   return (int)rand() / 1000; } void display() { glClearColor(0,0,0,1);   glClear(GL_COLOR_BUFFER_BIT);   glPointSize(2);   glBegin(GL_POINTS);   glColor3f(1,1,1);   for(int i=0;i<10;i++)   {   // cout<<randomFloat()<<endl;   glVertex3i(randomFloat(),randomFloat(),randomFloat());   glVertex3i(randomFloat(),-randomFloat(),-randomFloat());   glVertex3i(-randomFloat(),randomFloat(),randomFloat());   glVertex3i(-randomFloat(),-randomFloat(),randomFloat());   }   glEnd();   glFlush();     glPushMatrix(); glColor3f(1,0,0);   glTranslatef(8*cos(theta),8*sin(theta),0);   glutSolidSphere(1,50,50);   glPopMatrix();     glPushMatrix(); glColor3f(1,0,1);   glTransl