Wednesday, February 6, 2013

Heart

In Class we learned how to draw a heart using Bezier Curves and Quadratic Curves. This has helped me understand the basics of drawing curvy lines. This will greatly help me for my project later on.



<!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(150, 25, 500, 500);
var grd = context.createLinearGradient(400, 400, 100, 100);
grd.addColorStop(0, 'blue');
grd.addColorStop(1, 'green');
context.fillStyle = grd;
context.fill();
context.stroke();


context.beginPath();
context.moveTo(390, 175);
context.bezierCurveTo(285, 25, 125, 175, 300, 340);
context.quadraticCurveTo(350, 390, 390, 470);
context.quadraticCurveTo(430, 390, 480, 340);
context.bezierCurveTo(655, 175, 525, 25, 390, 175);
context.fillStyle = 'red';
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