Documente Academic
Documente Profesional
Documente Cultură
2014
I.
Synopsis
Introduction
1. Generate a graph to analyze the up and downs of a share market
using DDA algorith is about taking the data and showing it in chart type.
Advantage of chart is that it will be easy to understand the data differences
which is given by the user in terms of numbers, he can compare it with
previous
data
in
chart,
he
can
see
the
whether
there
is
2. Developement of
Page No.1
2014
II.
Design Specification
Design Specification provides explicit information about the requirements for the
project and how the project has been implemented. It is used to design document that
describes all data, architectural, interface and component-level design for the
software.
1. Generate a graph to analyze the up and downs of a share market using
DDA algorith
DDA algorithm is used to design the chart, when the user provides data, the
first data is taken and the line is drawn for that data, same functionality is
carried out for rest of the data provided by the user. DDA line algorithm is
called for n times, n is the number of times given by the user to draw columns
with n number of datas.
DDA line Algorithm
DDA Line ( X1, Y1, XN, YN):
Description: Here X1 and Y1 denote the starting x coordinate and y
coordinate of the line
and XN and YN denote the ending x coordinate and y coordinate.
1. Set M = (YN Y1) / (XN X1) [Calculate slope of line]
2. Repeat For I = X1 to XN
3. If (M <= 1) Then
4. Set DX = 1
5. Set DY = M * DX
6. Else
7. Set DY = 1
8. Set DX = DY / M
[End of If]
9. Set X1 = X1 + DX
10. Set Y1 = Y1 + DY
11. Call PutPixel(X1, Y1)
[End of For]
12. Exit
Dept.of MCA, RVCE
Page No.2
2014
DDA line function has to be called for two times with the given
coordinates.
This is a predefined line, so programmer has set the x,y and z coordinates and two lines has been drawn.
Using DDA line drawing algorithm draw the lines for n number of
times
While drawing the lines use different colours for different lines.
Since the next point (x i+1,y i+1) should satisfy y/ x =m, where y= y
i+1yi and x= x i+1xi, we have y i+1= yi + m x or x i+1=xi+ y/m.
Page No.3
2014
In DDA algorithm we have to find the new point xi+1 and yi+1 from the
existing points xi and yi. As a first step here we identify the major axis and the
minor axis of the line to be drawn. Once the major axis is found we sample the
major axis at unit intervals and find the value in the other axis by using the
slope equation of the line.
For example if the end points of the line is given as (x1,y1)= (2,2) and (x2,
y2)= (9,5). Here we will calculate y2-y1 and x2-x1 to find which one is
greater. Here y2-y1 =3 and x2-x1 =7; therefore here the major axis is the x
axis. So here we need to sample the x axis at unit intervals i.e. x = 1 and we
will find out the y values for each x in the x axis using the slope equation.
In DDA we need to consider two cases; one is slope of the line less than or
equal to one (|m| 1)and slope of the line greater than one (m| > 1). When |m|
1 means y2-y1 = x2-x1 or y2-y1 <x2-x1.In both these cases we assume x to be
the major axis. Therefore we sample x axis at unit intervals and find the y
values corresponding to each x value.
In general terms we can say that y i+1 - yi = m(x i+1 - xi ). But here x = 1;
therefore the equation reduces to y i+1= yi + m = yi + dy/dx.
When m| > 1 means y2-y1> x2-x1 and therefore we assume y to be the major
axis. Here we sample y axis at unit intervals and find the x values
corresponding to each y value. We have the slope equation as
y=m x
y2-y1 = m (x2-x1)
In general terms we can say that y i+1 - yi = m(x i+1 - xi ). But here y = 1;
therefore the equation reduces to 1 = m(x i+1 - xi). Therefore
x i+1=xi+ 1/m
x i+1=xi+ dx/dy
The DDA algorithm is faster than the direct use of the line equation since it calculates
points on the line without any floating point multiplication.
Page No.4
2014
The coordinates are passed to the drawstring function which draws the
text on to screen using glutBitmapChar() function.
Delay function
Delay function is used to keep some delay between calling the text
again, so that it makes effect of screen saver.
Applying rotation
Applying translation
glTranslatef(-750, 0, 0);
Page No.5
2014
III.
Graphical Features
The text on the graphical window is drawn with the help glutBitmapCharacter.
glColor3f
glMatrixMode
GL_PROJECTION
glClearColor
GL_POINTS
glBegin, glEnd
glFlush
glVertex2i
GL_LINES
GL_LINE_STRIP
GL_POLYGON
GL_LINE_LOOP
glRasterPos2i glutBitmapCharacter
Page No.6
2014
glutStrokeCharacter(font, message[i]);
Delay : Delay function is implemented to suspend the execution of a program for a
particular time. Here unsigned int is the number of milliseconds ( 1 second = 1000
milliseconds ).
void delay()
{
for( int i = 0; i <= 2000000; i++)
}
Graphic Library
A set of window system dependent libraries may also be necessary for linking
GLUT
programs.
For
example,
programs
using
the
X11
GLUT
glutInit(int *argc, char *argv) : It initializes GLUT and processes any command
line arguments.
glutInitDisplayMode(unsigned int mode) : It specifies whether to use an RGBA
or color-index color model. One can also specify whether they want a single or double
buffered window.
glutInitWindowPosition(int x,int y) : It specifies the screen location for upperleft corner of the window.
glutInitWindowSize(int w, int h) : It specifies the size in pixels of window.
glutCreateWindow(char *string) : It creates an window with openGL context. It
Dept.of MCA, RVCE
Page No.7
2014
returns a unique identifier for the new window. This function sends the request for
new window to be constructed.
glVertex : The main function (and probably the most used OpenGL function) is
function named glVertex. This function defines a point (or a vertex) in your 3D world
and it can vary from receiving 2 up to 4 coordinates.
takes only 2 parameters, z is always 0. glVertex2f can be used in special cases and
won't be used a lot unless you're working with pseudo-2D sprites or triangles and
points that always have to be constrained by the depth coordinate.
glVertex4f(100.0f, 150.0f, -25.0f, 1.0f); this is the same as glVertex3f, the only
difference is in the last coordinate that specifies a scaling factor. The scaling factor is
set to 1.0f by default. It can be used to make your 3D points look thicker than one
pixel.
glBegin and glEnd : glVertex alone won't draw anything on the screen, it merely
defines a vertex, usually of a more complex object. To really start displaying
something on the screen you will have to use two additional functions. These
functions are
glBegin(int mode); and glEnd( void );
glBegin and glEnd delimit the vertices of a primitive or a group of like primitives.
What this means is that everytime you want to draw a primitive on the screen you will
first have to call glBegin, specifying what kind of primitive it is that you want to draw
in the mode parameter of glBegin, and then list all vertices one by one (by
sequentially calling glVertex) and finally call glEnd to let OpenGL know that you're
done drawing a primitive. The parameter mode of the function glBegin can be one of
the following:
GL_POINTS
GL_LINES
GL_LINE_STRIP
Page No.8
2014
GL_LINE_LOOP
OpenGL Color effects: The goal of almost all OpenGL applications is to draw color
pictures in a window on the screen. The window is a rectangular array of pixels, each
of which contains and displays its own color. Thus, in a sense, the point of all the
calculations performed by an OpenGL implementation - calculations that take into
account OpenGL commands, state information, and values of parameters - is to
determine the final color of every pixel that's to be drawn in the window. This chapter
explains the commands for specifying colors and how OpenGL interprets them in the
following major sections:
"Computer
Color" describes
the
relationship
between
pixels
on
computer monitor and their colors; it also defines the two display modes, RGBA and
color index.
"RGBA versus Color-Index Mode" explains how the two display modes use
"Specifying a Color and a Shading Model" describes the OpenGL commands you
Page No.9
2014
2. OUTPUT SCREEN
Figure1: Graph to analyze the up and downs of a share market using DDA
algorith.
Dept.of MCA, RVCE
Page No.10
2014
Page No.11
2014
Conclusion
A chart visualizes the numeric data in a graphical format.Charts are often used to ease
understanding of large quantities of data and the relationships between parts of the
data. Charts can usually be read more quickly than the raw data that they are produced
from.
They are used in a wide variety of fields, and can be created by hand (often on graph
paper) or by computer using a charting application. Certain types of charts are more
useful for presenting a given data set than others. For example, data that
presents percentages in different groups (such as "satisfied, not satisfied, unsure") are
often displayed in a pie chart, but may be more easily understood when presented in a
horizontal bar chart. On the other hand, data that represents numbers that change over
a period of time (such as "annual revenue from 1990 to 2000") might be best shown
as a line chart.
The future enhancement of the dda line algorithm for making charts can be as
making use of keyboard/Mouse events for the dragging and releasing the columns
height to compare data by making changes. We can make the columns 3D which
looks better than 2D.
Many modern television operating systems, media players and other
entertainment systems have a form of screensaver integrated. Most simply display
a logo moving around the screen. We can implements screen savers not only with text
but with this we can include different objects and applying different transformations
to it.
Page No.12
2014
References
1. Donald D. Hearn, M Pauline Baker, Warren Carthers, Computer Graphics
output primitives in Computer Graphics with OpenGL, 4th edition, Pearson,
2014, Chapter 3, Page no. 45.
2. Donald D. Hearn, M Pauline Baker, Warren Carthers, Attributes of Graphics
primitives in Computer Graphics with OpenGL, 4th edition, Pearson, 2014,
Chapter 4, Page no. 99.
3. Donald D. Hearn, M Pauline Baker, Warren Carthers, Implementation
Algorithms for Graphics primitives and attributes in Computer Graphics with
OpenGL, 4th edition, Pearson, 2014, Chapter 5, Page no. 131.
Page No.13
2014
Source Code
//1. Generate a graph to analyze the up and downs of a share market using DDA
algorith
#include<iostream>
#include<cstdio>
#include<GL/gl.h>
#include<GL/glu.h>
#include<GL/glut.h>
#include<math.h>
using namespace std;
void initialize();
void display();
void dl(int,int,int,int);
void fill(int,int);
int a[20],n;
float f=0.2,e=1.0;
int main(int argc,char** argv){
cout<<"enter the number of bar charts\n";
cin>>n;
cout<<"enter user values\n";
for(int i=0;i<n;i++)
{
cin>>a[i];
}
for(int i=0;i<n;i++)
Dept.of MCA, RVCE
Page No.14
2014
{
a[i]=50+(a[i]*5);
}
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(900,900);
glutInitWindowPosition(00,00);
glutCreateWindow("chess board");
glutDisplayFunc(display);
initialize();
glutMainLoop();
return 0;
}
void initialize()
{
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.0,0.0,0.0,0.0);
glColor3f(1.0,1.0,1.0);
glPointSize(3.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//gluOrtho2D(10.0,499.0,10.0,499.0);
gluOrtho2D(00.0,700.0,00.0,700.0);
}
void fill(int x,int y)
Dept.of MCA, RVCE
Page No.15
2014
{
for(int i=x;i<x+50;i++)
dl(i,y,i,y+50);
}
void drawString1(float x, float y){
glColor3f(1.0, 0.0, 0.0);
glRasterPos2f(x, y);
char scoreArr[300];
sprintf(scoreArr, "Progress in percentage");
for (const char* c=scoreArr; *c != '\0'; c++){
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, *c); // Updates the
position
}
}
void drawString(float x, float y)
{
glColor3f(1.0, 0.0, 0.0);
glRasterPos2f(x, y);
char scoreArr[300];
sprintf(scoreArr, "
2010
2011
2012
2013
2014
<----work in year");
Page No.16
2014
}
}
void display()
{
int c=0;
dl(30,50,30,570);
dl(30,50,450,50);
drawString1(7,600);
drawString(20,30);
glRasterPos2i(10,50);
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,'0');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,'0');
glRasterPos2i(10,100);
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,'1');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,'0');
glRasterPos2i(10,150);
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,'2');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,'0');
glRasterPos2i(10,200);
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,'3');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,'0');
glRasterPos2i(10,250);
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,'4');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,'0');
glRasterPos2i(10,300);
Dept.of MCA, RVCE
Page No.17
2014
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,'5');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,'0');
glRasterPos2i(10,350);
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,'6');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,'0');
glRasterPos2i(10,400);
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,'7');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,'0');
glRasterPos2i(10,450);
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,'8');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,'0');
glRasterPos2i(10,500);
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,'9');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,'0');
glRasterPos2i(10,550);
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,'1');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,'0');
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,'0');
//drawString(10.0,45.0,0.0);
for(int z=0;z<n;z++)
{
glColor3f(0.5,0.5,f);
for(int i=55;i<a[z];i++)
dl(50*z+40,i,50*(z+1),i);
f=f+0.3;
Dept.of MCA, RVCE
Page No.18
2014
if(f>1)
f=f-1;
glFlush();
}
glFlush();
}
void dl(int x1,int y1,int x2,int y2)
{
int s,dx,dy,m;
float xi,yi,x,y;
dx=x2-x1;
dy=y2-y1;
if(abs(dx)>abs(dy))
s=abs(dx);
else
s=abs(dy);
xi=dx/float(s);
yi=dy/float(s);
x=x1;
y=y1;
glBegin(GL_POINTS);
glVertex2f(x,y);
glEnd();
for(m=0;m<s;m++)
{
Dept.of MCA, RVCE
Page No.19
2014
x+=xi;
y+=yi;
glBegin(GL_POINTS);
glVertex2f(x,y);
glEnd();
}
}
//2. Develop 2D Text screen saver with Rotation and Translation)
#include <string.h>
#include <GL/glut.h>
void *font = GLUT_BITMAP_TIMES_ROMAN_24;
void *fonts[] ={GLUT_STROKE_ROMAN, GLUT_STROKE_MONO_ROMAN};
char defaultMessage[] = "Neelendu Shekhar";
char defaultMessage1[] = "Shekhar";
char *message = defaultMessage;
int angle = 0;
void tick(void)
{
angle -= 5;
glutPostRedisplay();
}
void tick1(void)
{
angle += 5;
glutPostRedisplay();
Dept.of MCA, RVCE
Page No.20
2014
}
void display(void)
{
int len, i;
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(angle, 0.0, 0.0, 1.0);
glTranslatef(-750, 0, 0);
len = (int) strlen(message);
for (i = 0; i < len; i++) {
glutStrokeCharacter(font, message[i]);
}
glPopMatrix();
glutSwapBuffers();
}
void delay()
{
for(int i=0;i<=200000;i++)
}
int main(int argc, char **argv)
{
int i, submenu;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(600, 600);
Dept.of MCA, RVCE
Page No.21
2014
Page No.22