with bg colors, nose shapes, eye sizes, and more

This commit is contained in:
Jeffrey Sun 2016-12-15 17:14:03 -08:00
parent bc5f82e960
commit 928d123efd
2 changed files with 30 additions and 14 deletions

View file

@ -15,18 +15,18 @@ var Fox = function (IMG_WIDTH, IMG_HEIGHT) {
var headHeight = IMG_HEIGHT / 2;
var kappa = chance.floating({min: 0.2, max: 0.45})
var hue = chance.integer({min: 5, max: 55});
var hue = chance.integer({min: 5, max: 50});
var saturation = chance.integer({min: 70, max: 90});
var lightness = chance.integer({min: 40, max: 60});
var headColor = hsl(hue, saturation, lightness);
var ears = (function () {
var offsetX = chance.floating({min: 0.1 * headWidth, max: 0.4 * headWidth});
var angle = chance.floating({min: 0, max: 0.2 * Math.PI});
var offsetX = chance.floating({min: 0.17 * headWidth, max: 0.2 * headWidth});
var angle = chance.floating({min: 0.05 * Math.PI, max: 0.2 * Math.PI});
// TODO: size
return {
color: headColor,
kappa: kappa,
kappa: 0.9 * kappa,
left: {
x: origin.x + (headWidth/2) - offsetX,
y: origin.y + (0.15 * headHeight),
@ -49,9 +49,11 @@ var Fox = function (IMG_WIDTH, IMG_HEIGHT) {
var offsetY = chance.floating({min: -0.05 * headHeight, max: 0.05 * headHeight});
var offsetX = chance.floating({min: 0.13 * headWidth, max: 0.25 * headWidth});
var eyeHeight = chance.floating({min: 0.08 * headHeight, max: 0.13 * headHeight});
return {
height: 0.1 * headHeight,
width: 0.05 * headWidth,
height: eyeHeight,
width: eyeHeight/2,
left: {
x: origin.x + (headWidth/2) - offsetX,
y: origin.y + (headHeight/2) + offsetY
@ -67,8 +69,8 @@ var Fox = function (IMG_WIDTH, IMG_HEIGHT) {
return {
x: origin.x + (headWidth/2),
y: (eyes.left.y + 0.3 * (origin.y + headHeight - eyes.left.y)),
width: 0.05 * headWidth,
height: 0.05 * headHeight
width: 0.06 * headWidth,
height: 0.05 * headWidth
}
}(eyes));
@ -77,9 +79,9 @@ var Fox = function (IMG_WIDTH, IMG_HEIGHT) {
height: IMG_HEIGHT,
width: IMG_WIDTH,
color: hsl(
chance.integer({min:120, max:320}),
chance.integer({min:50, max:60}),
chance.integer({min:30, max:50})
chance.integer({min:0, max:360}),
chance.integer({min:0, max:100}),
chance.integer({min:10, max:100})
)
},
head: {
@ -88,7 +90,9 @@ var Fox = function (IMG_WIDTH, IMG_HEIGHT) {
height: headHeight,
color: headColor,
kappa: kappa,
maskColor: hsl(hue, saturation, 95)
maskColor: hsl(hue, saturation, 95),
maskWidth: chance.integer({min: 0.5 * IMG_WIDTH, max: IMG_WIDTH}),
maskHeight: chance.integer({min: 0.85 * IMG_HEIGHT, max: 1 * IMG_HEIGHT})
},
ears: ears,
eyes: eyes,

View file

@ -39,6 +39,8 @@ var renderFox = function (canvas, opts) {
var height = opts.canvas.height;
var ctx = canvas.getContext('2d');
ctx.fillStyle = opts.canvas.color;
ctx.fillRect(0, 0, width, height);
// draw ears
renderEars(ctx, opts.ears);
// draw head
@ -60,7 +62,7 @@ function renderHead(ctx, opts) {
drawEllipseByCenter(ctx, 0, 0, opts.width, opts.height, opts.color, null, opts.kappa);
ctx.restore();
ctx.clip();
drawEllipseByCenter(ctx, ctx.canvas.width / 2, ctx.canvas.height, ctx.canvas.width, 0.9 * ctx.canvas.height, '#fff', '#fff', 0.5);
drawEllipseByCenter(ctx, ctx.canvas.width / 2, ctx.canvas.height, opts.maskWidth, opts.maskHeight, '#fff', '#fff', 0.5);
}
function renderEars(ctx, opts) {
@ -87,7 +89,17 @@ function renderEyes(ctx, opts) {
}
function renderNose(ctx, opts) {
drawEllipseByCenter(ctx, opts.x, opts.y, opts.width, opts.height, "black", null, 0.5);
ctx.strokeStyle = "black";
ctx.beginPath();
ctx.moveTo(opts.x - opts.width/2, opts.y - opts.height/2);
ctx.bezierCurveTo(opts.x - opts.width/2, opts.y - opts.height/2, opts.x, opts.y - opts.height, opts.x + opts.width/2, opts.y - opts.height/2);
ctx.bezierCurveTo(opts.x + opts.width/2, opts.y - opts.height/2, opts.x + opts.width/2, opts.y + opts.height/2, opts.x, opts.y + opts.height/2);
ctx.bezierCurveTo(opts.x, opts.y + opts.height/2, opts.x - opts.width/2, opts.y + opts.height/2, opts.x - opts.width/2, opts.y - opts.height/2);
// drawEllipseByCenter(ctx, opts.x, opts.y, opts.width, opts.height, "black", null, 0.5);
ctx.fill();
//ctx.closePath(); // not used correctly, see comments (use to close off open path)
ctx.stroke();
}
function drawEllipseByCenter(ctx, cx, cy, w, h, color, fillColor, kappa) {