Difference between revisions of "Flags with Methods"

From ProgZoo
Jump to navigation Jump to search
Line 9: Line 9:
<pre class=ans>
<pre class=ans>
function drawFlag(ctx){
function drawFlag(ctx){
  ctx.fillStyle = 'gray';
  ctx.fillRect(0,0,180,130);
  tri(ctx,10,10,'red','white','blue');
  tri(ctx,95,10,'red','white','blue');
}
function tri(ctx,x,y,c1,c2,c3){
  ctx.translate(x,y);
  ctx.fillStyle = c1;
  ctx.fillRect(0,0,25,50);
  ctx.fillStyle = c2;
  ctx.fillRect(25,0,25,50);
  ctx.fillStyle = c3;
  ctx.fillRect(50,0,25,50);
}
}
</pre>
</pre>
</div>
</div>

Revision as of 23:47, 16 August 2021


Stars and Stripes

function drawFlag(ctx){
}
function drawFlag(ctx){
  ctx.fillStyle = 'gray';
  ctx.fillRect(0,0,180,130);
  tri(ctx,10,10,'red','white','blue');
  tri(ctx,95,10,'red','white','blue');
}

function tri(ctx,x,y,c1,c2,c3){
  ctx.translate(x,y);
  ctx.fillStyle = c1;
  ctx.fillRect(0,0,25,50);
  ctx.fillStyle = c2;
  ctx.fillRect(25,0,25,50);
  ctx.fillStyle = c3;
  ctx.fillRect(50,0,25,50);
}