bezier2.html 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Bezier Example</title>
  5. <!--<script src="../dist/kity.js"></script>-->
  6. <!--<script src="./coordinate/coordinate.js"></script>-->
  7. </head>
  8. <body></body>
  9. <script src="../dev-lib/sea.js"></script>
  10. <script>
  11. seajs.config({
  12. base: '../src'
  13. });
  14. define('start', function(require) {
  15. var kity = require('kity');
  16. // var Coordinate = require('../example/coordinate/coordinate');
  17. var BezierViewer = kity.createClass({
  18. base: kity.Group,
  19. constructor: function(bezier) {
  20. this.callBase();
  21. this.addShape(bezier);
  22. this.bezier = bezier.stroke(new kity.Color('red').set('a', 0.8));
  23. this.update();
  24. },
  25. update: function() {
  26. var points = this.bezier.getBezierPoints();
  27. if (this.group) {
  28. this.group.remove();
  29. }
  30. this.addShape(this.group = new kity.Group().pipe(function() {
  31. for (var i = 0; i < points.length; i++) {
  32. var p = points[i], f, b;
  33. f = p.getForward();
  34. b = p.getBackward();
  35. p = p.getVertex();
  36. this.addShape(new kity.Path().pipe(function() {
  37. var d = this.getDrawer();
  38. d.moveTo(b.x, b.y);
  39. d.lineTo(p.x, p.y);
  40. d.lineTo(f.x, f.y);
  41. // this.fill('none');
  42. this.stroke('red');
  43. }));
  44. this.addShape(new kity.Rect(6, 6, b.x - 3, b.y - 3).stroke('red').fill('white'));
  45. this.addShape(new kity.Rect(6, 6, f.x - 3, f.y - 3).stroke('red').fill('white'));
  46. this.addShape(new kity.Rect(6, 6, p.x - 3, p.y - 3).fill('red'));
  47. }
  48. }));
  49. }
  50. });
  51. var paper = new kity.Paper(document.body).pipe(function () {
  52. var width = 600, height = 400;
  53. this.setWidth(width).setHeight(height);
  54. // this.setViewBox(-40.5, -40.5, width + 40.5, height + 40.5);
  55. // this.addShape(new Coordinate('black', [0, 59], [0, 39]));
  56. var bezier = new kity.Bezier().addPoints([
  57. new kity.BezierPoint(100, 250).setForward(100, 100),
  58. new kity.BezierPoint(400, 250).setBackward(400, 100)
  59. // new kity.BezierPoint(300, 350, false).setForward(200, 300).setBackward(400, 300),
  60. // new kity.BezierPoint(150, 150).setBackward(130, 200),
  61. // new kity.BezierPoint(300, 150, false).setForward(350, 50).setBackward(250, 50)
  62. ]);
  63. this.addShape(window.v = new BezierViewer(bezier));
  64. window.p = bezier.getPoint(1);
  65. });
  66. });
  67. seajs.use('start');
  68. </script>
  69. </html>