新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论SVG, GML, X3D, VRML, VML, XAML, AVALON, Batik等基于XML的图形技术,以及有关GIS的应用。
    [返回] 中文XML论坛 - 专业的XML技术讨论区XML.ORG.CN讨论区 - 高级XML应用『 SVG/GML/VRML/X3D/XAML 』 → [转帖]svg实例--两点控制的线 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 6372 个阅读者浏览上一篇主题  刷新本主题   平板显示贴子 浏览下一篇主题
     * 贴子主题: [转帖]svg实例--两点控制的线 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     wanghai00 帅哥哟,离线,有人找我吗?魔羯座2000-12-31
      
      
      威望:4
      等级:大四(总算啃完XML规范了)
      文章:108
      积分:1085
      门派:XML.ORG.CN
      注册:2005/10/1

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给wanghai00发送一个短消息 把wanghai00加入好友 查看wanghai00的个人资料 搜索wanghai00在『 SVG/GML/VRML/X3D/XAML 』的所有贴子 点击这里发送电邮给wanghai00  访问wanghai00的主页 引用回复这个贴子 回复这个贴子 查看wanghai00的博客楼主
    发贴心情 [转帖]svg实例--两点控制的线

    svg源文件:

    <?xml version="1.0" standalone="no"?>
    <svg xml:space="preserve" viewBox="0 0 1.8 1.8" width="600" height="450" onload="DoOnLoad( evt )"
    contentScriptType="text/ecmascript"
    version="1.1" baseProfile="full"
    xmlns:a="http://www.adobe.com/svg10-extensions"
    xmlns="http://www.w3.org/2000/svg"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    xmlns:ev="http://www.w3.org/2001/xml-events" a:timeline="independent">
    <desc>Functional Key Spline graph created in SVG and Javascript</desc>
    <script><![CDATA[

    var dragger = null;
    var origTransform = "";
    var oldX;
    var oldY;
    var origX;
    var origY;
    var oldTranslateX;
    var oldTranslateY;
    function DoOnMouseOver(evt)
    {
      var onObject = evt.getTarget();
      if( onObject.getAttribute("id") == "pointOne" || onObject.getAttribute("id") == "pointTwo")
      {
      onObject.getStyle().setProperty("opacity", "0.5");
      }
    }
    function DoOnMouseOut(evt)
    {
      var onObject = evt.getTarget();
      if( onObject.getAttribute("id") == "pointOne" || onObject.getAttribute("id") == "pointTwo")
      {
      onObject.getStyle().setProperty("opacity", "0.3");
      }
    }
        
    function DoOnLoad(evt)
    {
      // useless leftovers
      var el = getSVGDocument(evt.getTarget()).getElementById("pointOne");
      el.getStyle().setProperty("fill", "black");
    }
    function DoOnMouseDown(evt)
    {
      var onObject = evt.getTarget();
      if( onObject.getAttribute("id") == "pointOne" || onObject.getAttribute("id") == "pointTwo")
      {
       dragger = onObject;
       oldX = Math.abs(dragger.getAttribute("cx")); // has to be abs'd so
       oldY = Math.abs(dragger.getAttribute("cy")); // it isn't a string(?)
       origX = evt.getClientX();
       origY = evt.getClientY();
       oldTranslateX = 0; // not used any more?
       oldTranslateY = 0;
      }
    }
    function DoOnMouseMove(evt)
    {
        if( dragger != null )
        {
      dragger.getStyle().setProperty("opacity", "0.75");
      // problem is here - initially drops to zero - also, it has
      // to be multiplied by 0.004 for the exact display resolution
      // - wanted replace oldTranslateX with oldX, but it adds as a string?
      var newX = Math.max(Math.min((oldX + (evt.getClientX() - origX) * 0.004),1),0);
      var newY = Math.max(Math.min((oldY + (evt.getClientY() - origY) *-0.004),1),0);
      var curve = getSVGDocument(evt.getTarget()).getElementById("kSpline");
      if( dragger.getAttribute("id") == "pointOne" )
      {
       var other = getSVGDocument(evt.getTarget()).getElementById("pointTwo");
       var cLine1 = getSVGDocument(evt.getTarget()).getElementById("cL1");
       var curX2 = other.getAttribute("cx");
       var curY2 = other.getAttribute("cy");
       var transformT = "keySplines=\"" +
         Math.round(newX*100)/100 + " " + Math.round(newY*100)/100 + "  " +
         Math.round(curX2*100)/100 + " " + Math.round(curY2*100)/100 + "\"";
       curve.setAttribute("d", "M0,0C" +
         newX + "," + newY + " " +
         curX2 + "," + curY2 + " 1,1");
       cLine1.setAttribute("x2", newX);
       cLine1.setAttribute("y2", newY);
      }
      else
      {
       var other = getSVGDocument(evt.getTarget()).getElementById("pointOne");
       var cLine2 = getSVGDocument(evt.getTarget()).getElementById("cL2");
       var curX1 = other.getAttribute("cx");
       var curY1 = other.getAttribute("cy");
       var transformT = "keySplines=\"" +
         Math.round(curX1*100)/100 + " " + Math.round(curY1*100)/100 + "  " +
         Math.round(newX*100)/100 + " " + Math.round(newY*100)/100 + "\"";
       curve.setAttribute("d", "M0,0C" +
         curX1 + "," + curY1 + " " +  
         newX + "," + newY + " 1,1");
       cLine2.setAttribute("x2", newX);
       cLine2.setAttribute("y2", newY);
      }
      var coordsText = getSVGDocument(evt.getTarget()).getElementById("coords");
      coordsText.getFirstChild().setData(transformT);
        
      dragger.setAttribute("cx", newX);
      dragger.setAttribute("cy", newY);
        }
    }
    function DoOnMouseUp(evt)
    {
      if( dragger != null )
      {
       dragger.getStyle().setProperty("opacity", "0.3");
       dragger = null;
       origTransform = ""
       oldX = 0;
       oldY = 0;
       origX = 0;
       origY = 0;
       oldTranslateX = 0;
       oldTranslateY = 0;
      }
    }
    function getSVGDocument(node)
    {
      // given any node of the tree, will obtain the SVGDocument node.
      // must be careful: a Document node's ownerDocument is null!
      if( node.getNodeType() != 9 )  // if not DOCUMENT_NODE
       return node.getOwnerDocument();
      else
       return node;
    }
    ]]></script>
    <defs>
       <line id="sLine" x1="0" y1="0" x2="1" y2="0"
    style="stroke:#BBB;stroke-width:0.01" />
       <g id="lSet1">
         <use xlink:href="#sLine" x="0" y="1.0" />
         <use xlink:href="#sLine" x="0" y="0.9" />
         <use xlink:href="#sLine" x="0" y="0.8" />
         <use xlink:href="#sLine" x="0" y="0.7" />
         <use xlink:href="#sLine" x="0" y="0.6" />
         <use xlink:href="#sLine" x="0" y="0.5" />
         <use xlink:href="#sLine" x="0" y="0.4" />
         <use xlink:href="#sLine" x="0" y="0.3" />
         <use xlink:href="#sLine" x="0" y="0.2" />
         <use xlink:href="#sLine" x="0" y="0.1" />
         <use xlink:href="#sLine" x="0" y="0.0" />
       </g>
    </defs>
    <g id="all" onmouseover="DoOnMouseOver( evt )" onmouseout="DoOnMouseOut( evt )" onmousedown="DoOnMouseDown( evt )" onmouseup="DoOnMouseUp( evt )" onmousemove="DoOnMouseMove( evt )">
    <rect id="bg" x="-0.3" y="0.05" width="2.6" height="1.75"
    style="fill:white" />
    <text x="0.15" y="0.2" style="fill:#348;stroke:none;font-size:0.15;">Key Splines graph tool</text>
    <text x="-0.1" y="0.4" style="fill:#444;stroke:none;font-size:0.054;">
    <tspan x="-0.25" y="0.5">  This SVG file</tspan>
    <tspan x="-0.25" y="0.56">demonstrates how</tspan>
    <tspan x="-0.25" y="0.62">the 'keySplines' </tspan>
    <tspan x="-0.25" y="0.68">setting works for key</tspan>
    <tspan x="-0.25" y="0.74">interpolation in SMIL</tspan>
    <tspan x="-0.25" y="0.8">based animation.</tspan>
    <tspan x="-0.25" y="0.86">  The handles can</tspan>
    <tspan x="-0.25" y="0.92">be manipulated by </tspan>
    <tspan x="-0.25" y="0.98">dragging them </tspan>
    <tspan x="-0.25" y="1.04">around.</tspan>
    </text>
    <g id="graph" transform="translate(0.4,1.4) scale(1,1)"
      style="fill:none; stroke:black; stroke-width:.01">
       <g id="grid" transform="scale(1,-1)">
           <use x="0" y="0" xlink:href="#lSet1" />
           <use x="0" y="-1" xlink:href="#lSet1" transform="rotate(90)" />
           <line id="cL1" x1="0" y1="0" x2="0.5" y2="0.1" style="stroke:#444;stroke-width:0.005;" />
           <line id="cL2" x1="1" y1="1" x2="0.5" y2="0.9" style="stroke:#444;stroke-width:0.005;" />
           <circle id="pointOne" cx="0.5" cy="0.1" r=".03" transform="translate(0 0)"
      style="fill:black;stroke:#F66;stroke-width:0.006;opacity:0.3;" />
           <circle id="pointTwo" cx="0.5" cy="0.9" r=".03" transform="translate(0 0)"
      style="fill:black;stroke:#F66;stroke-width:0.006;opacity:0.3;" />
           <path id="kSpline" x="0" y="0" d="M0,0 C0.5,0.1 0.5,0.9 1,1" style="stroke:red;" />
       </g>
       <g id="textGrp" transform="scale(1)">
         <text x="0" y="-1.05" style="fill:grey;stroke:none;font-size:0.1;">y</text>
         <text x="1.05" y="0" style="fill:grey;stroke:none;font-size:0.1;">x</text>
         <text x="-0.1" y="0.1" style="fill:grey;stroke:none;font-size:0.07;">0,0</text>
         <text x="1" y="-1.05" style="fill:grey;stroke:none;font-size:0.07;">1,1</text>
         <text id="explan" x="0.05" y="0.16"
      style="fill:#444;stroke:none; font-size:0.05;">(You can select and copy the text below)</text>
         <text id="coords" x="0.05" y="0.25"
      style="fill:black;stroke:none;font-size:0.07;">keySplines="0.5 0.1  0.5 0.9"</text>
         <text x="0.9" y="0.38" style="fill:#333;stroke:none;font-size:0.04;">Copyleft 2000 - Burning Pixel Productions</text>
       </g>
    </g>
    </g>
    </svg>

    实例演示:http://burningpixel.com/svg/keySplineTool.htm


       收藏   分享  
    顶(0)
      




    ----------------------------------------------
    交流提高呀!

    svg技术交流: 
    http://greaterthanme.blog.hexun.com/list.aspx?
    tag=svg
    svg技术交流群:24785607
    svg文件共享邮箱:svgcn@126.com  
    password:svg.net.cn

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/4/15 21:01:00
     
     GoogleAdSense魔羯座2000-12-31
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 SVG/GML/VRML/X3D/XAML 』的所有贴子 点击这里发送电邮给Google AdSense  访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/5/4 5:21:38

    本主题贴数2,分页: [1]

     *树形目录 (最近20个回帖) 顶端 
    主题:  [转帖]svg实例--两点控制的线(7836字) - wanghai00,2006年4月15日
        回复:  你好,这个例子很有意思,对我很有启发,谢谢! 有个问题请教:点击直线上的两点是否能计..(240字) - bluehxjing,2006年4月16日

    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    5,796.875ms