天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

用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實現畫板的代碼,轉載需保留來源!

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

主站蜘蛛池模板: 美女大本营 | 欧美手机在线 | 总攻催眠受的高h巨肉np | 青青伊人影院 | 欧美精品一区二区三区四区 | 男人大臿蕉香蕉大视频 | 九九精品久久 | 国产亚洲精品久久久久久鸭绿欲 | 青草在线在线d青草在线 | 99国内精品久久久久久久清纯 | 国拍在线精品视频免费观看 | 在线观看亚洲 日韩 国产 | 亚洲国产综合久久精品 | 办公室沙发口爆12P 办公室日本肉丝OL在线 | 91成品视频 | 国产福利视频一区二区 | 美女gif趴跪式动态图 | 国产探花在线精品一区二区 | 国产精品一区二区亚瑟不卡 | 乱爱性全过程免费视频 | 寂寞骚妇女被后入式抽插 | 亚洲午夜精品A片久久WWW软件 | 无码乱人伦一区二区亚洲 | 亚洲欧洲精品成人久久曰影片 | 美女被爆羞羞天美传媒 | 暖暖的高清视频在线观看免费中文 | 超碰在线视频 | 亚洲中文字幕无码一久久区 | 国产露脸A片国语露对白 | 秋霞在线观看视频一区二区三区 | 成都电影免费中文高清 | 手机在线免费观看毛片 | 日韩精品a在线视频 | 无码人妻精品国产婷婷 | 黑色丝袜美女被网站 | 久久99国产综合精品AV蜜桃 | 中文字幕人成人乱码亚洲AV | 亚洲日本欧美天堂在线 | 国产精品久久久久久久久久免费 | 91九色精品国产免费 | 在线观看视频中文字幕 |