Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Assignment-7

Name – Aditya Ram


Reg no: 20bce7102
Question 1:
1. Fill a rectangle (width= 200, height= 150) with red colour using Scan Line
Polygon Filling Algorithms.

Code:
function setup() {
createCanvas(600, 600);
}
function draw() {
background(220);
stroke(150,200,350);
fill(color('RED'));
rect(50,50,200,150);
}
function scan(y1,y2,c,b){
inside=false;
for(y=y1;y<y2;y++){
for(x=0;x<width;x++){
k=get(x,y)
if(k==b &&inside) inside=false;
else if(k==b && !inside) inside=true;
if(inside) set(x,y,c)
}
}
}
Output:

Question2:

Code:

2. Consider a polygon of 5 vertices with coordinates [30, 30] , [30 150] , [120, 60] , [120, 120] and
[210, 30]. Fill the polygon with green colour using Scan Line Polygon Filling Algorithms.

function setup() {

createCanvas(600, 600);

function draw() {

background(0);

stroke(150,200,350);

fill(color('green'));

beginShape();

vertex(30,30);

vertex(30,150);

vertex(120,60);

vertex(120,120);

vertex(210,30);
endShape(CLOSE);

function scan(y1,y2,c,b){

inside=false;

for(y=y1;y<y2;y++){

for(x=0;x<width;x++){

k=get(x,y)

if(k==b &&inside)

inside=false;

else if(k==b && !inside)

inside=true;

if(inside) set(x,y,c)

You might also like