<!DOCTYPE HTML>
<html>
<head>
<script>
window.onload = function() {
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
////////////////////////////////////// start below this line ˇˇˇˇˇˇˇˇˇˇ
//rectangle
var x2 = 0;
var y2 = 0;
var rectwidth = canvas.width;
var rectheight = canvas.height;
var startX = 400;
var startY = 100;
var endX6 = 400;
var endY6 = 550;
context.beginPath();
context.rect(x2,y2,rectwidth,rectheight);
var grd = context.createLinearGradient(startX, startY, endX6, endY6);
grd.addColorStop(0, 'rgb(300, 70, 200)');
grd.addColorStop(1, 'rgb(100, 30, 300)');
context.fillStyle = grd;
context.fill();
context.stroke();
//heart
//bezier
var x = 390;
var y = 175;
var controlX1 = 285;
var controlY1 = 25;
var controlX2 = 125;
var controlY2 = 175;
var endX2 = 300;
var endY2 = 340;
//quadratic
var controlX3 = 350;
var controlY3 = 390;
var endX3 = 390;
var endY3 = 470;
//quadratic
var controlX4 = 430;
var controlY4 = 390;
var endX4 = 470;
var endY4 = 350;
//bezier
var controlX5 = 655;
var controlY5 = 185;
var controlX6 = 525;
var controlY6 = 25;
var endX5 = x;
var endY5 = y;
context.beginPath();
context.moveTo(x, y);
context.bezierCurveTo(controlX1, controlY1, controlX2, controlY2, endX2, endY2);
context.quadraticCurveTo(controlX3, controlY3, endX3, endY3);
context.quadraticCurveTo(controlX4, controlY4, endX4, endY4);
context.bezierCurveTo(controlX5, controlY5, controlX6, controlY6, endX5, endY5);
context.closePath();
context.fillStyle = 'rgb(300, 0 , 0)';
context.fill();
context.lineWidth = 10;
context.strokeStyle = 'rgb(255, 150, 200)';
context.stroke();
////////////////////////////////////// end above this line ˆˆˆˆˆˆˆˆˆˆˆˆˆˆˆ
};
</script>
</head>
<body>
<canvas id="myCanvas" width="800" height="600"></canvas>
</body>
</html>
No comments:
Post a Comment