Skip to end of metadata
Go to start of metadata

CS 351 - Assignment 4:Scanline Fill

Titobiloluwa Awe and Elena Kirillova


In this project, we implemented the scanline algorithm for polygons, using bresenham's algorithm, and barycentric co-ordinates fill method. 

Problem Description

First of all, we had to implement the scanline algorithm for polygons. We used the skeleton specified in the skeleton code provided on the CS 351 website. Secondly, we implemented a second polygon fill algorithm that uses barycentric co-ordinates to fill a triangle. 


Scanline Fill Algorithm

To implement the scanline algorithm for polygons, method 1, we had to calculate the xIntersect and dxPerScan for each edge that we add to our list of edges. Then, using this information, we were able to call more functions within our program that colored the polygon, line by line.

Required Image 1:

Required Image 2:

Barycentric Coordinates Fill Algorithm

To implement the polygon fill algorithm for barycentric co-ordinate, we first had to find the bounding box for our triangle, calculate alpha, beta and gamma and if these values are in the range 0 to 1. Then, using these values, were able to color each point within the triangle. We also implemented color blending for each of the colors of the vertices as an extension.

Picture of a blue Box and a flower from top view?
Required Image 3:

Portfolio Images

Picture of clouds of different colors using the scanline fill method:

Picture of a head with a teeth that have their colors blended using Barycentric Coordinates Fill:

Sierpinski triangle

On the left - using Barycentric Coordinates Fill. On the right - using Scanline fill.

From the look of these two we can see that both implemented in this project algorithms output equally good quality images.

Interestingly enough gcc let us create a nested function.


  • We created an animated gif that demonstrates the scanline fill algorithm for the required image 1:

This animation shows how scanline algorithm very literally draws an image line by line.

  • We allowed the user to specify a gradient across any triangle through Polygon_drawFillB() method. In stead off one color, our function took three arguments for colors. Depending on position of triangle's vertices the amount of each color was weighted so that we would get a gradient of three colors across the shape. You can see results of this extension on few images from above.
  • Here just getting a little too excited about Sierpinski triangle:



This was a very interesting project, and we learned a lot about polygon filling using the two different methods and about some useful things like:

  • How to think upside down. (:
  • Assigning an operation of integers' division to another integer will not take you too far. Floats are the way to go.
  • How to think pixel-wide, pixel-side, pixel-center and pixel-across.

It was very hard to understand at first, but worth it in the end.