-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
100 lines (81 loc) · 2.74 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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="description" content="Re-draw circuit diagrams to explain it better.">
<meta name="Ankkit Modi" content="Circuit Diagram">
<title>Circuit Draw</title>
<script type="text/javascript" src="js/jquery-2.0.3.min.js"></script>
<script type="text/javascript" src="js/processing.js"></script>
<script type="text/javascript" src="js/gif.js"></script>
<script type="text/javascript" src="js/FileSaver.js"></script>
<script type="text/javascript" src="js/canvas-toBlob.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.10.3.custom.min.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<canvas id='draw' data-processing-sources="reDraw.pde"></canvas>
<div id='main'></div>
<button id='export'>Export</button>
<script type="text/javascript">
var canvas = document.getElementById('draw');
var context = canvas.getContext('2d');
var jsondata;
dragging = false;
// activeObject = { posX: 13, posY: 30, theid:'symbol' };
$(function(){
$.getJSON("all.json", function(d){
console.log(d);
$(d).each(function(i,item){
row = $("<div class='row' />");
var s = $("<div class='symbols' />");
s.css("background-image","url("+"images/" + item+")" );
s.appendTo(row);
s.attr('rel',item);
$("<div class='clear' />").appendTo(row);
$("#main").append(row);
var offsetTop = s.offset().top;
s.attr('data-top',offsetTop);
$(".symbols").draggable();
});
$(".symbols").bind('dragstart', function(e){
dragging = true;
}).bind('dragstop', function(){
var processing = Processing.getInstanceById('draw');
dragging = false;
var calculatedTop = $(this).offset().top - document.body.scrollTop;
//processing.drawObject($(this).attr('rel'), $(this).offset().left, $(this).offset().top);
processing.drawObject($(this).attr('rel'), $(this).offset().left-10, calculatedTop);
$(this).css({
left: '10px',
top: '10px'
})
})
});
});
$('#export').on('click', function(){
var processing = Processing.getInstanceById('draw');
var frames = processing.getFrames();
var encoder = new GIF({
workers: 4,
quality: 10,
width: $(window).width(),
height: $(window).height()
});
processing.stop();
console.log('Encoder started');
for (var i = 0; i < frames; i++) {
console.log('Adding frame', i, 'to encoder');
processing.setFrame(i);
processing.draw();
encoder.addFrame(context, { copy: true, delay: 20 });
}
console.log('Encoder finished');
encoder.on('finished', function(blob) {
saveAs(blob, 'circuit.gif');
});
encoder.render();
});
</script>
</body>
</html>