Posts

Showing posts from March, 2021

Assignment 3 .Bresenham’s circle drawing algorithm

Image
  Bresenham’s circle drawing algorithm Read Radius r x=0, y=r Set decision parameter d to d = 3 – (2 * r). do while x < = y Call 8way drawCircle(int x, int y). Increment value of x. If d < 0, set d = d + (4*x) + 6 Else, set d = d + 4 * (x – y) + 10 and decrement y by 1. while End; 8 Way Symmetry Assignment 03 Implement Bresenham circle drawing algorithm to draw any object. The object should be displayed in all the quadrants with respect to center and radius Code # include <GL/glut.h> # include <iostream> using namespace std ; int r; void E_way ( int x, int y) { glBegin(GL_POINTS); glVertex2i(x+ 320 ,y+ 240 ); glVertex2i(y+ 320 ,x+ 240 ); glVertex2i(y+ 320 , -x+ 240 ); glVertex2i(x+ 320 , -y+ 240 ); glVertex2i(-x+ 320 ,-y+ 240 ); glVertex2i(-y+ 320 ,-x+ 240 ); glVertex2i(-y+ 320 ,x+ 240 ); glVertex2i(-x+ 320 ,y+ 240 ); glEnd(); ...

Assignments No. 2

Image
Implement DDA and Bresenham line drawing algorithm to draw: i) Simple Line ii) Dotted Line iii) Dashed Line Using mouse interface Divide the screen in four quadrants with center as (0, 0). The line should work for all the slopes positive as well as negative. Code # include <iostream> # include <GL/glut.h> using namespace std ; int Algo,type; void Init () { glClearColor( 0 , 0 , 0 , 0 ); glColor3f( 0 , 1 , 0 ); gluOrtho2D( 0 , 640 , 0 , 480 ); glClear(GL_COLOR_BUFFER_BIT); } int sign ( float a) { if (a== 0 ){ return 0 ; } if (a> 0 ){ return 1 ; } return -1 ; } void B_Line ( int x_1, int y_1, int x_2, int y_2, int t) { float dy, dx, m , P; dy = y_2 - y_1; dx = x_2 - x_1; m = dy/dx; P = 2 *dy - dx; int x = x_1, y = y_1; cout << "\n x1 = " <<x<< " y1 = " <<y; if (m< 1 ){ int cnt= 1 ; for ( in...

Bresenham's Line Algorithm in C++ using Glut

Image
Algorithm Code in c++ using Glut #include<GL/glut.h> #include<math.h> #include<iostream> using namespace std; float x_1,y_1,x_2,y_2; void Line(){     float dy, dx, m , P;     dy = y_2 - y_1;     dx = x_2 - x_1;     m = dy/dx;     P = 2*dy - dx;     int x = x_1, y = y_1;     if(m<1){         for(int i=0; i<=dx;i++){             glBegin(GL_POINTS);                 glVertex2i(x,y);             glEnd();             if(P<0){                 x = x +1;           ...

DDA Line Drawing Algorithm in C++ using GLUT Basic

Image
  DDA Line Drawing Algorithm Given 2 point (x1, y1) to (x2,y2) 1. Read Line end point (x1,y1)(x2,y2) 2. ∆x = |x2-x1| , ∆y = |y2-y1| 3.      If(∆x ≥ ∆y)    Then  Length = ∆x         Else                        Length = ∆y 5. Select Raster Unit 1. ∆x = x2-x1 / Length 2. ∆y = y2-y1 / Length 3. This will make ∆x or ∆y = 1 6. X _( i+1 ) =  x _i +0.5∗Sign( ∆x)     //Sign retrun 1,0,-1 7. Y _(i+1) =  y _i +0.5 ∗Sign(∆ y) 8. i=0     whlie(i<=length)     {              plot(x,y)              x = x +  ∆x                    y = y + ∆y                    i=i+1  ...