-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
165 lines (154 loc) · 4.99 KB
/
index.html
File metadata and controls
165 lines (154 loc) · 4.99 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>plot-pc-set.js</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<link rel="stylesheet" href="css/bootstrap.min.css">
<style>
body {
padding-top: 60px;
}
#ribbon {
position: absolute;
top: 0;
right: 0;
border: 0;
}
</style>
</head>
<body>
<a href="https://github.com/jsgoyette"><img id="ribbon" src="css/forkme_right_white_ffffff.png" alt="Fork me on GitHub"></a>
<div class="container">
<h2>plot-pc-set.js</h2>
<div class="row">
<div class="span4">
<div class="well">
<form id="pcsform">
<label>Pitch classes</label>
<input type="text" id="pcs" class="span3" value="11 6 9 11 11 1"><br>
<label>Number of fixed pcs</label>
<input type="text" id="fixed" class="span1" value="1"><br>
<button type="submit" class="btn">Plot</button><br>
</form>
</div>
<div class="well">
<form id="tnform">
<label>Transpose</label>
<input type="text" id="tn" class="span1" value="3"><br>
<button id="transbutton" class="btn">Transpose</button>
</form>
</div>
<div class="well">
<form id="invform">
<label>Invert at index</label>
<input type="text" id="in" class="span1" value="10"><br>
<button id="invbutton" class="btn">Invert</button>
</form>
</div>
</div>
<div class="span2"> </div>
<div class="span6">
<div id="canvas_container"></div>
</div>
</div>
</div>
<script src="js/ready.min.js" type="text/javascript"></script>
<script src="js/raphael-min.js" type="text/javascript"></script>
<script src="js/plot-pc-set.min.js" type="text/javascript"></script>
<script type="text/javascript">
// first, a little selector function
var byId = function (id) {
return document.getElementById(id);
};
// a function to turn pc string into array
function pcstr2pcs(mod, pstr) {
var arr, outarr = [];
pstr = pstr.replace(/,/g," ");
pstr = pstr.replace(/_/g," ");
pstr = pstr.replace(/^\s+|\s+$/g,'').replace(/\s+/g,' ');
if (pstr == "") return [];
arr = pstr.split(' ');
for (x in arr) {
if (!isNaN(arr[x])) {
outarr.push(+arr[x]);
}
}
for (x in outarr) {
while (outarr[x] >= mod)
outarr[x] -= mod;
while (outarr[x] < 0)
outarr[x] += mod;
}
return outarr;
}
// SETUP
// initialize setGraph using the id of the element in which the canvas will appear
var sg = setGraph('canvas_container');
// optional adjustments
/*sg.configure({
'mod': 12,
'radius':120,
'padding':10,
'ticksize':4,
'dotsize':5,
});*/
sg.configure({
'dotclick': function () {
var r = this.attr('r');
this.animate({'r': r * 2}, 200, function () {
this.animate({'r': r}, 400);
});
}
});
var showpcs = function () {
byId('pcs').value = sg.getpcs().join(" ");
};
var engage = function () {
// get the pitch classes from the input
var pcstr = byId('pcs').value;
var fixed = byId('fixed').value;
// convert string to array
var pcs = pcstr2pcs(12, pcstr);
// plot the pcs (the first of which are fixed)
sg.plotpcs(pcs, +fixed);
};
domready(function() {
// draw the set
engage();
// Most of the action functions of setGraph (transpose, animTranpose, invert, animInvert, and
// animDirect) each take as the first argument the level of transposition or the index of
// inversion, and can also take a second argument that is a callback function. animDirect
// instead takes as the first argument the transformation to be executed. animTranspose and
// animInvert have two callbacks, one at each step of the animation and one at the end, but
// the other functions only have one callback, which is fired only upon completion.
setTimeout(function() {
sg.animTranspose(3, showpcs);
setTimeout(function() {
sg.animInvert(0, showpcs);
setTimeout(function() {
sg.animDirect('invert', 10, showpcs);
setTimeout(function() {
sg.animDirect('transpose', 6, showpcs);
}, 1500);
}, 1500);
}, 1500);
}, 1500);
// set up listeners
byId('pcsform').onsubmit = function() {
engage();
return false;
};
byId('tnform').onsubmit = function() {
sg.animTranspose(byId('tn').value, showpcs);
return false;
};
byId('invform').onsubmit = function() {
sg.animDirect('invert', byId('in').value, showpcs);
return false;
};
byId('pcs').focus();
});
</script>
</body>
</html>