Canvas画三个实心圆为什么中间会填充颜色?

Ice lie 2018-08-23 09:21:46
代码:

<!DOCTYPE HTML>

<head>

<title>this is a dice game!!!</title>

<style>

.btn-cls{

position:absolute;

top:400px;

left:250px;

}

</style>

</head>

<body>

<canvas id="canvas" width="600" height="600">

your browser doesn't support the HTML5 element canvas.

</canvas>

<button id="btn" class="btn-cls" onclick="Throw()" >开始投掷</button>

<script>

var ctx; // canvas上下文

var point1,point2;

ctx = document.getElementById('canvas').getContext('2d');

// 绘制画布

ctx.strokeRect(0,0,600,600);

// 绘制两个骰子

ctx.strokeRect(100,100,150,150);

ctx.strokeRect(350,100,150,150);

function Throw(){ // 投掷按钮

point1 = Math.ceil(Math.random() * 6);

point2 = Math.ceil(Math.random() * 6);

DrawPoint(point1,point2);

}

function DrawPoint(drawPoint1,drawPoint2){ // 绘制骰子上面的点

ctx.clearRect(110,110,130,130);

ctx.beginPath();

ctx.arc(135,215,5,0,2 * Math.PI);

ctx.arc(215,215,5,0,2 * Math.PI);

ctx.arc(215,135,5,0,2 * Math.PI);

ctx.fillStyle = "block";

ctx.closePath();

ctx.fill();

}

</script>

</body>
...全文
291 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Ice lie 2018-08-23
  • 打赏
  • 举报
回复
少了ctx.moveTO();

61,112

社区成员

发帖
与我相关
我的任务
社区描述
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
社区管理员
  • HTML(CSS)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧