Wednesday, February 6, 2013

Heart Design in HTML 5

It was very hard to get used finding the right coordinates to make a perfect rounded heart using the codes for a bezier and quadratic curve. But once I finished half of the heart, it was easier to match up the points on the other side to complete the heart. Then after I put color to it, it turned out a lot better than I thought!

<!DOCTYPE HTML>
<html>
<head>
<script>
window.onload = function() {
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");

////////////////////////////////////// start below this line ˇˇˇˇˇˇˇˇˇˇ

context.beginPath();
context.rect(0, 0, 800, 600);
var grd=context.createLinearGradient(0, 300, 800, 300);
grd.addColorStop(0, 'rgb(250, 50, 240)');
grd.addColorStop(1, 'rgb(100, 200, 50)');
context.fillStyle = grd;
context.fill();
context.stroke();


context.beginPath();
context.moveTo(390, 175);
context.bezierCurveTo(275, 25, 125, 175, 300, 340);
context.quadraticCurveTo(350, 390, 390, 450);
context.quadraticCurveTo(430, 390, 480, 340);
context.bezierCurveTo(655, 175, 505, 25, 390, 175);
context.fillStyle= 'rgb(255, 0, 0)';
context.fill();
context.stroke();










////////////////////////////////////// end above this line ˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆ

};

</script>
</head>
<body>
<canvas id="myCanvas" width="800" height="600"></canvas>
</body>
</html>

No comments:

Post a Comment