第25章 canvas绘制圆形
html
<!doctype html> <html> <head> <meta charset="utf-8"> <title></title> <script type="text/javascript" src="25.js"></script> <style type="text/css"> body{ margin:0; padding:0;} </style> </head> <body onLoad="draw('canvas')"> <canvas id="canvas" width='400' height="300"></canvas> </body> </html>
js
// JavaScript Document function draw(id){ var context = document.getElementById(id).getContext('2d'); context.beginPath(); context.strokeStyle = "rgb(0,0,0)"; context.arc(100,100,100,0,2*Math.PI,true); context.closePath(); context.fillStyle = 'rgb(200,0,200)'; context.fill(); context.beginPath(); context.arc(50,75,25,0,2*Math.PI,true); context.fillStyle = 'rgb(0,0,0)'; context.fill(); context.beginPath(); context.arc(150,75,25,0,2*Math.PI,true); context.fillStyle = 'rgb(0,0,0)'; context.fill(); context.beginPath(); context.arc(150,75,25,0,2*Math.PI,true); context.fillStyle = 'rgb(0,0,0)'; context.fill(); context.beginPath(); context.arc(100,125,10,0,2*Math.PI,true); context.fillStyle = 'rgb(0,0,0)'; context.fill(); context.beginPath(); context.strokeStyle = "rgb(0,0,0)"; context.lineWidth = 5; context.arc(100,150,25,Math.PI/6,5*Math.PI/6,false); context.stroke(); }
效果图:
相关推荐
大地飞鸿 2020-11-12
星星有所不知 2020-10-12
jinxiutong 2020-07-26
MIKUScallion 2020-07-05
songfens 2020-07-05
songfens 2020-06-11
songfens 2020-06-08
northwindx 2020-05-31
northwindx 2020-05-31
northwindx 2020-05-27
northwindx 2020-05-25
MIKUScallion 2020-05-25
jinxiutong 2020-05-10
xdyangxiaoromg 2020-05-10
大地飞鸿 2020-05-06
northwindx 2020-04-25