Difference between revisions of "Flags with Rectangles"

From ProgZoo
Jump to navigation Jump to search
Tag: Reverted
Tag: Reverted
Line 3: Line 3:


<div class='qu' data-width="240" data-height="240">
<div class='qu' data-width="240" data-height="240">
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.
<pre class='usr'>
<pre class='usr'>
function drawFlag(ctx)
function drawFlag(ctx)
Line 20: Line 21:
function drawFlag(ctx)
function drawFlag(ctx)
{
{
   ctx.fillStyle = 'green';
   ctx.fillStyle = 'white';
   ctx.fillRect(0,0,150,100);
   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;
  }
}   
}   
</pre>
</pre>
</div>
</div>

Revision as of 17: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);
  for(let y=0;y<12;y++){
    for(let x=0;x<24;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;
  }
}