Professional Documents
Culture Documents
A Project Report on
CHEMICAL REACTION
Submitted in partial fulfillment of VI semester course of
Bachelor of Engineering in Computer Science &
Engineering during the year 2014-2015
By
Chemical Reaction
RAMANAGARAM-562 159
CERTIFICATE
This is to certify that SHREYA
SHETTY
R(1GC12CS049),SUSHMITHA K S(1GC12CS052)
has satisfactorily completed the mini project on
CHEMICAL REACTION that has been approved as
it satisfies the academic requirements in view of
the
project
work
prescribed
for
partial
completion of the 6th semester B.E. degree in
Computer science course awarded by the
Vishveshvaraya Technological University,Belgaum
in the year 2013-2014.
Signature of the
Signature of the
Guide
Head of department
1.
Chemical Reaction
2.
ABSTRACT
CHEMICAL REACTION
When an acid reacts with the base, the mixture of these two
solutions gets neutralized
And this reaction is indicated by the color change in the resultant
solution.
Chemical Reaction
ACKNOWLEDGEMENT
It is the time to acknowledge all those who have extended their guidance, inspiration and their
whole hearted co-operation all along our project work.
At the outset we express our most sincere grateful thanks to the holy sanctum
GHOUSIA COLLEGE OF ENGINEERING for giving us an opportunity to pursue the
degree course in Computer Science and Engineering thus helping in shaping our career.
We are also grateful to Dr.Mr.MOHAMED HANEEF the principal, and also
Prof.Mr.DEEPAK N.A, HOD of CSE Department for having provided us academic
environment which nurtured our practical skills contributing to the success of our project.
We wish to place a deep sense of gratitude to our beloved project guide,
Prof.Mr.DEEPAK N.A, HOD of CSE Department for his whole-hearted guidance and constant
support without which Endeavour would not have been possible.
Our gratitude will not be complete without thanking the Almighty God and our beloved
Parents and also our Friends, who have been a constant source of blessings and aspirations.
Chemical Reaction
TABLE OF CONTENTS
CHAPTER
PAGE NO:
1. Introduction
6-7
2. System Requirements
3. Design
9-13
9-13
3.2. Algorithm
13-14
4. Implementation
15-19
5.Source code
20-38
39-46
7.Appendix
47-51
8.References
52
Chemical Reaction
Chapter 1
INTRODUCTION
1.1
Computer graphics are graphics created using computers and, more generally, the
representation
and
manipulation
of image data
by a
computer
with
help
from
have
had
profound
impact
on
many types
of
media
and
have
the sub-field of computer science which studies methods for digitally synthesizing
and manipulating visual content.
1.2
About OpenGL
OpenGL is the industrys most widely used, supported and best documented 2D/3D
Chemical Reaction
only needs to describe a scene and can let the library manage the details of rendering it.
OpenGL's low-level design requires programmers to have a good knowledge of the graphics
pipeline, but also gives a certain amount of freedom to implement novel rendering
algorithms.
1.3
About Project
In this project, we demonstrate the chemical reaction which takes place between 2
different chemicals placed in 2 different conical flasks. Here the 2 chemicals used are acid
and base.
We pipette in base from the conical flask using a standard pipette. Then we move this
pipette which is containing base to the other conical flask which contains acid so that we can
pipette out the base into the conical flask containing acid.
As the base solution is dropped into the acid solution contained in a flask, reaction
takes places between the 2 solutions and the resultant solution gets neutralized.
Chemical Reaction
Chapter 2
SYSTEM REQUIREMENTS
This chapter specifies the requirements needed in a system in order to run this
project in computer graphics using OpenGL interface.
: Microsoft Windows XP
Language
API
: OpenGL
Chemical Reaction
Chapter 3
DESIGN
3.1 High Level Design
3.1.1 Block Diagram
Objects
(2 conical flasks
filled with
solutions, 1 pipette)
Base solution
reacts with acid
solution
Reaction
Resultant solution
gets
Neutralized
Chemical Reaction
Main( )
Press p
Press m
Press d
display( )
display0( )
display1( )
display2( )
Output of
display( )
Output of
display0( )
Output of
display1( )
Output of
display2( )
Output
Input
Right
mouse
button
Mouse
Press 1
displaya()
Output of
displaya( )
Pressing
specified keys
Output is
sent to
Keyboard
Press 2
displayb()
displayc( )
10
display3( )
Output of
displayb( )
Output of
displayc( )
Standard Output
Chemical Reaction
Press 3
Output of
display3( )
Press r
11
Chemical Reaction
Start
main( )
DisplayFunc( )
display( )
CreateMenu( )
demo_menu( )
KeyboardFunc( )
If(key==p)
display0( )
if(key==m)
display1( )
if(key==d)
display2( )
if(key==1)
displaya( )
if(key==2)
displayb( )
if(key==3)
displayc( )
12
Chemical Reaction
A
if(key==r)
display3( )
Stop
3.2. Algorithm
Algorithm is a step by step procedure for solving a problem in finite no of steps that
frequently involves repetition of operation.
Algorithm for Chemical Reaction
Step 1: Start
Step 2: [Initialize the output window]
glutCreateWindow( ) func is called.
Step 3: [Output window consisting of 2 conical flasks and a pipette is displayed.]
The display( ) function is called.
Step 4: [Keyboard is used to interact with the user]
If selected key is pressed then
glutKeyboardFunc( ) function gets called
Dept of CSE,GCE Ramanagaram
13
Chemical Reaction
Step 5: if (key==p) then
the base solution gets pipetted.
Step 7: if (key==m) then
The pipette containing base solution moves towards the conical flask
containing acid solution using for( ) loop.
Step 8: if (key ==d) is pressed then
the base solution is pipetted out into the conical flask drop by drop.
Step 9: if (key ==1 || key==2||key==3) then
drop by drop movement of the solution is seen.
Step 10: if (key==r) then
the reaction between the acid and the base is seen.
Step 11:[ To display the popup menu & to exit ]
if(GLUT_RIGHT_BUTTON && GLUT_DOWN==Quit) then
The control comes out of the output window.
Step 12: Stop.
14
Chemical Reaction
Chapter 4
IMPLEMENTATION
4.1. Pseudo Code
Pseudo Code is a compact and informal high level description of
computer programming algorithm that uses the structural connections of a programming
language, but is intended for human reading rather than machine reading.
Initialize the Header files.
Void main(int argc, char**argv)
{
Initialize GLUT using glutInit( );
Set the display mode by enabling single buffer and use RGB colour by using
glutInitDisplayMode( );
Initialize the window size by the function glutInitWindowSize( );
15
Chemical Reaction
}
void display( )
{
Clear the color buffer;
Call conical1( ) function;
Call conical2( ) function;
Call pipette( ) function;
Flush the frames into the buffer.
}
void draw_text(int x, int y, char *s )
{
Initialise the character;
Set the position of the character;
Set the font type & font size of the character;
Flush the frames into the buffer;
}
void conical1( )
{
Clear the colour buffer;
Set the colour of the conical flask and the solution;
Create a conical flask containing solution;
Flush the frames into the buffer;
Call the draw_text( ) function with the name Base;
}
void conical2( )
{
Clear the colour buffer;
Set the colour of the conical flask and the solution;
Create a conical flask containing solution;
Flush the frames into the buffer;
Call the draw_text( ) function with the name Acid;
Dept of CSE,GCE Ramanagaram
16
Chemical Reaction
}
void pipette( int x, int y)
{
Clear the colour buffer;
Call conical1( ) & conical2( ) functions;
Initialise i & j;
Set the conditions for x & y using if & else loop;
Set the colour of the pipette;
Create the pipette along with the i & j values;
Flush the frames into the buffer;
Call draw_text( ) function with the name p;
}
void keys(unsigned character key, int x, int y)
{
Interface the keyboard with the program in such a way that when we :
Press p display0( ) function is called;
Press m display1( ) function is called;
Press d display2( ) function is called;
Press 1 displaya( ) function is called;
Press 2 displayb( ) function is called;
Press 3 displayc( ) function is called;
Press r display3( ) function is called;
}
void display0( )
{
Clear the colour buffer.
Set the colour of the conical flasks, pipette and also the solutions placed inside them;\
Create the conical flasks and pipette containing the solutions;
Flush the frames into the buffer;
Call draw_text( ) function for conical flasks and pipette;
}
Dept of CSE,GCE Ramanagaram
17
Chemical Reaction
void display1( )
{
Initialize i & j;
Set the condition for i & j using for loop;
Create and set the colour of the conical flask;
Create and move the pipette from one conical flask to the other;
Reduction in the amount of base solution inside the conical flask is shown;
Flush the frames into the buffer;
}
void display2( )
{
Create and set the colour of the conical flask & the pipette;
Pipette out the solution into the conical flask;
Flush the frames into the buffer;
}
void displaya( )
{
Create and set the colour of the conical flask & the pipette;
Drop the solution into the conical flask;
Show the reduction in the amount of the solution inside the pipette;
Flush the frames into the buffer;
}
void displayb( )
{
Create and set the colour of the conical flask & the pipette;
Drop the solution into the conical flask;
Show some more reduction in the amount of the solution inside the pipette;
Show the increase in the amount of the solution inside the 2nd conical flask.
Flush the frames into the buffer;
}
void displayc( )
Dept of CSE,GCE Ramanagaram
18
Chemical Reaction
{
Create and set the colour of the conical flask & the pipette;
Drop the solution into the conical flask;
Pipette is emptied and the whole solution is transferred into the conical flask;
Flush the frames into the buffer;
}
void display3( )
{
Create and set the colour of the conical flask & the pipette;
Reaction is indicated by changing the colour in the solution;
Flush the frames into the buffer;
}
void demo_menu( int id)
{
switch(id)
{
In case 1, if the right button of the mouse is clicked, then the control comes out of the
loop;
}
}
void myinit( )
{
Set the background colour of the output window to black;
Set the matrix mode to the projection matrix;
Load the identity matrix;
Call gluOrtho2D( ) function;
}
19
Chemical Reaction
SOURCE CODE
#include<stdio.h>
#include<time.h>
#include<math.h>
#include<GL/glut.h>
void display();
void draw_text(int x,int y,char *s)
{
char *p;
glRasterPos2f(x,y);
for(p=s;*p;++p)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,*p);
glFlush();
}
void conical1()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(70,25);
glVertex2f(200,25);
glVertex2f(177.5,100);
glVertex2f(97.5,100);
glEnd();
glColor3f(0.0,0.0,1.0);
glBegin(GL_LINE_LOOP);
glVertex2f(177.5,100);
glVertex2f(162.5,150);
glVertex2f(162.5,200);
glVertex2f(112.5,200);
glVertex2f(112.5,150);
glVertex2f(97.5,100);
glEnd();
glFlush();
glColor3f(0.0,0.0,0.0);
draw_text(117.5,55,"Base");
glColor3f(1.0,0.0,0.0);
draw_text(40,95,"Level1");
glColor3f(1.0,0.0,0.0);
draw_text(30,65,"Level2");
}
void conical2()
{
glColor3f(1.0,0.3,0.4);
glBegin(GL_POLYGON);
20
Chemical Reaction
glVertex2f(275,25);
glVertex2f(400,25);
glVertex2f(377.5,100);
glVertex2f(297.5,100);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(0.0,0.0,1.0);
glVertex2f(377.5,100);
glVertex2f(362.5,150);
glVertex2f(362.5,200);
glVertex2f(312.5,200);
glVertex2f(312.5,150);
glVertex2f(297.5,100);
glEnd();
glFlush();
glColor3f(0.0,0.0,0.0);
draw_text(320,55,"Acid");
glColor3f(1.0,0.0,0.0);
draw_text(270,90,"L1");
glColor3f(1.0,0.0,0.0);
draw_text(275,110,"L2");
glColor3f(1.0,0.0,0.0);
draw_text(280,135,"L3");
void pipette(int x,int y)
{
glClear(GL_COLOR_BUFFER_BIT);
conical1();
conical2();
int i,j;
if(x!=0&&y==0)
{
i=x;
j=0;
}
else if(x==0&&y!=0)
{
i=0;
j=y;
}
else if(x!=0&&y!=0)
{
i=x;
j=y;
}
else
{
i=0;
j=0;
}
glColor3f(1.0,0.0,0.0);
glBegin(GL_LINE_LOOP);
glVertex2f(137.5+i,100+j);
glVertex2f(142.5+i,107.5+j);
glVertex2f(142.5+i,132.5+j);
21
Chemical Reaction
glVertex2f(147.5+i,145+j);
glVertex2f(147.5+i,182.5+j);
glVertex2f(142.5+i,195+j);
glVertex2f(142.5+i,232.5+j);
glVertex2f(135+i,232.5+j);
glVertex2f(135+i,195+j);
glVertex2f(130+i,182.5+j);
glVertex2f(130+i,145+j);
glVertex2f(135+i,132.5+j);
glVertex2f(135+i,107.5+j);
glEnd();
glColor3f(1.0,0.0,0.0);
glBegin(GL_LINE_LOOP);
glVertex2f(142.5+i,232.5+j);
glVertex2f(142.5+i,257.5+j);
glVertex2f(135+i,257.5+j);
glVertex2f(135+i,232.5+j);
glEnd();
glColor3f(1.0,0.0,0.0);
draw_text(133.5+i,157.5+j,"P");
glFlush();
}
void display0()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);
glBegin(GL_LINE_LOOP);
glVertex2f(137.5,100);
glVertex2f(142.5,107.5);
glVertex2f(142.5,132.5);
glVertex2f(147.5,145);
glVertex2f(147.5,182.5);
glVertex2f(142.5,195);
glVertex2f(142.5,232.5);
glVertex2f(135,232.5);
glVertex2f(135,195);
glVertex2f(130,182.5);
glVertex2f(130,145);
glVertex2f(135,132.5);
glVertex2f(135,107.5);
glEnd();
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(137.5,100);
glVertex2f(142.5,107.5);
glVertex2f(135,107.5);
glEnd();
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(135,107.5);
glVertex2f(142.5,107.5);
glVertex2f(142.5,132.5);
glVertex2f(135,132.5);
glEnd();
22
Chemical Reaction
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(142.5,132.5);
glVertex2f(147.5,145);
glVertex2f(147.5,182.5);
glVertex2f(142.5,195);
glVertex2f(135,195);
glVertex2f(130,182.5);
glVertex2f(130,145);
glVertex2f(135,132.5);
glEnd();
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(135,195);
glVertex2f(142.5,195);
glVertex2f(142.5,232.5);
glVertex2f(135,232.5);
glEnd();
glColor3f(1.0,0.0,0.0);
glBegin(GL_LINE_LOOP);
glVertex2f(142.5,232.5);
glVertex2f(142.5,257.5);
glVertex2f(135,257.5);
glVertex2f(135,232.5);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(133.5,157.5,"P");
glColor3f(1.0,0.3,0.4);
glBegin(GL_POLYGON);
glVertex2f(275,25);
glVertex2f(400,25);
glVertex2f(377.5,100);
glVertex2f(297.5,100);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(0.0,0.0,1.0);
glVertex2f(377.5,100);
glVertex2f(362.5,150);
glVertex2f(362.5,200);
glVertex2f(312.5,200);
glVertex2f(312.5,150);
glVertex2f(297.5,100);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(320,55,"Acid");
glColor3f(1.0,0.0,0.0);
draw_text(270,90,"L1");
glColor3f(1.0,0.0,0.0);
draw_text(275,110,"L2");
glColor3f(1.0,0.0,0.0);
draw_text(280,135,"L3");
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(70,25);
glVertex2f(200,25);
23
Chemical Reaction
glVertex2f(185,75);
glVertex2f(90,75);
glEnd();
glColor3f(0.0,0.0,1.0);
glBegin(GL_LINE_LOOP);
glVertex2f(185,75);
glVertex2f(162.5,150);
glVertex2f(162.5,200);
glVertex2f(112.5,200);
glVertex2f(112.5,150);
glVertex2f(90,75);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(117.5,55,"Base");
glColor3f(1.0,0.0,0.0);
draw_text(40,95,"Level1");
glColor3f(1.0,0.0,0.0);
draw_text(30,65,"Level2");
glFlush();
}
void display1()
{
int i,j;
for(j=0;j<150;j++)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);
glBegin(GL_LINE_LOOP);
glVertex2f(137.5,100+j);
glVertex2f(142.5,107.5+j);
glVertex2f(142.5,132.5+j);
glVertex2f(147.5,145+j);
glVertex2f(147.5,182.5+j);
glVertex2f(142.5,195+j);
glVertex2f(142.5,232.5+j);
glVertex2f(135,232.5+j);
glVertex2f(135,195+j);
glVertex2f(130,182.5+j);
glVertex2f(130,145+j);
glVertex2f(135,132.5+j);
glVertex2f(135,107.5+j);
glEnd();
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(137.5,100+j);
glVertex2f(142.5,107.5+j);
glVertex2f(135,107.5+j);
glEnd();
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(135,107.5+j);
glVertex2f(142.5,107.5+j);
glVertex2f(142.5,132.5+j);
glVertex2f(135,132.5+j);
glEnd();
24
Chemical Reaction
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(142.5,132.5+j);
glVertex2f(147.5,145+j);
glVertex2f(147.5,182.5+j);
glVertex2f(142.5,195+j);
glVertex2f(135,195+j);
glVertex2f(130,182.5+j);
glVertex2f(130,145+j);
glVertex2f(135,132.5+j);
glEnd();
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(135,195+j);
glVertex2f(142.5,195+j);
glVertex2f(142.5,232.5+j);
glVertex2f(135,232.5+j);
glEnd();
glColor3f(1.0,0.0,0.0);
glBegin(GL_LINE_LOOP);
glVertex2f(142.5,232.5+j);
glVertex2f(142.5,257.5+j);
glVertex2f(135,257.5+j);
glVertex2f(135,232.5+j);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(133.5,157.5+j,"P");
glColor3f(1.0,0.3,0.4);
glBegin(GL_POLYGON);
glVertex2f(275,25);
glVertex2f(400,25);
glVertex2f(377.5,100);
glVertex2f(297.5,100);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(0.0,0.0,1.0);
glVertex2f(377.5,100);
glVertex2f(362.5,150);
glVertex2f(362.5,200);
glVertex2f(312.5,200);
glVertex2f(312.5,150);
glVertex2f(297.5,100);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(320,55,"Acid");
glColor3f(1.0,0.0,0.0);
draw_text(270,90,"L1");
glColor3f(1.0,0.0,0.0);
draw_text(275,110,"L2");
glColor3f(1.0,0.0,0.0);
draw_text(280,135,"L3");
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(70,25);
glVertex2f(200,25);
25
Chemical Reaction
glVertex2f(185,75);
glVertex2f(90,75);
glEnd();
glColor3f(0.0,0.0,1.0);
glBegin(GL_LINE_LOOP);
glVertex2f(185,75);
glVertex2f(162.5,150);
glVertex2f(162.5,200);
glVertex2f(112.5,200);
glVertex2f(112.5,150);
glVertex2f(90,75);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(117.5,55,"Base");
glColor3f(1.0,0.0,0.0);
draw_text(40,95,"Level1");
glColor3f(1.0,0.0,0.0);
draw_text(30,65,"Level2");
}
for(i=0;i<200;i++)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);
glBegin(GL_LINE_LOOP);
glVertex2f(137.5+i,100+j);
glVertex2f(142.5+i,107.5+j);
glVertex2f(142.5+i,132.5+j);
glVertex2f(147.5+i,145+j);
glVertex2f(147.5+i,182.5+j);
glVertex2f(142.5+i,195+j);
glVertex2f(142.5+i,232.5+j);
glVertex2f(135+i,232.5+j);
glVertex2f(135+i,195+j);
glVertex2f(130+i,182.5+j);
glVertex2f(130+i,145+j);
glVertex2f(135+i,132.5+j);
glVertex2f(135+i,107.5+j);
glEnd();
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(137.5+i,100+j);
glVertex2f(142.5+i,107.5+j);
glVertex2f(135+i,107.5+j);
glEnd();
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(135+i,107.5+j);
glVertex2f(142.5+i,107.5+j);
glVertex2f(142.5+i,132.5+j);
glVertex2f(135+i,132.5+j);
glEnd();
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(142.5+i,132.5+j);
glVertex2f(147.5+i,145+j);
26
Chemical Reaction
glVertex2f(147.5+i,182.5+j);
glVertex2f(142.5+i,195+j);
glVertex2f(135+i,195+j);
glVertex2f(130+i,182.5+j);
glVertex2f(130+i,145+j);
glVertex2f(135+i,132.5+j);
glEnd();
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(135+i,195+j);
glVertex2f(142.5+i,195+j);
glVertex2f(142.5+i,232.5+j);
glVertex2f(135+i,232.5+j);
glEnd();
glColor3f(1.0,0.0,0.0);
glBegin(GL_LINE_LOOP);
glVertex2f(142.5+i,232.5+j);
glVertex2f(142.5+i,257.5+j);
glVertex2f(135+i,257.5+j);
glVertex2f(135+i,232.5+j);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(133.5+i,157.5+j,"P");
glColor3f(1.0,0.3,0.4);
glBegin(GL_POLYGON);
glVertex2f(275,25);
glVertex2f(400,25);
glVertex2f(377.5,100);
glVertex2f(297.5,100);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(0.0,0.0,1.0);
glVertex2f(377.5,100);
glVertex2f(362.5,150);
glVertex2f(362.5,200);
glVertex2f(312.5,200);
glVertex2f(312.5,150);
glVertex2f(297.5,100);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(320,55,"Acid");
glColor3f(1.0,0.0,0.0);
draw_text(270,90,"L1");
glColor3f(1.0,0.0,0.0);
draw_text(275,110,"L2");
glColor3f(1.0,0.0,0.0);
draw_text(280,135,"L3");
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(70,25);
glVertex2f(200,25);
glVertex2f(185,75);
glVertex2f(90,75);
glEnd();
glColor3f(0.0,0.0,1.0);
27
Chemical Reaction
glBegin(GL_LINE_LOOP);
glVertex2f(185,75);
glVertex2f(162.5,150);
glVertex2f(162.5,200);
glVertex2f(112.5,200);
glVertex2f(112.5,150);
glVertex2f(90,75);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(117.5,55,"Base");
glColor3f(1.0,0.0,0.0);
draw_text(40,95,"Level1");
glColor3f(1.0,0.0,0.0);
draw_text(30,65,"Level2");
glFlush();
}
}
void display2()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(70,25);
glVertex2f(200,25);
glVertex2f(185,75);
glVertex2f(90,75);
glEnd();
glColor3f(0.0,0.0,1.0);
glBegin(GL_LINE_LOOP);
glVertex2f(185,75);
glVertex2f(162.5,150);
glVertex2f(162.5,200);
glVertex2f(112.5,200);
glVertex2f(112.5,150);
glVertex2f(90,75);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(117.5,55,"Base");
glColor3f(1.0,0.0,0.0);
draw_text(40,95,"Level1");
glColor3f(1.0,0.0,0.0);
draw_text(30,65,"Level2");
glColor3f(1.0,0.3,0.4);
glBegin(GL_POLYGON);
glVertex2f(275,25);
glVertex2f(400,25);
glVertex2f(377.5,100);
glVertex2f(297.5,100);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(0.0,0.0,1.0);
glVertex2f(377.5,100);
glVertex2f(362.5,150);
glVertex2f(362.5,200);
glVertex2f(312.5,200);
28
Chemical Reaction
glVertex2f(312.5,150);
glVertex2f(297.5,100);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(320,55,"Acid");
glColor3f(1.0,0.0,0.0);
draw_text(270,90,"L1");
glColor3f(1.0,0.0,0.0);
draw_text(275,110,"L2");
glColor3f(1.0,0.0,0.0);
draw_text(280,135,"L3");
glBegin(GL_LINE_LOOP);
glColor3f(1.0,0.0,0.0);
glVertex2f(337.5,192.5);
glVertex2f(342.5,200);
glVertex2f(342.5,237.5);
glVertex2f(347.5,250);
glVertex2f(347.5,300);
glVertex2f(342.5,312.5);
glVertex2f(342.5,350);
glVertex2f(335,350);
glVertex2f(335,312.5);
glVertex2f(330,300);
glVertex2f(330,250);
glVertex2f(335,237.5);
glVertex2f(335,200);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.3,0.4,1.0);
glVertex2f(337.5,192.5);
glVertex2f(342.5,200);
glVertex2f(335,200);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.3,0.4,1.0);
glVertex2f(335,200);
glVertex2f(342.5,200);
glVertex2f(342.5,237.5);
glVertex2f(335,237.5);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.3,0.4,1.0);
glVertex2f(335,237.5);
glVertex2f(342.5,237.5);
glVertex2f(347.5,250);
glVertex2f(347.5,300);
glVertex2f(342.5,312.5);
glVertex2f(335,312.5);
glVertex2f(330,300);
glVertex2f(330,250);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.3,0.4,1.0);
glVertex2f(335,312.5);
glVertex2f(342.5,312.5);
29
Chemical Reaction
glVertex2f(342.5,350);
glVertex2f(335,350);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(1.0,0.0,0.0);
glVertex2f(342.5,350);
glVertex2f(342.5,375);
glVertex2f(335,375);
glVertex2f(335,350);
glEnd();
glColor3f(1.0,0.0,0.0);
draw_text(333.9,265,"P");
glColor3f(0.3,0.4,1.0);
glBegin(GL_LINES);
glVertex2f(337.5,187.5);
glVertex2f(337.5,175);
glVertex2f(337.5,170);
glVertex2f(337.5,160);
glVertex2f(337.5,155);
glVertex2f(337.5,142.5);
glVertex2f(337.5,135);
glVertex2f(337.5,125);
glVertex2f(337.5,117.5);
glVertex2f(337.5,105);
glEnd();
glFlush();
}
void displaya()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(70,25);
glVertex2f(200,25);
glVertex2f(185,75);
glVertex2f(90,75);
glEnd();
glColor3f(0.0,0.0,1.0);
glBegin(GL_LINE_LOOP);
glVertex2f(185,75);
glVertex2f(162.5,150);
glVertex2f(162.5,200);
glVertex2f(112.5,200);
glVertex2f(112.5,150);
glVertex2f(90,75);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(117.5,55,"Base");
glColor3f(1.0,0.0,0.0);
draw_text(40,95,"Level1");
glColor3f(1.0,0.0,0.0);
draw_text(30,65,"Level2");
glColor3f(1.0,0.3,0.4);
glBegin(GL_POLYGON);
glVertex2f(275,25);
30
Chemical Reaction
glVertex2f(400,25);
glVertex2f(377.5,100);
glVertex2f(297.5,100);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(0.0,0.0,1.0);
glVertex2f(377.5,100);
glVertex2f(362.5,150);
glVertex2f(362.5,200);
glVertex2f(312.5,200);
glVertex2f(312.5,150);
glVertex2f(297.5,100);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(320,55,"Acid");
glColor3f(1.0,0.0,0.0);
draw_text(270,90,"L1");
glColor3f(1.0,0.0,0.0);
draw_text(275,110,"L2");
glColor3f(1.0,0.0,0.0);
draw_text(280,135,"L3");
glBegin(GL_LINE_LOOP);
glColor3f(1.0,0.0,0.0);
glVertex2f(337.5,192.5);
glVertex2f(342.5,200);
glVertex2f(342.5,237.5);
glVertex2f(347.5,250);
glVertex2f(347.5,300);
glVertex2f(342.5,312.5);
glVertex2f(342.5,350);
glVertex2f(335,350);
glVertex2f(335,312.5);
glVertex2f(330,300);
glVertex2f(330,250);
glVertex2f(335,237.5);
glVertex2f(335,200);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.3,0.4,1.0);
glVertex2f(337.5,192.5);
glVertex2f(342.5,200);
glVertex2f(335,200);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.3,0.4,1.0);
glVertex2f(335,200);
glVertex2f(342.5,200);
glVertex2f(342.5,237.5);
glVertex2f(335,237.5);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.3,0.4,1.0);
glVertex2f(335,237.5);
glVertex2f(342.5,237.5);
glVertex2f(347.5,250);
31
Chemical Reaction
glVertex2f(347.5,300);
glVertex2f(342.5,312.5);
glVertex2f(335,312.5);
glVertex2f(330,300);
glVertex2f(330,250);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(1.0,0.0,0.0);
glVertex2f(342.5,350);
glVertex2f(342.5,375);
glVertex2f(335,375);
glVertex2f(335,350);
glEnd();
glColor3f(1.0,0.0,0.0);
draw_text(333.9,265,"P");
glColor3f(0.3,0.4,1.0);
glBegin(GL_LINES);
glVertex2f(337.5,187.5);
glVertex2f(337.5,175);
glVertex2f(337.5,170);
glVertex2f(337.5,160);
glVertex2f(337.5,155);
glVertex2f(337.5,142.5);
glVertex2f(337.5,135);
glVertex2f(337.5,125);
glVertex2f(337.5,117.5);
glVertex2f(337.5,105);
glEnd();
glFlush();
}
void displayb()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(70,25);
glVertex2f(200,25);
glVertex2f(185,75);
glVertex2f(90,75);
glEnd();
glColor3f(0.0,0.0,1.0);
glBegin(GL_LINE_LOOP);
glVertex2f(185,75);
glVertex2f(162.5,150);
glVertex2f(162.5,200);
glVertex2f(112.5,200);
glVertex2f(112.5,150);
glVertex2f(90,75);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(117.5,55,"Base");
glColor3f(1.0,0.0,0.0);
draw_text(40,95,"Level1");
glColor3f(1.0,0.0,0.0);
draw_text(30,65,"Level2");
32
Chemical Reaction
glColor3f(1.0,0.3,0.4);
glBegin(GL_POLYGON);
glVertex2f(275,25);
glVertex2f(400,25);
glVertex2f(372.5,112.5);
glVertex2f(302.5,112.5);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(0.0,0.0,1.0);
glVertex2f(372.5,112.5);
glVertex2f(362.5,150);
glVertex2f(362.5,200);
glVertex2f(312.5,200);
glVertex2f(312.5,150);
glVertex2f(302.5,112.5);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(320,55,"Acid");
glColor3f(1.0,0.0,0.0);
draw_text(270,90,"L1");
glColor3f(1.0,0.0,0.0);
draw_text(275,110,"L2");
glColor3f(1.0,0.0,0.0);
draw_text(280,135,"L3");
glBegin(GL_LINE_LOOP);
glColor3f(1.0,0.0,0.0);
glVertex2f(337.5,192.5);
glVertex2f(342.5,200);
glVertex2f(342.5,237.5);
glVertex2f(347.5,250);
glVertex2f(347.5,300);
glVertex2f(342.5,312.5);
glVertex2f(342.5,350);
glVertex2f(335,350);
glVertex2f(335,312.5);
glVertex2f(330,300);
glVertex2f(330,250);
glVertex2f(335,237.5);
glVertex2f(335,200);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.3,0.4,1.0);
glVertex2f(337.5,192.5);
glVertex2f(342.5,200);
glVertex2f(335,200);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.3,0.4,1.0);
glVertex2f(335,200);
glVertex2f(342.5,200);
glVertex2f(342.5,237.5);
glVertex2f(335,237.5);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(1.0,0.0,0.0);
33
Chemical Reaction
glVertex2f(342.5,350);
glVertex2f(342.5,375);
glVertex2f(335,375);
glVertex2f(335,350);
glEnd();
glColor3f(1.0,0.0,0.0);
draw_text(333.9,265,"P");
glColor3f(0.3,0.4,1.0);
glBegin(GL_LINES);
glVertex2f(337.5,187.5);
glVertex2f(337.5,175);
glVertex2f(337.5,170);
glVertex2f(337.5,160);
glVertex2f(337.5,155);
glVertex2f(337.5,142.5);
glVertex2f(337.5,135);
glVertex2f(337.5,125);
glEnd();
glFlush();
}
void displayc()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(70,25);
glVertex2f(200,25);
glVertex2f(185,75);
glVertex2f(90,75);
glEnd();
glColor3f(0.0,0.0,1.0);
glBegin(GL_LINE_LOOP);
glVertex2f(185,75);
glVertex2f(162.5,150);
glVertex2f(162.5,200);
glVertex2f(112.5,200);
glVertex2f(112.5,150);
glVertex2f(90,75);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(117.5,55,"Base");
glColor3f(1.0,0.0,0.0);
draw_text(40,95,"Level1");
glColor3f(1.0,0.0,0.0);
draw_text(30,65,"Level2");
glColor3f(1.0,0.3,0.4);
glBegin(GL_POLYGON);
glVertex2f(275,25);
glVertex2f(400,25);
glVertex2f(367.5,137.5);
glVertex2f(310,137.5);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(0.0,0.0,1.0);
glVertex2f(367.5,137.5);
34
Chemical Reaction
glVertex2f(362.5,150);
glVertex2f(362.5,200);
glVertex2f(312.5,200);
glVertex2f(312.5,150);
glVertex2f(310,137.5);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(320,55,"Acid");
glColor3f(1.0,0.0,0.0);
draw_text(270,90,"L1");
glColor3f(1.0,0.0,0.0);
draw_text(275,110,"L2");
glColor3f(1.0,0.0,0.0);
draw_text(280,135,"L3");
glBegin(GL_LINE_LOOP);
glColor3f(1.0,0.0,0.0);
glVertex2f(337.5,192.5);
glVertex2f(342.5,200);
glVertex2f(342.5,237.5);
glVertex2f(347.5,250);
glVertex2f(347.5,300);
glVertex2f(342.5,312.5);
glVertex2f(342.5,350);
glVertex2f(335,350);
glVertex2f(335,312.5);
glVertex2f(330,300);
glVertex2f(330,250);
glVertex2f(335,237.5);
glVertex2f(335,200);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.3,0.4,1.0);
glVertex2f(337.5,192.5);
glVertex2f(342.5,200);
glVertex2f(335,200);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(1.0,0.0,0.0);
glVertex2f(342.5,350);
glVertex2f(342.5,375);
glVertex2f(335,375);
glVertex2f(335,350);
glEnd();
glColor3f(1.0,0.0,0.0);
draw_text(333.9,265,"P");
glColor3f(0.3,0.4,1.0);
glBegin(GL_LINES);
glVertex2f(337.5,187.5);
glVertex2f(337.5,175);
glVertex2f(337.5,170);
glVertex2f(337.5,160);
glVertex2f(337.5,155);
glVertex2f(337.5,142.5);
glEnd();
glFlush();
35
Chemical Reaction
}
void display3()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.3,0.4,1.0);
glBegin(GL_POLYGON);
glVertex2f(70,25);
glVertex2f(200,25);
glVertex2f(185,75);
glVertex2f(90,75);
glEnd();
glColor3f(0.0,0.0,1.0);
glBegin(GL_LINE_LOOP);
glVertex2f(185,75);
glVertex2f(162.5,150);
glVertex2f(162.5,200);
glVertex2f(112.5,200);
glVertex2f(112.5,150);
glVertex2f(90,75);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(117.5,55,"Base");
glColor3f(1.0,0.0,0.0);
draw_text(40,95,"Level1");
glColor3f(1.0,0.0,0.0);
draw_text(30,65,"Level2");
glColor3f(0.9,456.0,0.5);
glBegin(GL_POLYGON);
glVertex2f(275,25);
glVertex2f(400,25);
glVertex2f(367.5,137.5);
glVertex2f(310,137.5);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(0.0,0.0,1.0);
glVertex2f(367.5,137.5);
glVertex2f(362.5,150);
glVertex2f(362.5,200);
glVertex2f(312.5,200);
glVertex2f(312.5,150);
glVertex2f(310,137.5);
glEnd();
glColor3f(0.0,0.0,0.0);
draw_text(293.5,55,"Neutralized");
glColor3f(1.0,0.0,0.0);
draw_text(270,90,"L1");
glColor3f(1.0,0.0,0.0);
draw_text(275,110,"L2");
glColor3f(1.0,0.0,0.0);
draw_text(280,135,"L3");
glBegin(GL_LINE_LOOP);
glColor3f(1.0,0.0,0.0);
glVertex2f(337.5,192.5);
glVertex2f(342.5,200);
glVertex2f(342.5,237.5);
36
Chemical Reaction
glVertex2f(347.5,250);
glVertex2f(347.5,300);
glVertex2f(342.5,312.5);
glVertex2f(342.5,350);
glVertex2f(335,350);
glVertex2f(335,312.5);
glVertex2f(330,300);
glVertex2f(330,250);
glVertex2f(335,237.5);
glVertex2f(335,200);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(1.0,0.0,0.0);
glVertex2f(342.5,350);
glVertex2f(342.5,375);
glVertex2f(335,375);
glVertex2f(335,350);
glEnd();
glColor3f(1.0,0.0,0.0);
draw_text(333.9,265,"P");
glFlush();
}
void demo_menu(int id)
{
switch(id)
{
case 1:exit(0);
break;
}
}
void keys(unsigned char key,int x,int y)
{
if(key=='p') display0();
if(key=='m') display1();
if(key=='d') display2();
if(key=='1') displaya();
if(key=='2') displayb();
if(key=='3') displayc();
if(key=='r') display3();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
conical1();
conical2();
pipette(0,0);
glFlush();
}
void myinit()
{
glClearColor(0.0,0.0,0.0,1.0);
glColor3f(1.0,0.0,0.0);
glPointSize(1.0);
37
Chemical Reaction
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,499.0,0.0,499.0);
}
void main(int argc,char**argv)
{
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("chemical Reaction");
glutDisplayFunc(display);
glutCreateMenu(demo_menu);
glutAddMenuEntry("Quit",1);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutKeyboardFunc(keys);
myinit();
glutMainLoop();
}
38
Chemical Reaction
Chapter 5
SNAPSHOT AND RESULT DISCUSSION
Snapshot 5.1: Initial output window when the display( ) function is called.
When the display() function gets called, the o/p window displays the 2 conical flask, one
containing base solution and other one containing acid solution. And also, a pipette is
immersed in a conical flask containing base solution.
39
Chemical Reaction
Snapshot 5.2: The base solution is pipetted in when the key p is pressed.
When the key p is pressed, the base solution gets pipetted into the pipette. As the base
solution gets pipetted, the decrease in the level of the base solution is shown in the conical
flask.
40
Chemical Reaction
Snapshot 5.3: The pipette moves towards the conical flask containing acid when the key m
is pressed.
When the key m is pressed, the pipette moves from the conical flask containing
base solution to the conical flask containing acid solution.
41
Chemical Reaction
Snapshot 5.4: The base solution is pipetted out into the conical flask containing acid when the
key 1 is pressed.
When the key 1 is pressed, the base solution is pipetted out into the acid solution.
Also we can see that there is an increase in the level of the solution in the conical flask
containing acid.
42
Chemical Reaction
Snapshot 5.5: The base solution is pipetted out into the conical flask containing acid when the
key 2 is pressed.
When the key 2 is pressed, some more amount of base solution gets pippetted out
into the conical flask, and also we can see some more increase in the level of the acid
solution.
43
Chemical Reaction
Snapshot 5.6: The base solution is pipetted out into the conical flask containing acid when the
key 3 is pressed.
When the key 3 is pressed, the base solution is completely pipette out into the
conical flask containing acid solution. And thus we can see further more increase in the level
of the acid solution in the conical flask.
44
Chemical Reaction
Snapshot 5.7: Acid and base solution reacts and the resultant solution gets neutralized.
Finally when the key r is pressed, we can see the change in the colour of the acid
solution. This indicates that, there is a reaction between the base and the acid solution, and
the resultant solution gets neutralised.
45
Chemical Reaction
Future Enhancement
We can add these future enhancements to our mini project:
With complex interior structures, we can add the capabilities of lighting, shadows and
camera view.
Usage of complex graphics so that the appearance of the output can be beautified.
We can use different objects to make it more attractive.
We can create scenes with realistic atmospheric effects.
There can be future enhancements in the project like designing of a detailed 3D
chemical apparatus.
46
Chemical Reaction
Appendix
OpenGL functions used in Project:
Built In Functions used:
All these functions have been prototyped in the file GL/glut.h. Hence this file have to
be included whenever we use these functions in the program.
glutDisplayFunc( ) : glutDisplayFunc sets the display callback for the current window.
void glutDisplayFunc(void (*func)(void));
func
The new display callback function.
47
Chemical Reaction
glutDisplayFunc sets the display callback for the current window. When GLUT
determines that the normal plane for the window needs to be redisplayed, the display
callback for the window is called. Before the callback, the current window is set to the
window needing to be redisplayed and (if no overlay display callback is registered)
the layer in use is set to the normal plane. The display callback is called with no
parameters. The entire normal plane region should be redisplayed in response to the
callback (this includes ancillary buffers if your program depends on their state).
GLUT determines when the display callback should be triggered based on the
window's redisplay state. The redisplay state for a window can be either set explicitly by
calling glutPostRedisplay or implicitly as the result of window damage reported by the
window system. Multiple posted redisplays for a window are coalesced by GLUT to
minimize the number of display callbacks called.
48
Chemical Reaction
glutMainLoop enters the GLUT event processing loop. This routine should be called
at most once in a GLUT program. Once called, this routine will never return. It will call
as necessary any callbacks that have been registered.
glLoadIdentity ( ): glLoadIdentity replace the current matrix with the identity matrix
void glLoadIdentity(
void);
glLoadIdentity replaces the current matrix with the identity matrix. It is semantically
equivalent to calling glLoadMatrix with the identity matrix
1000010000100001
but in some cases it is more efficient.
49
Chemical Reaction
glClearColor specifies the red, green, blue, and alpha values used by glClear to
clear the color buffers. Values specified by glClearColor are clamped to the range 0 1.
the
subsequent glEnd.
Ten
symbolic
constants
are
void);
50
Chemical Reaction
glBegin and glEnd delimit the vertices that define a primitive or a group of like
primitives. glBegin accepts a single argument that specifies in which of ten ways the
vertices are interpreted.
( );
51
Chemical Reaction
References
[1] Interactive Computer Graphics a Top down Approach with OpenGL 5th Edition,
Addison- Wesley,2008 Edward Angel.
[2] Computer Graphics Using OpenGL 2nd Edition, Pearson Education, 2001- F.S.
Hill,Jr.
[3] Computer Graphics - OpenGL Version 2nd Edition, Pearson Education, 2003Donald Hearn and Pauline Baker,
http:// www.opengl.org/
52