From d75f446e848baa309e1b485be3504a609315aeea Mon Sep 17 00:00:00 2001 From: Jeffrey Sun Date: Thu, 15 Dec 2016 13:23:38 -0800 Subject: [PATCH] a fox is a red circle --- js/fox.js | 40 +++++++++++++------------ server.js | 89 +++++++++++-------------------------------------------- 2 files changed, 39 insertions(+), 90 deletions(-) diff --git a/js/fox.js b/js/fox.js index 25e7c3d..40359a3 100644 --- a/js/fox.js +++ b/js/fox.js @@ -1,31 +1,29 @@ // TODO: use query params for these var gen = require('random-seed'); -var IMG_WIDTH = 64; -var IMG_HEIGHT = 64; // move to helper function var genBetween = function (min, max) { return min + (max - min) * gen(); } -var randomFox = (function () { +var Fox = function (IMG_WIDTH, IMG_HEIGHT) { // head top left corner - var origin = Point(IMG_WIDTH / 4, IMG_HEIGHT / 4); - // head width and height - var width = IMG_WIDTH / 2; - var height = IMG_HEIGHT / 2; + 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; var ears = (function () { - var offsetX = genBetween(0, width/2); + var offsetX = genBetween(0, headWidth/2); // TODO: size, angle? return { left: { - x: origin.x + (width/2) - offsetX, + x: origin.x + (headWidth/2) - offsetX, y: origin.y }, right: { - x: origin.x + (width/2) + offsetX, + x: origin.x + (headWidth/2) + offsetX, y: origin.y } }; @@ -33,20 +31,24 @@ var randomFox = (function () { var eyes = (function () { // TODO: y, offsetX, color - return { - - }; + return null; }()); return { - shape: { + canvas: { + height: IMG_HEIGHT, + width: IMG_WIDTH + }, + head: { origin: origin, - width: width, - height: height + headWidth: headWidth, + headHeight:headHeight }, ears: ears, eyes: eyes, - nose: nose, - mouth: mouth + // nose: nose, + // mouth: mouth }; -}()); +}; + +module.exports = Fox; diff --git a/server.js b/server.js index 005d3ca..356aeca 100644 --- a/server.js +++ b/server.js @@ -1,3 +1,4 @@ +var Fox = require('./js/fox.js'); var davis = require('./js/davis.js'); var geo = require('./js/geo.js'); @@ -10,7 +11,7 @@ var ngon = function (c) { var r=c.r || 500; if (n%2==0){ var rotation=360/(n*2)*davis.random(n*2); - } + } else { var rotation=90+(180*davis.random(2)); }; @@ -33,70 +34,19 @@ var ngon = function (c) { return true; }; -var textIcon = function (canvas, width, height) { +var renderFox = function (canvas, opts) { + var width = opts.canvas.width; + var height = opts.canvas.height; var ctx = canvas.getContext('2d'); ctx.beginPath(); - var color=davis.randomColor(); - var gradient=ctx.createLinearGradient(0,0,0,height); - gradient.addColorStop(0,color); - gradient.addColorStop(1,davis.pick([color,davis.randomColor(),"#000","#fff",davis.alpha(color,0)])); - ctx.fillStyle=gradient; - ctx.fillRect(0,0,width,height); - - - for (var j=0;j