-
Notifications
You must be signed in to change notification settings - Fork 0
/
OMR.html
211 lines (177 loc) · 5.9 KB
/
OMR.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>OMR Generator</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
margin: 0;
padding: 0;
text-align: center;
}
.container {
margin-top: 50px;
}
.questionInput {
padding: 10px;
font-size: 16px;
border-radius: 12px;
border: 1px solid #ccc;
margin-bottom: 10px;
}
.generateBtn {
background-color: #4CAF50;
border: none;
color: white;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
transition-duration: 0.4s;
cursor: pointer;
border-radius: 12px;
}
.generateBtn:hover {
background-color: #45a049;
}
#downloadBtn {
background-color: #008CBA;
border: none;
color: white;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin-top: 20px;
transition-duration: 0.4s;
cursor: pointer;
border-radius: 12px;
}
#downloadBtn:hover {
background-color: #00688B;
}
.credit {
margin-top: 20px;
font-size: 14px;
}
.credit a {
color: #333;
text-decoration: none;
}
.credit a:hover {
text-decoration: underline;
}
h1 {
color: #333;
font-weight: bold;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}
</style>
</head>
<body>
<h1>GENERATE OMR SHEET</h1>
<div class="container">
<input type="number" id="numQuestions" class="questionInput" placeholder="Enter number of questions">
<button class="generateBtn">Generate OMR</button>
</div>
<div id="imageContainer"></div>
<button id="downloadBtn" style="display: none;">Download OMR</button>
<p class="credit">Created by: <a href="https://t.me/NEETJEECHANNEL" target="_blank">Telegram - @NEETJEECHANNEL</a></p>
<script>
// Function to generate OMR image based on the selected number of questions
function generateOMR(numQuestions) {
const imageContainer = document.getElementById("imageContainer");
imageContainer.innerHTML = ""; // Clear previous image if any
const numColumns = 4; // Constant number of columns
const numRows = Math.ceil(numQuestions / (numColumns * 5)); // Adjust rows based on questions
const canvasWidth = numColumns * 200 + 20; // Adjusted width for border
const canvasHeight = numRows * 120 + 20; // Adjusted height for border
const canvasData = createCanvas(imageContainer, canvasWidth, canvasHeight);
const canvas = canvasData.canvas;
const ctx = canvasData.ctx;
let questionCount = 0;
for (let row = 0; row < numRows; row++) {
for (let col = 0; col < numColumns; col++) {
const startX = col * 200 + 10; // Adjusted for border
const startY = row * 120 + 10; // Adjusted for border
// Draw border box
ctx.beginPath();
ctx.rect(startX, startY, 200, 120); // Adjusted height for small gap
ctx.stroke();
// Draw 5 questions
for (let i = 0; i < 5; i++) {
if (questionCount >= numQuestions) break;
const question = `Q${questionCount + 1}:`;
const questionX = startX + 10;
const questionY = startY + 30 + (i * 20);
ctx.fillText(question, questionX, questionY);
// Draw options with reduced gap
const optionStartX = startX + 50;
const optionStartY = startY + 26 + (i * 20);
const options = ['A', 'B', 'C', 'D'];
options.forEach((option, index) => {
const optionX = optionStartX + (index * 40);
const optionY = optionStartY;
// Draw circle for each option
ctx.beginPath();
ctx.arc(optionX, optionY, 8, 0, Math.PI * 2);
ctx.stroke();
// Position the option text
ctx.fillText(option, optionX - 3, optionY + 3);
});
questionCount++;
}
}
}
// Draw border around the canvas
ctx.beginPath();
ctx.rect(0, 0, canvasWidth, canvasHeight);
ctx.lineWidth = 5; // Border line width
ctx.strokeStyle = "#000"; // Border color
ctx.stroke();
// Show download button
const downloadBtn = document.getElementById("downloadBtn");
downloadBtn.style.display = "block";
// Store the generated canvas for download
downloadBtn.onclick = function() {
downloadOMR(canvas);
};
}
// Function to create canvas and return its context
function createCanvas(parent, width, height) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
parent.appendChild(canvas);
const ctx = canvas.getContext("2d");
return { canvas: canvas, ctx: ctx };
}
// Function to download the current OMR image
function downloadOMR(canvas) {
const dataURL = canvas.toDataURL();
const a = document.createElement("a");
a.href = dataURL;
a.download = "[email protected]";
a.style.display = "none";
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
// Event listener for generating OMR sheet
document.querySelector(".generateBtn").addEventListener("click", function() {
const numQuestions = parseInt(document.getElementById("numQuestions").value);
if (numQuestions > 0) {
generateOMR(numQuestions);
} else {
alert("Please enter a valid number of questions.");
}
});
</script>
</body>
</html>