-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.js
executable file
·72 lines (59 loc) · 2.39 KB
/
code.js
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
$(function(){
$("#holder").hide(); //hide SVG at first
$("#chairQ").bind("submit", function(e) {
var chairCheck = $("#addChairs").val(); //grab value from input
var intRegex = /^\d+$/; //regex to verify it is a positive number
var intCheck = intRegex.test(chairCheck); //test the regex
if( !intCheck || chairCheck >= 13 || chairCheck <= 3 ) {
$("div.error").text("Sorry, please enter a valid number between 4 and 12.");
return false; //if not a number or not in range, start over!
}
$("form").fadeOut(100); //ah, finally! a number! fade me out!
$("#holder").show().fadeIn(50); //now i can show chairs!
startTables(chairCheck); //pass me through the function below
e.preventDefault(); //prevent the form from submitting
});
var R = Raphael("holder", "100%", "100%"), //create Raphael SVG object
tableRadius = 108,
chairRadius = 20,
radius_space = tableRadius + chairRadius,
x = 500,
y = 200,
ox = 0,
oy = 0,
xArc = x,
yArc = y/2,
r = R.circle(x, y, tableRadius).attr({fill: "rgb(34, 102, 255)", stroke: "none", opacity: .8}),
pi = Math.PI,
dragging = false,
numCircles;
var startTables = function(chairs){
var spacing = 2 * pi / chairs; //spacing between chairs; dependent on # of chairs
var circs = [r]; //an array with the table already set (how nice of me)
for(var i = 0; i < 2 * pi; i += spacing) {
var b = R.circle(x + Math.cos(i) * radius_space, y + Math.sin(i) * radius_space, chairRadius).attr({fill: "rgb(136,221,255)", stroke: "#000", opacity: 0.8});
circs.push(b); //add this circle to the array
}
var wholeTable = R.set(circs); //place all circles in array in same canvas
//the rest of these are for the table draggability; need to be optimized for primetime but good for testing
wholeTable.mousedown(function(events){
ox = events.screenX;
oy = events.screenY;
wholeTable.attr({
opacity: 0.25
});
dragging = true;
});
wholeTable.mousemove(function(events){ //not the best but will change later to optimize
if (dragging) {
wholeTable.translate(events.screenX - ox, events.screenY - oy);
ox = events.screenX;
oy = events.screenY;
}
});
wholeTable.mouseup(function(events){
dragging = false;
wholeTable.attr({ opacity:0.8 });
});
};
});