• canvas画线条


    随手写的一个canvas 本想写成三角形  但存在bug  先记录 后面再改
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <link>
    <meta name="page-view-size" content="640*530">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <style type="text/css">
    body{
    background: #456E89;
    }
    .canvas {
    height: 300px;
    300px;
    margin: 0 auto;
    font-family: arial;

    }
    </style>
    </head>
    <body leftmargin="0" topmargin="0">

    <div class="canvas">
    <canvas id="cvs" width="300" height="300"></canvas>
    </div>

    <script type="text/javascript">


    function createObj(obj){
    this.obj=obj;
    var node=this.obj.Node,
    startX=this.obj.startX,
    endX=this.obj.endX,
    startY=this.obj.startY,
    endY= this.obj.endY,
    delay=this.obj.delay||0,
    numx=Math.abs(endX-startX)/ (this.obj.time/100),
    numy=Math.abs(endY-startY)/(this.obj.time/100);
    // console.log(n)
    this.obj.draw=function(){
    node.beginPath();
    node.moveTo(startX,startY);
    setTimeout(function (){
    var sx=startX,ex=endX,
    sy=startY,ey=endY;
    move();
    function move(){
    if(endX>startX) {
    if(sx>=endX){
    clearTimeout(timerx)
    }else{
    startX<endX?sx+=numx:sx-=numx;
    var timerx=setTimeout(function(){
    node.lineTo(sx,sy);
    move()
    },100);
    }

    }
    if(endX<startX) {
    if(sx<=endX) {
    clearTimeout(timerx)
    }else{
    startY<endY?sx+=numx:sx-=numx;
    var timerx=setTimeout(function(){
    node.lineTo(sx,sy);
    move()
    },100);
    }

    }

    if(endY>startY) {
    if(sy>=endY){
    clearTimeout(timery)
    }else{
    startY<endY?sy+=numy:sy-=numy;
    var timery=setTimeout(function(){
    node.lineTo(sx,sy);
    move()
    },100);
    }

    }
    if(endY<startY) {
    if(sy<=endY){
    clearTimeout(timery)
    }else{
    startY<endY?sy+=numy:sy-=numy; var timery=setTimeout(function(){ node.lineTo(sx,sy); move() },100); } } node.strokeStyle=this.obj.color; node.lineWidth=this.obj.width; node.stroke(); } },delay); } return this.obj; } window.onload=function(){ var cvs=document.getElementById('cvs').getContext("2d"); var line2={ Node:cvs, startX:10, startY:20, endX:60, endY:180, time:9000, color:'#ffffff', 5, }; var l2=createObj(line2); l2.draw(); }</script></body></html>
    万事开头难 然后中间难 最后结尾难
  • 相关阅读:
    Eclipse配置SVN的几种方法及使用详情
    重新定位svn地址的方法(windows和linux),svn switch(sw)的帮助信息
    SVN版本库修改URL路径或者IP地址
    DEA中MAVEN项目有多个子目录,如何加载构建
    DBA的40条军规
    搜索 比MySQL快10倍?这可能是目前AWS Aurora最详解读!
    HttpClient 4.5.3 get和post请求
    基于HttpClient4.5.2实现的HttpClient工具类
    httpClient使用总结
    为何只能在其关联的线程内启动timer?(Qt会检查一致性,否则就不执行)
  • 原文地址:https://www.cnblogs.com/chaimens/p/6367955.html
Copyright © 2020-2023  润新知