javascript 绘图

<html>
<head>


<script type="text/javascript">


var lineH = 3; //线条高度
var cirSize = 2;
var color = "#2E2E2E"; //颜色




function drawHLine(sx,sy,width,height,c)
{
var body = document.body;
var d_div = document.createElement('div');


d_div.style.left = sx + 'px';
d_div.style.top = sy + 'px';
d_div.style.width= width + 'px';
d_div.style.height = height + 'px'; 


d_div.style.position = 'absolute';


d_div.style.backgroundColor = c;


body.appendChild(d_div);
}




function drawCircle(left,top,width,height,c,isBold)
{
var body = document.body;
var e_div = document.createElement('div');


var r;


r = width / 2;


e_div.style.left = (left - r) + 'px';
e_div.style.top = (top - r) + 'px';
e_div.style.width= width + 'px';
e_div.style.height = height + 'px'; 


e_div.style.position = 'absolute';


if(1 == isBold)
{
e_div.style.backgroundColor = c;
}
else
{
e_div.style.border = cirSize+'px solid ' + c;
}


e_div.style.borderRadius = Math.round(width / 2) + 10 + 'px';


body.appendChild(e_div);
}




function drawRect(left,top,width,height,c)
{
var body = document.body;
var r_div = document.createElement('div');


r_div.style.left = (left - (width / 2)) + 'px';
r_div.style.top = (top - (height / 2)) + 'px';
r_div.style.width= width + 'px';
r_div.style.height = height + 'px'; 


r_div.style.position = 'absolute';
r_div.style.backgroundColor = c;
body.appendChild(r_div);
}




</script>


</head>
<body>


</body>
<script>


var baseX = 100;
var baseY = 100;


function drawPicture()
{
var lastPos = 0;


drawHLine(baseX,baseY,38,lineH,color);
lastPos = baseX + 38; 


drawCircle(lastPos + 27,baseY,54,54,color,0);
drawCircle(lastPos + 29,baseY + 2,48,48,color,1);
lastPos = lastPos + 54 + 4;


drawHLine(lastPos,baseY,18,lineH,color);
lastPos = lastPos + 18;


drawCircle(lastPos + 27,baseY,54,54,color,0);
drawRect(lastPos + 27,baseY + 30,65,54,'#FFF');
drawCircle(lastPos + 29,baseY + 2,48,48,color,1);
lastPos = lastPos + 54 + 4;


drawHLine(lastPos,baseY,18,lineH,color);
lastPos = lastPos + 18;


drawCircle(lastPos + 27,baseY,54,54,color,0);
drawRect(lastPos + 27,baseY - 27,65,54,'#FFF');
drawCircle(lastPos + 29,baseY + 2,48,48,color,1);
lastPos = lastPos + 54 + 4;


drawHLine(lastPos,baseY,18,lineH,color);
lastPos = lastPos + 18;


drawCircle(lastPos + 21,baseY + 2,36,36,color,1);
lastPos = lastPos + 42;


drawHLine(lastPos,baseY,38,lineH,color);
lastPos = lastPos + 35;


drawCircle(lastPos + 29,baseY + 2,48,48,color,1);
lastPos = lastPos + 55;


drawHLine(lastPos,baseY,18,lineH,color);
lastPos = lastPos + 18;


drawCircle(lastPos + 27,baseY,54,54,color,0);
drawRect(lastPos + 45,baseY - 15,30,30,'#FFF');
drawRect(lastPos + 45 - 27 - 5,baseY - 15 + 27 + 6,30,30,'#FFF');
drawCircle(lastPos + 29,baseY + 2,48,48,color,1);


lastPos = lastPos + 56;
drawHLine(lastPos,baseY,38,lineH,color);
}






drawPicture();


</script>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值