mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-07-05 01:10:27 -04:00
Add simple BooleanOperations Node example, illustrating how to serve results through a HTTP server.
This commit is contained in:
parent
098f3e84cc
commit
ca790f9339
1 changed files with 33 additions and 0 deletions
33
examples/Node.js/BooleanOperations.js
Normal file
33
examples/Node.js/BooleanOperations.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
var http = require('http');
|
||||
var paper = require('paper');
|
||||
|
||||
http.createServer(function(request, response) {
|
||||
var canvas = new paper.Canvas(800, 800);
|
||||
paper.setup(canvas);
|
||||
with(paper) {
|
||||
var style = {
|
||||
fillColor: new Color(1, 1, 0, 0.5),
|
||||
strokeColor: new Color(0, 0, 0),
|
||||
strokeWidth: 1.5
|
||||
};
|
||||
|
||||
var first = new Path.Rectangle([50, 50], [150, 150]);
|
||||
first.style = style;
|
||||
var second = first.clone().translate(50, 50);
|
||||
second.style = style;
|
||||
|
||||
var intersection = first.subtract(second);
|
||||
intersection.style = style;
|
||||
intersection.translate(250, 0);
|
||||
view.draw();
|
||||
}
|
||||
var stream = canvas.createPNGStream();
|
||||
stream.on('data', function(chunk) {
|
||||
response.write(chunk);
|
||||
});
|
||||
stream.on('end', function() {
|
||||
response.end();
|
||||
});
|
||||
}).listen(3000);
|
||||
|
||||
console.log('Server running at http://127.0.0.1:3000/');
|
Loading…
Add table
Add a link
Reference in a new issue