summaryrefslogtreecommitdiff
path: root/includes/js/dojox/gfx/demos/circles.html
blob: ce4d0cd8517d730d8b98f5a8dd8fa8e4285761a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
<head>
<title>dojox.gfx: 100 draggable circles</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
	@import "../../../dojo/resources/dojo.css";
	@import "../../../dijit/tests/css/dijitTests.css";
</style>
<!--
The next line should include Microsoft's Silverligth.js, if you plan to use the silverlight backend
<script type="text/javascript" src="Silverlight.js"></script>
-->
<script type="text/javascript" src="../../../dojo/dojo.js"></script>
<script type="text/javascript">

dojo.require("dojox.gfx");
dojo.require("dojox.gfx.move");

var container = null,
	surface = null,
	surface_size = null;

function getRand(from, to){
	return Math.random() * (to - from) + from;
}

var skew_stat_factor = 15;

function getRandSkewed(from, to){
	// let skew stats to smaller values
	var seed = 0;
	for(var i = 0; i < skew_stat_factor; ++i){
		seed += Math.random();
	}
	seed = 2 * Math.abs(seed / skew_stat_factor - 0.5);
	return seed * (to - from) + from;
}

function randColor(alpha){
	var red   = Math.floor(getRand(0, 255)),
		green = Math.floor(getRand(0, 255)),
		blue  = Math.floor(getRand(0, 255)),
		opacity = alpha ? getRand(0.1, 1) : 1;
	return [red, green, blue, opacity];
}

var gShapes = {}
var gShapeCounter = 0;

function makeCircleGrid(itemCount){
	var minR = 10, maxR = surface_size.width / 3;
	for(var j = 0; j < itemCount; ++j){
		var r = getRandSkewed(minR, maxR),
			cx = getRand(r, surface_size.width  - r),
			cy = getRand(r, surface_size.height - r),
			shape = surface.createCircle({cx: cx, cy: cy, r: r})
				.setFill(randColor(true))
				.setStroke({color: randColor(true), width: getRand(0, 3)})
				;
		new dojox.gfx.Moveable(shape);
	}
}

function initGfx(){
	container = dojo.byId("gfx_holder");
	surface = dojox.gfx.createSurface(container, 500, 500);
	surface_size = {width: 500, height: 500};

	makeCircleGrid(100);

	// cancel text selection and text dragging
	dojo.connect(container, "ondragstart",   dojo, "stopEvent");
	dojo.connect(container, "onselectstart", dojo, "stopEvent");
}

dojo.addOnLoad(initGfx);

</script>

<style type="text/css">
.movable { cursor: pointer; }
</style>

</head>
<body>
<h1>dojox.gfx: 100 draggable circles</h1>
<p>Warning: Canvas renderer doesn't implement event handling.</p>
<div id="gfx_holder" style="width: 500px; height: 500px;"></div>
</body>
</html>