7-7练习
来源:7-7 编程练习
夕落呀
2018-12-23 01:25:03
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Document</title>
<style>
canvas{background-color:#000;opacity:0.7}
</style>
</head>
<body>
<canvas id="canvas" width="1200px" height="1000px">
您的浏览器不支持canvas
</canvas>
<script>
var canvas=document.getElementById("canvas");
var ctx=canvas.getContext("2d");
// 月亮
ctx.save();
ctx.shadowOffsetX=5;
ctx.shadowOffsetY=5;
ctx.shadowBlur=10;
ctx.shadowColor="rgba(255,255,255,.5)";
ctx.arc(150,150,50,0,2*Math.PI,true);
ctx.fillStyle="yellow";
ctx.fill();
ctx.restore();
// 文字
ctx.save();
ctx.beginPath();
ctx.shadowOffsetX=7;
ctx.shadowOffsetY=12;
ctx.shadowBlur=8;
ctx.shadowColor="rgba(255,255,255,.5)";
ctx.font="bold 60px 楷体";
ctx.fillStyle="white";
ctx.fillText('山高月小',780,250);
ctx.restore();
// 山峰
ctx.beginPath();
ctx.strokeStyle="#4D5DB2";
ctx.lineWidth="15";
ctx.moveTo(0,1000);
ctx.quadraticCurveTo(150,250,300,1000);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(260,1000);
ctx.quadraticCurveTo(300,400,500,1000);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(500,1000);
ctx.quadraticCurveTo(550,80,750,1000);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(700,1000);
ctx.quadraticCurveTo(900,150,1200,1000);
ctx.stroke();
</script>
</body>
</html>
1回答
同学你好,经测试实现效果是可以的,但是山峰也是有shadow阴影的,可以添加一下:
自己完善测试下,祝学习愉快!