84549865a160b77332cfde7ce757d61db5b9e8da.svn-base 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
  2. <head>
  3. <title>dojox.gfx: 100 draggable circles</title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <style type="text/css">
  6. @import "../../../dojo/resources/dojo.css";
  7. @import "../../../dijit/tests/css/dijitTests.css";
  8. </style>
  9. <!--
  10. The next line should include Microsoft's Silverligth.js, if you plan to use the silverlight backend
  11. <script type="text/javascript" src="Silverlight.js"></script>
  12. -->
  13. <script type="text/javascript" src="../../../dojo/dojo.js"></script>
  14. <script type="text/javascript">
  15. dojo.require("dojox.gfx");
  16. dojo.require("dojox.gfx.move");
  17. var container = null;
  18. var container_position = null;
  19. var surface = null;
  20. var surface_size = null;
  21. function getRand(from, to){
  22. return Math.random() * (to - from) + from;
  23. }
  24. var skew_stat_factor = 15;
  25. function getRandSkewed(from, to){
  26. // let skew stats to smaller values
  27. var seed = 0;
  28. for(var i = 0; i < skew_stat_factor; ++i){
  29. seed += Math.random();
  30. }
  31. seed = 2 * Math.abs(seed / skew_stat_factor - 0.5);
  32. return seed * (to - from) + from;
  33. }
  34. function randColor(alpha){
  35. var red = Math.floor(getRand(0, 255));
  36. var green = Math.floor(getRand(0, 255));
  37. var blue = Math.floor(getRand(0, 255));
  38. var opacity = alpha ? getRand(0.1, 1) : 1;
  39. return [red, green, blue, opacity];
  40. }
  41. var gShapes = {}
  42. var gShapeCounter = 0;
  43. function makeCircleGrid(itemCount){
  44. var minR = 10, maxR = surface_size.width / 3;
  45. for(var j = 0; j < itemCount; ++j){
  46. var r = getRandSkewed(minR, maxR);
  47. var cx = getRand(r, surface_size.width - r);
  48. var cy = getRand(r, surface_size.height - r);
  49. var shape = surface.createCircle({cx: cx, cy: cy, r: r})
  50. .setFill(randColor(true))
  51. .setStroke({color: randColor(true), width: getRand(0, 3)})
  52. ;
  53. new dojox.gfx.Moveable(shape);
  54. }
  55. }
  56. function initGfx(){
  57. container = dojo.byId("gfx_holder");
  58. container_position = dojo.coords(container, true);
  59. surface = dojox.gfx.createSurface(container, 500, 500);
  60. surface_size = {width: 500, height: 500};
  61. makeCircleGrid(100);
  62. // cancel text selection and text dragging
  63. dojo.connect(container, "ondragstart", dojo, "stopEvent");
  64. dojo.connect(container, "onselectstart", dojo, "stopEvent");
  65. }
  66. dojo.addOnLoad(initGfx);
  67. </script>
  68. <style type="text/css">
  69. .movable { cursor: pointer; }
  70. </style>
  71. </head>
  72. <body>
  73. <h1>dojox.gfx: 100 draggable circles</h1>
  74. <p>Warning: Canvas renderer doesn't implement event handling.</p>
  75. <div id="gfx_holder" style="width: 500px; height: 500px;"></div>
  76. </body>
  77. </html>