一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

用javascript實現畫板的代碼

在控制臺中輸入 
db.drawCircle([50,50],20,"black"); 
db.drawLine([5,5],[36,44],"red"); 
可以看到效果 
復制代碼 代碼如下:
<body style="margin:0px;"> 
</body> 
<script> 
    function DrawingBoard(width,height,size) 
    { 
        size=size||3 
        var container=document.createElement("div"); 
        this.container=container; 

        container.runtimeStyle.width=(width)*size+"px"; 
        container.runtimeStyle.height=(height)*size+"px"; 
        container.runtimeStyle.margin="0px"; 
        //container.style.border="solid 1px blue"; 
        var count=0; 
                for(var y=0;y<height;y++) 
        { 
            for(var x=0;x<width;x++) 
            { 
                var curr=document.createElement("div"); 
                curr.runtimeStyle.height=size+"px"; 
                curr.runtimeStyle.width=size+"px"; 
                curr.runtimeStyle.display="inline"; 
                curr.runtimeStyle.overflow="hidden"; 
                curr.style.backgroundColor="green"; 
                curr.src=""; 
                container.appendChild(curr); 
            } 
        } 
                //alert(curr.currentStyle.display); 
        //document.body.appendChild(container); 

        this.drawLine=function(start,end,color) 
        { 
            var dx=start[0]-end[0]; 
            var dy=start[1]-end[1]; 
            var x,y; 

            if( Math.abs(dx) > Math.abs(dy) ) 
            { 
                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]) ) 
                { 
                    y=Math.round((x-start[0])/dx*dy+start[1]); 
                    this.container.childNodes[this.trans([x,y])].style.backgroundColor=color; 
                } 
            } 
            else 
            { 
                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]) ) 
                { 
                    x=Math.round((y-start[1])/dy*dx+start[0]); 
                    this.container.childNodes[this.trans([x,y])].style.backgroundColor=color; 
                } 
            } 
        } 
        this.drawCircle=function(m,R,color) 
        { 

            for(var r=0;r<=Math.floor(Math.sqrt(R*R-r*r));r++) 
            { 

                x=m[0]+r;y=m[1]+Math.floor(Math.sqrt(R*R-r*r)); 
                this.container.childNodes[this.trans([x,y])].style.backgroundColor=color; 
                x=m[0]-r;y=m[1]+Math.floor(Math.sqrt(R*R-r*r)); 
                this.container.childNodes[this.trans([x,y])].style.backgroundColor=color; 
                x=m[0]+r;y=m[1]-Math.floor(Math.sqrt(R*R-r*r)); 
                this.container.childNodes[this.trans([x,y])].style.backgroundColor=color; 
                x=m[0]-r;y=m[1]-Math.floor(Math.sqrt(R*R-r*r)); 
                this.container.childNodes[this.trans([x,y])].style.backgroundColor=color; 
                y=m[1]+r;x=m[0]+Math.floor(Math.sqrt(R*R-r*r)); 
                this.container.childNodes[this.trans([x,y])].style.backgroundColor=color; 
                y=m[1]-r;x=m[0]+Math.floor(Math.sqrt(R*R-r*r)); 
                this.container.childNodes[this.trans([x,y])].style.backgroundColor=color; 
                y=m[1]+r;x=m[0]-Math.floor(Math.sqrt(R*R-r*r)); 
                this.container.childNodes[this.trans([x,y])].style.backgroundColor=color; 
                y=m[1]-r;x=m[0]-Math.floor(Math.sqrt(R*R-r*r)); 
                this.container.childNodes[this.trans([x,y])].style.backgroundColor=color; 

            } 


        } 
        this.appendto=function(parent) 
        { 
            parent.appendChild(this.container); 
        } 

        this.drawPoint=function(p,color) 
        { 
            this.container.childNodes[this.trans(p)].style.backgroundColor=color; 
        } 
        this.trans=function(p) 
        { 
            return p[0]+p[1]*width; 
        } 

        container=null; 
    } 
    function Console(width,height,command) 
    { 
        var container=document.createElement("div"); 
        this.container=container; 

        container.runtimeStyle.width=(width); 
        container.runtimeStyle.height=(height); 
        container.runtimeStyle.margin="0px"; 
        container.runtimeStyle.backgroundColor="black"; 
        container.runtimeStyle.fontFamily="Terminal"; 
        container.runtimeStyle.color="white"; 
        container.runtimeStyle.fontSize="16px"; 
        this.output=document.createElement("div"); 
        container.appendChild(this.output); 
        container.innerHTML+="js>" 
        this.input=document.createElement("input"); 
        container.appendChild(this.input); 
        this.input.runtimeStyle.backgroundColor="black"; 
        this.input.runtimeStyle.borderWidth="0px"; 
        this.input.runtimeStyle.color="white"; 
        this.input.runtimeStyle.fontFamily="Terminal"; 
        this.input.runtimeStyle.width="90%" 
        this.input.runtimeStyle.fontSize="16px" 
        this.input.runtimeStyle.position="relative"; 
        this.input.runtimeStyle.top="2px"; 
        command=command||function(str) 
        { 

            var e; 
            try{ 
                var r=eval(str); 
            } catch(e) { 
                return "Bad command"; 
            } 
            return r; 

        } 
        this.run=function(str) 
        { 

            this.input.parentNode.childNodes[0].innerHTML+=str+'<br/>' 
            this.input.parentNode.childNodes[0].innerHTML+=(command(str)+"<br/>") 

        } 
        this.input.command=function() 
        { 
            this.parentNode.childNodes[0].innerHTML+=this.value+'<br/>' 
            this.parentNode.childNodes[0].innerHTML+=(command(this.value)+"<br/>") 
        } 
        this.input.onkeyup=new Function("e","e=e||event;if(e.keyCode!=13)return;this.command();this.value='';"); 
        this.appendto=function(parent) 
        { 
            parent.appendChild(this.container); 
        } 
        container=null; 
    } 

    var c=new Console("100%","50%"); 
    c.appendto(document.body); 
    c.run("window.db=new DrawingBoard(100,100);document.body.appendChild(db.container);"); 
</script>

JavaScript技術用javascript實現畫板的代碼,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 国产精品久久现线拍久青草 | 精品国产91乱码一区二区三区 | 久久综合中文字幕一区二区三区 | 欧美一级久久久久久久大片 | 蜜桃久久久 | 女人洗澡一级毛片一级毛片 | 在线日本妇人成熟免费观看 | 欧美成人网在线综合视频 | 第一页综合| 伊人久久大香线蕉综合热线 | 韩国美女爽快一级毛片黄 | 国内精品视频一区二区三区 | 亚洲一区精品视频在线 | 久久这里精品青草免费 | 亚洲人成图片小说网站 | 国产拍拍视频一二三四区 | 五月六月婷婷 | 国产精品久久精品福利网站 | 国产剧情一区二区 | 久久精品国产无限资源 | 日韩美女一级视频 | 一区二区三区在线播放视频 | 91在线网| 色综合天天综合网站中国 | 97精品伊人久久大香线蕉 | 黄色片网站在线免费观看 | 欧美精品做人一级爱免费 | 国产综合激情在线亚洲第一页 | 一木道一二三区精品 | 欧美在线tv | 夜色资源站www国产在线资源 | 国产成人精品综合网站 | 国产91一区二区在线播放不卡 | 91在线视频国产 | 国产一级久久免费特黄 | 黄色网址在线视频 | 国产91第一页 | 精品国产免费观看 | 亚洲人成图片欧美人成图片 | 国产男人女人做性全过程视频 | 国产高跟黑色丝袜在线 |