Thursday, September 17, 2015

CANVAS HTML5: WORKING WITH TEXT AND GRADIENT

<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title> here goes the title of your project </title>

<style type="text/css">
body,td,th {
font-family: Helvetica, Arial, sans-serif;
font-size: 12px;
color: #000;
}
body {
background-color: #FFF;
}
#myCanvas { border: rgb(102,0,255) medium dashed; }
</style>
</head>

<body>

<canvas id="myCanvas" width="400" height="400"></canvas>

<script>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');

//// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> START HERE

context.beginPath();

///background

context.rect(0,0,400,400);
context.fillStyle = "rgb(46,35,46)";
context.fill();
context.stroke();
context.closePath();

 var text = "AMANDA HO";
 var textcolor = context.createLinearGradient(70,200,350,200);
 textcolor.addColorStop(0,"rgb(245,66,167)");
 textcolor.addColorStop(0.5,"lightpink");
 textcolor.addColorStop(1,"grey");

 context.font = 'bold 50px Monaco';
 context.fillStyle= textcolor;
 context.fillText(text,70,200);
 context.closePath();


//// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< END HERE

</script>
</body>
</html>

No comments:

Post a Comment