Canvas - HTML 5

11
What is Canvas?

description

Canvas - HTML 5

Transcript of Canvas - HTML 5

Page 1: Canvas - HTML 5

What is Canvas?

Page 2: Canvas - HTML 5

The HTML5 <canvas> element isused to draw graphics, on the fly,via scripting (usually JavaScript).

Page 3: Canvas - HTML 5

Browser Support

• Internet Explorer 9+, Firefox, Opera,Chrome, and Safari

Page 4: Canvas - HTML 5

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

• To draw a line using HTML5 Canvas, wecan use the beginPath(), moveTo(),lineTo(), and stroke() methods.

Page 6: Canvas - HTML 5
Page 7: Canvas - HTML 5
Page 8: Canvas - HTML 5

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

context.beginPath();context.moveTo(100, 150);context.lineTo(450, 50);context.lineWidth = 15;context.stroke();

Page 10: Canvas - HTML 5

HTML5 Canvas Line Color

// set line colorcontext.strokeStyle = '#ff0000';context.stroke();

Page 11: Canvas - HTML 5

Thanks

http://www.gratisan.com

http://jogjawebcenter.com