Professional Documents
Culture Documents
Assignment-7: Name - Aditya Ram Reg No: 20bce7102
Assignment-7: Name - Aditya Ram Reg No: 20bce7102
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;
inside=true;
if(inside) set(x,y,c)