Tuesday, October 27, 2020

Drawing a circle using OpenGL

 // C program to demonstrate

// drawing a circle using

// OpenGL


#include<stdio.h>

#include<GL/glut.h>

#include<math.h>

#define pi 3.142857


// function to initialize

void myInit (void)

{

// making background color black as first

// 3 arguments all are 0.0

glClearColor(0.0, 0.0, 0.0, 1.0);


// making picture color green (in RGB mode), as middle argument is 1.0

glColor3f(0.0, 1.0, 0.0);


// breadth of picture boundary is 1 pixel

glPointSize(2.0);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();


// setting window dimension in X- and Y- direction

gluOrtho2D(-780, 780, -420, 420);

}


void display (void)

{

glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_POINTS);

float x, y, i;


// iterate y up to 2*pi, i.e., 360 degree

// with small increment in angle as

// glVertex2i just draws a point on specified co-ordinate

for ( i = 0; i < (2 * pi); i += 0.001)

{

// let 200 is radius of circle and as,

// circle is defined as x=r*cos(i) and y=r*sin(i)

x = 200 * cos(i);

y = 200 * sin(i);


glVertex2i(x, y);

}

glEnd();

glFlush();

}


int main (int argc, char** argv)

{

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);


// giving window size in X- and Y- direction

glutInitWindowSize(1366, 768);

glutInitWindowPosition(0, 0);


// Giving name to window

glutCreateWindow("Circle Drawing");

myInit();


glutDisplayFunc(display);

glutMainLoop();

}

Output:



Scanline Polygon Fill Algorithm

 


#include<GL/glut.h>

#include<stdio.h>

float x1,x2,x3,x4,y1,y2,y3,y4;


void draw_pixel(int x,int y)

{

    glColor3f(0.0,1.0,1.0);

    glPointSize(1.0);

    glBegin(GL_POINTS);

    glVertex2i(x,y);

    glEnd();

}


void edgedetect(float x1,float y1,float x2,float y2,int *le,int *re)

{

    float temp,x,mx;

    int i;


    if(y1>y2)

    {

        temp=x1,x1=x2,x2=temp;

        temp=y1,y1=y2,y2=temp;

    }


    if(y1==y2)

        mx=x2-x1;

    else

        mx=(x2-x1)/(y2-y1);


    x=x1;


    for(i=y1;i<=y2;i++)

    {

        if(x<(float)le[i]) le[i]=(int)x;

        if(x>(float)re[i]) re[i]=(int)x;

        x+=mx;

    }

}


void scanfill(float x1,float y1,float x2,float y2,float x3,float y3,float x4,float y4)

{

    int le[500],re[500],i,j;


    for(i=0;i<500;i++)

        le[i]=500,re[i]=0;


    edgedetect(x1,y1,x2,y2,le,re);

    edgedetect(x2,y2,x3,y3,le,re);

    edgedetect(x3,y3,x4,y4,le,re);

    edgedetect(x4,y4,x1,y1,le,re);


    for(j=0;j<500;j++)

    {

        if(le[j]<=re[j])

            for(i=le[j];i<re[j];i++)

                draw_pixel(i,j);

    }

}



void display()

{

    //x1=250.0;y1=200.0;x2=150.0;y2=300.0;x3=250.0;

    //y3=400.0;x4=350.0;y4=300.0;

    x1=50.0;y1=300.0;x2=300.0;y2=250.0;x3=250.0;

    y3=70.0;x4=70.0;y4=90.0;

    glClear(GL_COLOR_BUFFER_BIT);

    glColor3f(0.0,0.0,1.0);

    glBegin(GL_LINE_LOOP);

    glVertex2f(x1,y1);

    glVertex2f(x2,y2);

    glVertex2f(x3,y3);

    glVertex2f(x4,y4);

    glEnd();


    scanfill(x1,y1,x2,y2,x3,y3,x4,y4);


    glFlush();

}



void init()

{

    glClearColor(1.0,1.0,1.0,1.0);

    glMatrixMode(GL_PROJECTION);

    glLoadIdentity();

    gluOrtho2D(0.0,499.0,0.0,499.0);

}


int main(int argc,char **argv)

{

    glutInit(&argc,argv);

    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);

    glutInitWindowSize(500,500);


    glutCreateWindow("Scanline polgon fill algorithm");

    glutDisplayFunc(display);


    init();

    glutMainLoop();

    return 0;

}

Output:



Drawing a Wireframe using OpenGL

 


// C program to demonstrate

// drawing a hard wire house

// OpenGL

#include<stdio.h>

#include<GL/glut.h>

#include<math.h>

#define pi 3.142857


// function to initialize

void myInit (void)

{

// making background color grey as first

// 3 arguments all are 0.4

glClearColor(0.4, 0.4, 0.4, 0.4);


// making picture color green (in RGB mode), as middle argument is 1.0

    glColor3f(0.0, 1.0, 0.0);


// breadth of picture boundary is 2 pixel

glPointSize(2.0);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();


// setting window dimension in X- and Y- direction

gluOrtho2D(0.0,200.0, 0.0,150.0);

}


void display (void)

{

glClear(GL_COLOR_BUFFER_BIT);


glBegin(GL_LINES);

//horizontal base of the house

glVertex2i(50,0);

glVertex2i(100,0);

//horizontal ceiling of the house

glVertex2i(50,50);

glVertex2i(100,50);

//left roof top

glVertex2i(50,50);

glVertex2i(75,100);

//right roof

glVertex2i(75,100);

glVertex2i(100,50);

//left wall

glVertex2i(50,0);

glVertex2i(50,50);

//right wall

glVertex2i(100,0);

glVertex2i(100,50);


//Door top

glVertex2i(65,40);

glVertex2i(85,40);

//Door left side

glVertex2i(65,40);

glVertex2i(65,0);

//Door right side

glVertex2i(85,40);

glVertex2i(85,0);

    //Roof Box top

    glVertex2i(65,65);

glVertex2i(85,65);

    //Roof Box bottom

    glVertex2i(65,55);

glVertex2i(85,55);

    //Roof Box left side

    glVertex2i(65,65);

glVertex2i(65,55);

    //Roof Box right side

    glVertex2i(85,65);

glVertex2i(85,55);

//Out Box bottom left

    glVertex2i(0,25);

glVertex2i(25,0);

//Out Box bottom right

    glVertex2i(50,25);

glVertex2i(25,0);

    //Out Box top left

    glVertex2i(25,50);

glVertex2i(0,25);

//Out Box top right

    glVertex2i(25,50);

glVertex2i(50,25);



glEnd();

glFlush();

}


int main(int argc, char** argv)

{

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);


// giving window size in X- and Y- direction

glutInitWindowSize(800,600);

glutInitWindowPosition(0,0);


// Giving name to window

glutCreateWindow("Drawing a Hard wire House");

myInit();


glutDisplayFunc(display);

glutMainLoop();

}

Output:








Draw a circle inside a triangle using OpenGJ




// C program to demonstrate

// drawing a circle using

// OpenGL

#include<stdio.h>

#include<GL/glut.h>

#include<math.h>

#define pi 3.142857


// function to initialize

void myInit (void)

{

// making background color black as first

// 3 arguments all are 0.4

glClearColor(0.4, 0.4, 0.4, 1.0);


// making picture color green (in RGB mode), as middle argument is 1.0

//glColor3f(0.0, 1.0, 0.0);


// breadth of picture boundary is 1 pixel

glPointSize(1.0);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();


// setting window dimension in X- and Y- direction

gluOrtho2D(0.0,800.0, 0.0,600.0);

}


void display (void)

{

glClear(GL_COLOR_BUFFER_BIT);


glBegin(GL_LINES);

//set color to draw the triangle

glColor3f(1.0,0.5,0.0);

//first horizontal side of the triangle

glVertex2i(100,50);

glVertex2i(700,50);

//left side of the triangle

glVertex2i(100,50);

glVertex2i(400,500);

//third vertex

glVertex2i(400,500);

glVertex2i(700,50);


glEnd();


glBegin(GL_POINTS);

glColor3f(0.0, 1.0, 0.0);

float x, y, i;


// iterate y up to 2*pi, i.e., 360 degree

// with small increment in angle as

// glVertex2i just draws a point on specified co-ordinate

for ( i = 0; i < (2 * pi); i += 0.001)

{

// let 200 is radius of circle and as,

// circle is defined as x=r*cos(i) and y=r*sin(i)

x = 400+ 100 * cos(i);

y = 200+ 100 * sin(i);


glVertex2i(x, y);

}

glEnd();


glFlush();

}


int main(int argc, char** argv)

{

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);


// giving window size in X- and Y- direction

glutInitWindowSize(800,600);

glutInitWindowPosition(0, 0);


// Giving name to window

glutCreateWindow("Drawing Green Circle inside Orange Triangle");

myInit();


glutDisplayFunc(display);

glutMainLoop();

}



Output:



 

Cohen Line clipping algorithm

 



// C++ program to implement Cohen Sutherland algorithm

// for line clipping.

#include <iostream>

#include <GL/glut.h>

using namespace std;



// Defining region codes

const int INSIDE = 0; // 0000

const int LEFT = 1; // 0001

const int RIGHT = 2; // 0010

const int BOTTOM = 4; // 0100

const int TOP = 8; // 1000


// Defining x_max, y_max and x_min, y_min for

// clipping rectangle. Since diagonal points are

// enough to define a rectangle

const int x_max = 100;

const int y_max = 100;

const int x_min = 40;

const int y_min = 40;

int x1,x2,y1,y2;

// Function to compute region code for a point(x, y)

int computeCode(double x, double y)

{

// initialized as being inside

int code = INSIDE;


if (x < x_min) // to the left of rectangle

code |= LEFT;

else if (x > x_max) // to the right of rectangle

code |= RIGHT;

if (y < y_min) // below the rectangle

code |= BOTTOM;

else if (y > y_max) // above the rectangle

code |= TOP;


return code;

}


// Implementing Cohen-Sutherland algorithm

// Clipping a line from P1 = (x2, y2) to P2 = (x2, y2)

void cohenSutherlandClip(double x1, double y1,double x2, double y2)

{

// Compute region codes for P1, P2

int code1 = computeCode(x1, y1);

int code2 = computeCode(x2, y2);


// Initialize line as outside the rectangular window

bool accept = false;


while (true)

{

if ((code1 == 0) && (code2 == 0))

{

// If both endpoints lie within rectangle

accept = true;

break;

}

else if (code1 & code2)

{

// If both endpoints are outside rectangle,

// in same region

break;

}


}

if (accept)

{

cout <<"Line accepted from (" << x1 << ", "

<< y1 << " to "<< x2 << ", " << y2 << ") because its completely VISIBLE" << endl;

// Here the user can add code to display the rectangle

// along with the accepted (portion of) lines

}

else

        cout <<"Line rejected from (" << x1 << ", "

<< y1 << " to "<< x2 << ", " << y2 << ") because its completely INVISIBLE" << endl;

}


 void display()

 {

        glClear(GL_COLOR_BUFFER_BIT);

        glColor3f(0.0,1.0,0.0);

        glBegin(GL_LINES);

        glVertex2i(40,100);

        glVertex2i(40,10);

        glVertex2i(100,100);

        glVertex2i(100,10);


        glVertex2i(40,100);

        glVertex2i(100,100);

        glVertex2i(40,10);

        glVertex2i(100,10);


        glColor3f(1.0,0.0,0.0);

        //Visible line

        glVertex2i(50,60);

        glVertex2i(70,40);

        //Invisible line

        glVertex2i(150,100);

        glVertex2i(180,50);

        glEnd();

        glFlush();


 }

 void myInit(void)

        {


            glClearColor(0.0,0.0,0.0,1.0);


            glPointSize(2.0);

            glMatrixMode(GL_PROJECTION);


            glLoadIdentity();

            gluOrtho2D(0,200,0,200);


        }



// Driver code

int main(int argc, char**argv)

{

    cout<<" The coordinates of the clipping window are (40,100), (100,100), (100,10) and (40,40)"<<endl;

    // First Line segment

// P11 = (5, 5), P12 = (7, 7) completely VISIBLE(inside)

cohenSutherlandClip(50, 60, 70, 40);


// P11 = (5, 5), P12 = (7, 7) completely INVISIBLE(outside)

cohenSutherlandClip(150, 100, 180, 150);




    glutInit(&argc, argv);

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);


// giving window size in X- and Y- direction

glutInitWindowSize(400,400);

glutInitWindowPosition(0,0);


// Giving name to window

    glutCreateWindow("Cohen-Sutherland line clipping algorithm");

    myInit();


glutDisplayFunc(display);


glutMainLoop();


return 0;

}


output:



Thursday, October 8, 2020

Python String methods

Python methods for strings
  1.   title()
  2. capitalize()
  3. swapcase()
  4. find()
  5. count()
  6. replace()
  7. isalnum()
  8. format()

print(dir(variable_name)) gives all the functions that can be applied on the variable. If its a string variable, it will list all the functions applicable on strings. 

You can also use print(help(str)) go get all information about strings.

print(help.(str.find)) will give the details on how to use the find() function.

Python methods for objects:
  1. reverse()
  2. clear()
  3. add
  4. append()
  5. update()

Monday, October 5, 2020

MCA subject Video classes

  1. MCS  31 (Design and Analysis of Algorithms) 
    1. Introduction to Data Structures & Algorithms - IIT Delhi
    2. Introduction to Data Structures & Algorithms
    3. Sorting Algorithms & Asymptotic Analysis II - IGNOU
    4. Algorithmic Techniques for problem solving 2
    5. Stack Applications
    6. Queue Data Structure
    7. An introduction to trees
    8. DAA  - Abdul Bari
    9. DAA - Javatpoint
    10. Merge sort, how multiple recursion works under the hood  - Jenny's Lectures
    11. Shell sort - Jenny's Lectures
    12. Bubble sort - Jenny's Lectures
    13. TutorialsPoints - Analysis of  Algorithms
    14. Average case analysis - Abdul Bari
    15. Amortized analysis of Algorithms 
    16. Best First Search algorithm an example.
    17. Topological Sort or Ordering of a Graph  - Jenny's Lectures
    18. Probabilistic (randomized) Algorithms
    19. Genetic Algorithms - Nature inspired Algorithms IIT KGH
    20. TC - IITKGP 
    21. PDA Introduction - Neso Academy.
    22. Theory of Computation - Neso Academy
    23. Compiler Design IIT KGP
  2. MCS 33 (Advanced Discrete Mathematics - Recurrence Relations & Graph Theory
    1. Recurrence Relations
    2. Graph Theory - IIT KGP (Kharagpur)
    3. Tower of Hanoi
  3. MCS 34 (Software Engineerig)
    1. Software Engineering - IIT KGP
    2. Fact Finding Techniques 1
    3. Software Engineering Process An Overview - IGNOU
    4. Advanced Software Engineering Projects - IGNOU
    5. Spiral Life Cycles Models 
    6. Life cycle models 2 Win Win Spiral Model - IGNOU
  4. MCS 42 (Computer Networks & Distributed Systems)
    1. Cloud Computing & Distributed Systems IIT Patna
    2. Demystifying Networks IIT Bombay
  5. MCS 43 (Advanced Database Management Systems) 
    1. Advanced DBMS - limits of RDBMS
    2. Introduction to database systems IIT Madras
    3. Introduction to Relational Model/2 DBMS IIT Khg - Relational Algebra & its operations.
  6. MCS 51 (Advanced Java & Internet)
    1. Websites -1 - IGNOU
    2. Websites - 2 - IGNOU
    3. Servlets Basics - IGNOU
    4. Writing Servlets - IGNOU
    5. Session Tracking in Servlet programming - IGNOU
    6. Website management 1
    7. Website management 2
    8. Network Technology & Devices
    9. Basics of Internet
    10. Introduction to Computer & Networking
    11. Introduction to distributed systems - IGNOU
    12. Java Security
  7. MCS 52 (Management Information System)
    1. MIS - IIT Kharagpur
  8. MCS 53 (Computer Graphics)
    1. IIT - Guwahati
    2. Computer Graphics - Projections
    3. Computer Graphics - Transformation - IGNOU
    4. Multimedia Tutorials
  9. MCSE 003 (Artificial Intelligence)
    1. Fundamentals of AI - IIT Guwahati
    2. Introduction to Artificial Intelligence 2
    3. Knowledge Representation Part 1
    4. Symbolic Logic Knowledge Representation - IGNOU
    5. Fuzzy Logic why and what 1 - IGNOU
    6. Fuzzy Logic why and what 2 - IGNOU
    7. AI programming languages 1 Part 1 LISP 4- IGNOU
    8. AI languages LISP Artificial Intelligence
    9. AI programming languages 1 Part 2 - IGNOU
    10. AI programming LISP 1
    11. LISP part - 3 Artificial Intelligence 1 - IGNOU
    12. LISP Part - 3 Artificial Intelligence 2 - IGNOU
    13. LISP Part 5 - IGNOU
    14. Uncertain Knowledge & Reasoning 1
    15. Uncertain Knowledge & Reasoning 2
    16. AI programming language LISP 3 - IGNOU
    17. AI programming language LISP - 4 - IGNOU
    18. Introduction to PROLOG
    19. A Start informed search algorithm
    20. AO Star informed search algorithm also called as the AND-OR graphs.
    21. AI Education 4u series.
  10. MCSE 004 (Numerical & Statistical Computing)
    1. Scientific Computing using MATLAB - IIT Delhi
    2. Numerical & Statistical Techniques - IGNOU
    3. Numerical & Statistical Computing 2
    4. Random Variables and Probability 3
    5. Normal Distribution
    6. Random variables & Probability distributions 4
    7. Numerical and Statistical Techniques 6
  11. MCSE 011 ( Parallel Computing a.k.a. Super Computing)
    1. Parallel Algorithms - IIT Guwahati
    2. Introduction to Parallel Programming in Open MP - IIT Delhi
    3. Parallel Algorithms


Thursday, October 1, 2020

Top 10 online courses for learning DSA

 Top10 online courses for DSA

Retaining the color code in Notepad++

 When you open a supported file format in Notepad++, it performs syntax highlighting where it formats the text with various colors to make reading easier.

However, when you save the file or copy text from it to an external program, all of the syntax highlighting and formatting is lost, and the text will take on formatting of the program you’re pasting into. This shouldn’t be surprising as the program is basically a plain-text editor. The syntax highlighting you see is just a visual enhancement. Although, there is a way to retain this formatting, i.e. if you have NppExport plugin installed. Latest builds of Notepad++ ships with this plugin. If you don’t have NppExport installed, you can download it through the inbuilt plugin manager.

When you have it ready, highlight the code that you want to copy, then go to 

Plugins (on the menu bar) > Select NppExport > Copy all formats to clipboard

Now when you paste the code into a program that supports rich text formatting, for example Microsoft Word or Evernote, all of the formatting should be retained.

इश्क में ग़ैरत-ए-जज़्बात ने रोने ना दिया - सुदर्शन फ़ाकिर

 इश्क में ग़ैरत-ए-जज़्बात ने रोने ना दिया वरना क्या बात थी किस बात ने रोने ना दिया आप कहते थे कि रोने से ना बदलेंगे नसीब उमर भर आप की इस बात...