-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
213 lines (202 loc) · 7.16 KB
/
main.js
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
var a = 1;
function show_hide(){
if(a==0){
document.getElementById("no_body").style.display="inline";
document.getElementById("can").style.display="none";
document.getElementById("myinput").style.display="none";
document.getElementById("U").style.display="none";
document.getElementById("grey1").style.display="none";
document.getElementById("B").style.display="none";
document.getElementById("M").style.display="none";
document.getElementById("RightBar").style.display = "inline";
document.getElementsByTagName("h1")[0].style.display="inline";
document.getElementsByTagName("h3")[0].style.display="inline";
return a=1;
}
else{
document.getElementById("no_body").style.display="none";
document.getElementById("can").style.display="inline";
document.getElementById("myinput").style.display='inline';
document.getElementById("U").style.display='inline';
document.getElementById("grey1").style.display='inline';
document.getElementById("B").style.display="inline";
document.getElementById("M").style.display='inline';
document.getElementsByTagName("h1")[0].style.display="none";
document.getElementsByTagName("h3")[0].style.display="none";
document.getElementById("RightBar").style.display = "none";
return a=0;
}
}
var b = 1;
function changeColor(){
if(b==1){
document.getElementById("Sidebar").style.background = '#001d06';
document.getElementById("Z").style.background="#ffffff";
// document.getElementById("Z").style.color="#00d106";
document.body.style.background='#001d06';
var h1Elements = document.getElementsByTagName("h1");
for(var i = 0; i < h1Elements.length; i++) {
h1Elements[i].style.color = "#fff";
}
var h3Elements = document.getElementsByTagName("h3");
for(var i = 0; i < h3Elements.length; i++) {
h3Elements[i].style.color = "#fff";
}
document.getElementById("can").style.background = "#ffffff";
return b = 0;
}
else{
document.getElementById("Sidebar").style.background = '#ffffff';
document.getElementById("Z").style.background="#001d06";
document.body.style.background = '#ffffff';
var h1Elements = document.getElementsByTagName("h1");
for(var i = 0; i < h1Elements.length; i++) {
h1Elements[i].style.color = "#000";
}
var h3Elements = document.getElementsByTagName("h3");
for(var i = 0; i < h3Elements.length; i++) {
h3Elements[i].style.color = "#000";
}
document.getElementById("can").style.background = "#ffffff";
return b=1;
}
}
// var b = 0;
// function showorHidecalc(){
// if(b==1){
// document.getElementById("calculator").style.display = "inline";
// document.getElementById("can").style.display="none";
// }
// else{
// document.getElementById("can").style.display="inline";
// document.getElementById("calculator").style.display="none";
// }
// }
const canvas = document.getElementById("can");
var context = canvas.getContext("2d");
canvas.width = window.innerWidth*1.0 - 150.0;
canvas.height = window.innerHeight * 1.0;
window.addEventListener('resize', function(event) {
canvas.width = window.innerWidth*1.0 - 150.0;
canvas.height = window.innerHeight*1.0;
console.log(canvas.width*1.0,canvas.height*1.0);
}, true);
var draw_color="black";
let draw_width = "25.0";
let is_drawing = false;
// let is_writing = false;
var start_background_color;
canvas.addEventListener("touchstart",start, false);
canvas.addEventListener("touchmove", draw, false);
canvas.addEventListener("mousedown", start, false);
canvas.addEventListener("mousemove",draw,false);
canvas.addEventListener("touchend",stop,false);
canvas.addEventListener("mouseup",stop,false);
canvas.addEventListener("mouseout",stop,false);
// canvas.addEventListener("mousemove",draw,false);
function start(event){
is_drawing = true;
is_writing = false;
context.beginPath();
context.moveTo(event.clientX*1.0 - canvas.offsetLeft*1.0, event.clientY*1.0 - canvas.offsetTop*1.0);
event.preventDefault();
}
function draw(event){
if (is_drawing){
context.lineTo(event.clientX*1.0 - canvas.offsetLeft*1.0, event.clientY*1.0 - canvas.offsetTop*1.0);
context.strokeStyle = draw_color;
context.lineWidth = draw_width*1.0;
context.lineCap = "round";
context.lineJoin = "round";
context.stroke();
}
// else if(is_writing){
// context.font = draw_color;
// var t = prompt('Enter the text to be inputed');
// ctx.fillText(t,context.lineTo(event.clientX - canvas.offsetLeft, event.clientY - canvas.offsetTop));
// }
event.preventDefault();
}
let restore_array = [];
let index = -1;
function stop(event){
if(is_drawing){
context.stroke();
context.closePath();
is_drawing = false;
}
event.preventDefault();
if(event.type!='mouseout'){
restore_array.push(context.getImageData(0.0,0.0,canvas.width*1.0,canvas.height*1.0));
index++;
}
// console.log(restore_array);
}
function change_color(element){
console.log(element.style.background);
draw_color=element.style.background;
}
document.getElementById("pink").addEventListener('click',function () {
//console.log("pink");
draw_color="#f172b2";
});
document.getElementById("purple").addEventListener('click',function () {
// console.log("");
draw_color="#9400D3";
});
document.getElementById("green").addEventListener('click',function () {
// console.log("pink");
draw_color="#5cf05c";
});
document.getElementById("cyan").addEventListener('click',function () {
// console.log("pink");
draw_color="#6495ED";
});
document.getElementById("line1").addEventListener('click',function () {
// console.log("pink");
draw_color="#ffffff";
});
document.getElementById("hemi1").addEventListener('click',function () {
// console.log("pink");
draw_color="#ffffff";
});
document.getElementById("hemi2").addEventListener('click',function () {
// console.log("pink");
draw_color="#ffffff";
});
document.getElementById("hemi3").addEventListener('click',function () {
// console.log("pink");
draw_color="#ffffff";
});
document.getElementById("hemi4").addEventListener('click',function () {
// console.log("pink");
draw_color="#ffffff";
});
function clear_screen(){
start_background_color = '#ffffff';
context.fillStyle = start_background_color;
context.clearRect(0.0,0.0,canvas.width*1.0,canvas.height*1.0);
context.fillRect(0.0,0.0,canvas.width*1.0,canvas.height*1.0);
restore_array = [];
index = -1;
}
var m = 0;
var t = draw_color;
function erase(){
if(draw_color=='#ffffff'){
draw_color = t;
}
else{
draw_color = '#ffffff';
}
}
function undo_screen(){
if(index<=0){
clear_screen();
}
else{
index--;
restore_array.pop();
context.putImageData(restore_array[index],0.0,0.0);
}
}