This repository has been archived by the owner on May 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
94 lines (84 loc) · 2.74 KB
/
index.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
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
// Button Choices
// Box-Object
function drawObject() {
var getObjX = document.getElementById('inputObjX').value;
var getObjY = document.getElementById('inputObjY').value;
var getObjH = document.getElementById('inputObjH').value;
var getObjW = document.getElementById('inputObjW').value;
ctx.strokeRect(getObjX, getObjY, getObjH, getObjW);
}
// Circle-Object
function drawCircleObject() {
var getCObjX = document.getElementById('inputCObjX').value;
var getCObjY = document.getElementById('inputCObjY').value;
var getCObjR = document.getElementById('inputCObjR').value;
var getCObjSA = document.getElementById('inputCObjSA').value;
var getCObjEA = document.getElementById('inputCObjEA').value;
var getCObjCC = document.getElementById('inputCObjCC').value;
if (getCObjCC == true) {
ctx.beginPath();
ctx.arc(getCObjX, getCObjY, getCObjR, getCObjSA, getCObjEA, getCObjCC);
ctx.stroke();
}
else {
ctx.beginPath();
ctx.arc(getCObjX, getCObjY, getCObjR, getCObjSA, getCObjEA);
ctx.stroke();
}
}
function drawLineObject() {
var getLObjX = document.getElementById('inputLObjX').value;
var getLObjY = document.getElementById('inputLObjY').value;
var getLObjM1X = document.getElementById('inputLObjM1X').value;
var getLObjM1Y = document.getElementById('inputLObjM1Y').value;
var getLObjM2X = document.getElementById('inputLObjM2X').value;
var getLObjM2Y = document.getElementById('inputLObjM2Y').value;
var checkLObjM = [
getLObjM1X,
getLObjM1Y,
getLObjM2X,
getLObjM2Y
];
if (checkLObjM !== null) {
ctx.lineTo(getLObjX, getLObjY);
ctx.moveTo(getLObjM1X, getLObjM1Y);
ctx.moveTo(getLObjM2X, getLObjM2Y);
ctx.stroke();
}
else {
ctx.lineTo(getLObjX, getLObjY);
ctx.stroke();
}
}
// Canvas Reset
function clearCanvas() {
var print;
if (confirm('Are you sure you want to clear your canvas?')) {
ctx.clearRect(0, 0, canvas.width, canvas.height);
print = 'Canvas cleared by user.';
}
else {
print = 'Canvas clear canceled by user.';
}
document.getElementById('functionOutput').innerHTML = print;
}
// Canvas Key Input
document.addEventListener("keydown", keyStrokeListener);
function keyStrokeListener(e) {
if (e.keyCode === 67) {
clearCanvas();
}
if (e.keyCode === 68) {
if (drawObject !== undefined) {
drawObject();
}
if (drawCircleObject !== undefined) {
drawCircleObject();
}
if (drawLineObject !== undefined) {
drawLineObject();
}
}
}