Simple DynImage structure and command-line API
authorAlyssa Rosenzweig <bobbybee@users.noreply.github.com>
Mon, 11 May 2015 16:38:24 +0000 (12:38 -0400)
committerAlyssa Rosenzweig <bobbybee@users.noreply.github.com>
Mon, 11 May 2015 16:38:24 +0000 (12:38 -0400)
DynImage.js [new file with mode: 0644]
main.js [new file with mode: 0644]

diff --git a/DynImage.js b/DynImage.js
new file mode 100644 (file)
index 0000000..0227dfa
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * DynImage.js
+ * node.js module to perform the bulk of the calculations used in Dynartic
+ * main.js is a light frontend to this data structure
+ */
+
+function DynImage(width, height, buffer) {
+       this.width = width;
+       this.height = height;
+       this.buffer = buffer;
+
+       // prefill with black as opposed to nonsense from memory
+       this.fillColor(0, 0, 0, 0);
+}
+
+// blindly fills the entirety of the buffer with a given color
+// used for initialization, etc.
+DynImage.prototype.fillColor = function(r, g, b, a) {
+       for(var i = 0; i < (this.width * this.height * 4); i += 4) {
+               this.buffer[i + 0] = r;
+               this.buffer[i + 1] = g;
+               this.buffer[i + 2] = b;
+               this.buffer[i + 3] = a;
+       }
+}
+
+module.exports = DynImage;
diff --git a/main.js b/main.js
new file mode 100644 (file)
index 0000000..048e49f
--- /dev/null
+++ b/main.js
@@ -0,0 +1,26 @@
+/*
+ * Dynartic main.js
+ * Performs the bulk of the operation for Dynartic
+ * Dynartic is a tool for automatically generating beautiful yet abstract art
+ * Think of it as Lorem Ipsum for images
+ */
+
+var fs = require("fs");
+var Png = require("png").Png;
+var DynImage = require("./DynImage");
+
+// fetch configuration values
+// TODO: better way of doing this, maybe
+var width = process.argv[2]*1;
+var height = process.argv[3]*1;
+
+// buffer size is: width * height * 4 (RGBA is 4 bytes)
+var buffer = new Buffer(width * height * 4);
+
+// bare calculations are offset to DynImage
+var dynimage = new DynImage(width, height, buffer);
+
+var png = new Png(buffer, width, height, 'rgba');
+png.encode(function(image) {
+                       fs.writeFile("output.png", image);
+               });
This page took 0.024944 seconds and 4 git commands to generate.