Cgl Lab Manual.docx

  • Uploaded by: december bueno
  • 0
  • 0
  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Cgl Lab Manual.docx as PDF for free.

More details

  • Words: 4,603
  • Pages: 30
Programming Laboratory 2016-17

ISB&M SCHOOL OF TECHNOLOGY DEPARTMENT OF COMPUTER ENGINEERING

A Lab Manual For

COMPUTER GRAPHICS LABORATORY Second Year Computer Engineering

Prepared by Mrs. Komal Jagdale. Assistant Professor, Computer Department

ISB&M School of Technology, Nande, Pune

Page 1

Programming Laboratory 2016-17

List of Assignment Sr No.

Assignment Name

1.

Write a C++ class for a Line drawing method using DDA and Bresenham’s Algorithms. Inherit the pixel class and use function overloading.

2.

Write a C++ program to draw a circle using bresenham’s algorithm .Inherit pixel class.

3.

Write C++ program to draw 2-D object and perform following basic transformation-Scaling, Translation, Rotation.

4.

Write C++ program to draw inscribed and circumscribed circles in the triangle as shown as on example.

5.

Write C++ program to draw the following pattern using any line drawing algorithm.

6.

Write C++ program for line drawing using DDA or Bresenhams algorithm with patterns such as solid, dotted, dashed, dash dot and thick.

7.

Write C++ program to implement reflection of 2-D object about X axis, Y axis and about X=Y axis..

8.

Write program to implement Cohen Sutherland Hodgeman algorithm to clip any polygon. Provide the vertices of the polygon to be clipped and pattern of clipping interactively.

9.

Write C++ program to implement painter’s algorithm for hidden surface removal.

10.

Write C++ program to implement translation, shear, rotation and scaling transformations on equilateral triangle and rhombus

11.

Write C++/Java program to draw 3-D cube and perform following transformations on it using OpenGL. a) Scaling b) Translation c) Rotation about one axis

ISB&M School of Technology, Nande, Pune

Page 2

Programming Laboratory 2016-17

12.

Write C++/Java program to simulate any one of or similar sceneClock with pendulum

National Flag hoisting

Vehicle/boat locomotion waves after impact

Water drop falling into the water and generated

Kaleidoscope views generation (at least 3 colorful patterns)

ISB&M School of Technology, Nande, Pune

Page 3

Programming Laboratory 2016-17

Assignment No:- 1 Aim :- Write a C++ class for a Line drawing method using DDA and Bresenham’s Algorithms. Inherit the pixel class and use function overloading.

Objectives :-Learn and understand the concept of inheritance and overloading. Theory:What is inheritance? Types of inheritance.

DDA ( Digital Differential Analyzer)/ Vector generation algorithm:The vector generation algorithms which step along the line to determine the pixel which should be turned on are sometimes called “Digital Differential Analyzer”. As we know the slope of the straight line is given as M =

∆Y ∆X

=

Y2-Y1

------------------- (1)

X2-X1

The above differential equation can be used to obtain a rasterized straight line. For any given X interval ∆ X along a line, we can compute the corresponding y interval ∆Y from euation (1) as Y2-Y1 ∆Y =

----------------------(2) ∆X

X2-X1

Similarly, we can obtain X interval ∆X corresponding to a specified ∆Y as, X2-X1 ∆X

∆Y

= Y2-Y1

Once the intervals are known the values for next X and next Y on the straight line can be obtained as follows: Xi+1 = Xi + ∆X

-------(4)

and

Yi+1 = Yi + ∆Y ------(5)

Put the values of ∆X and ∆Y in the equations (4) and (5) , then these equation represent a recursion for successive values of X and Y along the required line. Such a way of rasterizing a line is called “ Digital Differential Analyzer (DDA).” For simple DDA either ∆X or ∆Y , whichever is larger, is chosen as one raster unit i.e,

ISB&M School of Technology, Nande, Pune

Page 4

Programming Laboratory 2016-17 |∆X| ≥ |∆Y| then

If

∆X = 1 Else ∆Y = 1. Let us see the algorithm for rasterizing a line.

Algorithm: STEP1: Read the line end points (x1,y1) and (x2,y2) STEP2: ∆X = |x2-x1| and ∆Y = |y2-y1| STEP3: If (∆X ≥∆Y) then Length = ∆X Else Length = ∆Y End if STEP 4: ∆X = (x2-x1) / length ∆Y = (y2-y1) / length STEP 5: X= X1+0.5*sign(∆X) Y=Y1+0.5*sign(∆Y)

sign function makes the algorithm work in all quadrant. It returns -1,0,1 depending on whether its argument is <0, =0, >0 respectively.

STEP 6: i=1 while (i ≤ length) { Plot(Integer(x), Integer(y)) X=X+∆X; Y=Y+∆Y; i=i+1 } STEP7: STOP

Flowchart: Bresenham’s Line drawing algorithm:Bresenham’s line algorithm uses only integer addition and subtraction and multiplication by 2, and we know that the computer can perform the operations of integer addition and subtraction very rapidly. The computer is also time-effiecient when performing integer multiplication by powers of 2. Therefore , it is an efficient method for scan converting straight lines.

ISB&M School of Technology, Nande, Pune

Page 5

Programming Laboratory 2016-17 The basic principle of bresenham’s line algorithm is to select the optimum raster locations to represent a straight line. To accomplish this the algorithm always increments either x or y by one unit depending upon the slope of line . To increment i the other variable is determined by examining the distance between the actual line location and the nearest pixel. This distance is called “Decision variable or the error”.

Algorithm:1. Read the line end points (x1,y1) and (x2,y2) such that they are not equal. 2. ∆x = |x2-x1| and ∆y = |y2-y1| 3. Initialize starting point x = x1 y = y1 4. e = 2* ∆y-∆x [initialize value of decision variable or error to compensate for nonzero intercepts] 5. i=1 [initialize counter] 6. plot(x,y) 7. while(e>=0) { y = y+1; e = e-2 * ∆x } x=x+1; e =e + 2*∆y 8. i =i+1 9. if(i<=∆x) then go to step 6 10. stop

Frequently Asked Questions :1. 2. 3. 4. 5. 6.

Define 1) Line 2) Line segment 3) Vector Which type of line you will get with DDA line drawing algorithm? What is one complete raster unit? What is the use of Sign() function? What are the disadvantages of DDA Algorithm? What is the difference between DDA line generation algorithm & Bresenham’s line generation algorithm?

Conclusion:Thus We’ve learnt and understood the concept of inheritance and overloading.

ISB&M School of Technology, Nande, Pune

Page 6

Programming Laboratory 2016-17

Assignment No:- 2 Aim:-Write a C++ program to draw a circle using bresenham’s algorithm .Inherit pixel class. Objectives:-Learn and understand the concept of circle drawing by inheriting line class. Theory:Algorithm:-

1.

Read the radius r of the circle 2. d = 5/4-r 3. x = 0, y = r ( initialize starting point) 4. do { putpixel(x,y,10); if(d<0) then { d=d + 2x +1 } else { d=d + 2(x-y) +1 y= y-1 } x = x+1 }while(x<=y) 5. stop The remaining part of circle can be drawn by reflecting point about y-axis , x-axis and about origin as shown in fig. Therefore, by adding seven more plot commands after the plot command in step 4 of the algorithm, the circle can be plotted . the remaining seven plot commands are: Plot(y,x) Plot(y,-x) Plot(x,-y) Plot(-x,-y) Plot(-y,-x) Plot(-y,x) and Plot(-x,y)

ISB&M School of Technology, Nande, Pune

Page 7

Programming Laboratory 2016-17

FAQ: 1. 2. 3. 4. 5. 6. 7. 8. 9.

What is inheritance? What is the advantage of inheritance? What is meant by single inheritance.? What is multiple inheritances? What is hierarchical inheritance? What is multilevel inheritance? What is hybrid inheritance? What is the need of Bresenham’s Circle drawing algorithm? What are the differences between a C++ struct and C++ class?

Conclusion:Thus we’ve learnt and understood the concept of circle drawing by inheriting line class.

ISB&M School of Technology, Nande, Pune

Page 8

Programming Laboratory 2016-17

Assignment No: A3 Aim : Write C++ program to draw 2-D object and perform following basic transformation-Scaling, Translation, Rotation.

Objective: Understand different transformations and implement them in laboratory Theory:

Translation A translation moves an object to a different position on the screen. You can translate a point in 2D by adding translation coordinate (tx, ty) to the original coordinate (X, Y) to get the new coordinate (X’, Y’).

From the above figure, you can write that − X’ = X + tx Y’ = Y + ty The pair (tx, ty) is called the translation vector or shift vector. The above equations can also be represented using the column vectors P=[X][Y]

P' = [X′][Y′]

T = [tx][ty]

ISB&M School of Technology, Nande, Pune

Page 9

Programming Laboratory 2016-17

We can write it as − P’ = P + T

Rotation In rotation, we rotate the object at particular angle θ (theta) from its origin. From the following figure, we can see that the point P(X, Y) is located at angle φ from the horizontal X coordinate with distance r from the origin. Let us suppose you want to rotate it at the angle θ. After rotating it to a new location, you will get a new point P’ (X’, Y’).

Scaling To change the size of an object, scaling transformation is used. In the scaling process, you either expand or compress the dimensions of the object. Scaling can be achieved by multiplying the original coordinates of the object with the scaling factor to get the desired result. Let us assume that the original coordinates are (X, Y), the scaling factors are (SX, SY), and the produced coordinates are (X’, Y’). This can be mathematically represented as shown below − X' = X . SX and Y' = Y . SY The scaling factor SX, SY scales the object in X and Y direction respectively. P’ = P . S

ISB&M School of Technology, Nande, Pune

Page 10

Programming Laboratory 2016-17

Where S is the scaling matrix. The scaling process is shown in the following figure.

If we provide values less than 1 to the scaling factor S, then we can reduce the size of the object. If we provide values greater than 1, then we can increase the size of the object. ConclusionThus we’ve understood different transformations and implemented them in laboratory

ISB&M School of Technology, Nande, Pune

Page 11

Programming Laboratory 2016-17

Assignment No: A4 Aim : Write C++ program to draw inscribed and circumscribed circles in the triangle as shown as on example:

Objective: Learn and understand the concept of line drawing and circle drawing Theory: DDA ( Digital Differential Analyzer)/ Vector generation algorithm:The vector generation algorithms which step along the line to determine the pixel which should be turned on are sometimes called “Digital Differential Analyzer”.

Algorithm: STEP1: Read the line end points (x1,y1) and (x2,y2) STEP2: ∆X = |x2-x1| and ∆Y = |y2-y1| STEP3: If (∆X ≥∆Y) then Length = ∆X Else Length = ∆Y End if STEP 4: ∆X = (x2-x1) / length ∆Y = (y2-y1) / length STEP 5: X= X1+0.5*sign(∆X) Y=Y1+0.5*sign(∆Y)

sign function makes the algorithm work in all quadrant. It returns -1,0,1 depending on whether its argument is <0, =0, >0 respectively.

STEP 6: i=1 while (i ≤ length) { Plot(Integer(x), Integer(y)) X=X+∆X; ISB&M School of Technology, Nande, Pune

Page 12

Programming Laboratory 2016-17 Y=Y+∆Y; i=i+1 } STEP7: STOP

Bresenham’s Circle Drawing Algorithm:-

1.

Read the radius r of the circle 2. d = 5/4-r 3. x = 0, y = r ( initialize starting point) 4. do { putpixel(x,y,10); if(d<0) then { d=d + 2x +1 } else { d=d + 2(x-y) +1 y= y-1 } x = x+1 }while(x<=y) 5. stop The remaining part of circle can be drawn by reflecting point about y-axis , x-axis and about origin as shown in fig. Therefore, by adding seven more plot commands after the plot command in step 4 of the algorithm, the circle can be plotted . the remaining seven plot commands are: Plot(y,x) Plot(y,-x) Plot(x,-y) Plot(-x,-y) Plot(-y,-x) Plot(-y,x) and Plot(-x,y)

Conclusion:Thus we’ve learnt and understood the concept of line drwing and circle drawing by inheriting line class.

ISB&M School of Technology, Nande, Pune

Page 13

Programming Laboratory 2016-17

Assignment No: A5 Aim : Write C++ program to draw the following pattern using any line drawing algorithm

Objective: Learn and understand the concept of line drawing Theory: DDA ( Digital Differential Analyzer)/ Vector generation algorithm:The vector generation algorithms which step along the line to determine the pixel which should be turned on are sometimes called “Digital Differential Analyzer”.

Algorithm: STEP1: Read the line end points (x1,y1) and (x2,y2) STEP2: ∆X = |x2-x1| and ∆Y = |y2-y1| STEP3: If (∆X ≥∆Y) then Length = ∆X Else Length = ∆Y End if STEP 4: ∆X = (x2-x1) / length ∆Y = (y2-y1) / length STEP 5: X= X1+0.5*sign(∆X) Y=Y1+0.5*sign(∆Y)

sign function makes the algorithm work in all quadrant. It returns -1,0,1 depending on whether its argument is <0, =0, >0 respectively.

STEP 6: i=1 while (i ≤ length) { Plot(Integer(x), Integer(y)) X=X+∆X; Y=Y+∆Y; i=i+1 } STEP7: STOP ISB&M School of Technology, Nande, Pune

Page 14

Programming Laboratory 2016-17

Conclusion:- Thus we’ve learnt and understood the concept of line drwing and circle drawing by inheriting line class.

Assignment No:- B6 Aim:- Write Write C++ program for line drawing using DDA or Bresenhams algorithm with patterns such as solid, dotted, dashed, dash dot and thick.

Theory: Basic attributes of a straight line segment are its type, its width, and its color. In some graphics packages, lines can also be displayed using selected pen or brush options. In the following sections, we consider how line drawing routines can be modified to accommodate various attribute specifications.

Line Type Possible selections for the line-type attribute include solid lines, dashed lines, and dotted lines. We modify a line drawing algorithm to generate such lines by setting the length and spacing of displayed solid sections along the line path. A dashed line could be displayed by generating an inter dash spacing that is equal to the length of the solid sections. Both the length of the dashes and the inter dash spacing are often specified as user options. A dotted line can be displayed by generating very short dashes with the spacing equal to or greater than the dash size. Similar methods are used to produce other line-type variations. Line Attributes To set line type attributes in a PHICS application program, a user invokes the function setLinetype (lt) where parameter 1t is assigned a positive integer value of 1,2,3, or 4 to generate lines that are, respectively, solid, dashed, dotted, or dash-dotted.

Line Width Implementation of line- width options depends on the capabilities of the output device. A heavy line on a monitor could be displayed as adjacent parallel lines, while a pen plotter might require pen changes. As with other PHIGS attributes, a line-width command is used to set the current line-width value in the attribute list. This value is then used by line-drawing algorithms to control the thickness of lines generated with subsequent output primitive commands We set the line-width attribute with the command: SetLinewidthScaleFactor(lw) Line-width parameter lw is assigned a positive number to indicate the relative width of the line to be displayed. A value of 1 specifies a standard width line. On a pen plotter, for instance, a user could set lw to a value of 0.5 to plot a line whose width is half that of the standard line. Values greater than 1 produce lines thicker than the standard.

Thick Line Segments ISB&M School of Technology, Nande, Pune

Page 15

Programming Laboratory 2016-17

We can draw lines with thickness greater than one pixel. To produce a thick line segment, we can draw two lines in parallel along the thick-line edges. As we step along the line finding successive edge pixels, we must turn ON all the pixels which lie between the boundaries.

To draw a line between (xa,ya) and (xb,yb) with thickness w, we would have a top boundary between the points (xa,ya+wy) and (xb,yb+wy) and a lower boundary between(xa,ya+wy) and (xb,yb-wy) where wy is given by,

( w  1) [( xb  xa ) 2  ( yb  ya )]1/ 2 wy  2 | xb  xa |

Conclusion: Thus, we have successfully studied to implement a program in C/C++ to draw a line with line style (Thick, Thin, Dotted).

ISB&M School of Technology, Nande, Pune

Page 16

Programming Laboratory 2016-17

Assignment No:- B7 Aim:- Write C++ program to implement reflection of 2-D object about X axis, Y axis and about X=Y axis

Objectives:-Learn and understand the concept of transformation- reflection. Theory:- Reflection Reflection is the mirror image of original object. In other words, we can say that it is a rotation operation with 180°. In reflection transformation, the size of the object does not change.The following figures show reflections with respect to X and Y axes, and about the origin

respectively.

ISB&M School of Technology, Nande, Pune

Page 17

Programming Laboratory 2016-17

Conclusion: Thus we’ve understood the concept of reflection. Assignment No: B8 Aim : Write program to implement Cohen Sutherland Hodgeman algorithm to clip any polygon. Provide the vertices of the polygon to be clipped and pattern of clipping interactively.

Objective: Understand polygon clipping algorithms and implement them in laboratory Theory:

Sutherland - Hodgman Polygon Clipping The Sutherland - Hodgman algorithm performs a clipping of a polygon against each window edge in turn. It accepts an ordered sequence of verices v1, v2, v3, ..., vn and puts out a set of vertices defining the clipped polygon.

This figure represents a polygon (the large, solid, upward pointing arrow) before clipping has occurred. The following figures show how this algorithm works at each edge, clipping the polygon.

a. b. c. d.

Clipping against the left side of the clip window. Clipping against the top side of the clip window. Clipping against the right side of the clip window. Clipping against the bottom side of the clip window.

ISB&M School of Technology, Nande, Pune

Page 18

Programming Laboratory 2016-17

Four Types of Edges As the algorithm goes around the edges of the window, clipping the polygon, it encounters four types of edges. All four edge types are illustrated by the polygon in the following figure. For each edge type, zero, one, or two vertices are added to the output list of vertices that define the clipped polygon.

The four types of edges are: 1. 2. 3. 4.

Edges that are totally inside the clip window. - add the second inside vertex point Edges that are leaving the clip window. - add the intersection point as a vertex Edges that are entirely outside the clip window. - add nothing to the vertex output list Edges that are entering the clip window. - save the intersection and inside points as vertices

How To Calculate Intersections Assume that we're clipping a polgon's edge with vertices at (x1,y1) and (x2,y2) against a clip window with vertices at (xmin, ymin) and (xmax,ymax). The location (IX, IY) of the intersection of the edge with the left side of the window is: i. ii.

IX = xmin IY = slope*(xmin-x1) + y1, where the slope = (y2-y1)/(x2-x1)

The location of the intersection of the edge with the right side of the window is: i. ii.

IX = xmax IY = slope*(xmax-x1) + y1, where the slope = (y2-y1)/(x2-x1)

The intersection of the polygon's edge with the top side of the window is: i. ii.

IX = x1 + (ymax - y1) / slope IY = ymax

Finally, the intersection of the edge with the bottom side of the window is: ISB&M School of Technology, Nande, Pune

Page 19

Programming Laboratory 2016-17 i. ii.

IX = x1 + (ymin - y1) / slope IY = ymin

ConclusionThus we’ve understood polygon clipping algorithms and implemented them in laboratory

ISB&M School of Technology, Nande, Pune

Page 20

Programming Laboratory 2016-17

Assignment No: B9 Aim:- Write C++ program to implement painter’s algorithm for hidden surface removal.. Theory:-

Depth Sorting Method Depth sorting method uses both image space and object-space operations. The depth-sorting method performs two basic functions −  

First, the surfaces are sorted in order of decreasing depth. Second, the surfaces are scan-converted in order, starting with the surface of greatest depth.

The scan conversion of the polygon surfaces is performed in image space. This method for solving the hidden-surface problem is often referred to as the painter's algorithm. The following figure shows the effect of depth sorting −

The algorithm begins by sorting by depth. For example, the initial “depth” estimate of a polygon may be taken to be the closest z value of any vertex of the polygon. Let us take the polygon P at the end of the list. Consider all polygons Q whose z-extents overlap P’s. Before drawing P, we make the following tests. If any of the following tests is positive, then we can assume P can be drawn before Q.     

Do the x-extents not overlap? Do the y-extents not overlap? Is P entirely on the opposite side of Q’s plane from the viewpoint? Is Q entirely on the same side of P’s plane as the viewpoint? Do the projections of the polygons not overlap?

ISB&M School of Technology, Nande, Pune

Page 21

Programming Laboratory 2016-17

If all the tests fail, then we split either P or Q using the plane of the other. The new cut polygons are inserting into the depth order and the process continues. Theoretically, this partitioning could generate O(n2) individual polygons, but in practice, the number of polygons is much smaller.

ConclusionThus we’ve understood painter’s algorithm for hidden surface removal and implemented them in laboratory

ISB&M School of Technology, Nande, Pune

Page 22

Programming Laboratory 2016-17

Assignment No: B10 Aim : Write C++ program to implement translation, shear, rotation and scaling transformations on equilateral triangle and rhombus

Objective: Understand different transformations and implement them in laboratory Theory:

Translation A translation moves an object to a different position on the screen. You can translate a point in 2D by adding translation coordinate (tx, ty) to the original coordinate (X, Y) to get the new coordinate (X’, Y’).

From the above figure, you can write that − X’ = X + tx Y’ = Y + ty The pair (tx, ty) is called the translation vector or shift vector. The above equations can also be represented using the column vectors P=[X][Y]

P' = [X′][Y′]

T = [tx][ty]

We can write it as − P’ = P + T

ISB&M School of Technology, Nande, Pune

Page 23

Programming Laboratory 2016-17

Rotation In rotation, we rotate the object at particular angle θ (theta) from its origin. From the following figure, we can see that the point P(X, Y) is located at angle φ from the horizontal X coordinate with distance r from the origin. Let us suppose you want to rotate it at the angle θ. After rotating it to a new location, you will get a new point P’ (X’, Y’).

Scaling To change the size of an object, scaling transformation is used. In the scaling process, you either expand or compress the dimensions of the object. Scaling can be achieved by multiplying the original coordinates of the object with the scaling factor to get the desired result. Let us assume that the original coordinates are (X, Y), the scaling factors are (SX, SY), and the produced coordinates are (X’, Y’). This can be mathematically represented as shown below − X' = X . SX and Y' = Y . SY The scaling factor SX, SY scales the object in X and Y direction respectively. P’ = P . S Where S is the scaling matrix. The scaling process is shown in the following figure.

ISB&M School of Technology, Nande, Pune

Page 24

Programming Laboratory 2016-17

If we provide values less than 1 to the scaling factor S, then we can reduce the size of the object. If we provide values greater than 1, then we can increase the size of the object.

Shear A transformation that slants the shape of an object is called the shear transformation. There are two shear transformations X-Shear and Y-Shear. One shifts X coordinates values and other shifts Y coordinate values. However; in both the cases only one coordinate changes its coordinates and other preserves its values. Shearing is also termed as Skewing.

ISB&M School of Technology, Nande, Pune

Page 25

Programming Laboratory 2016-17 X-Shear

The X-Shear preserves the Y coordinate and changes are made to X coordinates, which causes the vertical lines to tilt right or left as shown in below figure.

The transformation matrix for X-Shear can be represented as − X' = X + Shx . Y Y’ = Y Y-Shear

The Y-Shear preserves the X coordinates and changes the Y coordinates which causes the horizontal lines to transform into lines which slopes up or down as shown in the following figure.

The Y-Shear can be represented in matrix from as − Y’ = Y + Shy . X X’ = X ConclusionThus we’ve understood different transformations and implemented them in laboratory

ISB&M School of Technology, Nande, Pune

Page 26

Programming Laboratory 2016-17

Assignment No: B11 Aim : Write C++/Java program to draw 3-D cube and perform following transformations on it using OpenGL. a) Scaling b) Translation c) Rotation about one axis

Objective: Understand different transformations and implement them in laboratory Theory:

Rotation 3D rotation is not same as 2D rotation. In 3D rotation, we have to specify the angle of rotation along with the axis of rotation. We can perform 3D rotation about X, Y, and Z axes. They are represented in the matrix form as below –

ISB&M School of Technology, Nande, Pune

Page 27

Programming Laboratory 2016-17

The following figure explains the rotation about various axes –

Scaling You can change the size of an object using scaling transformation. In the scaling process, you either expand or compress the dimensions of the object. Scaling can be achieved by multiplying the original coordinates of the object with the scaling factor to get the desired result. The following figure shows the effect of 3D scaling −

ISB&M School of Technology, Nande, Pune

Page 28

Programming Laboratory 2016-17

In 3D scaling operation, three coordinates are used. Let us assume that the original coordinates are (X, Y, Z), scaling factors are (SX,SY,Sz) respectively, and the produced coordinates are (X’, Y’, Z’). This can be mathematically represented as shown below −

ConclusionThus we’ve understood different transformations and implemented them in laboratory

ISB&M School of Technology, Nande, Pune

Page 29

Programming Laboratory 2016-17

Assignment No: B12 Aim : Write C++/Java program to simulate any one of or similar scene-Clock with pendulum Theory: Outtextxy Function : outtextxy function display text or string at a specified point(x,y) on the screen. Declaration :- void outtextxy(int x, int y, char *string); x, y are coordinates of the point and third argument contains the address of string to be displayed. Circle Function Declaration :- void circle(int x, int y, int radius); Circle function is used to draw a circle with center (x,y) and third parameter specifies the radius of the circle. The code given below draws a circle. Line Function: line function is used to draw a line from a point(x1,y1) to point(x2,y2) i.e. (x1,y1) and (x2,y2) are end points of the line.The code given below draws a line. Declaration :- void line(int x1, int y1, int x2, int y2); Cleardevice Function: Declaration :- void cleardevice(); cleardevice function clears the screen in graphics mode and sets the current position to (0,0). Clearing the screen consists of filling the screen with current background color. Usleep Function #include int usleep(useconds_t useconds);

The usleep() function shall cause the calling thread to be suspended from execution until either the number of realtime microseconds specified by the argument useconds has elapsed or a signal is delivered to the calling thread and its action is to invoke a signal-catching function or to terminate the process. ConclusionThus we’ve implemented program to simulate Clock with pendulum ISB&M School of Technology, Nande, Pune

Page 30

Related Documents

Cgl Lab Manual.docx
October 2019 12
Cgl-syllabus.pdf
November 2019 11
Lab
May 2020 22
Lab
June 2020 19
Lab
April 2020 14
Lab
July 2020 11

More Documents from ""