-
Notifications
You must be signed in to change notification settings - Fork 0
/
designs.js
executable file
·70 lines (46 loc) · 1.39 KB
/
designs.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
/// This function makes the grid depending on grid height and grid width, submitted by the user.
function makeGrid() {
let gridstart = $("#pixelCanvas");
event.preventDefault();
gridstart.empty();
const inputHeight=$("#inputHeight").val();
const inputWeight=$("#inputWeight").val();
for (let i=1;i<=inputHeight;i++){
gridstart.append("<tr class='row'></tr>" );
}
for (let j=1;j<=inputWeight;j++){
$(".row").append("<td class='pixel'> </td>");
}
// dragging feature
let mouseDown = false;
$('td').on('mousemove', function() {
if (mouseDown) {
let color = $('#colorPicker').val();
$(this).css('background-Color', color);
}
});
$('td').on('mousedown', function() {
mouseDown = true;
});
$('td').on('mouseup', function() {
mouseDown = false;
});
//function to color the cell
$(".pixel").click(function() {
let color=$('#colorPicker').val();
$(this).css('background-color', color);
//Erasing the cell
if (event.shiftKey) {
$(this).css('background-color', '');
}
});
}
//Submit button
const submitButton=$("#sizeSelector").find("input[type='submit']");
submitButton.click(makeGrid);
//Reset button
const resetButton=$("#sizeSelector").find("input[type='reset']");
resetButton.click(function(){
$("#pixelCanvas").empty();
$('#colorPicker').val('#ff0000');
});