首页 > web前端 > js教程 > 正文

用javascript实现画板的代码_javascript技巧

php中文网
发布: 2016-05-16 19:09:17
原创
1376人浏览过

在控制台中输入 
db.drawCircle([50,50],20,"black"); 
db.drawLine([5,5],[36,44],"red"); 
可以看到效果 

国洋商务通
国洋商务通

Gyb2b V1.01免费版可终身使用,是一款功能强大的B2B电子商务应用软件。该软件不仅更新和修改了V1.0相关功能,更是采用了目前互联网上最流行的LAMP组合(Linux+Apache+Mysql+PHP)开发完成,模板技术实现了界面与代码的有效分离,用户可以快速地在此基础上编译模板;提供B2B电子商务应用最常见的求购、供应、商品、公司库、行业资讯、商圈、资信认证、在线交易、交易评分、留言、搜

国洋商务通 0
查看详情 国洋商务通
复制代码 代码如下:

 
 
<script> <BR> function DrawingBoard(width,height,size) <BR> { <BR> size=size||3 <BR> var container=document.createElement("div"); <BR> this.container=container; <br><br> container.runtimeStyle.width=(width)*size+"px"; <BR> container.runtimeStyle.height=(height)*size+"px"; <BR> container.runtimeStyle.margin="0px"; <BR> //container.style.border="solid 1px blue"; <BR> var count=0; <BR> for(var y=0;y<height;y++) <BR> { <BR> for(var x=0;x<width;x++) <BR> { <BR> var curr=document.createElement("div"); <BR> curr.runtimeStyle.height=size+"px"; <BR> curr.runtimeStyle.width=size+"px"; <BR> curr.runtimeStyle.display="inline"; <BR> curr.runtimeStyle.overflow="hidden"; <BR> curr.style.backgroundColor="green"; <BR> curr.src=""; <BR> container.appendChild(curr); <BR> } <BR> } <BR> //alert(curr.currentStyle.display); <BR> //document.body.appendChild(container); <br><br> this.drawLine=function(start,end,color) <BR> { <BR> var dx=start[0]-end[0]; <BR> var dy=start[1]-end[1]; <BR> var x,y; <br><br> if( Math.abs(dx) > Math.abs(dy) ) <BR> { <BR> for(var x=start[0];x!=end[0]+(end[0]-start[0])/Math.abs(end[0]-start[0]);x+=(end[0]-start[0])/Math.abs(end[0]-start[0]) ) <BR> { <BR> y=Math.round((x-start[0])/dx*dy+start[1]); <BR> this.container.childNodes[this.trans([x,y])].style.backgroundColor=color; <BR> } <BR> } <BR> else <BR> { <BR> for(var y=start[1];y!=end[1]+(end[1]-start[1])/Math.abs(end[1]-start[1]);y+=(end[1]-start[1])/Math.abs(end[1]-start[1]) ) <BR> { <BR> x=Math.round((y-start[1])/dy*dx+start[0]); <BR> this.container.childNodes[this.trans([x,y])].style.backgroundColor=color; <BR> } <BR> } <BR> } <BR> this.drawCircle=function(m,R,color) <BR> { <br><br> for(var r=0;r<=Math.floor(Math.sqrt(R*R-r*r));r++) <BR> { <br><br> x=m[0]+r;y=m[1]+Math.floor(Math.sqrt(R*R-r*r)); <BR> this.container.childNodes[this.trans([x,y])].style.backgroundColor=color; <BR> x=m[0]-r;y=m[1]+Math.floor(Math.sqrt(R*R-r*r)); <BR> this.container.childNodes[this.trans([x,y])].style.backgroundColor=color; <BR> x=m[0]+r;y=m[1]-Math.floor(Math.sqrt(R*R-r*r)); <BR> this.container.childNodes[this.trans([x,y])].style.backgroundColor=color; <BR> x=m[0]-r;y=m[1]-Math.floor(Math.sqrt(R*R-r*r)); <BR> this.container.childNodes[this.trans([x,y])].style.backgroundColor=color; <BR> y=m[1]+r;x=m[0]+Math.floor(Math.sqrt(R*R-r*r)); <BR> this.container.childNodes[this.trans([x,y])].style.backgroundColor=color; <BR> y=m[1]-r;x=m[0]+Math.floor(Math.sqrt(R*R-r*r)); <BR> this.container.childNodes[this.trans([x,y])].style.backgroundColor=color; <BR> y=m[1]+r;x=m[0]-Math.floor(Math.sqrt(R*R-r*r)); <BR> this.container.childNodes[this.trans([x,y])].style.backgroundColor=color; <BR> y=m[1]-r;x=m[0]-Math.floor(Math.sqrt(R*R-r*r)); <BR> this.container.childNodes[this.trans([x,y])].style.backgroundColor=color; <br><br> } <br><br><BR> } <BR> this.appendto=function(parent) <BR> { <BR> parent.appendChild(this.container); <BR> } <br><br> this.drawPoint=function(p,color) <BR> { <BR> this.container.childNodes[this.trans(p)].style.backgroundColor=color; <BR> } <BR> this.trans=function(p) <BR> { <BR> return p[0]+p[1]*width; <BR> } <br><br> container=null; <BR> } <BR> function Console(width,height,command) <BR> { <BR> var container=document.createElement("div"); <BR> this.container=container; <br><br> container.runtimeStyle.width=(width); <BR> container.runtimeStyle.height=(height); <BR> container.runtimeStyle.margin="0px"; <BR> container.runtimeStyle.backgroundColor="black"; <BR> container.runtimeStyle.fontFamily="Terminal"; <BR> container.runtimeStyle.color="white"; <BR> container.runtimeStyle.fontSize="16px"; <BR> this.output=document.createElement("div"); <BR> container.appendChild(this.output); <BR> container.innerHTML+="js>" <BR> this.input=document.createElement("input"); <BR> container.appendChild(this.input); <BR> this.input.runtimeStyle.backgroundColor="black"; <BR> this.input.runtimeStyle.borderWidth="0px"; <BR> this.input.runtimeStyle.color="white"; <BR> this.input.runtimeStyle.fontFamily="Terminal"; <BR> this.input.runtimeStyle.width="90%" <BR> this.input.runtimeStyle.fontSize="16px" <BR> this.input.runtimeStyle.position="relative"; <BR> this.input.runtimeStyle.top="2px"; <BR> command=command||function(str) <BR> { <br><br> var e; <BR> try{ <BR> var r=eval(str); <BR> } catch(e) { <BR> return "Bad command"; <BR> } <BR> return r; <br><br> } <BR> this.run=function(str) <BR> { <br><br> this.input.parentNode.childNodes[0].innerHTML+=str+'<br/>' <BR> this.input.parentNode.childNodes[0].innerHTML+=(command(str)+"<br/>") <br><br> } <BR> this.input.command=function() <BR> { <BR> this.parentNode.childNodes[0].innerHTML+=this.value+'<br/>' <BR> this.parentNode.childNodes[0].innerHTML+=(command(this.value)+"<br/>") <BR> } <BR> this.input.onkeyup=new Function("e","e=e||event;if(e.keyCode!=13)return;this.command();this.value='';"); <BR> this.appendto=function(parent) <BR> { <BR> parent.appendChild(this.container); <BR> } <BR> container=null; <BR> } <br><br> var c=new Console("100%","50%"); <BR> c.appendto(document.body); <BR> c.run("window.db=new DrawingBoard(100,100);document.body.appendChild(db.container);"); <BR></script>
java速学教程(入门到精通)
java速学教程(入门到精通)

java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号