-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTurningTable.html
More file actions
222 lines (209 loc) · 10.2 KB
/
Copy pathTurningTable.html
File metadata and controls
222 lines (209 loc) · 10.2 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Turning Table</title>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<style>
body {
background-image:url(Image/background.png);
}
</style>
</head>
<section style = "position:fixed; top:580px;left:80px; background:"black"">
<audio id = "audio" controls = "controls">
<source src="music/Adele-TurningTables.mp3" type="audio/mpeg">
</audio>
</section>
<p id = "lyrics" style = "position:relative;top: 80px; right: 0px;
transition:ease-in-out;
text-align:center;
font-size:40px;
color:rgb(225,225,225);
text-shadow:1px 1px 1px rgb(102,255,255);
font-family:Arial, Helvetica, sans-serif
">
Adele-Tunrning Tables
</p>
<svg id="chart" xmlns="http://www.w3.org/2000/svg" version="1.1">
</svg>
<p id = "t" style = "position:fixed; top: 0px; font-family:Arial, Helvetica, sans-serif; font-size:18px; color:rgb(225,225,225); right: 1250px; top: 30px">
Sentiment
</p>
<p style = "position:fixed; font-family:Arial, Helvetica, sans-serif; font-size:16px; color:rgb(153,153,153);right:1270px; top:490px">
Negative
</p>
<p style = "position:fixed; font-family:Arial, Helvetica, sans-serif; font-size:16px; color:rgb(255,102,153); right:1270px;top:110px">
Positive
</p>
<p style = "position:fixed; font-family:Arial, Helvetica, sans-serif; font-size:16px; color:rgb(255,255,153);right:1270px; top:282px">
Neutral
</p>
<p id = "t" style = "position:fixed; font-family:Arial, Helvetica, sans-serif; font-size:18px; color:rgb(225,225,225); right: 60px; top: 520px">
Frequency
</p>
<p id = "t" style = "position:fixed; font-family:Arial, Helvetica, sans-serif; font-size:16px; color:#CCC; right: 1200px; top: 522px">
Low
</p>
<p id = "t" style = "position:fixed; font-family:Arial, Helvetica, sans-serif; font-size:16px; color:#CCC; right: 190px; top: 522px">
High
</p>
<script>
var lyric = new Array(
{time:"13.30",line:"Close enough to start a war", value:"-2"},
{time:"18.03",line:"All that I have is on the floor", value:"-6"},
{time:"25.27",line:"God only knows what we're fighting for", value:"-2"},
{time:"30.24",line:"All that I say' you always say more", value:"6"},
{time:"37.30",line:"I can't keep up with your turning tables", value:"-10"},
{time:"43.04",line:"Under your thumb' I can't breathe", value:"-10"},
{time:"49.67",line:"So I won't let you close enough to hurt me no", value:"-10"},
{time:"55.63",line:"I won't ask you' you to just desert me", value:"-6"},
{time:"61.41",line:"I can't give you' what you think you gave me", value:"-6"},
{time:"67.52",line:"It's time to say goodbye to turning tables", value:"-6"},
{time:"78.01",line:"To turning tables", value:"-6"},
{time:"86.41",line:"Under haunted skies I see you", value:"-2"},
{time:"91.51",line:"Where love is lost' your ghost is found", value:"-2"},
{time:"98.16",line:"I've lived a hundred storms to leave you", value:"-6"},
{time:"103.08",line:"As hard as you try' no I will never be knocked down or around", value:"-10"},
{time:"109.95",line:"I can't keep up with your turning tables", value:"-10"},
{time:"115.89",line:"Under your thumb' I can't breathe", value:"-10"},
{time:"122.46",line:"So I won't let you close enough to hurt me' no", value:"-10"},
{time:"128.22",line:"I won't ask you' you to just desert me", value:"-6"},
{time:"134.29",line:"I can't give you' what you think you gave me", value:"-6"},
{time:"140.35",line:"It's time to say goodbye to turning tables", value:"-6"},
{time:"150.78",line:"Turning tables", value:"-6"},
{time:"158.33",line:"Next time I'll be braver", value:"-6"},
{time:"161.33",line:"I'll be my own savior", value:"6"},
{time:"164.39",line:"When the thunder cause for me", value:"2"},
{time:"170.20",line:"Next time I'll be braver", value:"-6"},
{time:"173.46",line:"I'll be my own savior", value:"6"},
{time:"176.65",line:"Standing on my own two feet", value:"2"},
{time:"184.35",line:"I won't let you close enough to hurt me' no", value:"-10"},
{time:"189.88",line:"I won't ask you' you to just desert me", value:"-6"},
{time:"196.01",line:"I cant give you' what you think you gave me", value:"-6"},
{time:"201.97",line:"It's time to say goodbye to turning tables", value:"-6"},
{time:"212.89",line:"To turning tables", value:"-6"},
{time:"219.04",line:"Turning tables' yeah", value:"-6"},
{time:"226.06",line:"Turning ohh...", value:"-6"}
);
var frequency = new Array();
$(document).ready(function() {
$.getJSON("Lyrics/Adele-TurningTables.json", function(data){
$.each(data, function(index, info){
frequency.push({time: info["time"], color: info["color"]});
});
});
});
lyric[0].width = "0";
for(var i = 1; i < lyric.length; i++){
lyric[i].width = lyric[i].time - lyric[i - 1].time;
}
var a = document.getElementById("audio");
var vis = d3.select('#chart');
var data = new Array();
var lineFunc = d3.svg.line()
.x(function(d){
return 5*d.time + 80;})
.y(function(d){
return (-1*d.value + 10)*15 + 30;})
.interpolate("basis");
var path = vis.append('svg:path')
.attr('d', lineFunc(lyric))
.attr('stroke', "rgb(225,225,225)")
.attr('stroke-width', '5')
.attr('fill', 'none');
var svg = document.getElementById("chart");
setTimeout(function(){
for(var i = 0; i < frequency.length; i++){
var newBar = document.createElementNS("http://www.w3.org/2000/svg", 'rect');
var barWidth = 3.02;
newBar.setAttribute("x", 5*frequency[i].time + 80);
newBar.setAttribute("y", "0");
newBar.setAttribute("width", barWidth);
newBar.setAttribute("height", "400");
newBar.style.opacity = "1";
newBar.style.fill = frequency[i].color;
newBar.style.position = "fixed";
svg.insertBefore(newBar, svg.childNodes[0]);
}
}, 6000);
for(var i = 15 ; i< 205; i++){
var newBar = document.createElementNS("http://www.w3.org/2000/svg", 'rect');
var hue = 'rgb('
+ Math.floor(1.1842*i) +','
+ Math.floor(1.1842*i) +','
+ Math.floor(1.1842*i) +')';
newBar.setAttribute("x", 5*i + 80);
newBar.setAttribute("y", 420);
newBar.setAttribute("width", 5);
newBar.setAttribute("height", 10);
newBar.style.opacity = "1";
newBar.style.fill = hue;
newBar.style.position = "fixed";
svg.insertBefore(newBar, svg.childNodes[0]);
}
var lookup = [];
var granularity = 5000;
var l = path.node().getTotalLength();
for(var i = 1; i <= granularity; i++) {
var p = path.node().getPointAtLength(l * (i/granularity))
lookup.push({
x: p.x,
y: p.y
})
}
/* var cdata = [{value:"10", color:"rgb(255,106,106)"},{value: "6", color:"rgb(255,193,193)"}, {value: "2", color:"rgb(255,255,210)"},{value:"-2", color:"rgb(238,216,174)"},{value:"-6",color:"rgb(205,186,150)"}, {value:"-10", color:"rgb(139,115,85)"}];
for(var i = 0; i < cdata.length; i++){
var newCircle = document.createElementNS("http://www.w3.org/2000/svg", 'circle');
newCircle.setAttribute("cx", 600);
newCircle.setAttribute("cy", (-1*cdata[i].value + 10)*15 + 30);
newCircle.setAttribute("r", 10);
newCircle.style.fill = cdata[i].color;
svg.insertBefore(newCircle, svg.childNodes[0]);
}*/
var index;
var dragListener = d3.behavior.drag()
.on("drag", function() {
if(d3.event.dx <= 0){
for( index = 0; lookup[index].x < d3.event.x; index++);
circle.attr("transform", "translate(" + [lookup[index].x, lookup[index].y] + ")");
}
else{
for(index = lookup.length - 1; lookup[index].x > d3.event.x; index--);
circle.attr("transform", "translate(" + [lookup[index].x, lookup[index].y] + ")");
}
})
.on("dragend", function(){
var time = (lookup[index].x - 80)/5;
a.currentTime = time;
});for(var i = 0; i < 230; i++){
var newCircle = document.createElementNS("http://www.w3.org/2000/svg", 'circle');
newCircle.setAttribute("cx", 5*i + 80);
newCircle.setAttribute("cy", 180);
newCircle.setAttribute("r", 2);
newCircle.style.fill = "rgb(255,255,210)";
svg.insertBefore(newCircle, svg.childNodes[0]);
}
var circle = d3.select("#chart").append("circle")
.attr("r", 13)
.attr("transform", "translate(" + [5*lyric[0].time + 80,(-1*lyric[0].value + 10)*15 + 30 ] + ")")
.style("fill", "rgb(244,164,96)")
.call(dragListener);
var cur = 0;
a.ontimeupdate = function(){
for(var i = cur; i < lookup.length; i++){
if(this.currentTime*5 + 80 - lookup[i].x <= 0.15 && this.currentTime*5 + 80 - lookup[i].x >= -0.15){
circle.attr("transform", "translate(" + [lookup[i].x, lookup[i].y] + ")");
cur++;
}
}
for(var i = 0; i < lyric.length; i++){
if(lyric[i].time <= this.currentTime){
document.getElementById("lyrics").innerHTML = lyric[i].line;
}
}
}
</script>
</body>
</html>