-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
185 lines (138 loc) · 5.79 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
179
180
181
182
183
184
185
<html>
<head>
<title>
GtL (Beta)
</title>
<link rel="stylesheet" href="stylesheet.css">
</head>
<body>
<canvas id="myCanvas" width=x height=y> </canvas>
<div style="margin-left: 10px;">
<h3 id="selection">
> Edit Mode
</h3>
<input type="search" placeholder="Preview" id="preview" disabled="true" hidden="true">
<table style="text-align: centers;">
<tr>
<th class="info"> Drawing Functionality: </th>
<th onclick="set_mode(param=1)"> ◯ </th>
<th onclick="set_mode(param=2)"> ▢ </th>
<th onclick="set_mode(param=5)"> A_ </th>
<th onclick="set_mode(param=3)"> ⚊ </th>
</tr>
<tr class="alternating_row">
<th class="info_alternating_row"> Editing Functionality: </th>
<th class="alternating_row" onclick="switch_grid_status()"> ✕ </th>
<th class="alternating_row" onclick="switch_curve_status()"> ◠ </th>
<th class="alternating_row" onclick="clear_canvas(clear_objects=true)"> Clear </th>
<th class="alternating_row" onclick="set_mode(param=4)"> Edit </th>
</tr>
<tr>
<th class="info"> Visual Functionality: </th>
<th onclick="scale(operator='+')"> + </th>
<th onclick="scale(operator='-')"> - </th>
<th onclick="light_dark_mode()" id="l_d_switch"> Dark Mode </th>
<th> <img src="LaTeX.png" width="35px" onclick="compile_latex(toJSON())"></th>
</tr>
</table>
<br>
<button onclick="safe()"> Safe Graph to File</button>
<br>
<button onclick="load_from_json();"> Load Graph </button>
<input type="file" value="Load">
<br>
<h5 id="mouse" hidden="true"> 0,0 </h5>
<br>
<i style="color: #d0d0d0; font-size: 10px;">
GtL (Beta) by
<a href="https://twitter.com/max_loeffler">
@Maximilian Löffler
</a> &
<a href="https://twitter.com/tintinmaster_">
@Tim Schneider
</a>
</i>
<input id="latex_output" hidden="true"></input>
</div>
<script type="text/javascript" src="objects.js"></script>
<script type="text/javascript" src="helpers.js"></script>
<script type="text/javascript" src="grid_functions.js"></script>
<script type="text/javascript" src="global_varibales.js"></script>
<script type="text/javascript" src="event_handling.js"></script>
<script>
/**
* drawing objects on the canvas
*/
let draw = function() {
clear_canvas(clear_objects=false);
// for all lines ...
for (var i = 0; i < lines.length; i++) {
s = lines[i].s;
e = lines[i].e;
ctx.strokeStyle = main_stroke_color;
// move "pencil" to start point
ctx.beginPath();
ctx.moveTo(s.get_x(), s.get_y());
if (curve_status) {
// calculate the bezier points for the curve
x_diff = (e.get_x() - s.get_x()) / 5;
y_diff = s.get_y() - e.get_y();
y_diff = y_diff > 0 ? Math.abs(y_diff) / 2 : -Math.abs(y_diff) / 2;
bez_1_x = s.get_x() + x_diff * 1.5;
bez_1_y = s.get_y() - y_diff * 1.5;
bez_2_x = e.get_x() - x_diff * 2;
bez_2_y = e.get_y() - y_diff / 8;
// move to "pencil" to end point
ctx.bezierCurveTo(bez_1_x, bez_1_y, bez_2_x, bez_2_y, e.get_x(), e.get_y())
} else {
// move pencil to end point
ctx.lineTo(e.get_x(), e.get_y());
}
ctx.stroke();
// draw dot at the end of the line
ctx.beginPath();
ctx.arc(e.get_x(), e.get_y(), 5, 0, 2 * Math.PI);
ctx.fillStyle = main_stroke_color;
ctx.fill();
}
// for all objects ...
for (var i = 0; i < objects.length; i++) {
x = objects[i].get_x();
y = objects[i].get_y();
type = objects[i].type;
ctx.fillStyle = main_fill_color;
ctx.beginPath();
// if object is circle
if (type == "circle") {
// draw circle
ctx.arc(x, y, radius, 0, 2 * Math.PI);
ctx.fill();
} else if (type == "square") {
// if object is no text object, draw box
if (!objects[i].is_text()) {
ctx.rect(x - square_w / 2, y - square_h / 2, square_w, square_h);
ctx.fill();
}
}
ctx.fillStyle = objects[i].get_color();
ctx.strokeStyle = objects[i].get_color();
ctx.lineWidth = 1;
ctx.stroke();
// write content of object
ctx.font = text_size + " Arial";
ctx.textAlign = "center";
ctx.fillText(translation_table(String(objects[i].get_content())), x, y + Number(text_size.replace('px', '') / 2));
}
}
window.onresize = rescale_canvas;
window.onload = function(event) {
rescale_canvas();
config();
document.getElementById('myCanvas').style.border = "1px solid " + main_stroke_color;
document.body.style.backgroundColor = main_fill_color;
document.body.style.color = main_stroke_color;
draw();
}
</script>
</body>
</html>