如何在HTML5 Canvas中绘制云形状? [英] How to draw Cloud shape in HTML5 Canvas?
本文介绍了如何在HTML5 Canvas中绘制云形状?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用HTML5 Canvas& javascript。但我不知道在HTML5Canvas中绘制CLOUD形状的计算。
我试图使用2点(即开始点和结束点)绘制CLOUD形状。
请提出一些想法?
感谢
I am working on drawing of different shapes using HTML5 Canvas & javascript. But i am not gettting the calculation for drawing CLOUD shape in HTML5Canvas. I am trying to draw CLOUD shape using 2 points (i.e. Start point & End point). kindly suggest some ideas? Thanks
推荐答案
链接: http://www.html5canvastutorials.com/advanced/html5-canvas -save-drawing-as-an-image /
<!DOCTYPE HTML>
<html>
<head>
<style>
body {
margin: 0px;
padding: 0px;
}
</style>
</head>
<body>
<canvas id="myCanvas" width="578" height="200" style="display:none;"></canvas>
<img id="canvasImg" alt="Right click to save me!">
<script>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
// draw cloud
context.beginPath();
context.moveTo(170, 80);
context.bezierCurveTo(130, 100, 130, 150, 230, 150);
context.bezierCurveTo(250, 180, 320, 180, 340, 150);
context.bezierCurveTo(420, 150, 420, 120, 390, 100);
context.bezierCurveTo(430, 40, 370, 30, 340, 50);
context.bezierCurveTo(320, 5, 250, 20, 250, 50);
context.bezierCurveTo(200, 5, 150, 20, 170, 80);
context.closePath();
context.lineWidth = 5;
context.fillStyle = '#8ED6FF';
context.fill();
context.strokeStyle = '#0000ff';
context.stroke();
// save canvas image as data url (png format by default)
var dataURL = canvas.toDataURL();
// set canvasImg image src to dataURL
// so it can be saved as an image
document.getElementById('canvasImg').src = dataURL;
</script>
</body>
</html>
这篇关于如何在HTML5 Canvas中绘制云形状?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文