复制代码代码如下: !DOCTYPE html html xmlns="http://www.w3.org/1999/xhtml" head title /title script type="text/javascript" function draw() { //获取canvas对象 var canvas = document.getElementById('canvas'); if (canvas == null) { return false; } var context = canvas.getContext('2d'); context.fillStyle = '#99d9ea'; context.fillRect(0, 0, 300, 200); //填充画布结束
复制代码代码如下: 我是纯js画的圆 !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" html xmlns="http://www.w3.org/1999/xhtml" head title /title style type="text/css" div { position: absolute; width: 1px; height: 1px; line-height: 1px; } /style script src="http://www.cnblogs.com/jquery-1.7.1.js" type="text/javascript" /script script type="text/javascript" //x2 + y2 = r2; $(document).ready(function () { //先画x,y var box = $('#box'); var NUM = 200; var R = NUM / 2; var RR = R * R; for (var i = 0; i = NUM; i = i + 6) { //var divX = $(' div style="left:' + i + 'px;top:' + R + 'px;" * /div ') // var divY = $(' div style="top:' + i + 'px;left:' + R + 'px;" * /div ')
var ti = i; //sqrt(x) if (ti R) { ti = ti - R; var ty = Math.sqrt((RR - ti * ti)); var y = $(' div style="left:' + (R - ty) + 'px;top:' + i + 'px;" * /div ') var y1 = $(' div style="left:' + (R + ty) + 'px;top:' + i + 'px;" * /div ') box.append(y); box.append(y1); } else if (ti R) { ti = R - ti; var ty = Math.sqrt((RR - ti * ti)); var y = $(' div style="left:' + (R - ty) + 'px;top:' + i + 'px;" * /div ') var y1 = $(' div style="left:' + (R + ty) + 'px;top:' + i + 'px;" * /div ') box.append(y); box.append(y1); } //box.append(divX); //box.append(divY); }
for (var i = 0; i = NUM; i = i + 6) { //var divX = $(' div style="left:' + i + 'px;top:' + R + 'px;" * /div ') // var divY = $(' div style="top:' + i + 'px;left:' + R + 'px;" * /div ') var ti = i; //sqrt(x) if (ti R) { ti = ti - R; var ty = Math.sqrt((RR - ti * ti)); var y = $(' div style="top:' + (R - ty) + 'px;left:' + i + 'px;" * /div ') var y1 = $(' div style="top:' + (R + ty) + 'px;left:' + i + 'px;" * /div ') box.append(y); box.append(y1); } else if (ti R) { ti = R - ti; var ty = Math.sqrt((RR - ti * ti)); var y = $(' div style="top:' + (R - ty) + 'px;left:' + i + 'px;" * /div ') var y1 = $(' div style="top:' + (R + ty) + 'px;left:' + i + 'px;" * /div ') box.append(y); box.append(y1); } } });
复制代码代码如下: 正时针逆时针 !DOCTYPE html html xmlns="http://www.w3.org/1999/xhtml" head title /title script type="text/javascript" function draw() { //获取canvas对象 var canvas = document.getElementById('canvas'); if (canvas == null) { return false; } var context = canvas.getContext('2d'); context.fillStyle = '#99d9ea'; context.fillRect(0, 0, 400, 300); //填充画布结束
复制代码代码如下: 两次moveto !DOCTYPE html html xmlns="http://www.w3.org/1999/xhtml" head title /title script type="text/javascript" function draw() { //获取canvas对象 var canvas = document.getElementById('canvas'); if (canvas == null) { return false; } var context = canvas.getContext('2d'); context.fillStyle = '#99d9ea'; context.fillRect(0, 0, 300, 200); //填充画布结束
复制代码代码如下: 一次moveto !DOCTYPE html html xmlns="http://www.w3.org/1999/xhtml" head title /title script type="text/javascript" function draw() { //获取canvas对象 var canvas = document.getElementById('canvas'); if (canvas == null) { return false; } var context = canvas.getContext('2d'); context.fillStyle = '#99d9ea'; context.fillRect(0, 0, 300, 200); //填充画布结束
复制代码代码如下: 三次moveto !DOCTYPE html html xmlns="http://www.w3.org/1999/xhtml" head title /title script type="text/javascript" function draw() { //获取canvas对象 var canvas = document.getElementById('canvas'); if (canvas == null) { return false; } var context = canvas.getContext('2d'); context.fillStyle = '#99d9ea'; context.fillRect(0, 0, 300, 200); //填充画布结束