| 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 | <script type="text/javascript" src="../../../dojo/dojo.js"></script> |
| 10 | <script type="text/javascript"> |
| 11 | |
| 12 | dojo.require("dojox.gfx"); |
| 13 | dojo.require("dojox.gfx.move"); |
| 14 | |
| 15 | var container = null, |
| 16 | surface = null, |
| 17 | surface_size = null; |
| 18 | |
| 19 | function getRand(from, to){ |
| 20 | return Math.random() * (to - from) + from; |
| 21 | } |
| 22 | |
| 23 | var skew_stat_factor = 15; |
| 24 | |
| 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 | |
| 35 | function randColor(alpha){ |
| 36 | var red = Math.floor(getRand(0, 255)), |
| 37 | green = Math.floor(getRand(0, 255)), |
| 38 | blue = Math.floor(getRand(0, 255)), |
| 39 | opacity = alpha ? getRand(0.1, 1) : 1; |
| 40 | return [red, green, blue, opacity]; |
| 41 | } |
| 42 | |
| 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 | cx = getRand(r, surface_size.width - r), |
| 48 | cy = getRand(r, surface_size.height - r), |
| 49 | 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 | |
| 57 | function initGfx(){ |
| 58 | container = dojo.byId("gfx_holder"); |
| 59 | surface = dojox.gfx.createSurface(container, 500, 500); |
| 60 | surface_size = {width: 500, height: 500}; |
| 61 | |
| 62 | makeCircleGrid(100); |
| 63 | |
| 64 | // cancel text selection and text dragging |
| 65 | dojo.connect(container, "ondragstart", dojo, "stopEvent"); |
| 66 | dojo.connect(container, "onselectstart", dojo, "stopEvent"); |
| 67 | } |
| 68 | |
| 69 | dojo.addOnLoad(initGfx); |
| 70 | |
| 71 | </script> |
| 72 | |
| 73 | <style type="text/css"> |
| 74 | .movable { cursor: pointer; } |
| 75 | </style> |
| 76 | |
| 77 | </head> |
| 78 | <body> |
| 79 | <h1>dojox.gfx: 100 draggable circles</h1> |
| 80 | <p>Warning: Canvas renderer doesn't implement event handling.</p> |
| 81 | <div id="gfx_holder" style="width: 500px; height: 500px;"></div> |
| 82 | </body> |
| 83 | </html> |