最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

html4画直线不是用的html5技术_html/css

来源:动视网 责编:小采 时间:2020-11-27 16:31:32
文档

html4画直线不是用的html5技术_html/css

html4画直线不是用的html5技术_html/css_WEB-ITnose:html4 画直线 div模拟点 直线算法 line.html //能画直线就能画其他的图像,只是需要相应的算法,不过这样用性能不是很好,当然一下的代码还有不完善的地方,在这里只是做个演示 //因为公司最近要做个图像化的功能,我只会
推荐度:
导读html4画直线不是用的html5技术_html/css_WEB-ITnose:html4 画直线 div模拟点 直线算法 line.html //能画直线就能画其他的图像,只是需要相应的算法,不过这样用性能不是很好,当然一下的代码还有不完善的地方,在这里只是做个演示 //因为公司最近要做个图像化的功能,我只会


html4 画直线 div模拟点 直线算法




line.html














//能画直线就能画其他的图像,只是需要相应的算法,不过这样用性能不是很好,当然一下的代码还有不完善的地方,在这里只是做个演示
//因为公司最近要做个图像化的功能,我只会js
function Point(x,y,c){//用一个div模拟一个像素点x和y是坐标c是颜色
var div;
this.div=document.createElement("div");
this.div.style.fontSize="0px";
this.div.style.overFlow="hidden";
this.div.style.width="1px";
this.div.style.height="1px";
this.div.style.position="absolute";
this.div.style.backgroundColor=c;
this.div.style.top=y+"px";
this.div.style.left=x+"px";
document.body.appendChild(this.div);

}




function drawLine(x0,y0,x1,y1,c){//画一条直线x0,y0,x1,y1分别是开始坐标和结束坐标c是颜色
var x,y;
var cx,cy;
var steps=Math.abs(x1-x0)>Math.abs(y1-y0)?Math.abs(x1-x0):Math.abs(y1-y0);
x=parseFloat(x0);
y=parseFloat(y0);
cx=(x1-x0)/steps;
cy=(y1-y0)/steps;
for(var i=0;i new Point(Math.round(x),Math.round(y),c);
x+=cx;
y+=cy;
}

}
// drawLine(0,0,200,200,"red");
/* for(var i=0;i<1000;i+=20){
//drawLine(0,0,200,i,"#00ff00");
drawLine(i,0,i,1000,"#00ff00");
drawLine(0,i,1000,i,"#00ff00");
}*/
drawLine(20,1000,0,0,"#00ff00");
var posX,posY,selectDiv;//这里的 selectDiv是一个选择框
document.onmousedown=function(e){
if(!e)e=window.event;
posX=e.clientX;
posY=e.clientY;
selectDiv=document.createElement("div");
selectDiv.style.fontSize="0px";
selectDiv.style.overFlow="hidden";
selectDiv.style.width="1px";
selectDiv.style.height="1px";
selectDiv.style.position="absolute";

selectDiv.style.top=posY+"px";
selectDiv.style.left=posX+"px";
selectDiv.style.border="1px dashed #B3B3B3";
document.body.appendChild(selectDiv);

}
document.onmousemove=function(e){
if(!e)e=window.event;
if(selectDiv){

selectDiv.style.width=(e.clientX-posX)+"px";
selectDiv.style.height=(e.clientY-posY)+"px";
drawLine(posX,posY,e.clientX,e.clientY,"red");
}
}


//new Point(20,20,"green");



回复讨论(解决方案)



屏幕绘制像素级别的直线可以直接确定每个点的坐标 因为不会出现小数坐标

x 每个点必须 1-x
y 根据 1 - (1-x)/(x/y)比例增加

文档

html4画直线不是用的html5技术_html/css

html4画直线不是用的html5技术_html/css_WEB-ITnose:html4 画直线 div模拟点 直线算法 line.html //能画直线就能画其他的图像,只是需要相应的算法,不过这样用性能不是很好,当然一下的代码还有不完善的地方,在这里只是做个演示 //因为公司最近要做个图像化的功能,我只会
推荐度:
标签: html5 html css
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top