From a3d5414ac34f59ecf62892386452a6f8ab728da2 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Mon, 18 May 2015 12:33:58 -0400 Subject: [PATCH] More pretty things --- DynImage.js | 13 +++++++++++++ main.js | 52 ++++++++++++++++++++++++++++------------------------ 2 files changed, 41 insertions(+), 24 deletions(-) diff --git a/DynImage.js b/DynImage.js index d17e22d..5a3b957 100644 --- a/DynImage.js +++ b/DynImage.js @@ -125,6 +125,19 @@ DynImage.prototype.pointRing = function(sx, sy, height, layerIntensity) { } } +DynImage.prototype.punchImage = function(sx, sy, sw, sh, force, spread) { + for(var i = -(sw / 2); i < (sw/2); ++i) { + for(var j = (-(sh/2)); j < (sh/2); ++j) { + var x = sx + i, + y = sy + j; + + var intensity = Math.sqrt( (i*i) + (j*j) ); + intensity = Math.pow(2, -intensity / spread); + this.punchPoint(x, y, intensity * force); + } + } +} + // opposite of point pulling; works on a single point only DynImage.prototype.punchPoint = function(x, y, force) { diff --git a/main.js b/main.js index bcfb67e..39d7c7a 100644 --- a/main.js +++ b/main.js @@ -14,27 +14,31 @@ var DynImage = require("./DynImage"); 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); - -// fill the image with a random, opaque color to start with -dynimage.fillColor( - Math.floor(Math.random() * 255), - Math.floor(Math.random() * 255), - Math.floor(Math.random() * 255), - 0 - ); - -// make a beautiful point ring -//dynimage.pointRing(width / 2, height / 2, width, 2); - -// punch a point -dynimage.punchPoint(50, 50, 100); - -var png = new Png(buffer, width, height, 'rgba'); -png.encode(function(image) { - fs.writeFile("output.png", image); - }); +function pretty(name, ringConstant) { + // 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); + + // fill the image with a random, opaque color to start with + dynimage.fillColor( + Math.floor(Math.random() * 255), + Math.floor(Math.random() * 255), + Math.floor(Math.random() * 255), + 0 + ); + + // make a beautiful point ring + + dynimage.punchImage(width / 2, height / 2, width, height, (Math.floor(Math.random() * 96)), width / 3); + + dynimage.pointRing(width / 2, height / 2, width, ringConstant) + + var png = new Png(buffer, width, height, 'rgba'); + png.encode(function(image) { + fs.writeFile(name+".png", image); + }); +} + +pretty("output", Math.E); -- 2.20.1