foxy-moxy/js/fox.js

70 lines
1.7 KiB
JavaScript
Raw Normal View History

2016-12-15 20:06:02 +00:00
// TODO: use query params for these
2016-12-15 22:21:30 +00:00
var Chance = require('chance');
var chance = new Chance();
2016-12-15 20:06:02 +00:00
2016-12-15 21:23:38 +00:00
var Fox = function (IMG_WIDTH, IMG_HEIGHT) {
2016-12-15 20:06:02 +00:00
// head top left corner
2016-12-15 21:23:38 +00:00
var origin = {x: IMG_WIDTH / 4, y: IMG_HEIGHT / 4};
// TODO: head headWidth and height
var headWidth = IMG_WIDTH / 2;
var headHeight = IMG_HEIGHT / 2;
2016-12-15 20:06:02 +00:00
var ears = (function () {
2016-12-15 22:23:00 +00:00
var offsetX = chance.floating({min: 0.1 * headWidth, max: 0.4 * headWidth});
2016-12-15 22:21:30 +00:00
var angle = chance.floating({min: 0, max: Math.PI / 6});
2016-12-15 22:42:11 +00:00
// TODO: size
2016-12-15 20:06:02 +00:00
return {
left: {
2016-12-15 21:23:38 +00:00
x: origin.x + (headWidth/2) - offsetX,
2016-12-15 22:21:30 +00:00
y: origin.y + (0.15 * headHeight),
angle: angle,
width: 0.4 * headWidth,
2016-12-15 22:23:00 +00:00
height: 0.6 * headHeight
2016-12-15 20:06:02 +00:00
},
right: {
2016-12-15 21:23:38 +00:00
x: origin.x + (headWidth/2) + offsetX,
2016-12-15 22:21:30 +00:00
y: origin.y + (0.15 * headHeight),
angle: -angle,
width: 0.4 * headWidth,
2016-12-15 22:23:00 +00:00
height: 0.6 * headHeight
2016-12-15 20:06:02 +00:00
}
};
}());
var eyes = (function () {
2016-12-15 22:42:11 +00:00
// TODO: color
var offsetY = chance.floating({min: -0.05 * headHeight, max: 0.05 * headHeight});
var offsetX = chance.floating({min: 0.2 * headWidth, max: 0.25 * headWidth});
return {
left: {
x: origin.x + (headWidth/2) - offsetX,
y: origin.y + (headHeight/2) + offsetY
},
right: {
x: origin.x + (headWidth/2) + offsetX,
y: origin.y + (headHeight/2) + offsetY
}
}
}());
2016-12-15 20:06:02 +00:00
return {
2016-12-15 21:23:38 +00:00
canvas: {
height: IMG_HEIGHT,
width: IMG_WIDTH
},
head: {
origin: origin,
2016-12-15 21:39:02 +00:00
width: headWidth,
height: headHeight
},
2016-12-15 20:06:02 +00:00
ears: ears,
eyes: eyes,
2016-12-15 21:23:38 +00:00
// nose: nose,
// mouth: mouth
2016-12-15 20:06:02 +00:00
};
2016-12-15 21:23:38 +00:00
};
module.exports = Fox;