From d46a4ad83f0c6c10e39ec29790e42fc504e16887 Mon Sep 17 00:00:00 2001 From: Kshitij Date: Fri, 1 Dec 2023 19:27:17 +0530 Subject: [PATCH] Added scan line fill code --- README.md | 19 +++--- Scan Line Fill.cpp | 154 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 165 insertions(+), 8 deletions(-) create mode 100644 Scan Line Fill.cpp diff --git a/README.md b/README.md index fbd6deb..3529452 100644 --- a/README.md +++ b/README.md @@ -8,13 +8,6 @@ This repository contains codes, write-ups, lab manuals, lab notes and question p ### Codes -#### Digital Differential Analyzer (DDA): -> Digital Differential Analyzer (DDA) is a line-drawing algorithm for digital displays, using incremental calculations to plot points between endpoints. - -1. [Line](https://git.kska.io/sppu-se-comp-codes/CG/src/branch/main/DDA-line.cpp) -2. [Triangle](https://git.kska.io/sppu-se-comp-codes/CG/src/branch/main/DDA-triangle.cpp) -3. [Circle](https://git.kska.io/sppu-se-comp-codes/CG/src/branch/main/DDA-circle.cpp) - #### Lab Codes: 1. [Assignment A-1 (Scan Fill)](https://git.kska.io/sppu-se-comp-codes/CG/src/branch/main/Assignment%20A-1%20%28Scan%20Fill%29.cpp) 2. Assignment A-2 (Cohen Sutherland Line Clipping) @@ -28,6 +21,16 @@ This repository contains codes, write-ups, lab manuals, lab notes and question p 8. [Assignment C-6c (Sunrise and Sunset)](https://git.kska.io/sppu-se-comp-codes/CG/src/branch/main/Assignment%20C-6c%20%28Sunrise%20and%20Sunset%29.cpp) 9. [Assignment C-7b (Bouncing Ball)](https://git.kska.io/sppu-se-comp-codes/CG/src/branch/main/Assignment%20C-7b%20%28Bouncing%20Ball%29.cpp) +#### Digital Differential Analyzer (DDA): +> Digital Differential Analyzer (DDA) is a line-drawing algorithm for digital displays, using incremental calculations to plot points between endpoints. + +1. [Line](https://git.kska.io/sppu-se-comp-codes/CG/src/branch/main/DDA-line.cpp) +2. [Triangle](https://git.kska.io/sppu-se-comp-codes/CG/src/branch/main/DDA-triangle.cpp) +3. [Circle](https://git.kska.io/sppu-se-comp-codes/CG/src/branch/main/DDA-circle.cpp) + +#### Miscellaneous Codes: +- [Scan Line Fill](https://git.kska.io/sppu-se-comp-codes/CG/src/branch/main/Scan%20Line%20Fill.cpp) + ### Lab Manual - [Full lab manual](https://git.kska.io/sppu-se-comp-codes/CG/src/branch/main/lab-manual/CGL%20Lab%20Manual.pdf) @@ -46,7 +49,7 @@ This repository contains codes, write-ups, lab manuals, lab notes and question p 1. [Unit 1 - Graphics Primitives and Scan Conversion Algorithms](https://git.kska.io/sppu-se-comp-codes/CG/src/branch/main/notes/Unit%201) 2. [Unit 2 - Polygon, Windowing and Clipping](https://git.kska.io/sppu-se-comp-codes/CG/src/branch/main/notes/Unit%202) 3. [Unit 3 - 2D, 3D Transformations and Projections](https://git.kska.io/sppu-se-comp-codes/CG/src/branch/main/notes/Unit%203) -4. [Unit 4 - Light, Colour, Shading and Hidden Surfaces](https://git.kska.io/sppu-se-comp-codes/CG/src/branch/main/notes/Unit%204) +4. [Unit 4 - Light, Colour, Shading and Hidden Surfaces](https://git.kska.io/sppu-se-comp-codes/CG/src/branch/main/notes/Unit%204/) 5. [Unit 5 - Curves and Fractals](https://git.kska.io/sppu-se-comp-codes/CG/src/branch/main/notes/Unit%205) #### Lab Notes (Computer Graphics **Lab**) diff --git a/Scan Line Fill.cpp b/Scan Line Fill.cpp new file mode 100644 index 0000000..ee97644 --- /dev/null +++ b/Scan Line Fill.cpp @@ -0,0 +1,154 @@ +/* Define the structure to store the edges*/ +#include +#include +using namespace std; +struct edge{ + int x1,y1,x2,y2,flag; +}; +int main() +{ + int gd=DETECT,gm,n,i,j,k; + struct edge ed[10],temped; + float dx,dy,m[10],x_int[10],inter_x[10]; + int x[10],y[10],ymax=0,ymin=480,yy,temp; + initgraph(&gd,&gm,NULL); + +/*read the number of vertices of the polygon*/ + cout<<"Enter the no.of vertices of the graph :"; + cin>>n; + +/*read the vertices of the polygon and also find ymax and ymin*/ + cout<<"Enter the vertices"; + for(i=0;i>x[i]; + cin>>y[i]; + if(y[i]>ymax) + ymax=y[i]; + if(y[i]y2, if not interchnge y1 and y2 */ + cout<<"\nUpdated Edge Information\n"; + for(i=0;iymin) + { + //cout<<"\n\t"<ed[i].y2 && yy<=ed[i].y1) + ed[i].flag=1; //Active edge + else + ed[i].flag=0; //not Active edge + } + j=0; + for(i=0;ix_int[k+1]) + { + temp=(int)x_int[k]; + x_int[k]=x_int[k+1]; + x_int[k+1]=temp; + } + } + } + + + /*extracting pairs of values to draw lilnes*/ + for(i=0;i