-
Notifications
You must be signed in to change notification settings - Fork 0
/
FunnyDrawer.html
117 lines (85 loc) · 2 KB
/
FunnyDrawer.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
<DOCTYPE html>
<html lang="pt_BR">
<head>
<meta charset="utf-8"/>
</head>
<body>
<div id="toolbar">
<div id="title">
<h1>Funny</h1>
<h2>Drawer</h2>
</div>
<div id="tools">
<button type="button" id="pencil"> PENCIL </button>
<button type="button" id="square" disabled> SQUARE </button>
<button type="button" id="circle" disabled> CIRCLE </button>
<select id="colors" size="5">
<option value="#FFFFFF" style="background-color:#FFF;">#FFFFFF</option>
<option value="#000000" style="background-color:#000; color:#FFF">#000000</option>
<option value="#FF0000" style="background-color:#F00;">#FF0000</option>
<option value="#00FF00" style="background-color:#0F0;">#00FF00</option>
<option value="#0000FF" style="background-color:#00F;">#0000FF</option>
</select>
<p id="cursorPosition"></p>
</div>
</div>
<canvas id="canvas"/>
</body>
<style>
body{
border:0;
margin:0;
padding:0;
font-family: monospace;
}
#title{
margin: 1em;
}
button,input,select {
font-family: monospace;
margin: 1em;
}
#toolbar{
width: 10%;
height: 100%;
background-color: #AAA;
float:left;
}
#canvas{
width: 90%;
height: 100%;
background-color: #FFF;
float:left;
}
}
</style>
<script type="text/javascript">
var canvas = document.getElementById('canvas');
var c2d = canvas.getContext("2d");
var colors = document.getElementById('colors');
var currentColor;
colors.onchange = function(e){
currentColor = colors.value;
c2d.fillStyle=currentColor;
}
resizeCanvas();
window.addEventListener('resize',resizeCanvas,false);
function resizeCanvas() {
canvas.width = window.innerWidth*0.9;
canvas.height = window.innerHeight;
}
var shouldDraw = false;
canvas.onmousedown = function(e){
shouldDraw = true;
};
canvas.onmouseup = function(e){
shouldDraw = false;
}
canvas.onmousemove = function(e){
if(!shouldDraw){return;}
var x = e.offsetX;
var y = e.offsetY;
c2d.fillRect(x,y,5,5);
}
</script>
</html>