Difference between revisions of "Flags with Rectangles"

From ProgZoo
Jump to navigation Jump to search
Tag: Reverted
Tag: Reverted
Line 9: Line 9:
   ctx.fillStyle = 'white';
   ctx.fillStyle = 'white';
   ctx.fillRect(0,0,240,240);
   ctx.fillRect(0,0,240,240);
  ctx.fillStyle = 'black';
   for(let y=0;y<12;y++){
   for(let y=0;y<12;y++){
     for(let x=0;x<24;x++){
     for(let x=0;x<31;x++){
       if ((x+y)%2==1){
       if ((x+y)%2==1){
         ctx.fillRect(240*x/24,240*y/12,240/24,240/12);
         ctx.fillRect(240*x/24,240*y/12,240/24,240/12);

Revision as of 16:44, 9 July 2023


Movement in Squares

For each of the first 16 columns the width is 90% of the previous. This pattern is reversed for the remainder. There are 31 columns.

function drawFlag(ctx)
{
  ctx.fillStyle = 'white';
  ctx.fillRect(0,0,240,240);
  ctx.fillStyle = 'black';
  for(let y=0;y<12;y++){
    for(let x=0;x<31;x++){
       if ((x+y)%2==1){
         ctx.fillRect(240*x/24,240*y/12,240/24,240/12);
       }
    }
  }
}  
function drawFlag(ctx)
{
  ctx.fillStyle = 'white';
  ctx.fillRect(0,0,240,240);
  ctx.fillStyle = 'black';
  let a = 0;
  let w = 240/12;
  for(let x=0;x<31;x++){
    for(let y=0;y<12;y++){
       if ((x+y)%2==1){
         ctx.fillRect(a,240*y/12,w,240/12);
       }
    }
    if (x<16){
      w *= 0.9;
    }else{
      w *= 1/0.9;
    }
    a += w;
  }
}