Pages

Tuesday, September 15, 2015

Sailboat



Here is the code for the sailboat:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title> here goes the title of your project </title>

<style type="text/css">
body,td,th {
font-family: Helvetica, Arial, sans-serif;
font-size: 12px;
color: #000;
}
body {
background-color: #FFF;
}
#myCanvas { border: rgb(102,0,255) medium dashed; }
</style>
</head>

<body>

<canvas id="myCanvas" width="800" height="600"></canvas>

<script>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');

//// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> START HERE


// the radial gradient
context.rect(0,0, canvas.width, canvas.height);
context.stroke();
// inner circle
var circ1X = 10;
var circ1Y = 10;
var circ1Radius = 100;

// outer circle
var circ2X = 10;
var circ2Y = 10;
var circ2Radius = 200;

// create radial gradient
var grd = context.createRadialGradient(circ1X, circ1Y, circ1Radius, circ2X, circ2Y, circ2Radius);
// inner color
grd.addColorStop(0, "gold");

// you can add intermediate colors using N greater than 0 and smaller then 1
var N = 0.5;
grd.addColorStop(N, "lightyellow");

// outer color
grd.addColorStop(1, "lightblue");

context.fillStyle = grd;
context.fill();


// boat

context.beginPath();
      context.arc(488, 435, 90, 0, Math.PI, false);
      context.closePath();
      context.lineWidth = 5;
      context.fillStyle = 'silver';
      context.fill();
      context.strokeStyle = 'black';
      context.stroke();
context.closePath();

// ocean

context.beginPath();
      context.rect(0, 500, 800, 100);
      context.fillStyle = 'blue';
      context.fill();
      context.lineWidth = 7;
      context.strokeStyle = 'blue';
      context.stroke();
context.closePath();


// mast

context.beginPath();
      context.moveTo(480, 435);
      context.lineTo(480, 300);
      context.lineWidth = 8;
      context.strokeStyle = 'black';
      context.stroke();
context.closePath();

// right sail

context.beginPath();
context.moveTo(485, 300);
context.lineTo(550, 410);
context.lineTo(485, 400);
context.lineTo(485, 300);

context.lineWidth = 5;
context.lineCap = 'round'
context.lineJoin = 'round';
context.strokeStyle = 'white'
context.stroke();
context.fillStyle = "white";
context.fill();
context.closePath();

//left sail

context.beginPath();
context.moveTo(475, 300);
context.lineTo(475, 400);
context.lineTo(400, 410);
context.lineTo(475, 300);

context.lineWidth = 5;
context.lineCap = 'round'
context.lineJoin = 'round';
context.strokeStyle = 'white'

context.stroke();
context.fillStyle = "white";
context.fill();
context.closePath();
/**/



//// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< END HERE

</script>
</body>
</html>

No comments:

Post a Comment