Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 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
 
16
dojo.require("dojox.gfx");
17
dojo.require("dojox.gfx.move");
18
 
19
var container = null;
20
var container_position = null;
21
var surface = null;
22
var surface_size = null;
23
 
24
function getRand(from, to){
25
	return Math.random() * (to - from) + from;
26
}
27
 
28
var skew_stat_factor = 15;
29
 
30
function getRandSkewed(from, to){
31
	// let skew stats to smaller values
32
	var seed = 0;
33
	for(var i = 0; i < skew_stat_factor; ++i){
34
		seed += Math.random();
35
	}
36
	seed = 2 * Math.abs(seed / skew_stat_factor - 0.5);
37
	return seed * (to - from) + from;
38
}
39
 
40
function randColor(alpha){
41
	var red   = Math.floor(getRand(0, 255));
42
	var green = Math.floor(getRand(0, 255));
43
	var blue  = Math.floor(getRand(0, 255));
44
	var opacity = alpha ? getRand(0.1, 1) : 1;
45
	return [red, green, blue, opacity];
46
}
47
 
48
var gShapes = {}
49
var gShapeCounter = 0;
50
 
51
function makeCircleGrid(itemCount){
52
	var minR = 10, maxR = surface_size.width / 3;
53
	for(var j = 0; j < itemCount; ++j){
54
		var r = getRandSkewed(minR, maxR);
55
		var cx = getRand(r, surface_size.width  - r);
56
		var cy = getRand(r, surface_size.height - r);
57
		var shape = surface.createCircle({cx: cx, cy: cy, r: r})
58
			.setFill(randColor(true))
59
			.setStroke({color: randColor(true), width: getRand(0, 3)})
60
			;
61
		new dojox.gfx.Moveable(shape);
62
	}
63
}
64
 
65
function initGfx(){
66
	container = dojo.byId("gfx_holder");
67
	container_position = dojo.coords(container, true);
68
	surface = dojox.gfx.createSurface(container, 500, 500);
69
	surface_size = {width: 500, height: 500};
70
 
71
	makeCircleGrid(100);
72
 
73
	// cancel text selection and text dragging
74
	dojo.connect(container, "ondragstart",   dojo, "stopEvent");
75
	dojo.connect(container, "onselectstart", dojo, "stopEvent");
76
}
77
 
78
dojo.addOnLoad(initGfx);
79
 
80
</script>
81
 
82
<style type="text/css">
83
.movable { cursor: pointer; }
84
</style>
85
 
86
</head>
87
<body>
88
<h1>dojox.gfx: 100 draggable circles</h1>
89
<p>Warning: Canvas renderer doesn't implement event handling.</p>
90
<div id="gfx_holder" style="width: 500px; height: 500px;"></div>
91
</body>
92
</html>