task3.html 1.07 KB
Newer Older
Evelim Carla Ribeiro's avatar
Evelim Carla Ribeiro committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
<!DOCTYPE html>
<html>
<body>

<canvas id="myCanvas" width="700" height="400" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>

<script>

var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.beginPath();
var y1 = 20;
var y2 = 100;
var x1 = 20;
var x2 = 100;
ctx.moveTo(x1,y1);//posicao inicial 
ctx.lineTo(x2,y1);
<!--ctx.moveTo(x2,y1);-->
<!--ctx.lineTo(x2,y2);-->
ctx.moveTo(x2,y2);
ctx.lineTo(x1,y2);
ctx.lineTo(x1,y1);
<!--penta-->
ctx.moveTo(x2,y1);
ctx.lineTo(150,60);
27
ctx.lineTo(x2,y2);
Evelim Carla Ribeiro's avatar
Evelim Carla Ribeiro committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52

function Shape(x, y, w, h, fill) {
  // This is a very simple and unsafe constructor. 
  // All we're doing is checking if the values exist.
  // "x || 0" just means "if there is a value for x, use that. Otherwise use 0."
  this.x = x || 0;
  this.y = y || 0;
  this.w = w || 1;
  this.h = h || 1;
  this.fill = fill || '#AAAAAA';
}
 
// Draws this shape to a given context
Shape.prototype.draw = function(ctx) {
  ctx.fillStyle = this.fill;
  ctx.fillRect(this.x, this.y, this.w, this.h);
}


ctx.stroke();

</script>

</body>
</html>