Quote:

The amount of happiness that you have depends on the amount of freedom you have in your heart

Monday 26 December 2011

CS602 – Computer Graphics Assignment 3 Fall2011

Assignment No. 03
Fall 2011
CS602 – Computer Graphics
Total Marks: 20
Due Date:
December 28, 2011
Question                                      20 marks
In the handouts of CS602 – Computer Graphics many examples are given in which GRAPHICS.H Header file is used. If you compile the given code in Dev-C++ IDE / Compiler the errors are reported because the given code is using GRAPHICS.H which is originally provided by Borland (www.borland.com). But there are ways to compile that code on Dev-C++. For this purpose you can consult the following tutorials:

  1. http://vulms.vu.edu.pk/Courses/CS602/Downloads/DevCppTutorialGraphics_h.pdf
  2. http://www.uniqueness-template.com/devcpp/

You are required to compile the given code after following the above tutorial and submit the following files in zip archive:
  1. Dev-C++ Project File (e.g. Project1.dev)
  2. C++ Source (e.g. main.cpp)
  3. O/Object File (mian.o)
  4. Makefile.win
  5. Executable File (e.g. Project1.exe) it is much necessary as a proof that you have successfully compiled the code.
  6. Microsoft Word File explaining the code.


Source Code:
#include <graphics.h>
#include <iostream>
#include <conio.h>
#include <math.h>
float round(float x){
      return x+0.5;
}
class Table{
private:
        int xc, yc;
        int xp, yp;
        int x1, x2, x3, x4;
        int y1, y2, y3, y4;
        int legLength;
        int sfx, sfy;
public:
Table(){
        xc=320, yc=240;
        xp=0; yp=0;
        x1=-10, x2=10, x3=10, x4=-10;
        y1=-7, y2=-7, y3=7, y4=7;
        legLength=10;
        sfx=1, sfy=1;
}
void translate(int tx, int ty){
        xp+=tx;
        yp+=ty;
}
void rotate (float angle){
        int tempx=x1;
        x1=tempx*cos(angle)-y1*sin(angle);
        y1=tempx*sin(angle)+y1*cos(angle);
        tempx=x2;
        x2=tempx*cos(angle)-y2*sin(angle);
        y2=tempx*sin(angle)+y2*cos(angle);
        tempx=x3;
        x3=tempx*cos(angle)-y3*sin(angle);
        y3=tempx*sin(angle)+y3*cos(angle);
        tempx=x4;
        x4=tempx*cos(angle)-y4*sin(angle);
        y4=tempx*sin(angle)+y4*cos(angle);
}
void scale(int sx, int sy){
        x1=x1*sx;
        x2=x2*sx;
        x3=x3*sx;
        x4=x4*sx;
        y1=y1*sy;
        y2=y2*sy;
        y3=y3*sy;
        y4=y4*sy;
        legLength=legLength*sy;
}
void draw(){
        int xc=this->xc+xp;
        int yc=this->yc+yp;
        line (xc+x1, yc+y1, xc+x2, yc+y2);
        line (xc+x2, yc+y2, xc+x3, yc+y3);
        line (xc+x3, yc+y3, xc+x4, yc+y4);
        line (xc+x4, yc+y4, xc+x1, yc+y1);
        line (xc+x1, yc+y1, xc+x1, yc+y1+legLength);
        line (xc+x2, yc+y2, xc+x2, yc+y2+legLength);
        line (xc+x3, yc+y3, xc+x3, yc+y3+legLength);
        line (xc+x4, yc+y4, xc+x4, yc+y4+legLength);
}};
int main(){
        //clrscr(); //it is not needed in DevCPP
        int gdriver = DETECT, gmode, errorcode;
        initgraph(&gdriver, &gmode, "c:\\Dev-Cpp\\lib");
        Table table;
        table.draw();
        setcolor(CYAN);
        table.translate(15, 25);
        table.draw();
        table.translate(50, 0);
        table.scale(3,2);
        table.draw();
        table.translate(-100, 0);
        table.rotate(3.14/4);
        table.draw();
        getch();
        closegraph();
return 0;
}

No comments:

Post a Comment

“You can't change the past, but you can ruin the present by worrying about the future”