mirror of
https://git.sleeping.town/mirrors/foxy-moxy
synced 2024-11-21 19:47:43 +00:00
with bg colors, nose shapes, eye sizes, and more
This commit is contained in:
parent
bc5f82e960
commit
928d123efd
2 changed files with 30 additions and 14 deletions
28
js/fox.js
28
js/fox.js
|
@ -15,18 +15,18 @@ var Fox = function (IMG_WIDTH, IMG_HEIGHT) {
|
||||||
var headHeight = IMG_HEIGHT / 2;
|
var headHeight = IMG_HEIGHT / 2;
|
||||||
var kappa = chance.floating({min: 0.2, max: 0.45})
|
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 saturation = chance.integer({min: 70, max: 90});
|
||||||
var lightness = chance.integer({min: 40, max: 60});
|
var lightness = chance.integer({min: 40, max: 60});
|
||||||
var headColor = hsl(hue, saturation, lightness);
|
var headColor = hsl(hue, saturation, lightness);
|
||||||
|
|
||||||
var ears = (function () {
|
var ears = (function () {
|
||||||
var offsetX = chance.floating({min: 0.1 * headWidth, max: 0.4 * headWidth});
|
var offsetX = chance.floating({min: 0.17 * headWidth, max: 0.2 * headWidth});
|
||||||
var angle = chance.floating({min: 0, max: 0.2 * Math.PI});
|
var angle = chance.floating({min: 0.05 * Math.PI, max: 0.2 * Math.PI});
|
||||||
// TODO: size
|
// TODO: size
|
||||||
return {
|
return {
|
||||||
color: headColor,
|
color: headColor,
|
||||||
kappa: kappa,
|
kappa: 0.9 * kappa,
|
||||||
left: {
|
left: {
|
||||||
x: origin.x + (headWidth/2) - offsetX,
|
x: origin.x + (headWidth/2) - offsetX,
|
||||||
y: origin.y + (0.15 * headHeight),
|
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 offsetY = chance.floating({min: -0.05 * headHeight, max: 0.05 * headHeight});
|
||||||
var offsetX = chance.floating({min: 0.13 * headWidth, max: 0.25 * headWidth});
|
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 {
|
return {
|
||||||
height: 0.1 * headHeight,
|
height: eyeHeight,
|
||||||
width: 0.05 * headWidth,
|
width: eyeHeight/2,
|
||||||
left: {
|
left: {
|
||||||
x: origin.x + (headWidth/2) - offsetX,
|
x: origin.x + (headWidth/2) - offsetX,
|
||||||
y: origin.y + (headHeight/2) + offsetY
|
y: origin.y + (headHeight/2) + offsetY
|
||||||
|
@ -67,8 +69,8 @@ var Fox = function (IMG_WIDTH, IMG_HEIGHT) {
|
||||||
return {
|
return {
|
||||||
x: origin.x + (headWidth/2),
|
x: origin.x + (headWidth/2),
|
||||||
y: (eyes.left.y + 0.3 * (origin.y + headHeight - eyes.left.y)),
|
y: (eyes.left.y + 0.3 * (origin.y + headHeight - eyes.left.y)),
|
||||||
width: 0.05 * headWidth,
|
width: 0.06 * headWidth,
|
||||||
height: 0.05 * headHeight
|
height: 0.05 * headWidth
|
||||||
}
|
}
|
||||||
}(eyes));
|
}(eyes));
|
||||||
|
|
||||||
|
@ -77,9 +79,9 @@ var Fox = function (IMG_WIDTH, IMG_HEIGHT) {
|
||||||
height: IMG_HEIGHT,
|
height: IMG_HEIGHT,
|
||||||
width: IMG_WIDTH,
|
width: IMG_WIDTH,
|
||||||
color: hsl(
|
color: hsl(
|
||||||
chance.integer({min:120, max:320}),
|
chance.integer({min:0, max:360}),
|
||||||
chance.integer({min:50, max:60}),
|
chance.integer({min:0, max:100}),
|
||||||
chance.integer({min:30, max:50})
|
chance.integer({min:10, max:100})
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
head: {
|
head: {
|
||||||
|
@ -88,7 +90,9 @@ var Fox = function (IMG_WIDTH, IMG_HEIGHT) {
|
||||||
height: headHeight,
|
height: headHeight,
|
||||||
color: headColor,
|
color: headColor,
|
||||||
kappa: kappa,
|
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,
|
ears: ears,
|
||||||
eyes: eyes,
|
eyes: eyes,
|
||||||
|
|
16
server.js
16
server.js
|
@ -39,6 +39,8 @@ var renderFox = function (canvas, opts) {
|
||||||
var height = opts.canvas.height;
|
var height = opts.canvas.height;
|
||||||
var ctx = canvas.getContext('2d');
|
var ctx = canvas.getContext('2d');
|
||||||
|
|
||||||
|
ctx.fillStyle = opts.canvas.color;
|
||||||
|
ctx.fillRect(0, 0, width, height);
|
||||||
// draw ears
|
// draw ears
|
||||||
renderEars(ctx, opts.ears);
|
renderEars(ctx, opts.ears);
|
||||||
// draw head
|
// draw head
|
||||||
|
@ -60,7 +62,7 @@ function renderHead(ctx, opts) {
|
||||||
drawEllipseByCenter(ctx, 0, 0, opts.width, opts.height, opts.color, null, opts.kappa);
|
drawEllipseByCenter(ctx, 0, 0, opts.width, opts.height, opts.color, null, opts.kappa);
|
||||||
ctx.restore();
|
ctx.restore();
|
||||||
ctx.clip();
|
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) {
|
function renderEars(ctx, opts) {
|
||||||
|
@ -87,7 +89,17 @@ function renderEyes(ctx, opts) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderNose(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) {
|
function drawEllipseByCenter(ctx, cx, cy, w, h, color, fillColor, kappa) {
|
||||||
|
|
Loading…
Reference in a new issue