Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added color support #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ <h1>ArUco markers generator!</h1>
<label for="frm-size">Marker size, mm:</label>
<input id="frm-size" name="size" type="number" min="10" max="5000" value="100">
</div>
<div class="field">
<label for="frm-color">Color:</label>
<input id="frm-color" name="color" type="color" value="#000000">
</div>
</form>

<div class="marker-id"></div>
Expand Down
16 changes: 9 additions & 7 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function generateMarkerSvg(width, height, bits) {
function generateMarkerSvg(width, height, bits, color) {
var svg = $('<svg/>').attr({
viewBox: '0 0 ' + (width + 2) + ' ' + (height + 2),
xmlns: 'http://www.w3.org/2000/svg',
Expand All @@ -11,19 +11,19 @@ function generateMarkerSvg(width, height, bits) {
y: 0,
width: width + 2,
height: height + 2,
fill: 'black'
fill: color
}).appendTo(svg);

// "Pixels"
for (var i = 0; i < height; i++) {
for (var j = 0; j < width; j++) {
var color = bits[i * height + j] ? 'white' : 'black';
var square_color = bits[i * height + j] ? 'white' : color;
var pixel = $('<rect/>').attr({
width: 1,
height: 1,
x: j + 1,
y: i + 1,
fill: color
fill: square_color
});
pixel.appendTo(svg);
}
Expand All @@ -34,7 +34,7 @@ function generateMarkerSvg(width, height, bits) {

var dict;

function generateArucoMarker(width, height, dictName, id) {
function generateArucoMarker(width, height, dictName, id, size, color) {
console.log('Generate ArUco marker ' + dictName + ' ' + id);

var bytes = dict[dictName][id];
Expand All @@ -49,7 +49,7 @@ function generateArucoMarker(width, height, dictName, id) {
}
}

return generateMarkerSvg(width, height, bits);
return generateMarkerSvg(width, height, bits, color);
}

var loadDict = $.getJSON('dict.json', function(data) {
Expand All @@ -60,18 +60,20 @@ $(function() {
var dictSelect = $('.setup select[name=dict]');
var markerIdInput = $('.setup input[name=id]');
var sizeInput = $('.setup input[name=size]');
var colorInput = $('.setup input[name=color]');

function updateMarker() {
var markerId = Number(markerIdInput.val());
var size = Number(sizeInput.val());
var dictName = dictSelect.val();
var color = String(colorInput.val());
var width = Number(dictSelect.find('option:selected').attr('data-width'));
var height = Number(dictSelect.find('option:selected').attr('data-height'));

// Wait until dict data is loaded
loadDict.then(function() {
// Generate marker
var svg = generateArucoMarker(width, height, dictName, markerId, size);
var svg = generateArucoMarker(width, height, dictName, markerId, size, color);
svg.attr({
width: size + 'mm',
height: size + 'mm'
Expand Down