-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaint.js
More file actions
143 lines (118 loc) · 3.67 KB
/
paint.js
File metadata and controls
143 lines (118 loc) · 3.67 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
var h = 5;
var w = 5;
var colr = "black";
var t;
var x;
var y;
var radius = "0%";
var Cwidth = 500;
var Cheight= 500;
var m;
var elmnt;
var dclass="divs";
function setpoint() {
document.getElementById("scren").addEventListener("mousemove", setpoint);
x = event.clientX;
y = event.clientY;
t = document.createElement("div");
t.id = "line";
t.className = dclass;
t.style.top = y + "px";
t.style.left = x + "px";
t.style.position = "absolute";
t.style.height = h + "px";
t.style.width = w + "px";
t.style.backgroundColor = colr;
t.style.borderRadius = radius;
t.style.position ="absolute";
console.log('Click')
document.getElementById("scren").append(t);
}
document.getElementById("scren").addEventListener("mousedown", setpoint);
document.getElementById("scren").addEventListener("mouseup", () => { document.getElementById("scren").removeEventListener("mousemove", setpoint) });
//Set Color
document.getElementById("blue").addEventListener("click", subc);
document.getElementById("red").addEventListener("click", subc);
document.getElementById("black").addEventListener("click", subc);
document.getElementById("green").addEventListener("click", subc);
document.getElementById("yellow").addEventListener("click", subc);
document.getElementById("orange").addEventListener("click", subc);
document.getElementById("eraser").addEventListener("click", subc);
var ColorStore = {
colors: [
{ id: "black", color: "black", }, { id: "orange", color: "orange", }, { id: "yellow", color: "yellow", },
{ id: "blue", color: "blue", }, { id: "red", color: "red", }, { id: "green", color: "green", }, { id: "eraser", color: "white", },
]
}
function subc() {
setColor(ColorStore,this.id);
}
function setColor(Store, id) {
for (i = 0; i < Store.colors.length; i++) {
if (Store.colors[i].id === id) {
colr = Store.colors[i].color;
}
}
}
//Set Brush size
document.getElementById('sub').addEventListener("click", subm);
document.getElementsByClassName('one')[0].addEventListener('click', function() {this.value = ""});
function subm() {
var answer = document.getElementsByName('sizess')[0].value;
var options = document.getElementsByTagName('option');
for (var i = 0; i < options.length; i++) {
if (options[i].value === answer) {
setSize(SizeStore, options[i].id);
}
}
}
function setSize(Store, id) {
for (i = 0; i < Store.sizes.length; i++) {
if (Store.sizes[i].id === id) {
h = Store.sizes[i].size;
w = Store.sizes[i].size;
}
}
}
var SizeStore = {
sizes: [
{ id: "1", size: 5, }, { id: "2", size: 10, }, { id: "3", size: 15, }, { id: "4", size: 20, }, { id: "5", size: 30, },
]
}
//Set Canvas size
document.getElementById('canvasz').addEventListener("click", setCnvasSizel);
function setCnvasSizel() {
Cwidth = document.getElementById("width").value;
Cheight = document.getElementById("heigth").value;
m = document.getElementById("scren");
if(Cheight<551)
{
m.style.height = Cheight + "px";
}
if(Cheight>551)
{
alert("Height should be less than 550px")
}
if(Cwidth<1101)
{
m.style.width= Cwidth + "px";
}
if(Cwidth>1101)
{
alert("Width should be less than 1100px")
}
}
//BRUSH TYPE
document.getElementById('cir').addEventListener("click", function() {
radius = "100%";
});
document.getElementById('boxx').addEventListener("click", function() {
radius = "0%";
});
//EraseALL
document.getElementById('eraseAll').addEventListener("click", function() {
elmnt = document.getElementById("scren");
while (elmnt.firstChild) {
elmnt.removeChild(elmnt.firstChild);
}
});