 Good morning. Let us first look at the execution of some of the sample programs which we will discuss in the course. So, this is this one just draws a simple window. There is another one which draws a window which is titled CS 101 window. Of course, you cannot see this here, but in a smaller size, can you see a string written in between? What does it say? Oh, you can read that. So, this merely demonstrates how you can write text in a specific box inside a window that you have opened. Here is another sample which says give a width and height for the window. So, let us say 15 and 15 and then it says how many points you want to draw. So, it is basically you have let us say electrocardiogram analysis your various points on the ECG. You just want to display them. Of course, here I do not have an ECG. So, I am randomly generating points and displaying them with some labels. So, let us say I want to display 10 points. So, what the program does is it generates 10 random points using the random number generator, but uses then graphics to plot these points. So, can you see this? So, it says 0th point at 3 1, 1st point at 4 4, 7th point at 4 2 etcetera. Remember the coordinate system is x is increasing in this direction and y is increasing in this direction. Here is another sample. It draws pattern. So, these patterns are drawn by straight lines. So, you draw large number of straight lines at a particular from starting point to end point and you will see patterns there. All these patterns could be drawn basically it is line drawing with a specific purpose. Here is another program which draws some basic shapes rectangle eclipse or sorry ellipse. This is another shape drawing program arbitrarily it expects an input any input I can give here. So, this is drawing more shapes and each of these ordinarily would be a very difficult task to write complete graphic program. So, remember the classes that we mentioned somebody has written a window e z window library of classes. The first class was simple window which we saw. There are other classes like rectangle shape, line, ellipse, text etcetera, etcetera using these we showing this. Here is a one which draws any picture. So, this is called a bit map drawing. The e z windows has a facility that if you have any bit map image you can display it there. The problem is that it expects bit maps in a specific file format called XPM. Remember I had mentioned a lot of file formats. So, normal file formats are BMP, JPJ, etcetera etcetera. So, ordinarily this was a photograph from my camera which was a JPEG file. There is a convert utility which comes along with the e z windows package it will be available with you. So, you can take any image is practically any format is a convert to XPM it will convert it to XPM. Once it is converted you can show it. This program is not just simply showing that this program actually illustrates that you can move this image. So, basically how to capture a mouse position. For example, if I move the mouse here you can see the pointer here. Now, if I click it will move the image that side. If I come here and click here it will move the image here. So, basically there is a function to capture the mouse movement and set some position and there is another function to erase an image at some original place and redraw it at some other place. There is I have not compiled this. So, let us say I want to I want to plot a graph let me compile. Incidentally you cannot compile this program using normal compile it requires a special thing I will discuss what that compile is. So, let me compile this new sign and then let me execute this new sign it basically plots a sign function. Why is it plotting? So, slowly just to illustrate that various points are plotted after every 500 points I have put a sleep command a sleep is another inbuilt function in Ubuntu. After the word sleep in bracket you write some number those many seconds it will sleep. So, in fact it is worthwhile. So, here you see if count module of 500 equal to 0 sleep for 1 second that is what I have stated. Suppose I just command this recompile this and run it again it will draw it quickly. So, it is drawing a sign graph, but you can draw any graph. Notice that the points which are drawn here are different from the points which you drew in earlier graph for the ECG there the points were sort of small rectangular block. Here I am using a different technique of remember what I said that you cannot draw points in easier window. So, either you draw a small rectangle to show a point here I am drawing a line from a point to itself. So, that becomes a point it is cheating. So, these are various programs we shall see the graphic classes and how to use them and so on. Now, this is what you can do. So, most of you if you wish to add any kind of graphical user interface or any kind of graphic display are most welcome to use this. There will be a tar file called ezwindows.tar.gz and the instructions will be there in the next week's lab handout. There is no regular lab no assignments, but use that all the sample programs will be there. So, you can actually compile see they make some modifications and actually read those programs to understand how graphic programming is done. The important point in any class library is that so far you know we are seen all the procedural programming paradigms if then else why to simplify matters we learnt how to write function definitions. The whole idea is how can I reduce the amount of text that I have to write in my program and yet achieve something remarkable. So, to reduce this I keep on looking for things which I have to do multiple times like a function call and then I say I write that function once and that is the end of it. In exactly the same fashion the object oriented paradigm extends that notion to permit you to define classes, member functions and objects of those classes. So, once the class properties are defined somewhere any object of that class that you define automatically inherits all member functions and you can execute those member functions. That is the reason why the graphic programming becomes so simple that somebody has thoughtfully prepared a large number of classes, defined all the member functions for those classes, defined all the elements for those classes. In fact, when you write your project programs you are expected to do that you can either use classes and class library functions or you can use conventional functions the choice is yours. So, we shall be seeing a few things before we look at the graphics thing which was supposed to be at the end. We will look at another preprocessor macro which is an extension of hash define and then we will revisit the notion of classes and objects in the process we shall see another important class library which is provided by C plus plus called string library. We shall see how the facilities compare with our conventional handling of strings a very brief exam and then of course we shall spend some time looking at the graphics using these air windows. So, here is the notion of preprocessor macros you are familiar with these you know if I said preprocessor macro name followed by a sequence of tokens. Sequence of tokens is a keyword it is actually a list so far we had used only one item say 45000. Remember last time we discussed this that if I say hash define max size 45000 and later on in my program if I say int field data max size an array I am defining with max size as the value and then somewhere else I have for int k equal to 0 k less than max size etcetera. So, I might use max size many times in my program, but because of this hash define macro physically all the max size occurrences will be replaced as if in a g edit find and replace by the number 45000. So, this helps as I said you can define a fixed size or typically max height max weight or whatever such parameters once and use them many times and if you want to change that you need to change only once in your program recompile and everything will work. There is a greater usage of such preprocessor macros because these macros also permit parameter substitution parameter definition and parameter substitution almost like functions almost, but they are not functions because functions are invoked dynamically here the preprocessor macro is invoked in the preprocessing state before compilation. So, let us look at one of these is called a parameterized macro a parameterized macro will have a macro name followed by certain parameters and these list of tokens will use those parameters for defining what the replacement is going to be. Consider this for example define absolute x. So, absolute is the name of the macro x is a parameter and wherever absolute something occurs in my program it will be replaced by the right hand side instead of x that something will be there. What does this macro do if x is greater than equal to 0 question mark. So what is the value of this expression you remember this kind of if statement this condition is evaluated if it is true the value of the expression is the first value written if it is false the value of the expression is the second value all that it is doing is it is setting the value to either x if it is positive or minus x if it is negative in the process it is getting absolute value of x. Now every time I need an absolute value I will have to write this kind of expression or I will have to put an if statement if z greater than 0 then exp value equal to z else exp value equal to minus z and then use exp value wherever instead like the abs function in built in library of c you have absolute definition of yourself now if within the program suppose you write this statement z is equal to 5 star absolute y minus 73.5 the physical occurrence of absolute y will be replaced by this. So this is compiled before compilation so your text itself will change and then this text will go to the compiler of course it will correctly compile you can of course write macros with multiple parameters and all those parameters will be taken remember it is not that this x is replaced by all of this. So this y is replaced by all it is not a single character replaced it is absolute bracket x bracket. So the word absolute is to be replaced but what it will be replaced by is decided by this and instead of x whatever parameters you have given will be used for it. So this is clear simple we look at another class in c plus plus called the string class and the string library this is completely different from the conventional library that we have been using which is called what c string. So we say include c string in our programs this is the library that we use and so far how we have been denoting or representing strings we represent strings as a null terminated sequence of characters stored in an array. So you have to take the responsibility of defining a large size array then push characters one by one whenever the last character of a string goes in you have to push a backslash zero c in and c out statements for example automatically include a backslash zero at the end. Similarly whenever you want to operate upon those arrays you have to actually keep looking at those characters individually terminate your processing when you encounter a backslash zero. There are built in functions like string compare string copy etcetera they all depend on the fact that there is a backslash zero at the end and there is no normal operator available you want to concatenate two strings why cannot I say my final string is equal to this string plus this string of course that plus should not be meant to be a addition of numbers. So if I use plus in the context of such strings it should mean concatenate now how do I convey this meaning the notion of classes permits you actually not only to define member data elements not only to define member functions but it also permits you to redefine operators for that class. Now since plus is already defined as an operator for addition if you redefine that it is called overloading the operator like you have a truck which is already carrying lot of luggage you put one more package on top of it you are overloading the truck now that package is different from other package it is exactly the same fashion if the symbol plus is used in normal arithmetic it will mean plus in any C plus plus but if you use it in the context of strings of this special class then it will suddenly mean to the compiler that concatenation is implied let us look at some example string class that is the name of the class. So the library that you use is not C string you have to say include string the string class itself is defined in C plus. So let us see the definition you say include string here string means get the string classes of C plus plus library I want to use them. So let us look at how it is being used I am now defining C string is a class so I can define objects of the string class the string class is actually normal string that you deal with but you do not have to worry about backslash 0 nothing like in fact you do not even know how these strings are internally reprinted you do not even know that is a private data member of that string you do not have to worry about how it is reprinted. So you just define objects let us say str1 str2 str3 these are three string objects each one of them can contain a string what is the maximum size of the string you do not have to worry about it it is a implementation dependent size it is a very large size you can actually assign two string one or any one of these objects any string of it you do not have to worry about of course if there is an exception the system will crib about it later notice what I am doing str1 is equal to computer this is not an assignment I am making to a character array which must be done only at the time of definition this is an assignment I am making to a string object and this is perfectly valid. So when I say str1 equal to something in double quotes that string becomes a value of str1 str1 now is a proper string object similarly str2 is equal to programming if I say str1 is equal to str1 plus str2 str3 equal to str1 plus str2 this plus is the concatenation of notice this c out str1 less less two spaces less less str2 what does this c out produce this will produce on the output computer blank blank programming right. Because I say c out str3 what will I get so there are a few subtleties which you must keep in mind blank spaces in between two strings are never automatically put together. So you need to put them separate you can actually do something like str1 itself you define to have a blank here or while concatenating nothing prevents you from saying str3 equal to str1 plus double quote blank double quote plus this because double quote blank double quote is a string constant. So just like you are saying c out the difference in c out and this is that c out will merely print strings in a legible fashion but internally if you want a composite string computer space programming as a single string you can't have it without concatenating. Now you will recall that if I have a first name middle name last name of a person it was greatly difficult for me to extract these and put them separately and so on. I could actually have a data structure in which first name is stored separately last name is stored separately and yet I could create a full name equal to first name plus blank plus second name and that would become a valid full string with full name I can do variety of things like just as you have functions in classical c string library to compare strings to concatenate strings etcetera. There are some functions in string library as well however c plus plus still depends largely on the classical method of representing strings. So what it does simply is it provides a special function called c underscore string what it does it will take a string object from the class library and convert it into an array of string with backslash 0 at the end. So you can take any string convert it into a regular array and then do whatever processing that you want to do normally later on you can again assign it back to a string object you will get that object back. We again visit the notion of application programmer interface because that is the most important conclusion that we can derive out of all the studies of different elements of programming that we have seen so far namely while we can write programs for anything and everything detailing every small action that we wish to take it makes a lot of sense for us to rewrite to write some commonly used statements together originally we saw that as a function now we know that we can do that as a class library with class member functions. Now whenever you write functions in the classical style of c plus plus or whenever you define classes and member functions the function names actually provide you with a application programmer interface. That means when you write your main program you are actually invoking only that function name with parameters function name with parameters and you are only defining either objects or variables of the specific type that you have. So these function names and the parameters that you need to pass to functions and how the functions behave becomes an application programmer interface problem. In fact I would say if is a application programmer interface problem because if you say if x greater than 0 something then the c plus plus defines how that particular segment will behave. So every statement in some sense is a application programmer interface but most of the statements are direct instruction and API is a higher level abstract considering this the modern programming of any professional style actually attempts to define as many APIs as you can that is part of the design of your project or design of a large programming system unlike normally when you start writing a program for anything that any problem that comes here you will first think of writing either functions or classes and member functions and you may not write the full details of the implementation of each and every function or class but you should write that prototype what you are doing you are defining an API. They are saying that while developing this project while developing this large program these are the APIs that I will use that you can define at the design stage. Now somebody else may have a responsibility of implementing those APIs. So writing the detail functions writing the detail doing the detail testing etcetera. Now API is a very common term in most professional programming. EZ window happens to be a package which has taken this API to heart what they have done is they have assert the int main routine int main routine when you use EZ windows cannot be written by you they say we write it instead they say you have to write a program called API main and link that with my library which contains the main. So that is a peculiarity it is normally not so normally you would be entitled to write your main program and combine it with other APIs through the class libraries through the function libraries etcetera. In a nutshell then any API will consist through functions. So prototype function definitions and the parameters must be known or public member functions of classes which also constitute an API. It is in this context that we look at the graphics. Remember last time I mentioned very briefly what a graphics window system would be. So basically we want to deal with graphic objects we want to draw graphic objects on our screen. We typically draw these graphic objects in some windows. So whenever you work on Ubuntu for example you will open a editor window you will open a terminal window you may open a browser window for files and you may say click here for this file edit it save it there go to terminal compile it run it these windows help you. So far in all these windows you have been displaying editing and using text but the fact that text is being displayed in different windows the fact that windows are being displayed with some borders should tell you immediately that there must be some basic graphical capabilities available with the system. As a matter of fact all systems after it was discovered that you could handle pixel level drawings on a monitor. The early monitors were not like that the early monitors could display only text nothing else. But when these graphic monitors came into being operating systems and programming languages realized that I should be able to exploit this facility and show some graphics. Various graphic libraries were built at the PC level or at the personal computer level these were the first ones to be built. In fact the first major graphics was built by Apple computers way back when their first Apple machines were meant to be used by individual people. Microsoft followed suit and of course Microsoft windows became the most popular operating system so people started using that. Unix which was originally not meant to be used by individuals it was meant to be a server class operating system did not pay attention to graphics and audio for quite some time. However somewhere around 80s and 90s a major project was undertaken in some universities in the US and in AT and a graphic library or graphic system got developed which is called X 11 graphics. So X 11 is the name to the base root graphic facilities in any Unix machine. X 11 is not very easy to use directly it was meant for programmers with high exposure to that kind of handle. Now people wanted something simple to use so a large number of graphic packages were then developed around X 11 to give you simplified facilities. EZ windows is the simplest of the simple packages which actually uses X 11 at the base. It permits you to draw different windows, it permits you to draw different shapes like rectangles, circles, lines etcetera, permits you to write text strings, permits you to draw bitmap images. This such packages are developed and used. Now EZ windows is actually a library of classes. So it is not a library of functions. The API is not a function called where the functions are the API is a class interface. So what you have to do is you have to use all the classes which are defined in EZ windows in your program define objects belonging to those classes and operate upon those objects using the member functions which are defined for those classes. So as long as you understand what are those classes what are the properties of those classes and how do you invoke member functions you are done everything else will be taken care of by the library. As I mentioned you need to name your main function as int api main you cannot name them as int main that is the requirement of the class library EZ window. These are the basics we had seen last time I may want to draw some shape some window inside my screen. So the window will have width and height and window will have certain position and window will have some text which is written on top. So this is a simple window. Having drawn a simple window I might want to draw various shapes here. I want to write some string here. These are the facilities I want to learn how to use such facilities in the graphics window. So here is something that we had very briefly seen last time. EZ windows is the library name and the major class is a simple window class. A simple window class permits us to define a window object. I can have as many windows as I want and I can render all of those windows keep all of them alive and draw something in one window something else in other window something else in third window etcetera etcetera. Each window will be an object of the windows class. Remember EZ object is independent. Each object is worked upon by the member functions of that class. So in one window I can draw a rectangle, one window object, another window object I can draw a line whatever I wish to do. The basic way of defining an object of say W of this class is to say simple window W and then I write some name here sample window CS 101 window, my window, abrakad abrakad whatever. This becomes the title that will come on top of that window. Please note that the window style is frozen. You cannot control it. The window style is a boundary then a line somewhere and a text title that you specify is written somewhere. The font of that text is frozen. You would like of course when you become professional programmer you would like variety of freedom in that. Why do I have to write font in a small size when I write text inside the window? Why does the title font come like that? Can't I change the font? Can't I change the style? I should be able to but EZ windows does not permit. There are other windows packages which will permit that. Once you define an object called W all the member functions of that class can operate upon that W. So W dot open is a is a is a W dot close is a F. Here I have specified something called width and height but you can also specify the position where this window should appear. If you don't prescribe the position there is a default. Incidentally when you download EZ windows there is a whole lot of documentation available which describes every class every member function of the class the meaning of the parameters in those member functions and what is the behavior what are the return values etcetera etcetera. I would suggest that you should read that entire manual first as a storybook and then maybe attempt to look at executing some of those programs some of those features. Here is a rectangle class remember a rectangle class is a different from window class window itself is rectangular but that is incidental. Having drawn a window say W inside that W you want to draw a rectangle. So how can you do that? First of all you have to specify the window in which it is to be displayed because you might have multiple window objects in that window what is the position in which you want to draw the rectangle which color you want to draw that rectangle and the width and height of a rectangle. So once you specify this the member function which can draw rectangle can actually draw this. There are several member functions draw is the major function. So once you define the attributes of a rectangle object remember rectangle is a class. So you have to define a rectangle object once you define a rectangle object with these parameters it can be drawn it can be drawn where in the window in which you have specified that object. Draw is a plane draw suppose you have drawn suppose you have drawn multiple things now you know somewhere briefly that in this window W 3 there is a rectangle object called R 5 but I have forgotten how I have drawn this R 5 or may be a friend of mine in the project has drawn this R 5. So I do not know what color he has where it is drawn etc. I would like to enquire from the EZ window system where have you drawn this I can do that by running any one of these functions get color will get me color of that object get width will get me width of that object get height will get me height of that object here is a sample program. So I mentioned sample program I am just describing a few simple samples the detailed of S 1 S 2 S 3 S 4 S 5 S 6 S 7 all of these I will be uploading it by tonight. So it will be available along with the tar file that you get for graphics you can use it apart from these there are various samples that are already available. So here is a definition I say simple window W my first window W dot open type any character to remove it either controls here some there is a small problem in EZ windows package the program you will be executing on terminal window which is one window when you execute this program another window will be drawn. Now typically that hidden cursor actually goes to that window no input can be accepted from your terminal because that window is not alive at this moment the new window which are drawn is alive. So you have to actually drag that pointer by mouse click on to your terminal window and then type a character to terminate this particular how do you write a text in a window. So this is your larger screen and this is your window. Let us say this is my window and in that you wanted to write a string like we saw namaste CS 101 students. Now the way you write a text is you first define a bounding rectangle for the text. This rectangle is not a rectangle shape you define the position of some winding points that left corner is here left upper corner is here right lower corner is here within that text whatever within that bounding rectangular space any text that you write will be displayed. So this bounding rectangle is a hypothetical thing it is not visible to you you have to define this position and this position and once you define this position and say please display this string here the string will come here for example namaste whatever whatever what a string you write here is a program which does that notice that I am creating a 15 by 10 window notice that the system that E Z windows follows is that first width and then height is written. So 15 is the width 10 is the height notice that this simple window H W which I am opening this H W is short for hello window I want to say hello to my students so H W CS 101 window is that title that will appear in that window this will be the width and height and additionally I can specify parameter position. So 1 comma 1 means that the whole window with respect to the screen will start at 1 comma 1 this 1 2 15 10 etcetera are not pixel value these are centimeters actual centimeters can you tell me why it is not pixels and why it is centimeters first of all pixels are often relative to a particular hardware that you are using suppose your computer has a large resolution number of pixels will be 1800 6 by 1600 a small machine like this it may be 700 by 600 so it is very difficult to write in terms of absolute pixels. Secondly things become hardware dependent also on what is the pixel size a centimeter is an absolute unit it does not matter on which computer you run this for that computer that library will automatically convert these centimeters into appropriate number of pixels depending upon the current resolution that you have set for your hardware and that is why easy windows uses size in centimeters of course you can write fractional centimeters it will appropriately compute. So here I am defining a simple window H W this object is defined here in my main program when I say H W dot open this window will be open that means this window will be created next you remember I have to define a bounding box for that text. So this is what I do here I first I want to write my namaste CS 1 on students in the center of that window now notice this I know there is a window called H W but I need not remember where that window is the absolute position on the screen of my text will depend upon where that window is if window is somewhere here the text should be here window is somewhere there text should be there how do I know where the window is I want to find out the center of the window for that there is a thing called get center. So for any window when I say get center this member function will get me x and y coordinates of the center point of that window automatic now that I assign to another class object called position position class I name an object called center I could have said x y whatever I wanted this center is not a simple single value this center has x and y coordinates that is the definition of the member data elements of class position. So position also is a class so I extract into the position class member center I could have said position center semicolon and later on I could have said center equal to this but I am initializing it in the class member definition itself. So center is this now I create the bounding box for that text. So position upper left position lower right remember position is a member so it is instead of saying x 1 y 1 x 2 y 2 position means some x and y. So I call it position upper left I a member of the class and that is equal to center plus position this. So notice that in classes I can actually handle two points to be added center is a point position minus 1 minus 1 is a point. So what I am doing with respect to center I want to go minus 1 minus 1 and that becomes my left corner similarly with respect to the same center I want to go plus 1 plus 1 that will become my right corner and in this two centimeter by two centimeter box I want to write my text. So the notice how the arithmetic is being done it is not normal arithmetic okay having done that I can display the text for which there is a member function called render text h w is my window object it could have been any windows if I have five windows in any one window I can use that window dot render text and whatever I write will be rendered there. Render text require these parameters upper left lower right these are positions okay is not x coordinate y coordinate x coordinate these are positions which incidentally have x and y coordinate and then I write the string and I can also specify in which color I would like to write this. Unfortunately e z windows being a simplistic system it does not permit me to write millions of colors although the underlying x 11 windows permits you to draw individual pixel with any color e z windows system because it is limited to simple shapes text etc etc it does not permit them. So it permits some few colors which have been named specifically red blue green black these are the colors which have been named then what are the names they are also available you can use those. So is this clear how do I draw a rectangle I want to display points with labels so here is this is my window as I said there is some text here some title now in this window I want to draw points as I mentioned to you there is no member function which says draw point or draw a pixel. So I will approximate a pixel by a rectangle suppose I want to draw a point here let's say somewhere here I will draw a small rectangle which is visible to me I can draw it in any color so that that particular blob rectangle or blob is visible to me just drawing a point in any kind of representation is not very meaningful because I want to write some associated text with that point so that is like text but it is called a label for that point and I can write that label somewhere here along with these are the facilities that I seek let us see how do we write these points and labels notice the way I am mixing the conventional data structures such as character strings and the classes here I am defining a function called display data is my function what are the parameters of display data first parameter is a pointer to simple window so whichever window I want to display data in w h w w 1 whatever then I have an integer array it's a multi-dimensional array many rows and two columns two columns will contain x coordinate and y coordinate. So these are the electrocardiogram points that I have got I call them ECG signal notice the way the parameter is passed ECG signal name itself will be a pointer but when you pass a two-dimensional array the exact nature of the two-dimensional array storage is not known to the called function unless it knows the columns and rows it so happens that if it knows number of columns that is sufficient for it to calculate the pointer addresses because the storage is always row major why so first row if there are two columns then first element 0th element first element then 0th element first element 0th element it is known only columns need to be specified explicitly you can of course also specify the rows that is not objected to but this is one way of doing and then there is of course something called size which is the actual number of rows which are used remember in your declaration you may have a 500 points thousand points of water so as many points as you what am I doing I am saying for i equal to 0 to size minus 1 I am getting the x coordinate as i 0 and y coordinate as i 1 apparently somebody else would have assembled this entire array of positions x and y for those points having got these I want to draw a point so I define a point to be an object of rectangle shape you get my point rectangle shape is a class of that class I define an object which I call point it is a incidental name I could have called it anything P R1 whatever what now this point has which are the parameters of this when I create this object I am specifying z x y blue 0.1 0.1 that means x is this y is this blue is the color 0.1 to 0.1 and in which window I want to draw it the window pointed to by z and z is the pointer I have got z is the name of the window so z is the name of the window remember this does not draw a point this merely defines an object but this object is being dynamically instantiated in my program in the within the executable I am creating an object now this is something fundamentally different from defining your arrays and int and float variables you can define something in between but all those definitions are instantiated at the compile type after compilation there is no new memory allocation no nothing happens in case of classes and objects your objects are dynamically created any memory that is required to hold information about an object is demanded by your compiled program from the operating system give me so many bytes I want to create this object the operating system will give you so many bytes and this object will be created so this object is created using dynamically available values of x and y and having created that object now you said draw so point is the object point dot draw means draw that point this point will be drawn now you want to put a label to that point you are defined a car array my string 80 the printing of label is you print a string first s print f that means print a formatted string using I which is the point number and x and y coordinates and this you are printing as percent 2d percent 2d percent 2d you have inserted a character at so you will actually get say 5 at 10 comma 20 so 5 is the fifth is the point number at is the word it's this is the string now this string instead of rendering it as a text line which we had seen you can render it as a label item label is another class so you are creating a object of class label called item what are the parameters for this class objects first the window in which you want to draw second the bounding parameter the same thing left corner sorry sorry this is x plus point 2 y plus point 2 so this is not the this is not a bounding box that you write in the text but this is the starting position where you want this label to add up here what you are defining is that if my point was somewhere here then just below it I want to write this so it says x plus point 2 y plus point 2 my string so this string will appear there you saw that example will once again go very quickly through those demonstrations so you will see exactly how this program executes and renders it once I define this item I again have to say item dot draw it will draw that displaying patterns you had suppose this is your window and the point is if you draw a line first this line then let's say from here to here then here to here then here to here and here to here so you will see some pattern emerging like this what this program is doing is it is drawing lines like this first drawing from horizontal line then you go down y and before the last point of x so you draw another line and last line drawn will be this vertical so you will get a pattern like this then I am also plotting in the same program a mirror image so I am plotting lines which start from the right most corner here so I draw this line first then maybe this line then maybe this line maybe this line etc whatever and I will get another pattern so it is the other way that I write this line this line and so on let's see that pattern here is the way I am drawing those lines notice the use of assert library which is useful even here what I am asserting here my window dot get status get status is another member function this get status tells you whether window open or window closed so I want to it's just like file is open or file is closed so if I say window dot get status it will it should be window open if it is not window open I want to assert that I want to say that assertion has failed I want to get out I define x y and i j as float and I draw some lines to create an interesting pattern my window is 15 by 15 so notice what I am doing I am running a loop from x equal to 0 to just 15 less than 15 in steps of point now on my window I first render a line from position x 0 to 0 15 minus x as x changes you will notice that this line will also shift like this first directly here then here then here and this I draw in black simultaneously I render another line which is 15 x and 15 minus x 15 so 15 x x will be 0 initially so this becomes a y coordinate so I am drawing a line starting with x equal to 15 y equal to 0 going up to x equal to 15 minus x that is 15 only and up to 15 so 15 0 15 that is the line I am drawing so full vertical and then accordingly that line will also shift so when I complete this iteration it would have drawn a large number of lines creating the pattern that we we saw we will see that again displaying shapes again the same thing we already seen how rectangular shapes are written drawn but I can actually draw triangular shape with some color inside I can draw a line I can draw an ellipse for each of these these are all separate classes defined rectangular shape line ellipse etc etc for each of these there are member data elements that means there are some parameters by which you prescribe those values and again render line render ellipse or draw all such member functions are available how do I display bitmaps is my window and I want to I have a photograph now photograph will be in a file so let us say I have a file called pick dot j p j agreed is the most common file I will have from any digital photograph first I will have to write it use a convert utility which is part of this program and get this file converted into pick dot x p m x p m is a file format with which the easy windows can deal with so easy windows a member function which says load a bitmap with this file so what that easy windows member function will do is it will open that file read all the pixel specifications and draw those in whatever area you have defined so this will be actual picture how it can do that it then permit you to draw pictures it then permit you to draw millions of colors but remember it is ultimately based on x 11 window system which can do everything x 11 has a fundamental facility of what is known as raster image drawing raster means going point by point point by point and drawing something all that is that windows apparently is doing is it is invoking that facility and taking pixel data from the image file and putting it so you can draw bitmaps anywhere that you want any bitmap that additionally what that program does is that that program actually draws a bitmap then permits you to move the mouse somewhere and says you click oh you want that bitmap to be redrawn here so how how does that picture move actually picture cannot move so what you do is you erase that picture and read all that picture at new police so it appears as if the picture is moved and you can do variety of very interesting graphic things you can actually give an appearance of movie so many animations for example like if you are simulating the movement of a ball under gravitation when it is thrown so it will come out here bounce back go further bounce back you can actually show different points and show the ball and you erase redraw erase redraw erase redraw so it will keep moving like that you can actually demonstrate an animation here is a standard definition of a window that we often use say window 1 25 by 15 position 1 comma 1 now I define a bitmap object so bitmap is another class remember the nomenclature it typically is first letter capital and some other word letter capital incidentally my colleague miss feroza has written a set of coding standards so I will be putting them up and it is expected that when you write your programs you try to adhere to those coding standards so that programs written by anyone will look very similar in structure similar in nomenclature that is a mandatory requirement in professional programming environment we would like you to learn part of it so bitmap is a class and of that class you are defining an object called w 1 b m p and this object is stacked to the window w 1 which I have defined that means whenever I ask the system to load that bitmap or draw that bitmap it will be drawn in w 1 because w 1 is implicitly associated with that object called w 1 b m p this w 1 b m p is my name I could have given any name to it the way I display bitmap is like this I say w 1 b m p dot load scene 1 dot x p n this is an absolute filename which means it must be in the current director so as I said the scene that you saw was the was the scene from some picture from my camera I use the convert to convert it from j p j to x p m I have got several other things which we will see that you remember I had shown you a fingerprint image a fingerprint image in e z windows can be displayed like that I have a robo picture sony is the name of my esteemed colleague is a professor he was like you one of my students in c s 101 course he is the first one to introduce e z windows in c s 101 when he taught it most of the programs that I am demonstrating were originally written by him I have merely modified them it is only appropriate that we see his photograph in the demonstrations so you see that what I have done is in the sample programs all the files are there and these are all commented so you can simply remove those comments recompile and run it of course a far better technique would be in actual practice you want to show different pictures in your windows you should ask for a file name as input take that file name which is a normal string and put that string array of characters here as a parameter and it will open them so these are all definitions of bitmaps when you load nothing gets displayed all that is happening is that w 1 b m p object which was defined by you as a bitmap object now contains data from the file so load merely means inside memory you have an object defined the data is on file b m p load dot load will mean take the data from that file and put it inside this object bitmap object later on when you say w 1 b m p dot set position and w 1 b m p draw so this will set the position initially it will draw at 1 point 0 1 point 0 and then it will any position that you give it will draw at that point and this is the exact issue that if I want to keep the image moving if I change this position then it will draw at that position but I must first erase the image so just like w 1 b m p dot draw will draw w 1 e b m p dot erase will erase plotting graphs we do not have a function to draw points we used rectangles earlier now we will use to draw a line using w dot render line w is a window in which I am drawing a line line is from position to position but if I give the same position here and same position here then obviously it will be a line from point to point and hopefully I should get the point this is blue what is this 0 point 0 this is being defined as absolute x and y okay I will leave it to wonder you just look at the documentation for line render line see what those parameters are you will find out it is it is trivial before I shift over very quickly we will see we have seen most of the samples I just show you the last few ones to tell you how they work but this is how you use z window there is a tile dot gz package instantly this package also works on windows environment there is another version available so those of you have windows machines at home you can try and use them but Ubuntu this is how it will work so you should compile and link your programs using a special script api compile so instead of saying c++ you should say api compile myprog not myprog dot cpp I will tell you the reason in a moment okay so the program is myprog.cpp and it will create an executable called myprog you can simply run it by dot slash myprog okay this is the reason why you should not give something dot cpp remember I told you the compilation phase consists of preprocessing then compiling then assembling and linking here I have shown different portions in api compile there are different commands api compile is known to be a shell script so when you try api type api compile actually the commands in this file get executed one after another the first command is c++ minus i user x11 r6 include minus i something something so this tells the compiler that before you compile include these files just like your include dot you have said include something dot h include c string normally c++ will automatically include some standard libraries you have given include here also you would have include statements in your main program but where is the location of those that depends on where your ez windows is the way you will style your location is you will install this package you will have a ez windows directory in which there will be include lib etcetera etcetera and there will be a samples directory where your sample programs will be there so notice that I am saying include this x11 r6 x11 is the base library revision six of them that is not with you that is somewhere in the main system that is why slash user slash x11 r6 slash include but this says dot dot ez windows slash include that means I am in the samples directory above me below next to me is a include directory which is part of ez windows so I go first go to ez windows and go to this include it minus c so this means you just compile do not create a final output assemble pro link program so minus c dollar one dot cpp will create dollar one dot o that is the object now it says c++ minus o create an output file called dollar one using dollar one dot o and then link it with user x11 library minus x11 minus l dot dot ez windows dot lib minus l ez windows slash user slash lib etcetera etcetera all these additional libraries get created when you install the package so this is the program which draws a this professor sony this photograph I think belongs to the time when he was like you a student here but he currently heads the sitara and a world renowned authority in basic algorithms and so on so we can also keep moving sony wherever we want there was another one where I have a small bitmap image of a robo so these are our robo and robo can be made to dance like this now here in this program I am moving it as per the mouse click nothing prevents you from writing your own ingenious algorithm whereby you can make the robo dance around nothing prevents you from drawing a maze and make the robo walk through that maze nothing prevents you from writing a complicated intelligent algorithm to figure out what should be the next step that means that robo should take and make the robo move there now what we are looking at are display characteristics how to handle display underlying any project that you do there has to be a lot of interesting and useful computations that you do independent combine that with this and you get a absolutely production grade industry grade professionally written software so that is why it may be useful I thought you would like to use that there was a shape thing I think you look at these shapes there could be many shapes that you could draw any kind of shapes you could draw here I have drawn a red rectangle and then a white rectangle on top if I had drawn this line earlier this portion of the line would have gone since I have drawn this line later it superimposes on this you can see variety of graphic characteristics so in conclusion I will say that using the easy window classes and class libraries you now have a reasonably good facility to handle any kind of display that you want to look at last year people created using the same easy windows snakes and ladder boards they actually showed the movement of coins there the people who have done all all kinds of crazy things using this ok you are most welcome to use them thank you so much