mirror of
https://git.sleeping.town/mirrors/foxy-moxy
synced 2024-11-22 03:57:43 +00:00
Merge pull request #2 from Patreon/luke---actually-make-the-server-practical
Make the server actually do something useful.
This commit is contained in:
commit
4214bcb788
1 changed files with 26 additions and 19 deletions
45
server.js
45
server.js
|
@ -118,6 +118,29 @@ var circle = function(c){
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function writeFoxesToDisk (width, height, n=10) {
|
||||||
|
var fileNames = [];
|
||||||
|
for (var i = 0; i < n; i++) {
|
||||||
|
var width = 200;
|
||||||
|
var height = 200;
|
||||||
|
var Image = Canvas.Image;
|
||||||
|
var canvas = new Canvas(width, height);
|
||||||
|
var ctx = canvas.getContext('2d');
|
||||||
|
var fox = Fox(width, height);
|
||||||
|
renderFox(canvas, fox);
|
||||||
|
var img = new Buffer(canvas.toDataURL(), 'base64');
|
||||||
|
var fileName = "fox" + Math.floor(Math.random() * 10000) + ".png";
|
||||||
|
var filePath = __dirname + '/images/' + fileName;
|
||||||
|
|
||||||
|
fs.writeFile(filePath, canvas.toBuffer(), function(err) {
|
||||||
|
if (err) console.log('error', err);
|
||||||
|
});
|
||||||
|
|
||||||
|
fileNames.push(fileName);
|
||||||
|
}
|
||||||
|
return fileNames;
|
||||||
|
};
|
||||||
|
|
||||||
var Canvas = require('canvas');
|
var Canvas = require('canvas');
|
||||||
var express = require('express');
|
var express = require('express');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
@ -127,25 +150,9 @@ var app = express();
|
||||||
app.use(express.static(__dirname + '/images'));
|
app.use(express.static(__dirname + '/images'));
|
||||||
|
|
||||||
app.get('/', function(req, res) {
|
app.get('/', function(req, res) {
|
||||||
|
var fileNames = writeFoxesToDisk(300, 300, 30);
|
||||||
var width = 200;
|
var images = fileNames.map(fileName => '<img src="/' + fileName + '"/>');
|
||||||
var height = 200;
|
res.send(images.join(''));
|
||||||
var Canvas = require('canvas');
|
|
||||||
var Image = Canvas.Image;
|
|
||||||
var canvas = new Canvas(width, height);
|
|
||||||
var ctx = canvas.getContext('2d');
|
|
||||||
var fox = Fox(width, height);
|
|
||||||
console.log("fox", fox);
|
|
||||||
renderFox(canvas, fox);
|
|
||||||
var img = new Buffer(canvas.toDataURL(), 'base64');
|
|
||||||
var fileName = "fox" + Math.floor(Math.random() * 10000) + ".png";
|
|
||||||
|
|
||||||
fs.writeFile(__dirname + '/images/' + fileName, canvas.toBuffer(), function(err) {
|
|
||||||
console.log('error', err);
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(fileName);
|
|
||||||
res.redirect(301, fileName);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue