-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·178 lines (152 loc) · 4.15 KB
/
index.html
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
<!doctype html>
<html>
<head>
<title>nodes</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font: 13px Helvetica, Arial;
}
form {
background: #000;
padding: 3px;
position: fixed;
bottom: 0;
width: 100%;
}
form input {
border: 0;
padding: 10px;
width: 90%;
margin-right: .5%;
}
form button {
width: 9%;
background: rgb(130, 224, 255);
border: none;
padding: 10px;
}
html,
body,
.cont {
height: 90%;
}
body {
font-family: helvetica;
margin: 0;
padding: 0;
}
.cont {
position: relative;
overflow: hidden;
}
.circle {
z-index: 3;
height: 40px;
line-height: 40px;
width: 40px;
text-align: center;
color: #fff;
background-color: #2aE;
border-radius: 150px;
position: absolute;
}
.line {
height: 3px;
background-color: #aaa;
transform-origin: left center;
position: absolute;
z-index: 1;
}
#messages {
list-style-type: none;
margin: 0;
padding: 0;
}
#messages li {
padding: 5px 10px;
}
#messages li:nth-child(odd) {
background: #eee;
}
#messages {
margin-bottom: 40px
}
</style>
</head>
<body>
<ul id="messages"></ul>
<form action="">
<input id="m" autocomplete="off" /><button>Send</button>
</form>
<div class="cont">
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js"></script>
<script src="https://code.jquery.com/jquery-1.11.1.js"></script>
<script>
$(function () {
var socket = io();
$('form').submit(function(){
socket.emit('chat message', $('#m').val());
$('#m').val('');
return false;
});
socket.on('chat message', function(msg){
$('#messages').append($('<li>').text(msg));
window.scrollTo(0, document.body.scrollHeight);
});
});
// Nodes
var circles = $('<div class="circle">'),
cont = $('.cont'),
n = 2;
//generate circles
while (n--) cont.append(circles.clone().text(n + 1));
circles = $('.circle');
//position circles randomly
var w = $('.cont').width(),
h = $('.cont').height();
console.log(w, h);
var id = 0;
circles.each(function() {
$(this).addClass(id);
if(id == circles.length - 1){
$(this).css('top', 200 + 'px');
$(this).css('left', 200 + 'px');
} else {
$(this).css('top', h * Math.random() + 'px');
$(this).css('left', w * Math.random() + 'px');
}
id++;
});
$('0').removeClass('.circle').addClass('.baseNode');
//generate lines
circles.each(function(i) {
var pos0 = $(this).position(),
pos1 = (circles.eq(i + 1) || {}).position();
if (pos1 == undefined) return;
var x0 = pos0.left,
y0 = pos0.top,
x1 = pos1.left,
y1 = pos1.top;
line(x0, y0, x1, y1);
});
function line(x, y, x1, y1) {
var l = $("<div class='line'>");
//soh cah TOA and pythargoream theorem
var w = circles.width() / 2;
l.css({
top: y + w,
left: x + w,
width: Math.sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y)),
transform: 'rotate(' + Math.atan2((y1 - y), (x1 - x)) + 'rad)'
});
cont.append(l);
}
</script>
</body>
</html>