var PDFDocument = require('pdfkit');
var fs = require('fs');
var factor = 300;

var doc = new PDFDocument({layout: 'landscape', size: 'A0'});

doc.pipe(fs.createWriteStream('output.pdf'));
// background
doc.polygon([0,0], [4000, 0], [4000,2500], [0, 2500]).fill("#000");
// doc.polygon([100, 200], [600, 200], [600,1600], [100, 1600]).fill("#fff");

for (var i = 0; i < 80; i++) {
   var width = doc._pageBuffer[0].width;
   var height = doc._pageBuffer[0].height;

   var x = Math.random()*width;
   var y = Math.random()*height;

   var figure_prob = Math.random();
   if (figure_prob < 1/3.0) {
      // rectangle
      var a = [x-factor*Math.random(), y-factor*Math.random()];
      var b = [x+factor*Math.random(), y-factor*Math.random()];
      var c = [x+factor*Math.random(), y+factor*Math.random()];
      var d = [x-factor*Math.random(), y+factor*Math.random()];
      doc.polygon(a, b, c, d).fill("#fff");
      console.log("REC", a, b, c, d);
   } else if (figure_prob < 2/3.0) {
      var radius = factor*Math.random()+factor/10;
      doc.circle(x, y, radius).fill("#fff");
      console.log("CIRCLE", x, y, radius);
   } else {
      // triangle
      var a = [x-factor*Math.random(), y-factor*Math.random()];
      var b = [x+factor*Math.random(), y-factor*Math.random()];
      var c = [x+factor*Math.random(), y+factor*Math.random()];
      doc.polygon(a, b, c).fill("#fff");
      console.log("TRIANGLE", a, b, c);
   }
}




doc.end();
