Canvas - HTML 5
-
Upload
jaeni-sahuri -
Category
Technology
-
view
584 -
download
5
description
Transcript of Canvas - HTML 5
![Page 1: Canvas - HTML 5](https://reader030.fdocuments.in/reader030/viewer/2022020306/554f8cceb4c905435d8b4e48/html5/thumbnails/1.jpg)
What is Canvas?
![Page 2: Canvas - HTML 5](https://reader030.fdocuments.in/reader030/viewer/2022020306/554f8cceb4c905435d8b4e48/html5/thumbnails/2.jpg)
The HTML5 <canvas> element isused to draw graphics, on the fly,via scripting (usually JavaScript).
![Page 3: Canvas - HTML 5](https://reader030.fdocuments.in/reader030/viewer/2022020306/554f8cceb4c905435d8b4e48/html5/thumbnails/3.jpg)
Browser Support
• Internet Explorer 9+, Firefox, Opera,Chrome, and Safari
![Page 4: Canvas - HTML 5](https://reader030.fdocuments.in/reader030/viewer/2022020306/554f8cceb4c905435d8b4e48/html5/thumbnails/4.jpg)
HTML5 Canvas Template
<body><canvas id="myCanvas" width="500"
height="250"></canvas><script>
var canvas = document.getElementById('myCanvas');var context = canvas.getContext('2d');
// do stuff here</script>
</body>
![Page 5: Canvas - HTML 5](https://reader030.fdocuments.in/reader030/viewer/2022020306/554f8cceb4c905435d8b4e48/html5/thumbnails/5.jpg)
• To draw a line using HTML5 Canvas, wecan use the beginPath(), moveTo(),lineTo(), and stroke() methods.
![Page 6: Canvas - HTML 5](https://reader030.fdocuments.in/reader030/viewer/2022020306/554f8cceb4c905435d8b4e48/html5/thumbnails/6.jpg)
![Page 7: Canvas - HTML 5](https://reader030.fdocuments.in/reader030/viewer/2022020306/554f8cceb4c905435d8b4e48/html5/thumbnails/7.jpg)
![Page 8: Canvas - HTML 5](https://reader030.fdocuments.in/reader030/viewer/2022020306/554f8cceb4c905435d8b4e48/html5/thumbnails/8.jpg)
HTML5 Canvas Line WidthTutorial
• To define the width of an HTML5 Canvasline, we can use the lineWidth property ofthe canvas context. The lineWidthproperty must be set before callingstroke().
![Page 9: Canvas - HTML 5](https://reader030.fdocuments.in/reader030/viewer/2022020306/554f8cceb4c905435d8b4e48/html5/thumbnails/9.jpg)
context.beginPath();context.moveTo(100, 150);context.lineTo(450, 50);context.lineWidth = 15;context.stroke();
![Page 10: Canvas - HTML 5](https://reader030.fdocuments.in/reader030/viewer/2022020306/554f8cceb4c905435d8b4e48/html5/thumbnails/10.jpg)
HTML5 Canvas Line Color
// set line colorcontext.strokeStyle = '#ff0000';context.stroke();
![Page 11: Canvas - HTML 5](https://reader030.fdocuments.in/reader030/viewer/2022020306/554f8cceb4c905435d8b4e48/html5/thumbnails/11.jpg)
Thanks
http://www.gratisan.com
http://jogjawebcenter.com