国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 開發(fā) > HTML5 > 正文

詳解如何用canvas畫一個(gè)微笑的表情

2024-09-05 07:19:36
字體:
供稿:網(wǎng)友

實(shí)習(xí)期間讓我用canvas畫一個(gè)表情,比較簡(jiǎn)單,話不多說直接上代碼:

<body><div id="canvas-warp">    <canvas id="canvas" style="display: block; margin: 200px auto;">        你的瀏覽器居然不支持Canvas!    </canvas></div><script>    window.onload = function () {        var canvas = document.getElementById("canvas");        canvas.width = 400;        canvas.height = 400;        //獲取上下文        var context = canvas.getContext("2d");        //用于畫有填充色圓的函數(shù)  參數(shù)分別為圓心坐標(biāo) ,半徑,起始與終止位置,線顏色,填充顏色        function drawCircle(x2, y2, r2, a2, b2, lineColor, FillColor) {            context.beginPath();            context.arc(x2, y2, r2, a2, b2 * Math.PI);            context.strokeStyle = lineColor;            context.fillStyle = FillColor;            context.fill(); //確認(rèn)填充            context.stroke();        };        //用于畫圓弧函數(shù) 默認(rèn)線條為黑色 無(wú)填充 參數(shù)分別為:圓心x坐標(biāo),圓心y坐標(biāo),半徑,開始位置,終止位置        function drawsArc(x, y, r, l1, l2) {            context.beginPath();            context.arc(x, y, r, l1 * Math.PI, l2 * Math.PI);            context.strokeStyle = "black";            context.stroke();        };        //用于畫眼睛的函數(shù)        function darwEyes(x1, y1, a1, b1) { //參數(shù)分別為橢圓圓心位置 長(zhǎng)軸  短軸            context.strokeStyle = "#754924"            ParamEllipse(context, x1, y1, a1, b1); //橢圓            function ParamEllipse(context, x, y, a, b) {                //使每次循環(huán)所繪制的路徑(弧線)接近1像素                var step = (a > b) ? 1 / a : 1 / b;                context.beginPath();                context.moveTo(x + a, y); //從橢圓的左端點(diǎn)開始繪制                for (var i = 0; i < 2 * Math.PI; i += step) {                    //參數(shù)為i,表示度數(shù)(弧度)                    context.lineTo(x + a * Math.cos(i), y + b * Math.sin(i));                }                context.closePath();                context.fillStyle = "#754924";                context.fill();                 context.stroke();            };        };        //臉        drawCircle(200, 200, 200, 0, 2, "#EEE685", "#FCF200");        //左眼        context.strokeStyle = "#754924"        darwEyes(116, 130, 18, 25);        drawCircle(110, 127, 12, 0, 2, "#754924", "#F5F5F5");        //右眼        darwEyes(296, 130, 18, 25);        drawCircle(290, 127, 12, 0, 2, "#754924", "#F5F5F5");        //左眉毛        drawsArc(100, 100, 50, 1.3, 1.7);        //右眉毛        drawsArc(300, 100, 50, 1.3, 1.7);        //嘴巴        drawsArc(200, 120, 180, 0.3, 0.7);    }</script></body>

效果圖

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 娱乐| 高台县| 沁源县| 桓台县| 桐柏县| 谷城县| 保靖县| 马公市| 井研县| 拉萨市| 美姑县| 客服| 同江市| 太仆寺旗| 屯门区| 巍山| 定日县| 平原县| 满城县| 泽普县| 天门市| 内江市| 乌鲁木齐县| 夹江县| 河津市| 蕉岭县| 城固县| 遵化市| 论坛| 凉城县| 江安县| 拜城县| 方正县| 铁力市| 澄城县| 正镶白旗| 密山市| 密山市| 辽源市| 蒙阴县| 满城县|