Bezier Path Animation : Bezier « Ajax Layer « JavaScript DHTML

JavaScript DHTML
1. Ajax Layer
2. Data Type
3. Date Time
4. Development
5. Document
6. Event
7. Event onMethod
8. Form Control
9. GUI Components
10. HTML
11. Javascript Collections
12. Javascript Objects
13. Language Basics
14. Node Operation
15. Object Oriented
16. Page Components
17. Security
18. Style Layout
19. Table
20. Utilities
21. Window Browser
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
JavaScript DHTML » Ajax Layer » Bezier 
Bezier Path Animation


http://dynapi.sourceforge.net/
GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999
<html>
<head>
<title>DynAPI Examples - Bezier Path Animation</title>
<script language="JavaScript" src="./dynapisrc/dynapi.js"></script>
<script language="Javascript">
dynapi.library.setPath('./dynapisrc/');
dynapi.library.include('dynapi.api');
dynapi.library.include('dynapi.debug');
dynapi.library.include('dynapi.fx.Thread');
dynapi.library.include('dynapi.fx.Bezier');
</script>
<script language="Javascript">

var path;

var dots = [];
var cps = [];

function drawBezier() {
  clearPage();

  var controlPoints = eval(document.b.cp.value);
  var steps = parseInt(document.b.steps.value);

  // the path includes starting and ending points
  // results in total of steps+1 points along path
  path = Bezier(controlPoints, steps);

  for (var i=0;i<controlPoints.length/2;i++) {
    var x = controlPoints[i*2];
    var y = controlPoints[i*2+1];
    var color = 'red';
    if (i==|| i==controlPoints.length/2-1color = 'yellow'
    if (!cps[i]) cps[i= dynapi.document.addChild(new DynLayer('',x-2,y-2,5,5,color));
    else {
      cps[i].setLocation(x-2,y-2);
      cps[i].setBgColor(color);
    }
    cps[i].setVisible(true);
  }

  for (var i=0;i<path.length/2;i++) {
    var x = path[i*2];
    var y = path[i*2+1];
    if (!dots[i]) dots[i= dynapi.document.addChild(new DynLayer('',x,y,2,2,'black'));
    else {
      dots[i].setLocation(x-2,y-2);
    }
    dots[i].setVisible(true);
  }
}

var playblock = dynapi.document.addChild(new DynLayer('',0,0,15,15,'red'));
playblock.setVisible(false);
var pathanim = new Thread(playblock);
pathanim.loop = true;

function startAnim() {
  if (path) {
    playblock.setVisible(true);

    var speed = parseInt(document.b.speed.value);
    pathanim.sleep(speed);
    pathanim.play(path);
  }
}
function stopAnim() {
  playblock.setVisible(false);
  pathanim.stop();
}

function clearPage() {
  for (var i=0;i<dynapi.document.children.length;i++) {
    var c = dynapi.document.children[i];
    if (c!=playblockc.setVisible(false);
  }
}

function setCP(cp) {
  document.b.cp.value = cp;
  drawBezier();
  startAnim();
}

var t="drawBezier();\nstartAnim();\nthis.watch('playblock.getX()');\n"
+"this.watch('playblock.getY()');\n"
+"this.switchMode('watch');";
dynapi.debug.setEvaluate(t);


</script>
</head>
<body bgcolor="#999999">

<form name=b>
Control Points: <input type=text name="cp" value="[200,150, 200,400, 250,100, 500,300]" size=50>
try these <input type=button value="1" onclick="setCP('[200,150, 200,150, 200,150, 400,150, 400,150, 400,150]');">
<input type=button value="2" onclick="setCP('[200,150, 200,150, 400,300]');">
<input type=button value="3" onclick="setCP('[200,200, 400,200, 400,400, 200,400, 200,200]');">
<input type=button value="4" onclick="setCP('[200,200, 200,300, 300,100, 500,200, 300,400, 500,300]');">
<br>
Steps: <input type=text name="steps" value="25" size=4><br>
Speed: <input type=text name="speed" value="40" size=4>ms<br>
<input type=button value="Draw" onclick="drawBezier()"><br>
<input type=button value="Clear Page" onclick="clearPage()"><br>
<input type=button value="Start Animation" onclick="startAnim()"><br>
<input type=button value="Stop Animation" onclick="stopAnim()"><br>
</form>

</body>
</html>

           
       
dynapi.zip( 791 k)
Related examples in the same category
w___w___w___.ja___v__a___2s._c__o_m__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.