Wednesday, September 12, 2012
Heart Homework
<!DOCTYPE HTML>
<html>
<head>
<script>
window.onload = function() {
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
////////////////////////////////////// start below this line ˇˇˇˇˇˇˇˇˇˇ
var controlX1 = 300;
var controlY1 = 0;
var controlX2 = 100;
var controlY2 = 200;
var endX = 250;
var endY = 325;
var controlX3 = 380;
var controlY3 = 450;
var endX3 = 400;
var endY3 = 500;
var controlX4 = 435;
var controlY4 = 400;
var endX4 = 550;
var endY4 = 325;
var controlX5 = 700;
var controlY5 = 200;
var controlX6 = 500;
var controlY6 = 0;
var endX5 = 400;
var endY5 = 200;
var grdstartX = 0;
var grdstartY = 0;
var grdendX = 600;
var grdendY = 800;
//Rectangle
context.beginPath();
context.rect(0, 0, canvas.width, canvas.height);
var grd = context.createLinearGradient(grdstartX, grdstartY, grdendX, grdendY);
grd.addColorStop(0,'rgb(204,204,204)' );
grd.addColorStop(1,'rgb(102,102,102)' );
context.fillStyle = grd;
context.fill();
context.stroke();
//Heart
context.beginPath();
context.moveTo(400,200);
context.bezierCurveTo(controlX1, controlY1, controlX2, controlY2, endX, endY);
context.quadraticCurveTo(controlX3, controlY3, endX3, endY3);
context.quadraticCurveTo(controlX4, controlY4, endX4, endY4);
context.bezierCurveTo(controlX5, controlY5, controlX6, controlY6, endX5, endY5);
context.strokeStyle = 'rgb(255,204,204)';
context.fillStyle = 'rgb(153,204,255)';
context.lineCap = 'round';
context.fill();
context.lineWidth = 10;
context.stroke();
////////////////////////////////////// end above this line ˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆ
};
</script>
</head>
<body>
<canvas id="myCanvas" width="800" height="600"></canvas>
</body>
</html>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment