heart with gradient background
<!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, canvas.width, canvas.height);
//Midnight gradient
var grd = context.createLinearGradient(400, 0, 400, 600);
// dark blue
grd.addColorStop(0, "rgb(140, 230, 250)");
// lighter blue
grd.addColorStop(1, "rgb(321, 160, 221)");
context.fillStyle = grd;
context.fill();
context.stroke();
//Heart
//Bezier Curve Variables
var Ax = 360;
var Ay = 200;
var Bx = 360;
var By = 500;
var control1x = 160;
var control1y = -50;
var control2x = 40;
var control2y = 300;
var control3x = 730;
var control3y = 300;
var control4x = 560;
var control4y = -50;
context.beginPath();
context.moveTo(Ax, Ay);
context.bezierCurveTo(control1x, control1y, control2x, control2y, Bx, By);
context.bezierCurveTo(control3x, control3y, control4x, control4y, Ax, Ay);
// line color
context.lineCap = 'round';
context.stroke();
context.fillStyle = 'rgb(255, 0, 0)';
context.fill();
grd.addColorStop(0, "rgb(255, 0, 0)");
// lighter blue
////////////////////////////////////// end above this line ˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆ
};
</script>
</head>
<body>
<canvas id="myCanvas" width="800" height="600"></canvas>
</body>
</html>
Comments
Post a Comment