无为清净楼资源网 Design By www.qnjia.com

在控制台中输入 
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="/UploadFiles/2021-04-02/">                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实现画板的代码

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。