/**
Decidesifa pointata specificlocationisf illedornot.
@paramxisthe xcoordinate ofthe point beingchecked
@paramy isthe y coordinate ofthe point beingchecked
@paramwidthisthe widthofthe Sierpins kiCarpetbeingchecked
@paramheightisthe heightofthe Sierpi nskiCarpetbeingchecked
@return1 ifitistobe filledor0 ifitisnot
*/ intisSierpinskiCarpetPixelFilled(intx,in ty,intwidth,intheight)
{
// base case
if(x<1)
{
return0;
}
// generalcase
{
/*
Ifthe gridwassplitin9 parts,whatpart(x 2,y2) wouldx,y fitinto?
*/
intx2 = x*3/width;// anintegerfrom0..2 inclusive
inty2 = y*3/height;// anintegerfrom0..2 inclusive
if(x2==1 &&y2==1) // ifinthe centre squ aure,itshouldbe filled.
return1;
/* offsetxandy soitbecomesboundedb y 0..width/3 and0..height/3
andpreparesforrecursive call
*/
x-=x2*width/3;
y-=y2*height/3;
}
returnisSierpinskiCarpetPixelFilled(x,y,wi dth/3,height/3);
}
Decidesifa pointata specificlocationisf illedornot.
@paramxisthe xcoordinate ofthe point beingchecked
@paramy isthe y coordinate ofthe point beingchecked
@paramwidthisthe widthofthe Sierpins kiCarpetbeingchecked
@paramheightisthe heightofthe Sierpi nskiCarpetbeingchecked
@return1 ifitistobe filledor0 ifitisnot
*/ intisSierpinskiCarpetPixelFilled(intx,in ty,intwidth,intheight)
{
// base case
if(x<1)
{
return0;
}
// generalcase
{
/*
Ifthe gridwassplitin9 parts,whatpart(x 2,y2) wouldx,y fitinto?
*/
intx2 = x*3/width;// anintegerfrom0..2 inclusive
inty2 = y*3/height;// anintegerfrom0..2 inclusive
if(x2==1 &&y2==1) // ifinthe centre squ aure,itshouldbe filled.
return1;
/* offsetxandy soitbecomesboundedb y 0..width/3 and0..height/3
andpreparesforrecursive call
*/
x-=x2*width/3;
y-=y2*height/3;
}
returnisSierpinskiCarpetPixelFilled(x,y,wi dth/3,height/3);
}